From 15c5cd516c9f17bf8e36559b429836fa4e3a8f71 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 1 Sep 2020 08:09:02 +1000 Subject: [PATCH] Rename AxisSpec.Mid to Neutral (resolves #2345) --- src/BizHawk.Client.Common/Controller.cs | 6 ++--- .../display/IInputDisplayGenerator.cs | 2 +- .../movie/bk2/Bk2Controller.cs | 2 +- .../movie/bk2/Bk2LogEntryGenerator.cs | 2 +- .../movie/interfaces/IMovieController.cs | 2 +- .../tools/Macros/MovieZone.cs | 2 +- .../tools/TAStudio/TAStudio.ListView.cs | 4 ++-- .../controls/VirtualPadAnalogStick.cs | 16 ++++++------- .../controls/components/AnalogStickPanel.cs | 8 +++---- .../Base Implementations/Axes/AxisSpec.cs | 6 ++--- src/BizHawk.Emulation.Common/Extensions.cs | 24 +++++++++---------- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/BizHawk.Client.Common/Controller.cs b/src/BizHawk.Client.Common/Controller.cs index d1b794430b..862312de13 100644 --- a/src/BizHawk.Client.Common/Controller.cs +++ b/src/BizHawk.Client.Common/Controller.cs @@ -14,7 +14,7 @@ namespace BizHawk.Client.Common Definition = definition; foreach (var kvp in Definition.Axes) { - _axes[kvp.Key] = kvp.Value.Mid; + _axes[kvp.Key] = kvp.Value.Neutral; _axisRanges[kvp.Key] = kvp.Value; } } @@ -69,8 +69,8 @@ namespace BizHawk.Client.Common value *= kvp.Value.Mult; // -1..1 -> range - value *= Math.Max(range.Mid - range.Min, range.Max - range.Mid); - value += range.Mid; + value *= Math.Max(range.Neutral - range.Min, range.Max - range.Neutral); + value += range.Neutral; // finally, constrain to range again in case the original value was unexpectedly large, or the deadzone and scale made it so, or the axis is lopsided _axes[kvp.Key] = ((int) value).ConstrainWithin(range.Range); diff --git a/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs b/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs index bfe18ecec9..3865bbd529 100644 --- a/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs +++ b/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs @@ -41,7 +41,7 @@ namespace BizHawk.Client.Common { var val = _source.AxisValue(button); - if (val == range.Mid) + if (val == range.Neutral) { sb.Append(" "); } diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs index c0ec1adae6..15dcd334ec 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs @@ -69,7 +69,7 @@ namespace BizHawk.Client.Common // axes don't have sticky logic, so latch default value foreach (var kvp in Definition.Axes) { - _myAxisControls[kvp.Key] = kvp.Value.Mid; + _myAxisControls[kvp.Key] = kvp.Value.Neutral; } } diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index e399150522..c0168eed28 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -75,7 +75,7 @@ namespace BizHawk.Client.Common { if (_source.Definition.Axes.TryGetValue(button, out var range)) { - var val = createEmpty ? range.Mid : _source.AxisValue(button); + var val = createEmpty ? range.Neutral : _source.AxisValue(button); sb.Append(val.ToString().PadLeft(5, ' ')).Append(','); } diff --git a/src/BizHawk.Client.Common/movie/interfaces/IMovieController.cs b/src/BizHawk.Client.Common/movie/interfaces/IMovieController.cs index 1cfabb5efe..73240c2e22 100644 --- a/src/BizHawk.Client.Common/movie/interfaces/IMovieController.cs +++ b/src/BizHawk.Client.Common/movie/interfaces/IMovieController.cs @@ -11,7 +11,7 @@ namespace BizHawk.Client.Common /// /// Latches to the given - /// For buttons it latches autohold state, for analogs it latches mid value. + /// For buttons it latches autohold state, for axes it latches neutral value. /// void SetFromSticky(IStickyAdapter controller); diff --git a/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs b/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs index d3fe8d29ba..b26758e16b 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs @@ -296,7 +296,7 @@ namespace BizHawk.Client.EmuHawk foreach (string name in latching.Definition.Axes.Keys) { var axisValue = source.AxisValue(name); - if (axisValue == source.Definition.Axes[name].Mid) + if (axisValue == source.Definition.Axes[name].Neutral) { latching.SetAxis(name, axisValue); } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index 51ed8e19a0..b3081719df 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -359,7 +359,7 @@ namespace BizHawk.Client.EmuHawk if (column.Type == ColumnType.Axis) { // feos: this could be cached, but I don't notice any slowdown this way either - if (text == ((float) ControllerType.Axes[columnName].Mid).ToString()) + if (text == ((float) ControllerType.Axes[columnName].Neutral).ToString()) { text = ""; } @@ -423,7 +423,7 @@ namespace BizHawk.Client.EmuHawk } else { - // feos: there's no default value other than mid, and we can't go arbitrary here, so do nothing for now + // feos: there's no default value other than neutral, and we can't go arbitrary here, so do nothing for now // autohold is ignored for axes too for the same reasons: lack of demand + ambiguity } diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs index ee3f800ff0..d87b87aa96 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs @@ -42,13 +42,13 @@ namespace BizHawk.Client.EmuHawk PolarToRectHelper = (r, θ) => { var (x, y) = PolarRectConversion.PolarToRectLookup((ushort) r, (ushort) θ); - var x1 = (RangeX.IsReversed ? RangeX.Mid - x : RangeX.Mid + x).ConstrainWithin(RangeX.Range); - var y1 = (RangeY.IsReversed ? RangeY.Mid - y : RangeY.Mid + y).ConstrainWithin(RangeY.Range); + var x1 = (RangeX.IsReversed ? RangeX.Neutral - x : RangeX.Neutral + x).ConstrainWithin(RangeX.Range); + var y1 = (RangeY.IsReversed ? RangeY.Neutral - y : RangeY.Neutral + y).ConstrainWithin(RangeY.Range); return ((short) x1, (short) y1); }; RectToPolarHelper = (x, y) => PolarRectConversion.RectToPolarLookup( - (sbyte) (RangeX.IsReversed ? RangeX.Mid - x : x - RangeX.Mid), - (sbyte) (RangeY.IsReversed ? RangeY.Mid - y : y - RangeY.Mid) + (sbyte) (RangeX.IsReversed ? RangeX.Neutral - x : x - RangeX.Neutral), + (sbyte) (RangeY.IsReversed ? RangeY.Neutral - y : y - RangeY.Neutral) ); } else @@ -60,14 +60,14 @@ namespace BizHawk.Client.EmuHawk { var x = (short) (r * Math.Cos(θ * DEG_TO_RAD_FACTOR)); var y = (short) (r * Math.Sin(θ * DEG_TO_RAD_FACTOR)); - var x1 = (RangeX.IsReversed ? RangeX.Mid - x : RangeX.Mid + x).ConstrainWithin(RangeX.Range); - var y1 = (RangeY.IsReversed ? RangeY.Mid - y : RangeY.Mid + y).ConstrainWithin(RangeY.Range); + var x1 = (RangeX.IsReversed ? RangeX.Neutral - x : RangeX.Neutral + x).ConstrainWithin(RangeX.Range); + var y1 = (RangeY.IsReversed ? RangeY.Neutral - y : RangeY.Neutral + y).ConstrainWithin(RangeY.Range); return ((short) x1, (short) y1); }; RectToPolarHelper = (x, y) => { - double x1 = RangeX.IsReversed ? RangeX.Mid - x : x - RangeX.Mid; - double y1 = RangeY.IsReversed ? RangeY.Mid - y : y - RangeY.Mid; + double x1 = RangeX.IsReversed ? RangeX.Neutral - x : x - RangeX.Neutral; + double y1 = RangeY.IsReversed ? RangeY.Neutral - y : y - RangeY.Neutral; var θ = Math.Atan2(y1, x1) * RAD_TO_DEG_FACTOR; return ((uint) Math.Sqrt(x1 * x1 + y1 * y1), (uint) (θ < 0 ? 360.0 + θ : θ)); }; diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs index a21ce7d810..18a3d98769 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs @@ -90,10 +90,10 @@ namespace BizHawk.Client.EmuHawk _reverseX = _fullRangeX.IsReversed ^ _userRangePercentageX < 0; _reverseY = _fullRangeY.IsReversed ^ _userRangePercentageY < 0; - _rangeX = (_fullRangeX.Mid - (_fullRangeX.Mid - _fullRangeX.Min) * _userRangePercentageX / 100) - .RangeTo(_fullRangeX.Mid + (_fullRangeX.Max - _fullRangeX.Mid) * _userRangePercentageX / 100); - _rangeY = (_fullRangeY.Mid - (_fullRangeY.Mid - _fullRangeY.Min) * _userRangePercentageY / 100) - .RangeTo(_fullRangeY.Mid + (_fullRangeY.Max - _fullRangeY.Mid) * _userRangePercentageY / 100); + _rangeX = (_fullRangeX.Neutral - (_fullRangeX.Neutral - _fullRangeX.Min) * _userRangePercentageX / 100) + .RangeTo(_fullRangeX.Neutral + (_fullRangeX.Max - _fullRangeX.Neutral) * _userRangePercentageX / 100); + _rangeY = (_fullRangeY.Neutral - (_fullRangeY.Neutral - _fullRangeY.Min) * _userRangePercentageY / 100) + .RangeTo(_fullRangeY.Neutral + (_fullRangeY.Max - _fullRangeY.Neutral) * _userRangePercentageY / 100); _x = _x.ConstrainWithin(_rangeX); _y = _y.ConstrainWithin(_rangeY); diff --git a/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisSpec.cs b/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisSpec.cs index 229da39724..41679550fe 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisSpec.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisSpec.cs @@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Common /// does not include the extra char needed for a minus sign public int MaxDigits => Math.Max(Math.Abs(Min).ToString().Length, Math.Abs(Max).ToString().Length); - public readonly int Mid; + public readonly int Neutral; public int Min => Range.Start; @@ -31,11 +31,11 @@ namespace BizHawk.Emulation.Common public readonly Range Range; - public AxisSpec(Range range, int mid, bool isReversed = false, AxisConstraint? constraint = null) + public AxisSpec(Range range, int neutral, bool isReversed = false, AxisConstraint? constraint = null) { Constraint = constraint; IsReversed = isReversed; - Mid = mid; + Neutral = neutral; Range = range; } } diff --git a/src/BizHawk.Emulation.Common/Extensions.cs b/src/BizHawk.Emulation.Common/Extensions.cs index f02ca4832a..325a748585 100644 --- a/src/BizHawk.Emulation.Common/Extensions.cs +++ b/src/BizHawk.Emulation.Common/Extensions.cs @@ -405,9 +405,9 @@ namespace BizHawk.Emulation.Common /// /// pass only for one axis in a pair, by convention the X axis /// identical reference to ; the object is mutated - public static ControllerDefinition AddAxis(this ControllerDefinition def, string name, Range range, int mid, bool isReversed = false, AxisConstraint constraint = null) + public static ControllerDefinition AddAxis(this ControllerDefinition def, string name, Range range, int neutral, bool isReversed = false, AxisConstraint constraint = null) { - def.Axes.Add(name, new AxisSpec(range, mid, isReversed, constraint)); + def.Axes.Add(name, new AxisSpec(range, neutral, isReversed, constraint)); return def; } @@ -417,12 +417,12 @@ namespace BizHawk.Emulation.Common /// /// format string e.g. "P1 Left {0}" (will be used to interpolate "X" and "Y") /// identical reference to ; the object is mutated - public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range rangeX, int midX, Range rangeY, int midY, AxisConstraint constraint = null) + public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range rangeX, int neutralX, Range rangeY, int neutralY, AxisConstraint constraint = null) { var yAxisName = string.Format(nameFormat, "Y"); var finalConstraint = constraint ?? new NoOpAxisConstraint(yAxisName); - return def.AddAxis(string.Format(nameFormat, "X"), rangeX, midX, ((byte) pDir & 2) != 0, finalConstraint) - .AddAxis(yAxisName, rangeY, midY, ((byte) pDir & 1) != 0); + return def.AddAxis(string.Format(nameFormat, "X"), rangeX, neutralX, ((byte) pDir & 2) != 0, finalConstraint) + .AddAxis(yAxisName, rangeY, neutralY, ((byte) pDir & 1) != 0); } /// @@ -431,8 +431,8 @@ namespace BizHawk.Emulation.Common /// /// format string e.g. "P1 Left {0}" (will be used to interpolate "X" and "Y") /// identical reference to ; the object is mutated - public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range rangeBoth, int midBoth, AxisConstraint constraint = null) - => def.AddXYPair(nameFormat, pDir, rangeBoth, midBoth, rangeBoth, midBoth, constraint); + public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range rangeBoth, int neutralBoth, AxisConstraint constraint = null) + => def.AddXYPair(nameFormat, pDir, rangeBoth, neutralBoth, rangeBoth, neutralBoth, constraint); /// /// Adds an X/Y/Z triple of axes to the receiver , and returns it. @@ -440,11 +440,11 @@ namespace BizHawk.Emulation.Common /// /// format string e.g. "P1 Tilt {0}" (will be used to interpolate "X", "Y", and "Z") /// identical reference to ; the object is mutated - public static ControllerDefinition AddXYZTriple(this ControllerDefinition def, string nameFormat, Range rangeAll, int midAll) - => def.AddAxis(string.Format(nameFormat, "X"), rangeAll, midAll) - .AddAxis(string.Format(nameFormat, "Y"), rangeAll, midAll) - .AddAxis(string.Format(nameFormat, "Z"), rangeAll, midAll); + public static ControllerDefinition AddXYZTriple(this ControllerDefinition def, string nameFormat, Range rangeAll, int neutralAll) + => def.AddAxis(string.Format(nameFormat, "X"), rangeAll, neutralAll) + .AddAxis(string.Format(nameFormat, "Y"), rangeAll, neutralAll) + .AddAxis(string.Format(nameFormat, "Z"), rangeAll, neutralAll); - public static AxisSpec With(this in AxisSpec spec, Range range, int mid) => new AxisSpec(range, mid, spec.IsReversed, spec.Constraint); + public static AxisSpec With(this in AxisSpec spec, Range range, int neutral) => new AxisSpec(range, neutral, spec.IsReversed, spec.Constraint); } } \ No newline at end of file