From e8417a29fb2153ea035a757f36bfa300cf8b480d Mon Sep 17 00:00:00 2001
From: a1xd <68629610+a1xd@users.noreply.github.com>
Date: Thu, 30 Jul 2020 17:07:35 -0400
Subject: add tweaks for st-refactor
---
common/rawaccel.hpp | 73 ++++++++++++++++++++++++-----------------------------
1 file changed, 33 insertions(+), 40 deletions(-)
(limited to 'common/rawaccel.hpp')
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index b480e87..0aeb42d 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -7,13 +7,13 @@
#include "x64-util.hpp"
#include "external/tagged-union-single.h"
-#include "accel_linear.cpp"
-#include "accel_classic.cpp"
-#include "accel_natural.cpp"
-#include "accel_logarithmic.cpp"
-#include "accel_sigmoid.cpp"
-#include "accel_power.cpp"
-#include "accel_noaccel.cpp"
+#include "accel-linear.hpp"
+#include "accel-classic.hpp"
+#include "accel-natural.hpp"
+#include "accel-logarithmic.hpp"
+#include "accel-sigmoid.hpp"
+#include "accel-power.hpp"
+#include "accel-noaccel.hpp"
namespace rawaccel {
@@ -75,11 +75,11 @@ namespace rawaccel {
};
/// Tagged union to hold all accel implementations and allow "polymorphism" via a visitor call.
- using accel_implementation_t = tagged_union;
+ using accel_impl_t = tagged_union;
struct accel_fn_args {
- accel_args acc_args = accel_args{};
- int accel_mode = 0;
+ accel_args acc_args;
+ int accel_mode = accel_impl_t::id;
milliseconds time_min = 0.4;
vec2d weight = { 1, 1 };
vec2d cap = { 0, 0 };
@@ -100,21 +100,24 @@ namespace rawaccel {
double speed_offset = 0;
/// The acceleration implementation (i.e. curve)
- accel_implementation_t accel;
+ accel_impl_t accel;
/// The weight of acceleration applied in {x, y} dimensions.
vec2d weight = { 1, 1 };
+ /// The constant added to weighted accel values to get the acceleration scale.
+ double scale_base = 1;
+
/// The object which sets a min and max for the acceleration scale.
vec2 clamp;
- accel_function(accel_fn_args args) {
+ accel_function(accel_fn_args args) : accel_function() {
+ verify(args);
+
accel.tag = args.accel_mode;
- accel.visit([&](auto& a){ a = {args.acc_args}; });
+ accel.visit([&](auto& impl){ impl = { args.acc_args }; });
- // Verification is performed by the accel_implementation object
- // and therefore must occur after the object has been instantiated
- verify(args.acc_args);
+ if (accel.tag == accel_impl_t::id) scale_base = 0;
time_min = args.time_min;
speed_offset = args.acc_args.offset;
@@ -124,20 +127,12 @@ namespace rawaccel {
}
///
- /// Applies mouse acceleration to a given speed, via visitor function to accel_implementation_t
- ///
- /// Speed from which to determine acceleration
- /// Acceleration as a ratio magnitudes, as a double
- double apply(double speed) const {
- return accel.visit([=](auto accel_t) { return accel_t.accelerate(speed); });
- }
-
- ///
- /// Verifies acceleration arguments, via visitor function to accel_implementation_t
+ /// Verifies acceleration arguments, via visitor function to accel_impl_t
///
/// Arguments to be verified
- void verify(accel_args args) const {
- return accel.visit([=](auto accel_t) { accel_t.verify(args); });
+ void verify(accel_fn_args args) {
+ if (args.time_min <= 0) error("min time must be positive");
+ if (args.acc_args.offset < 0) error("offset must not be negative");
}
///
@@ -151,10 +146,12 @@ namespace rawaccel {
double time_clamped = clampsd(time, time_min, 100);
double speed = maxsd(mag / time_clamped - speed_offset, 0);
- double accel_val = apply(speed);
+ double accel_val = accel.visit([=](auto&& impl) {
+ return impl.accelerate(speed);
+ });
- double scale_x = weight.x * accel_val + 1;
- double scale_y = weight.y * accel_val + 1;
+ double scale_x = weight.x * accel_val + scale_base;
+ double scale_y = weight.y * accel_val + scale_base;
return {
input.x * clamp.x(scale_x),
@@ -165,11 +162,10 @@ namespace rawaccel {
accel_function() = default;
};
- struct modifier_args
- {
+ struct modifier_args {
double degrees = 0;
vec2d sens = { 1, 1 };
- accel_fn_args acc_fn_args = accel_fn_args{};
+ accel_fn_args acc_fn_args;
};
/// Struct to hold variables and methods for modifying mouse input
@@ -187,8 +183,8 @@ namespace rawaccel {
if (apply_rotate) rotate = rotator(args.degrees);
else rotate = rotator();
- apply_accel = (args.acc_fn_args.accel_mode != 0 &&
- args.acc_fn_args.accel_mode != accel_implementation_t::id);
+ apply_accel = args.acc_fn_args.acc_args.accel != 0 &&
+ args.acc_fn_args.accel_mode != accel_impl_t::id;
if (args.sens.x == 0) args.sens.x = 1;
if (args.sens.y == 0) args.sens.y = 1;
@@ -226,10 +222,7 @@ namespace rawaccel {
input = rotate(input);
}
- if (apply_accel)
- {
- input = accel_fn(input, time);
- }
+ input = accel_fn(input, time);
input.x *= sensitivity.x;
input.y *= sensitivity.y;
--
cgit v1.2.3
From b59cf98c2f326abeb6b993d8ecc5759d23096253 Mon Sep 17 00:00:00 2001
From: a1xd <68629610+a1xd@users.noreply.github.com>
Date: Thu, 30 Jul 2020 22:04:44 -0400
Subject: Make weight a member of accel_base
This exposes weight to derived accel types, which now supply a method to transform acceleration into scale.
---
common/rawaccel.hpp | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
(limited to 'common/rawaccel.hpp')
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index 0aeb42d..7be37c2 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -81,7 +81,6 @@ namespace rawaccel {
accel_args acc_args;
int accel_mode = accel_impl_t::id;
milliseconds time_min = 0.4;
- vec2d weight = { 1, 1 };
vec2d cap = { 0, 0 };
};
@@ -102,26 +101,17 @@ namespace rawaccel {
/// The acceleration implementation (i.e. curve)
accel_impl_t accel;
- /// The weight of acceleration applied in {x, y} dimensions.
- vec2d weight = { 1, 1 };
-
- /// The constant added to weighted accel values to get the acceleration scale.
- double scale_base = 1;
-
/// The object which sets a min and max for the acceleration scale.
vec2 clamp;
- accel_function(accel_fn_args args) : accel_function() {
+ accel_function(accel_fn_args args) {
verify(args);
accel.tag = args.accel_mode;
accel.visit([&](auto& impl){ impl = { args.acc_args }; });
- if (accel.tag == accel_impl_t::id) scale_base = 0;
-
time_min = args.time_min;
speed_offset = args.acc_args.offset;
- weight = args.weight;
clamp.x = accel_scale_clamp(args.cap.x);
clamp.y = accel_scale_clamp(args.cap.y);
}
@@ -146,16 +136,14 @@ namespace rawaccel {
double time_clamped = clampsd(time, time_min, 100);
double speed = maxsd(mag / time_clamped - speed_offset, 0);
- double accel_val = accel.visit([=](auto&& impl) {
- return impl.accelerate(speed);
+ vec2d scale = accel.visit([=](auto&& impl) {
+ double accel_val = impl.accelerate(speed);
+ return impl.scale(accel_val);
});
- double scale_x = weight.x * accel_val + scale_base;
- double scale_y = weight.y * accel_val + scale_base;
-
return {
- input.x * clamp.x(scale_x),
- input.y * clamp.y(scale_y)
+ input.x * clamp.x(scale.x),
+ input.y * clamp.y(scale.y)
};
}
--
cgit v1.2.3
From b3ed8fd4e4fcad0b749126dee62588260d74b106 Mon Sep 17 00:00:00 2001
From: a1xd <68629610+a1xd@users.noreply.github.com>
Date: Fri, 31 Jul 2020 01:37:41 -0400
Subject: add more tweaks for st-refactor
---
common/rawaccel.hpp | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
(limited to 'common/rawaccel.hpp')
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index 7be37c2..59a0360 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -3,7 +3,6 @@
#define _USE_MATH_DEFINES
#include
-#include "vec2.h"
#include "x64-util.hpp"
#include "external/tagged-union-single.h"
@@ -104,8 +103,9 @@ namespace rawaccel {
/// The object which sets a min and max for the acceleration scale.
vec2 clamp;
- accel_function(accel_fn_args args) {
- verify(args);
+ accel_function(const accel_fn_args& args) {
+ if (args.time_min <= 0) error("min time must be positive");
+ if (args.acc_args.offset < 0) error("offset must not be negative");
accel.tag = args.accel_mode;
accel.visit([&](auto& impl){ impl = { args.acc_args }; });
@@ -116,15 +116,6 @@ namespace rawaccel {
clamp.y = accel_scale_clamp(args.cap.y);
}
- ///
- /// Verifies acceleration arguments, via visitor function to accel_impl_t
- ///
- /// Arguments to be verified
- void verify(accel_fn_args args) {
- if (args.time_min <= 0) error("min time must be positive");
- if (args.acc_args.offset < 0) error("offset must not be negative");
- }
-
///
/// Applies weighted acceleration to given input for given time period.
///
@@ -164,19 +155,22 @@ namespace rawaccel {
accel_function accel_fn;
vec2d sensitivity = { 1, 1 };
- mouse_modifier(modifier_args args)
+ mouse_modifier(const modifier_args& args)
: accel_fn(args.acc_fn_args)
{
apply_rotate = args.degrees != 0;
+
if (apply_rotate) rotate = rotator(args.degrees);
else rotate = rotator();
- apply_accel = args.acc_fn_args.acc_args.accel != 0 &&
+ apply_accel = args.acc_fn_args.accel_mode != 0 &&
args.acc_fn_args.accel_mode != accel_impl_t::id;
- if (args.sens.x == 0) args.sens.x = 1;
- if (args.sens.y == 0) args.sens.y = 1;
- sensitivity = args.sens;
+ if (args.sens.x == 0) sensitivity.x = 1;
+ else sensitivity.x = args.sens.x;
+
+ if (args.sens.y == 0) sensitivity.y = 1;
+ else sensitivity.y = args.sens.y;
}
///
--
cgit v1.2.3