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 | |
| 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
| -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 | ||||
| -rw-r--r-- | converter/converter.cpp | 2 | ||||
| -rw-r--r-- | grapher/Layouts/ClassicLayout.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/DefaultLayout.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/JumpLayout.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/LUTLayout.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/LayoutBase.cs | 11 | ||||
| -rw-r--r-- | grapher/Layouts/LinearLayout.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/MotivityLayout.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/NaturalLayout.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/OffLayout.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/PowerLayout.cs | 2 | ||||
| -rw-r--r-- | grapher/Layouts/UnsupportedLayout.cs | 31 | ||||
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 23 | ||||
| -rw-r--r-- | grapher/Models/Options/AccelOptionSet.cs | 9 | ||||
| -rw-r--r-- | grapher/Models/Options/AccelTypeOptions.cs | 121 | ||||
| -rw-r--r-- | grapher/Models/Options/ApplyOptions.cs | 57 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 1 | ||||
| -rw-r--r-- | wrapper/wrapper.cpp | 177 |
24 files changed, 312 insertions, 246 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"); diff --git a/converter/converter.cpp b/converter/converter.cpp index 70593a7..ad92f8c 100644 --- a/converter/converter.cpp +++ b/converter/converter.cpp @@ -153,7 +153,7 @@ ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) { bool try_convert(const ia_settings_t& ia_settings) { auto get = make_extractor(ia_settings); - ra::settings ra_settings; + ra::settings& ra_settings = *(new ra::settings()); ra_settings.degrees_rotation = get("Angle", "AngleAdjustment").value_or(0); ra_settings.sens = { diff --git a/grapher/Layouts/ClassicLayout.cs b/grapher/Layouts/ClassicLayout.cs index e9013b6..fe5c25d 100644 --- a/grapher/Layouts/ClassicLayout.cs +++ b/grapher/Layouts/ClassicLayout.cs @@ -8,7 +8,7 @@ namespace grapher.Layouts : base() { Name = "Classic"; - Index = (int)AccelMode.classic; + Mode = AccelMode.classic; GainSwitchOptionLayout = new OptionLayout(true, Gain); AccelLayout = new OptionLayout(true, Acceleration); diff --git a/grapher/Layouts/DefaultLayout.cs b/grapher/Layouts/DefaultLayout.cs index 42de7f3..8146255 100644 --- a/grapher/Layouts/DefaultLayout.cs +++ b/grapher/Layouts/DefaultLayout.cs @@ -8,7 +8,7 @@ namespace grapher.Layouts : base() { Name = "Default"; - Index = (int)AccelMode.noaccel; + Mode = AccelMode.noaccel; LogarithmicCharts = false; GainSwitchOptionLayout = new OptionLayout(true, Gain); diff --git a/grapher/Layouts/JumpLayout.cs b/grapher/Layouts/JumpLayout.cs index d78d273..cf5eb24 100644 --- a/grapher/Layouts/JumpLayout.cs +++ b/grapher/Layouts/JumpLayout.cs @@ -8,7 +8,7 @@ namespace grapher.Layouts : base() { Name = "Jump"; - Index = (int)AccelMode.jump; + Mode = AccelMode.jump; LogarithmicCharts = false; GainSwitchOptionLayout = new OptionLayout(true, Gain); diff --git a/grapher/Layouts/LUTLayout.cs b/grapher/Layouts/LUTLayout.cs index fd0b75a..5505114 100644 --- a/grapher/Layouts/LUTLayout.cs +++ b/grapher/Layouts/LUTLayout.cs @@ -14,7 +14,7 @@ namespace grapher.Layouts : base() { Name = "LookUpTable"; - Index = (int)AccelMode.noaccel + 1; + Mode = AccelMode.lut; GainSwitchOptionLayout = new OptionLayout(false, string.Empty); AccelLayout = new OptionLayout(false, Acceleration); diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs index e3583c4..900d611 100644 --- a/grapher/Layouts/LayoutBase.cs +++ b/grapher/Layouts/LayoutBase.cs @@ -34,11 +34,7 @@ namespace grapher.Layouts LogarithmicCharts = false; } - /// <summary> - /// Gets or sets mapping from acceleration type to identifying integer. - /// Must match accel_mode defined in rawaccel-settings.h - /// </summary> - public int Index { get; protected set; } + public AccelMode Mode { get; protected set; } public string Name { get; protected set; } @@ -64,6 +60,11 @@ namespace grapher.Layouts protected OptionLayout GainSwitchOptionLayout { get; set; } + public override string ToString() + { + return Name; + } + public void Layout( IOption gainSwitchOption, IOption accelOption, diff --git a/grapher/Layouts/LinearLayout.cs b/grapher/Layouts/LinearLayout.cs index 31ae353..88be3d4 100644 --- a/grapher/Layouts/LinearLayout.cs +++ b/grapher/Layouts/LinearLayout.cs @@ -10,7 +10,7 @@ namespace grapher.Layouts : base() { Name = LinearName; - Index = (int)AccelMode.classic; + Mode = AccelMode.classic; LogarithmicCharts = false; GainSwitchOptionLayout = new OptionLayout(true, Gain); diff --git a/grapher/Layouts/MotivityLayout.cs b/grapher/Layouts/MotivityLayout.cs index e9c81f4..7458dfc 100644 --- a/grapher/Layouts/MotivityLayout.cs +++ b/grapher/Layouts/MotivityLayout.cs @@ -13,7 +13,7 @@ namespace grapher.Layouts : base() { Name = "Motivity"; - Index = (int)AccelMode.motivity; + Mode = AccelMode.motivity; LogarithmicCharts = true; GainSwitchOptionLayout = new OptionLayout(true, Gain); diff --git a/grapher/Layouts/NaturalLayout.cs b/grapher/Layouts/NaturalLayout.cs index 070a249..ece2b00 100644 --- a/grapher/Layouts/NaturalLayout.cs +++ b/grapher/Layouts/NaturalLayout.cs @@ -8,7 +8,7 @@ namespace grapher.Layouts : base() { Name = "Natural"; - Index = (int)AccelMode.natural; + Mode = AccelMode.natural; LogarithmicCharts = false; GainSwitchOptionLayout = new OptionLayout(true, Gain); diff --git a/grapher/Layouts/OffLayout.cs b/grapher/Layouts/OffLayout.cs index 9c56632..e802113 100644 --- a/grapher/Layouts/OffLayout.cs +++ b/grapher/Layouts/OffLayout.cs @@ -8,7 +8,7 @@ namespace grapher.Layouts : base() { Name = "Off"; - Index = (int)AccelMode.noaccel; + Mode = AccelMode.noaccel; LogarithmicCharts = false; GainSwitchOptionLayout = new OptionLayout(false, string.Empty); diff --git a/grapher/Layouts/PowerLayout.cs b/grapher/Layouts/PowerLayout.cs index 8304ccf..bb07457 100644 --- a/grapher/Layouts/PowerLayout.cs +++ b/grapher/Layouts/PowerLayout.cs @@ -6,7 +6,7 @@ : base() { Name = "Power"; - Index = (int)AccelMode.power; + Mode = AccelMode.power; LogarithmicCharts = false; GainSwitchOptionLayout = new OptionLayout(true, Gain); diff --git a/grapher/Layouts/UnsupportedLayout.cs b/grapher/Layouts/UnsupportedLayout.cs new file mode 100644 index 0000000..1607a6c --- /dev/null +++ b/grapher/Layouts/UnsupportedLayout.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class UnsupportedLayout : LayoutBase + { + public const string LUTLayoutText = "This mode is unsupported by this program. See the guide for details."; + + public UnsupportedLayout() + : base() + { + Name = "Unsupported"; + Mode = AccelMode.noaccel + 1; + + GainSwitchOptionLayout = new OptionLayout(false, string.Empty); + AccelLayout = new OptionLayout(false, Acceleration); + ScaleLayout = new OptionLayout(false, string.Empty); + CapLayout = new OptionLayout(false, Cap); + WeightLayout = new OptionLayout(false, Weight); + OffsetLayout = new OptionLayout(false, Offset); + LimitLayout = new OptionLayout(false, string.Empty); + ExponentLayout = new OptionLayout(false, Exponent); + MidpointLayout = new OptionLayout(false, string.Empty); + LUTTextLayout = new OptionLayout(true, LUTLayoutText); + } + } +}
\ No newline at end of file diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index ec570d3..324dcb1 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -114,20 +114,19 @@ namespace grapher public void UpdateActiveSettingsFromFields() { - var settings = new DriverSettings + var settings = new DriverSettings(); + + settings.rotation = ApplyOptions.Rotation.Field.Data; + settings.sensitivity = new Vec2<double> { - rotation = ApplyOptions.Rotation.Field.Data, - sensitivity = new Vec2<double> - { - x = ApplyOptions.Sensitivity.Fields.X, - y = ApplyOptions.Sensitivity.Fields.Y - }, - combineMagnitudes = ApplyOptions.IsWhole, - args = ApplyOptions.GetArgs(), - domainArgs = ApplyOptions.Directionality.GetDomainArgs(), - rangeXY = ApplyOptions.Directionality.GetRangeXY(), - deviceID = DeviceIDManager.ID, + x = ApplyOptions.Sensitivity.Fields.X, + y = ApplyOptions.Sensitivity.Fields.Y }; + settings.combineMagnitudes = ApplyOptions.IsWhole; + ApplyOptions.SetArgs(ref settings.args); + settings.domainArgs = ApplyOptions.Directionality.GetDomainArgs(); + settings.rangeXY = ApplyOptions.Directionality.GetRangeXY(); + settings.deviceID = DeviceIDManager.ID; Settings.SetHiddenOptions(settings); diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs index f4c08a1..8b957f1 100644 --- a/grapher/Models/Options/AccelOptionSet.cs +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -103,16 +103,11 @@ namespace grapher.Models.Options Options.SetArgs(ref args); } - public AccelArgs GenerateArgs() - { - return Options.GenerateArgs(); - } - - public void SetActiveValues(AccelArgs args) + public void SetActiveValues(ref AccelArgs args) { if (!Hidden) { - Options.SetActiveValues(args); + Options.SetActiveValues(ref args); } } diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index b12ad8a..62a923d 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -12,19 +12,15 @@ namespace grapher { #region Fields - public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase> - { - new LinearLayout(), - new ClassicLayout(), - new NaturalLayout(), - new JumpLayout(), - new PowerLayout(), - new MotivityLayout(), - new LUTLayout(), - new OffLayout(), - }.ToDictionary(k => k.Name); - - public static readonly AccelArgs DefaultArgs = new DriverSettings().args.x; + public static readonly LayoutBase Linear = new LinearLayout(); + public static readonly LayoutBase Classic = new ClassicLayout(); + public static readonly LayoutBase Jump = new JumpLayout(); + public static readonly LayoutBase Natural = new NaturalLayout(); + public static readonly LayoutBase Motivity = new MotivityLayout(); + public static readonly LayoutBase Power = new PowerLayout(); + public static readonly LayoutBase LUT = new LUTLayout(); + public static readonly LayoutBase Off = new OffLayout(); + public static readonly LayoutBase Unsupported = new UnsupportedLayout(); #endregion Fields @@ -47,7 +43,19 @@ namespace grapher { AccelDropdown = accelDropdown; AccelDropdown.Items.Clear(); - AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray()); + AccelDropdown.Items.AddRange( + new LayoutBase[] + { + Linear, + Classic, + Jump, + Natural, + Motivity, + Power, + LUT, + Off + }); + AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); GainSwitch = gainSwitch; @@ -67,7 +75,8 @@ namespace grapher AccelTypeActiveValue.Height = AccelDropdown.Height; GainSwitch.Left = Acceleration.Field.Left; - Layout("Off"); + AccelerationType = Off; + Layout(); ShowingDefault = true; } @@ -80,16 +89,6 @@ namespace grapher public ComboBox AccelDropdown { get; } - public int AccelerationIndex - { - get - { - return AccelerationType.Index; - } - } - - public LayoutBase AccelerationType { get; private set; } - public ActiveValueLabel AccelTypeActiveValue { get; } public Option Acceleration { get; } @@ -112,6 +111,18 @@ namespace grapher public CheckBoxOption GainSwitch { get; } + public LayoutBase AccelerationType + { + get + { + return AccelDropdown.SelectedItem as LayoutBase; + } + private set + { + AccelDropdown.SelectedItem = value; + } + } + public override int Top { get @@ -201,18 +212,15 @@ namespace grapher Show(); } - public void SetActiveValues(AccelArgs args) + public void SetActiveValues(ref AccelArgs args) { - AccelerationType = AccelTypeFromSettings(args); + AccelerationType = AccelTypeFromSettings(ref args); AccelTypeActiveValue.SetValue(AccelerationType.Name); - // Add one to include linear, which is not represented separately in the config - AccelDropdown.SelectedIndex = AccelerationType.Index + 1; - GainSwitch.SetActiveValue(args.legacy); Weight.SetActiveValue(args.weight); Cap.SetActiveValue(args.cap); Offset.SetActiveValue(args.offset); - Acceleration.SetActiveValue(AccelerationParameterFromArgs(args)); + Acceleration.SetActiveValue(AccelerationParameterFromArgs(ref args)); Scale.SetActiveValue(args.scale); Limit.SetActiveValue(args.limit); Exponent.SetActiveValue(args.exponent); @@ -243,7 +251,10 @@ namespace grapher public void SetArgs(ref AccelArgs args) { - args.mode = (AccelMode)AccelerationType.Index; + if (AccelerationType == Unsupported) throw new NotImplementedException(); + + args.mode = AccelerationType.Mode; + if (Acceleration.Visible) { if (args.mode == AccelMode.natural) @@ -273,13 +284,6 @@ namespace grapher if (Weight.Visible) args.weight = Weight.Field.Data; } - public AccelArgs GenerateArgs() - { - AccelArgs args = new DriverSettings().args.x; - SetArgs(ref args); - return args; - } - public override void AlignActiveValues() { AccelTypeActiveValue.Align(); @@ -296,17 +300,10 @@ namespace grapher private void OnIndexChanged(object sender, EventArgs e) { - var accelerationTypeString = AccelDropdown.SelectedItem.ToString(); - Layout(accelerationTypeString, Beneath); + Layout(Beneath); ShowingDefault = false; } - private void Layout(string type, int top = -1) - { - AccelerationType = AccelerationTypes[type]; - Layout(top); - } - private void Layout(int top = -1) { if (top < 0) @@ -328,23 +325,31 @@ namespace grapher top); } - private LayoutBase AccelTypeFromSettings(AccelArgs args) - { - LayoutBase type; - if (args.mode == AccelMode.classic && args.exponent == 2) + private LayoutBase AccelTypeFromSettings(ref AccelArgs args) + { + if (args.spacedTableArgs.mode != SpacedTableMode.off) { - type = AccelerationTypes.Values.Where(t => string.Equals(t.Name, LinearLayout.LinearName)).FirstOrDefault(); + if (!AccelDropdown.Items.Contains(Unsupported)) + { + AccelDropdown.Items.Add(Unsupported); + } + + return Unsupported; } - else + + switch (args.mode) { - int index = (int)args.mode; - type = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value; + case AccelMode.classic: return (args.power == 2) ? Linear : Classic; + case AccelMode.jump: return Jump; + case AccelMode.natural: return Natural; + case AccelMode.motivity: return Motivity; + case AccelMode.power: return Power; + case AccelMode.lut: return LUT; + default: return Off; } - - return type; } - private double AccelerationParameterFromArgs(AccelArgs args) + private double AccelerationParameterFromArgs(ref AccelArgs args) { if (args.mode == AccelMode.motivity) { diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index 43a2da8..06854b8 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -81,55 +81,30 @@ namespace grapher.Models.Options #region Methods - public Vec2<AccelMode> GetModes() + public void SetArgs(ref Vec2<AccelArgs> args) { - var xMode = (AccelMode)OptionSetX.Options.AccelerationIndex; + OptionSetX.SetArgs(ref args.x); - return new Vec2<AccelMode> + if (ByComponentVectorXYLock.Checked) { - x = xMode, - y = ByComponentVectorXYLock.Checked ? xMode : (AccelMode)OptionSetY.Options.AccelerationIndex - }; - } - - public Vec2<AccelArgs> GetArgs() - { - var xArgs = OptionSetX.GenerateArgs(); - - return new Vec2<AccelArgs> + OptionSetX.SetArgs(ref args.y); + } + else { - x = xArgs, - y = ByComponentVectorXYLock.Checked ? xArgs : OptionSetY.GenerateArgs() - }; - - } - - public void SetActiveValues( - double xSens, - double ySens, - double rotation, - AccelArgs xArgs, - AccelArgs yArgs, - bool isWhole) - { - Sensitivity.SetActiveValues(xSens, ySens); - Rotation.SetActiveValue(rotation); - OptionSetX.SetActiveValues(xArgs); - WholeVectorCheckBox.Checked = isWhole; - ByComponentVectorCheckBox.Checked = !isWhole; - ByComponentVectorXYLock.Checked = xArgs.Equals(yArgs); - OptionSetY.SetActiveValues(yArgs); + OptionSetY.SetArgs(ref args.y); + } } public void SetActiveValues(DriverSettings settings) { - SetActiveValues( - settings.sensitivity.x, - settings.sensitivity.y, - settings.rotation, - settings.args.x, - settings.args.y, - settings.combineMagnitudes); + Sensitivity.SetActiveValues(settings.sensitivity.x, settings.sensitivity.y); + Rotation.SetActiveValue(settings.rotation); + + WholeVectorCheckBox.Checked = settings.combineMagnitudes; + ByComponentVectorCheckBox.Checked = !settings.combineMagnitudes; + ByComponentVectorXYLock.Checked = settings.args.x.Equals(settings.args.y); + OptionSetX.SetActiveValues(ref settings.args.x); + OptionSetY.SetActiveValues(ref settings.args.y); Directionality.SetActiveValues(settings); diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index b453b6f..50545e4 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -81,6 +81,7 @@ <Compile Include="Layouts\LUTLayout.cs" /> <Compile Include="Layouts\MotivityLayout.cs" /> <Compile Include="Layouts\JumpLayout.cs" /> + <Compile Include="Layouts\UnsupportedLayout.cs" /> <Compile Include="MessageDialog.cs"> <SubType>Form</SubType> </Compile> diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index 1f27415..6344b77 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -9,7 +9,7 @@ using namespace System; using namespace System::Collections::Generic; using namespace System::Runtime::InteropServices; using namespace System::Reflection; - +using namespace System::Runtime::Serialization; using namespace Newtonsoft::Json; using namespace Newtonsoft::Json::Linq; @@ -20,20 +20,20 @@ ra::settings default_settings; [JsonConverter(Converters::StringEnumConverter::typeid)] public enum class AccelMode { - classic, jump, natural, power, motivity, lut, noaccel + classic, jump, natural, motivity, power, lut, noaccel }; [JsonConverter(Converters::StringEnumConverter::typeid)] -public enum class TableMode +public enum class SpacedTableMode { - off, binlog, linear, arbitrary + off, binlog, linear }; [StructLayout(LayoutKind::Sequential)] -public value struct TableArgs +public value struct SpacedTableArgs { [JsonIgnore] - TableMode mode; + SpacedTableMode mode; [MarshalAs(UnmanagedType::U1)] bool transfer; @@ -56,6 +56,50 @@ public value struct Vec2 }; [StructLayout(LayoutKind::Sequential)] +public value struct TableArgs +{ + [JsonProperty("Whether points affect velocity (true) or sensitivity (false)")] + [MarshalAs(UnmanagedType::U1)] + bool velocity; + + [JsonIgnore] + int length; + + [MarshalAs(UnmanagedType::ByValArray, SizeConst = ra::ARB_LUT_CAPACITY)] + array<Vec2<float>>^ points; + + virtual bool Equals(Object^ ob) override { + if (ob->GetType() == this->GetType()) { + TableArgs^ other = (TableArgs^)ob; + + if (this->length != other->length) return false; + if (this->points == other->points) return true; + + if (unsigned(length) >= ra::ARB_LUT_CAPACITY || + points == nullptr || + other->points == nullptr) { + throw gcnew InteropException("invalid table args"); + } + + for (int i = 0; i < length; i++) { + if (points[i].x != other->points[i].x || + points[i].y != other->points[i].y) + return false; + } + + return true; + } + else { + return false; + } + } + + virtual int GetHashCode() override { + return points->GetHashCode() ^ length.GetHashCode(); + } +}; + +[StructLayout(LayoutKind::Sequential)] public value struct AccelArgs { AccelMode mode; @@ -63,9 +107,6 @@ public value struct AccelArgs [MarshalAs(UnmanagedType::U1)] bool legacy; - [JsonProperty(Required = Required::Default)] - TableArgs lutArgs; - double offset; double cap; double accelClassic; @@ -79,6 +120,11 @@ public value struct AccelArgs double limit; double midpoint; double smooth; + + [JsonProperty(Required = Required::Default)] + SpacedTableArgs spacedTableArgs; + + TableArgs tableData; }; [StructLayout(LayoutKind::Sequential)] @@ -155,57 +201,48 @@ public ref struct DriverSettings { Marshal::PtrToStructure(IntPtr(&default_settings), this); } -}; -[JsonObject(ItemRequired = Required::Always)] -public ref struct LutBase -{ - [JsonConverter(Converters::StringEnumConverter::typeid)] - enum class Mode +private: + [OnDeserialized] + void OnDeserializedMethod(StreamingContext context) { - logarithmic, linear, arbitrary - } mode; + args.x.tableData.length = args.x.tableData.points->Length; + args.y.tableData.length = args.y.tableData.points->Length; - virtual void SetArgs(TableArgs%) {} - virtual void SetData(ra::accel_union&) {} -}; - -[JsonObject(ItemRequired = Required::Always)] -public ref struct ArbitraryLut sealed : public LutBase -{ - [JsonProperty("Whether points affect velocity (true) or sensitivity (false)")] - bool transfer; - - array<float, 2>^ data; - - ArbitraryLut() - { + array<Vec2<float>>::Resize(args.x.tableData.points, ra::ARB_LUT_CAPACITY); + array<Vec2<float>>::Resize(args.y.tableData.points, ra::ARB_LUT_CAPACITY); } - ArbitraryLut(const ra::arbitrary_lut& table) + [OnSerializing] + void OnSerializingMethod(StreamingContext context) { - mode = Mode::arbitrary; - transfer = true; - data = gcnew array<float, 2>(table.last_arbitrary_index + 1, 2); - - pin_ptr<float> pdata = &data[0,0]; - std::memcpy(pdata, &table.raw_data_in, sizeof(float) * 2 * (table.last_arbitrary_index + 1)); + array<Vec2<float>>::Resize(args.x.tableData.points, args.x.tableData.length); + array<Vec2<float>>::Resize(args.y.tableData.points, args.y.tableData.length); } - virtual void SetArgs(TableArgs% args) override + [OnSerialized] + void OnSerializedMethod(StreamingContext context) { - args.mode = TableMode::arbitrary; - args.transfer = transfer; + array<Vec2<float>>::Resize(args.x.tableData.points, ra::ARB_LUT_CAPACITY); + array<Vec2<float>>::Resize(args.y.tableData.points, ra::ARB_LUT_CAPACITY); } - virtual void SetData(ra::accel_union& accel) override +}; + +[JsonObject(ItemRequired = Required::Always)] +public ref struct LutBase +{ + [JsonConverter(Converters::StringEnumConverter::typeid)] + enum class Mode { - pin_ptr<float> pdata = &data[0,0]; + logarithmic, linear + } mode; - accel.arb_lut.fill(reinterpret_cast<vec2<float>*>(pdata), data->Length/2); - } + virtual void SetArgs(AccelArgs%) {} + virtual void SetData(ra::accel_union&) {} }; + [JsonObject(ItemRequired = Required::Always)] public ref struct SpacedLut abstract : public LutBase { @@ -216,11 +253,11 @@ public ref struct SpacedLut abstract : public LutBase double stop; array<float>^ data; - void SetArgsBase(TableArgs% args) + void SetArgsBase(AccelArgs% args) { - args.transfer = transfer; - args.start = start; - args.stop = stop; + args.spacedTableArgs.transfer = transfer; + args.spacedTableArgs.start = start; + args.spacedTableArgs.stop = stop; } void SetDataBase(ra::accel_union& accel) @@ -250,11 +287,11 @@ public ref struct LinearLut sealed : public SpacedLut std::memcpy(pdata, &table.data, sizeof(float) * data->Length); } - virtual void SetArgs(TableArgs% args) override + virtual void SetArgs(AccelArgs% args) override { SetArgsBase(args); - args.num = data->Length; - args.mode = TableMode::linear; + args.spacedTableArgs.num = data->Length; + args.spacedTableArgs.mode = SpacedTableMode::linear; } virtual void SetData(ra::accel_union& accel) override @@ -270,6 +307,10 @@ public ref struct BinLogLut sealed : public SpacedLut { short num; + BinLogLut() + { + } + BinLogLut(const ra::binlog_lut& table) { mode = Mode::logarithmic; @@ -283,11 +324,11 @@ public ref struct BinLogLut sealed : public SpacedLut std::memcpy(pdata, &table.data, sizeof(float) * data->Length); } - virtual void SetArgs(TableArgs% args) override + virtual void SetArgs(AccelArgs% args) override { SetArgsBase(args); - args.num = num; - args.mode = TableMode::binlog; + args.spacedTableArgs.num = num; + args.spacedTableArgs.mode = SpacedTableMode::binlog; } virtual void SetData(ra::accel_union& accel) override @@ -333,8 +374,6 @@ public ref struct RaConvert { return NonNullable<BinLogLut^>(jObject); case LutBase::Mode::linear: return NonNullable<LinearLut^>(jObject); - case LutBase::Mode::arbitrary: - return NonNullable<ArbitraryLut^>(jObject); default: throw gcnew NotImplementedException(); } @@ -401,7 +440,7 @@ private: if (xTableJson) { tables.x = RaConvert::Table(xTableJson); - tables.x->SetArgs(baseSettings->args.x.lutArgs); + tables.x->SetArgs(baseSettings->args.x); } if (yTableJson) { @@ -412,7 +451,7 @@ private: tables.y = RaConvert::Table(yTableJson); } - tables.y->SetArgs(baseSettings->args.y.lutArgs); + tables.y->SetArgs(baseSettings->args.y); } } @@ -443,15 +482,16 @@ public: auto fp = static_cast<void (*)(const char*)>( Marshal::GetFunctionPointerForDelegate(del).ToPointer()); - ra::settings args; - Marshal::StructureToPtr(settings, (IntPtr)&args, false); + ra::settings* args_ptr = new ra::settings(); + Marshal::StructureToPtr(settings, (IntPtr)args_ptr, false); list = gcnew List<String^>(); - auto [cx, cy, _] = ra::valid(args, fp); + auto [cx, cy, _] = ra::valid(*args_ptr, fp); countX = cx; countY = cy; gch.Free(); + delete args_ptr; } bool Empty() @@ -535,9 +575,9 @@ public: { auto settings = gcnew ExtendedSettings(); Marshal::PtrToStructure(IntPtr(&instance->data.args), settings->baseSettings); - settings->tables.x = extract(instance->data.args.argsv.x.lut_args.mode, + settings->tables.x = extract(instance->data.args.argsv.x.spaced_args.mode, instance->data.mod.accel.x); - settings->tables.y = extract(instance->data.args.argsv.y.lut_args.mode, + settings->tables.y = extract(instance->data.args.argsv.y.spaced_args.mode, instance->data.mod.accel.y); return settings; } @@ -573,13 +613,12 @@ public: } private: - LutBase^ extract(ra::table_mode mode, ra::accel_union& au) + LutBase^ extract(ra::spaced_lut_mode mode, ra::accel_union& au) { switch (mode) { - case ra::table_mode::off: return nullptr; - case ra::table_mode::linear: return gcnew LinearLut(au.lin_lut); - case ra::table_mode::binlog: return gcnew BinLogLut(au.log_lut); - case ra::table_mode::arbitrary: return gcnew ArbitraryLut(au.arb_lut); + case ra::spaced_lut_mode::off: return nullptr; + case ra::spaced_lut_mode::linear: return gcnew LinearLut(au.lin_lut); + case ra::spaced_lut_mode::binlog: return gcnew BinLogLut(au.log_lut); default: throw gcnew NotImplementedException(); } } |