diff options
| author | Jacob Palecki <[email protected]> | 2020-09-03 19:36:44 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-09-03 19:36:44 -0700 |
| commit | 01f870a493378a62ab76dcbf5dc37c0390ca7afe (patch) | |
| tree | b3dac41f6c0fa67b6c62c6643145f01b464c1a46 /common | |
| parent | Change classic, natural, naturalgain to use gain offset (diff) | |
| download | rawaccel-01f870a493378a62ab76dcbf5dc37c0390ca7afe.tar.xz rawaccel-01f870a493378a62ab76dcbf5dc37c0390ca7afe.zip | |
Refactor for nice gain offset
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-base.hpp | 8 | ||||
| -rw-r--r-- | common/accel-classic.hpp | 4 | ||||
| -rw-r--r-- | common/accel-linear.hpp | 3 | ||||
| -rw-r--r-- | common/accel-logarithmic.hpp | 3 | ||||
| -rw-r--r-- | common/accel-natural.hpp | 4 | ||||
| -rw-r--r-- | common/accel-naturalgain.hpp | 9 | ||||
| -rw-r--r-- | common/accel-noaccel.hpp | 1 | ||||
| -rw-r--r-- | common/accel-sigmoid.hpp | 1 | ||||
| -rw-r--r-- | common/accel-sigmoidgain.hpp | 1 |
9 files changed, 26 insertions, 8 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp index b42f23d..714162f 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -5,6 +5,7 @@ namespace rawaccel { /// <summary> Struct to hold arguments for an acceleration function. </summary> struct accel_args { double offset = 0; + double legacy_offset = 0; double accel = 0; double limit = 2; double exponent = 2; @@ -19,6 +20,7 @@ namespace rawaccel { template <typename Func> struct accel_val_base { + bool legacy_offset = false; double offset = 0; double weight = 1; Func fn; @@ -31,15 +33,15 @@ namespace rawaccel { struct additive_accel : accel_val_base<Func> { additive_accel(const accel_args& args) : accel_val_base(args) { - offset = args.offset; + legacy_offset = args.offset <= 0 && args.legacy_offset > 0; + offset = legacy_offset ? args.legacy_offset : args.offset; weight = args.weight; } inline double operator()(double speed) const { double offset_speed = speed - offset; - return offset_speed > 0 ? 1 + fn(offset_speed) * weight : 1; + return offset_speed > 0 ? ( legacy_offset ? 1 + fn.legacy_offset(offset_speed) * weight : 1 + fn(offset_speed) ) : 1; } - }; template <typename Func> diff --git a/common/accel-classic.hpp b/common/accel-classic.hpp index 3f409c3..1df888a 100644 --- a/common/accel-classic.hpp +++ b/common/accel-classic.hpp @@ -25,6 +25,10 @@ namespace rawaccel { double base_speed = speed + offset; return multiplicative_const * pow(speed, power_inc) / base_speed; } + + inline double legacy_offset(double speed) const { + return pow(accel * speed, power); + } }; using accel_classic = additive_accel<classic_impl>; diff --git a/common/accel-linear.hpp b/common/accel-linear.hpp index 95ba261..2bd57b8 100644 --- a/common/accel-linear.hpp +++ b/common/accel-linear.hpp @@ -21,6 +21,9 @@ namespace rawaccel { return accel * base_speed - subtractive_const + divisive_const / base_speed; } + inline double legacy_offset(double speed) const { + return accel * speed; + } }; using accel_linear = additive_accel<linear_impl>; diff --git a/common/accel-logarithmic.hpp b/common/accel-logarithmic.hpp index c7991c7..1ab0e53 100644 --- a/common/accel-logarithmic.hpp +++ b/common/accel-logarithmic.hpp @@ -16,6 +16,9 @@ namespace rawaccel { //f(x) = log(m*x+1) return log(accel * speed + 1); } + + // incorrect but this style is slated for removal + inline double legacy_offset(double speed) const { return operator()(speed); } }; using accel_logarithmic = additive_accel<logarithmic_impl>; diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp index 32bc365..03700c1 100644 --- a/common/accel-natural.hpp +++ b/common/accel-natural.hpp @@ -24,6 +24,10 @@ namespace rawaccel { return limit * (1 - ((exp(-rate * speed) * speed + offset) / base_speed)); } + inline double legacy_offset(double speed) const { + return limit - (limit * exp(-rate * speed)); + } + }; using accel_natural = additive_accel<natural_impl>; diff --git a/common/accel-naturalgain.hpp b/common/accel-naturalgain.hpp index 5979d92..cdfd1fa 100644 --- a/common/accel-naturalgain.hpp +++ b/common/accel-naturalgain.hpp @@ -13,16 +13,15 @@ namespace rawaccel { inline double operator()(double speed) const { // f(x) = k((e^(-mx)-1)/mx + 1) - if (speed <= 0) - { - return 0; - } - double base_speed = speed + offset; double scaled_speed = rate * speed; return limit * (((exp(-scaled_speed) - 1) / (base_speed * rate) ) + 1 - offset / base_speed); } + inline double legacy_offset(double speed) const { + double scaled_speed = rate * speed; + return limit * (((exp(-scaled_speed) - 1) / scaled_speed) + 1); + } }; using accel_naturalgain = additive_accel<naturalgain_impl>; diff --git a/common/accel-noaccel.hpp b/common/accel-noaccel.hpp index ae6f5f8..c803c2f 100644 --- a/common/accel-noaccel.hpp +++ b/common/accel-noaccel.hpp @@ -12,6 +12,7 @@ namespace rawaccel { inline double operator()(double) const { return 1; } + inline double legacy_offset(double speed) const { return operator()(speed); } }; } diff --git a/common/accel-sigmoid.hpp b/common/accel-sigmoid.hpp index c8112ee..239bd9d 100644 --- a/common/accel-sigmoid.hpp +++ b/common/accel-sigmoid.hpp @@ -21,6 +21,7 @@ namespace rawaccel { return limit / (exp(-rate * (speed - midpoint)) + 1); } + inline double legacy_offset(double speed) const { return operator()(speed); } }; using accel_sigmoid = additive_accel<sigmoid_impl>; diff --git a/common/accel-sigmoidgain.hpp b/common/accel-sigmoidgain.hpp index 99bb146..bed2f16 100644 --- a/common/accel-sigmoidgain.hpp +++ b/common/accel-sigmoidgain.hpp @@ -26,6 +26,7 @@ namespace rawaccel { return limit * ((log(additive_constant+exp(scaled_speed)) - integration_constant)/scaled_speed); } + inline double legacy_offset(double speed) const { return operator()(speed); } }; using accel_sigmoidgain = additive_accel<sigmoidgain_impl>; |