Rename AxisSpec.Mid to Neutral (resolves #2345)

This commit is contained in:
YoshiRulz 2020-09-01 08:09:02 +10:00
parent 8e4c774169
commit 15c5cd516c
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
11 changed files with 37 additions and 37 deletions

View File

@ -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);

View File

@ -41,7 +41,7 @@ namespace BizHawk.Client.Common
{
var val = _source.AxisValue(button);
if (val == range.Mid)
if (val == range.Neutral)
{
sb.Append(" ");
}

View File

@ -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;
}
}

View File

@ -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(',');
}

View File

@ -11,7 +11,7 @@ namespace BizHawk.Client.Common
/// <summary>
/// Latches to the given <see cref="IStickyAdapter" />
/// For buttons it latches autohold state, for analogs it latches mid value.
/// For buttons it latches autohold state, for axes it latches neutral value.
/// </summary>
void SetFromSticky(IStickyAdapter controller);

View File

@ -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);
}

View File

@ -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
}

View File

@ -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 + θ : θ));
};

View File

@ -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);

View File

@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Common
/// <remarks>does not include the extra char needed for a minus sign</remarks>
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<int> Range;
public AxisSpec(Range<int> range, int mid, bool isReversed = false, AxisConstraint? constraint = null)
public AxisSpec(Range<int> range, int neutral, bool isReversed = false, AxisConstraint? constraint = null)
{
Constraint = constraint;
IsReversed = isReversed;
Mid = mid;
Neutral = neutral;
Range = range;
}
}

View File

@ -405,9 +405,9 @@ namespace BizHawk.Emulation.Common
/// </summary>
/// <param name="constraint">pass only for one axis in a pair, by convention the X axis</param>
/// <returns>identical reference to <paramref name="def"/>; the object is mutated</returns>
public static ControllerDefinition AddAxis(this ControllerDefinition def, string name, Range<int> range, int mid, bool isReversed = false, AxisConstraint constraint = null)
public static ControllerDefinition AddAxis(this ControllerDefinition def, string name, Range<int> 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
/// </summary>
/// <param name="nameFormat">format string e.g. <c>"P1 Left {0}"</c> (will be used to interpolate <c>"X"</c> and <c>"Y"</c>)</param>
/// <returns>identical reference to <paramref name="def"/>; the object is mutated</returns>
public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range<int> rangeX, int midX, Range<int> rangeY, int midY, AxisConstraint constraint = null)
public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range<int> rangeX, int neutralX, Range<int> 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);
}
/// <summary>
@ -431,8 +431,8 @@ namespace BizHawk.Emulation.Common
/// </summary>
/// <param name="nameFormat">format string e.g. <c>"P1 Left {0}"</c> (will be used to interpolate <c>"X"</c> and <c>"Y"</c>)</param>
/// <returns>identical reference to <paramref name="def"/>; the object is mutated</returns>
public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, Range<int> 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<int> rangeBoth, int neutralBoth, AxisConstraint constraint = null)
=> def.AddXYPair(nameFormat, pDir, rangeBoth, neutralBoth, rangeBoth, neutralBoth, constraint);
/// <summary>
/// Adds an X/Y/Z triple of axes to the receiver <see cref="ControllerDefinition"/>, and returns it.
@ -440,11 +440,11 @@ namespace BizHawk.Emulation.Common
/// </summary>
/// <param name="nameFormat">format string e.g. <c>"P1 Tilt {0}"</c> (will be used to interpolate <c>"X"</c>, <c>"Y"</c>, and <c>"Z"</c>)</param>
/// <returns>identical reference to <paramref name="def"/>; the object is mutated</returns>
public static ControllerDefinition AddXYZTriple(this ControllerDefinition def, string nameFormat, Range<int> 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<int> 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<int> range, int mid) => new AxisSpec(range, mid, spec.IsReversed, spec.Constraint);
public static AxisSpec With(this in AxisSpec spec, Range<int> range, int neutral) => new AxisSpec(range, neutral, spec.IsReversed, spec.Constraint);
}
}