diff options
| author | a1xd <[email protected]> | 2020-08-31 19:41:21 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-08-31 19:41:21 -0400 |
| commit | 9010cc593af419dd824dba0ade6a2022aea6143f (patch) | |
| tree | 90a82ee14dbb112621657efbd2523ed35f59d154 /common/accel-base.hpp | |
| parent | clean up wrapper, minimize heap alloc (diff) | |
| download | rawaccel-9010cc593af419dd824dba0ade6a2022aea6143f.tar.xz rawaccel-9010cc593af419dd824dba0ade6a2022aea6143f.zip | |
add independent xy accel to driver
other changes:
modifier_args type name is now settings,
which is now the type passed in driver ioctl
remove most settings/args verification from driver,
plan to let gui handle most of it
add another accel arg, rate, which is used to set
the 'accel' parameter of types which call exp (nat/sig),
might want to cap it
add (update) serializable DriverSettings (ModifierArgs) class to
gui and static methods for interop
remove properties from ManagedAccel, its now just a black box
for accessing modifier methods
add exception handling in wrapper_io to throw proper managed types
change SettingsManager::Startup to make a new settings file
if an error occurs during deserialization
change structure of accel types; how offset and weight are applied
now depend on additivity of types
remove tagged_union and add a handrolled variant/visit impl
AccelGui::UpdateActiveValueLabels currently broken for caps
and a few other args
remove gui default layout and initial natural accel setup
cli not updated
Diffstat (limited to 'common/accel-base.hpp')
| -rw-r--r-- | common/accel-base.hpp | 73 |
1 files changed, 26 insertions, 47 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp index f280e3e..560c0b5 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -1,19 +1,5 @@ #pragma once -#include "vec2.h" - -void bad_arg(const char*); - -#ifndef _KERNEL_MODE - -#include "rawaccel-error.hpp" - -inline void bad_arg(const char* s) { - throw rawaccel::invalid_argument(s); -} - -#endif - namespace rawaccel { /// <summary> Struct to hold arguments for an acceleration function. </summary> @@ -24,55 +10,48 @@ namespace rawaccel { double exponent = 2; double midpoint = 0; double power_scale = 1; + double power_exp = 0.05; + double weight = 1; + double rate = 0; + double scale_cap = 0; double gain_cap = 0; - vec2d weight = { 1, 1 }; }; - /// <summary> - /// Struct to hold common acceleration curve implementation details. - /// </summary> - struct accel_base { + template <typename Func> + struct accel_val_base { + double offset = 0; + double weight = 1; + Func fn; - /// <summary> Coefficients applied to acceleration per axis.</summary> - vec2d weight = { 1, 1 }; + accel_val_base(const accel_args& args) : fn(args) {} - /// <summary> Generally, the acceleration ramp rate.</summary> - double speed_coeff = 0; + }; - accel_base(const accel_args& args) { - verify(args); + template <typename Func> + struct additive_accel : accel_val_base<Func> { - speed_coeff = args.accel; + additive_accel(const accel_args& args) : accel_val_base(args) { + offset = args.offset; weight = args.weight; } - /// <summary> - /// Default transformation of speed -> acceleration. - /// </summary> - inline double accelerate(double speed) const { - return speed_coeff * speed; + inline double operator()(double speed) const { + return 1 + fn(maxsd(speed - offset, 0)) * weight; } - /// <summary> - /// Default transformation of acceleration -> mouse input multipliers. - /// </summary> - inline vec2d scale(double accel_val) const { - return { - weight.x * accel_val + 1, - weight.y * accel_val + 1 - }; + }; + + template <typename Func> + struct nonadditive_accel : accel_val_base<Func> { + + nonadditive_accel(const accel_args& args) : accel_val_base(args) { + if (args.weight != 0) weight = args.weight; } - /// <summary> - /// Verifies arguments as valid. Errors if not. - /// </summary> - /// <param name="args">Arguments to verified.</param> - void verify(const accel_args& args) const { - if (args.accel < 0) bad_arg("accel can not be negative, use a negative weight to compensate"); - if (args.gain_cap > 0 && weight.x != weight.y) bad_arg("weight x and y values must be equal with a gain cap"); + inline double operator()(double speed) const { + return fn(speed) * weight; } - accel_base() = default; }; } |