diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-base.hpp | 9 | ||||
| -rw-r--r-- | common/accel-classic.hpp | 14 | ||||
| -rw-r--r-- | common/accel-linear.hpp | 14 | ||||
| -rw-r--r-- | common/accel-logarithmic.hpp | 3 | ||||
| -rw-r--r-- | common/accel-natural.hpp | 8 | ||||
| -rw-r--r-- | common/accel-naturalgain.hpp | 7 | ||||
| -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, 49 insertions, 9 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp index 560c0b5..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,14 +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 { - return 1 + fn(maxsd(speed - offset, 0)) * weight; + double offset_speed = speed - offset; + 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 4cc52ca..1df888a 100644 --- a/common/accel-classic.hpp +++ b/common/accel-classic.hpp @@ -10,13 +10,23 @@ namespace rawaccel { struct classic_impl { double accel; double power; + double power_inc; + double offset; + double multiplicative_const; classic_impl(const accel_args& args) : - accel(args.accel), power(args.exponent - 1) - {} + accel(args.accel), power(args.exponent - 1), offset(args.offset) { + multiplicative_const = pow(accel, power); + power_inc = power + 1; + } inline double operator()(double speed) const { //f(x) = (mx)^(k-1) + 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); } }; diff --git a/common/accel-linear.hpp b/common/accel-linear.hpp index a943594..2bd57b8 100644 --- a/common/accel-linear.hpp +++ b/common/accel-linear.hpp @@ -7,13 +7,23 @@ namespace rawaccel { /// <summary> Struct to hold linear acceleration implementation. </summary> struct linear_impl { double accel; + double offset; + double subtractive_const; + double divisive_const; - linear_impl(const accel_args& args) : accel(args.accel) {} + linear_impl(const accel_args& args) : accel(args.accel), offset(args.offset) { + subtractive_const = 2 * accel * offset; + divisive_const = accel * offset * offset; + } inline double operator()(double speed) const { - return accel * speed; + double base_speed = speed + offset; + 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 c7d0dcd..03700c1 100644 --- a/common/accel-natural.hpp +++ b/common/accel-natural.hpp @@ -10,15 +10,21 @@ namespace rawaccel { struct natural_impl { double rate; double limit; + double offset; natural_impl(const accel_args& args) : - rate(args.accel), limit(args.limit - 1) + rate(args.accel), limit(args.limit - 1), offset(args.offset) { rate /= limit; } inline double operator()(double speed) const { // f(x) = k(1-e^(-mx)) + double base_speed = speed + offset; + return limit * (1 - ((exp(-rate * speed) * speed + offset) / base_speed)); + } + + inline double legacy_offset(double speed) const { return limit - (limit * exp(-rate * speed)); } diff --git a/common/accel-naturalgain.hpp b/common/accel-naturalgain.hpp index 646b2bb..cdfd1fa 100644 --- a/common/accel-naturalgain.hpp +++ b/common/accel-naturalgain.hpp @@ -13,10 +13,15 @@ namespace rawaccel { inline double operator()(double speed) const { // f(x) = k((e^(-mx)-1)/mx + 1) + double base_speed = speed + offset; double scaled_speed = rate * speed; - return limit * (((exp(-scaled_speed) - 1) / scaled_speed) + 1); + 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>; |