diff options
| author | a1xd <[email protected]> | 2020-07-30 17:07:35 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-07-30 17:07:35 -0400 |
| commit | e8417a29fb2153ea035a757f36bfa300cf8b480d (patch) | |
| tree | 802905bbf262196678e140463150e66d0a674b01 /common/rawaccel.hpp | |
| parent | Merge remote-tracking branch 'downstream/Inheritance' into st-refactor (diff) | |
| download | rawaccel-e8417a29fb2153ea035a757f36bfa300cf8b480d.tar.xz rawaccel-e8417a29fb2153ea035a757f36bfa300cf8b480d.zip | |
add tweaks for st-refactor
Diffstat (limited to 'common/rawaccel.hpp')
| -rw-r--r-- | common/rawaccel.hpp | 73 |
1 files changed, 33 insertions, 40 deletions
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 { }; /// <summary> Tagged union to hold all accel implementations and allow "polymorphism" via a visitor call. </summary> - using accel_implementation_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_noaccel>; + using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_noaccel>; 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<accel_noaccel>; milliseconds time_min = 0.4; vec2d weight = { 1, 1 }; vec2d cap = { 0, 0 }; @@ -100,21 +100,24 @@ namespace rawaccel { double speed_offset = 0; /// <summary> The acceleration implementation (i.e. curve) </summary> - accel_implementation_t accel; + accel_impl_t accel; /// <summary> The weight of acceleration applied in {x, y} dimensions. </summary> vec2d weight = { 1, 1 }; + /// <summary> The constant added to weighted accel values to get the acceleration scale. </summary> + double scale_base = 1; + /// <summary> The object which sets a min and max for the acceleration scale. </summary> vec2<accel_scale_clamp> 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<accel_power>) scale_base = 0; time_min = args.time_min; speed_offset = args.acc_args.offset; @@ -124,20 +127,12 @@ namespace rawaccel { } /// <summary> - /// Applies mouse acceleration to a given speed, via visitor function to accel_implementation_t - /// </summary> - /// <param name="speed">Speed from which to determine acceleration</param> - /// <returns>Acceleration as a ratio magnitudes, as a double</returns> - double apply(double speed) const { - return accel.visit([=](auto accel_t) { return accel_t.accelerate(speed); }); - } - - /// <summary> - /// Verifies acceleration arguments, via visitor function to accel_implementation_t + /// Verifies acceleration arguments, via visitor function to accel_impl_t /// </summary> /// <param name="args">Arguments to be verified</param> - 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"); } /// <summary> @@ -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; }; /// <summary> Struct to hold variables and methods for modifying mouse input </summary> @@ -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<accel_noaccel>); + apply_accel = args.acc_fn_args.acc_args.accel != 0 && + args.acc_fn_args.accel_mode != accel_impl_t::id<accel_noaccel>; 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; |