diff options
| author | a1xd <[email protected]> | 2021-04-13 23:59:21 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-04-13 23:59:21 -0400 |
| commit | a6926be0e911b7b7637861866f41c3bca31a87a3 (patch) | |
| tree | a8d7cd5afb4c093e6f97e8d772b139dd5d749988 /common | |
| parent | additional fixes (diff) | |
| download | rawaccel-a6926be0e911b7b7637861866f41c3bca31a87a3.tar.xz rawaccel-a6926be0e911b7b7637861866f41c3bca31a87a3.zip | |
move arbitrary input into settings
separate arbitrary mode from spaced modes, arbitrary now deserializes from default settings file
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-lookup.hpp | 35 | ||||
| -rw-r--r-- | common/accel-motivity.hpp | 4 | ||||
| -rw-r--r-- | common/accel-power.hpp | 1 | ||||
| -rw-r--r-- | common/accel-union.hpp | 32 | ||||
| -rw-r--r-- | common/rawaccel-base.hpp | 25 | ||||
| -rw-r--r-- | common/rawaccel-validate.hpp | 11 |
6 files changed, 64 insertions, 44 deletions
diff --git a/common/accel-lookup.hpp b/common/accel-lookup.hpp index 968eb6a..4e8354f 100644 --- a/common/accel-lookup.hpp +++ b/common/accel-lookup.hpp @@ -97,7 +97,7 @@ namespace rawaccel { return y; } - linear_lut(const table_args& args) : + linear_lut(const spaced_lut_args& args) : range({ args.start, args.stop, @@ -106,7 +106,7 @@ namespace rawaccel { transfer(args.transfer) {} linear_lut(const accel_args& args) : - linear_lut(args.lut_args) {} + linear_lut(args.spaced_args) {} }; struct binlog_lut : lut_base<binlog_lut> { @@ -138,7 +138,7 @@ namespace rawaccel { return y; } - binlog_lut(const table_args& args) : + binlog_lut(const spaced_lut_args& args) : range({ static_cast<int>(args.start), static_cast<int>(args.stop), @@ -148,7 +148,7 @@ namespace rawaccel { transfer(args.transfer) {} binlog_lut(const accel_args& args) : - binlog_lut(args.lut_args) {} + binlog_lut(args.spaced_args) {} }; struct si_pair { @@ -162,12 +162,10 @@ namespace rawaccel { }; struct arbitrary_lut { - enum { capacity = SPACED_LUT_CAPACITY / 4 }; + enum { capacity = ARB_LUT_CAPACITY }; fp_rep_range range; -; arbitrary_lut_point data[capacity] = {}; - float raw_data_in[capacity*2] = {}; int log_lookup[capacity] = {}; double first_point_speed; double last_point_speed; @@ -175,6 +173,7 @@ namespace rawaccel { int last_log_lookup_index; double last_log_lookup_speed; double first_log_lookup_speed; + bool velocity_points; double operator()(double speed) const { @@ -205,6 +204,7 @@ namespace rawaccel { int log_index = get_log_index(speed); if (unsigned(log_index) >= capacity) return 1; int arbitrary_index = log_lookup[log_index]; + if (arbitrary_index < 0) return 1; index = search_from(arbitrary_index, last_arb_index, speed); } @@ -238,12 +238,19 @@ namespace rawaccel { double inline apply(int index, double speed) const { - si_pair pair = data[index].slope_intercept; - return pair.slope + pair.intercept / speed; - } + auto [slope, intercept] = data[index].slope_intercept; + if (velocity_points) + { + return slope + intercept / speed; + } + else + { + return slope * speed + intercept; + } + } - void fill(vec2<float>* points, int length) + void fill(const vec2<float>* points, int length) { first_point_speed = points[0].x; last_arbitrary_index = length - 1; @@ -268,8 +275,6 @@ namespace rawaccel { for (int i = 0; i < length; i++) { next = points[i]; - raw_data_in[i * 2] = next.x; - raw_data_in[i * 2 + 1] = next.y; double slope = (next.y - current.y) / (next.x - current.x); double intercept = next.y - slope * next.x; si_pair current_si = { @@ -295,8 +300,10 @@ namespace rawaccel { } } - arbitrary_lut(const accel_args&) + arbitrary_lut(const accel_args& args) { + velocity_points = args.arb_args.velocity; + fill(args.arb_args.data, args.arb_args.length); } }; } diff --git a/common/accel-motivity.hpp b/common/accel-motivity.hpp index c7ecb13..0efe7ea 100644 --- a/common/accel-motivity.hpp +++ b/common/accel-motivity.hpp @@ -36,8 +36,8 @@ namespace rawaccel { double sum = 0; double a = 0; auto sigmoid_sum = [&, sig = sigmoid(args)](double b) mutable { - double interval = (b - a) / args.lut_args.partitions; - for (int i = 1; i <= args.lut_args.partitions; i++) { + double interval = (b - a) / args.spaced_args.partitions; + for (int i = 1; i <= args.spaced_args.partitions; i++) { sum += sig(a + i * interval) * interval; } a = b; diff --git a/common/accel-power.hpp b/common/accel-power.hpp index a21f926..c8faabb 100644 --- a/common/accel-power.hpp +++ b/common/accel-power.hpp @@ -24,5 +24,4 @@ namespace rawaccel { } }; - using power_legacy = power; } diff --git a/common/accel-union.hpp b/common/accel-union.hpp index f5c26ba..8495a62 100644 --- a/common/accel-union.hpp +++ b/common/accel-union.hpp @@ -16,27 +16,31 @@ namespace rawaccel { jump_gain, natural_lgcy, natural_gain, - power_lgcy, - power_gain, motivity_lgcy, motivity_gain, + power, + lut_arb, lut_log, lut_lin, - lut_arb, noaccel }; - constexpr internal_mode make_mode(accel_mode mode, table_mode lut_mode, bool legacy) + constexpr internal_mode make_mode(accel_mode mode, spaced_lut_mode lut_mode, bool legacy) { - if (lut_mode != table_mode::off) { + if (lut_mode != spaced_lut_mode::off) { switch (lut_mode) { - case table_mode::binlog: return internal_mode::lut_log; - case table_mode::linear: return internal_mode::lut_lin; - case table_mode::arbitrary: return internal_mode::lut_arb; + case spaced_lut_mode::binlog: return internal_mode::lut_log; + case spaced_lut_mode::linear: return internal_mode::lut_lin; default: return internal_mode::noaccel; } } - else if (mode == accel_mode::noaccel) { + else if (mode == accel_mode::power) { + return internal_mode::power; + } + else if (mode == accel_mode::arb_lookup) { + return internal_mode::lut_arb; + } + else if (mode >= accel_mode::noaccel) { return internal_mode::noaccel; } else { @@ -47,7 +51,7 @@ namespace rawaccel { constexpr internal_mode make_mode(const accel_args& args) { - return make_mode(args.mode, args.lut_args.mode, args.legacy); + return make_mode(args.mode, args.spaced_args.mode, args.legacy); } template <typename Visitor, typename AccelUnion> @@ -60,13 +64,12 @@ namespace rawaccel { case internal_mode::jump_gain: return vis(u.jump_g); case internal_mode::natural_lgcy: return vis(u.natural_l); case internal_mode::natural_gain: return vis(u.natural_g); - case internal_mode::power_lgcy: return vis(u.power_l); - case internal_mode::power_gain: return vis(u.power_g); case internal_mode::motivity_lgcy: return vis(u.motivity_l); case internal_mode::motivity_gain: return vis(u.motivity_g); + case internal_mode::power: return vis(u.power); + case internal_mode::lut_arb: return vis(u.arb_lut); case internal_mode::lut_log: return vis(u.log_lut); case internal_mode::lut_lin: return vis(u.lin_lut); - case internal_mode::lut_arb: return vis(u.arb_lut); default: return vis(u.noaccel); } } @@ -78,8 +81,7 @@ namespace rawaccel { jump_legacy jump_l; natural natural_g; natural_legacy natural_l; - power power_g; - power_legacy power_l; + power power; sigmoid motivity_l; motivity motivity_g; linear_lut lin_lut; diff --git a/common/rawaccel-base.hpp b/common/rawaccel-base.hpp index 2f49ec0..c1b2db3 100644 --- a/common/rawaccel-base.hpp +++ b/common/rawaccel-base.hpp @@ -16,6 +16,7 @@ namespace rawaccel { inline constexpr size_t MAX_DEV_ID_LEN = 200; inline constexpr size_t SPACED_LUT_CAPACITY = 1025; + inline constexpr size_t ARB_LUT_CAPACITY = SPACED_LUT_CAPACITY / 4; inline constexpr double MAX_NORM = 16; inline constexpr double PI = 3.14159265358979323846; @@ -24,21 +25,20 @@ namespace rawaccel { classic, jump, natural, - power, motivity, - lookuptable, + power, + arb_lookup, noaccel }; - enum class table_mode { + enum class spaced_lut_mode { off, binlog, - linear, - arbitrary + linear }; - struct table_args { - table_mode mode = table_mode::off; + struct spaced_lut_args { + spaced_lut_mode mode = spaced_lut_mode::off; bool transfer = true; unsigned char partitions = 2; short num_elements = 8; @@ -46,12 +46,16 @@ namespace rawaccel { double stop = 8; }; + struct table_args { + bool velocity = true; + int length = 0; + vec2<float> data[ARB_LUT_CAPACITY] = {}; + }; + struct accel_args { accel_mode mode = accel_mode::noaccel; bool legacy = false; - table_args lut_args = {}; - double offset = 0; double cap = 1.5; double accel_classic = 0.005; @@ -65,6 +69,9 @@ namespace rawaccel { double limit = 1.5; double midpoint = 5; double smooth = 0.5; + + spaced_lut_args spaced_args; + table_args arb_args; }; struct domain_args { diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index ef6f667..2f54b5f 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -29,13 +29,13 @@ namespace rawaccel { auto check_accel = [&error](const accel_args& args) { static_assert(SPACED_LUT_CAPACITY == 1025, "update error msg"); - const auto& lut_args = args.lut_args; + const auto& lut_args = args.spaced_args; if (lut_args.partitions <= 0) { error("lut partitions"" must be positive"); } - if (lut_args.mode == table_mode::linear) { + if (lut_args.mode == spaced_lut_mode::linear) { if (lut_args.start <= 0) { error("start"" must be positive"); } @@ -49,7 +49,7 @@ namespace rawaccel { error("num must be between 2 and 1025"); } } - else if (lut_args.mode == table_mode::binlog) { + else if (lut_args.mode == spaced_lut_mode::binlog) { int istart = static_cast<int>(lut_args.start); int istop = static_cast<int>(lut_args.stop); @@ -73,6 +73,11 @@ namespace rawaccel { } } + if (args.mode == accel_mode::arb_lookup) { + if (args.arb_args.length < 2) { + error("lookup mode requires at least 2 points"); + } + } if (args.offset < 0) { error("offset can not be negative"); |