summaryrefslogtreecommitdiff
path: root/common/accel-base.hpp
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-09-03 19:36:44 -0700
committerJacob Palecki <[email protected]>2020-09-03 19:36:44 -0700
commit01f870a493378a62ab76dcbf5dc37c0390ca7afe (patch)
treeb3dac41f6c0fa67b6c62c6643145f01b464c1a46 /common/accel-base.hpp
parentChange classic, natural, naturalgain to use gain offset (diff)
downloadrawaccel-01f870a493378a62ab76dcbf5dc37c0390ca7afe.tar.xz
rawaccel-01f870a493378a62ab76dcbf5dc37c0390ca7afe.zip
Refactor for nice gain offset
Diffstat (limited to 'common/accel-base.hpp')
-rw-r--r--common/accel-base.hpp8
1 files changed, 5 insertions, 3 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>