diff options
| author | a1xd <[email protected]> | 2020-09-22 03:01:34 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-09-22 03:01:34 -0400 |
| commit | 75c5f80cad2b671df2d20c4b0395b5aec1bc10af (patch) | |
| tree | 6f899c988afc2a7e36d632d5a6b742f4cf670990 /common | |
| parent | Merge remote-tracking branch 'downstream/experiment' into Experiment (diff) | |
| download | rawaccel-75c5f80cad2b671df2d20c4b0395b5aec1bc10af.tar.xz rawaccel-75c5f80cad2b671df2d20c4b0395b5aec1bc10af.zip | |
add lut exp to driver
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-experimenttwo.hpp | 43 | ||||
| -rw-r--r-- | common/rawaccel.hpp | 27 |
2 files changed, 44 insertions, 26 deletions
diff --git a/common/accel-experimenttwo.hpp b/common/accel-experimenttwo.hpp index 73428f7..a961f78 100644 --- a/common/accel-experimenttwo.hpp +++ b/common/accel-experimenttwo.hpp @@ -4,8 +4,17 @@ #include "accel-base.hpp" +#define RA_LOOKUP + namespace rawaccel { + constexpr size_t LUT_SIZE = 601; + + struct si_pair { + double slope = 0; + double intercept = 0; + }; + /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary> struct experimenttwo_impl { double rate; @@ -27,51 +36,49 @@ namespace rawaccel { inline double legacy_offset(double speed) const { return operator()(speed); } - inline double apply(double* lookup, double speed) + inline double apply(si_pair* lookup, double speed) const { - int index = map(speed); - double slope = lookup[index]; - double intercept = lookup[index + 1]; - return slope + intercept / speed; + si_pair pair = lookup[map(speed)]; + return pair.slope + pair.intercept / speed; } - inline int map(double speed) + inline int map(double speed) const { - int index = speed > 0 ? (int)floor(200*log10(speed)+402) : 0; + int index = speed > 0 ? (int)(100 * log10(speed) + 201) : 0; if (index < 0) return 0; - if (index > 1200) return 1200; + if (index >= LUT_SIZE) return LUT_SIZE - 1; return index; } - inline double fill(double* lookup) + inline void fill(si_pair* lookup) const { double lookup_speed = 0; double gain_integral_speed = 0; double gain = 0; double intercept = 0; double output = 0; - int index = 0; + double x = -2; - lookup[index] = gain; - lookup[index + 1] = intercept; + lookup[0] = {}; - for (double x = -2.0; x <= 4.0; x += 0.01) + for (size_t i = 1; i < LUT_SIZE; i++) { - index+=2; - lookup_speed = pow(10,x); + x += 0.01; + + lookup_speed = pow(10, x); while (gain_integral_speed < lookup_speed) { gain_integral_speed += 0.001; gain = operator()(gain_integral_speed); - output += gain*0.001; + output += gain * 0.001; } intercept = gain * lookup_speed - output; - lookup[index] = gain; - lookup[index + 1] = intercept; + + lookup[i] = { gain, intercept }; } } diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 2914225..ca2d4d7 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -13,7 +13,7 @@ #include "accel-naturalgain.hpp" #include "accel-power.hpp" #include "accel-sigmoidgain.hpp" -#include "accel-experimentone.hpp" +#include "accel-experimenttwo.hpp" #include "accel-noaccel.hpp" namespace rawaccel { @@ -93,6 +93,8 @@ namespace rawaccel { } struct accel_variant { + si_pair* lookup; + accel_mode tag = accel_mode::noaccel; union union_t { @@ -107,15 +109,24 @@ namespace rawaccel { accel_noaccel noaccel = {}; } u = {}; - accel_variant(const accel_args& args, accel_mode mode) : - tag(mode) + accel_variant(const accel_args& args, accel_mode mode, si_pair* lut = nullptr) : + tag(mode), lookup(lut) { visit_accel([&](auto& impl) { impl = { args }; }, *this); + + if (lookup && tag == accel_mode::experimentone) { + u.experimentone.fn.fill(lookup); + } + } inline double apply(double speed) const { + if (lookup && tag == accel_mode::experimentone) { + return u.experimentone.fn.apply(lookup, speed); + } + return visit_accel([=](auto&& impl) { return impl(speed); }, *this); @@ -193,8 +204,8 @@ namespace rawaccel { velocity_gain_cap gain_cap; accel_scale_clamp clamp; - accelerator(const accel_args& args, accel_mode mode) : - accel(args, mode), gain_cap(args.gain_cap, accel), clamp(args.scale_cap) + accelerator(const accel_args& args, accel_mode mode, si_pair* lut = nullptr) : + accel(args, mode, lut), gain_cap(args.gain_cap, accel), clamp(args.scale_cap) {} inline double apply(double speed) const { @@ -216,7 +227,7 @@ namespace rawaccel { vec2<accelerator> accels; vec2d sensitivity = { 1, 1 }; - mouse_modifier(const settings& args) : + mouse_modifier(const settings& args, vec2<si_pair*> luts = {}) : combine_magnitudes(args.combine_mags) { if (args.degrees_rotation != 0) { @@ -233,8 +244,8 @@ namespace rawaccel { return; } - accels.x = accelerator(args.argsv.x, args.modes.x); - accels.y = accelerator(args.argsv.y, args.modes.y); + accels.x = accelerator(args.argsv.x, args.modes.x, luts.x); + accels.y = accelerator(args.argsv.y, args.modes.y, luts.y); apply_accel = true; } |