From e12b5d8137805b74c17cfd91d00ef65de6380e6a Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 13 Mar 2020 15:40:36 +1000 Subject: [PATCH] Refactor FloatRange creation and usage effectively resolves #1200 * Replaced floats in FloatRange with ints (would have used shorts but SubGBHawk/SubNesHawk use an axis to hack in cycle count or something), added both Range and Range auto-properties * Added bool field IsReversed to FloatRange * Added enum AxisPairOrientation and factory method using it * Cleaned up usages of FloatRange fields and properties * Added new properties to PadSchema.ButtonSchema for type PadInputType.AnalogStick (to hold the two FloatRanges) and used ControllerDefinitions from cores to dedup these ranges in the schemata * Made VirtualPadAnalogStick work properly: both the direction and bounds are correctly set from the controller schemata, the polar conversion measures angles consistently (though I think it might not work outside -128..127 e.g. for PSX), and I didn't break the sensitivity override, plus negative percentages might work now but I didn't allow those * Renamed FloatRange to AxisRange, but did not rename related symbols --- BizHawk.Client.Common/Controller.cs | 20 +---- .../movie/bk2/Bk2LogEntryGenerator.cs | 2 +- .../tools/TAStudio/TAStudio.ListView.cs | 45 ++-------- .../tools/TAStudio/TAStudio.cs | 4 +- .../tools/VirtualPads/VirtualPad.cs | 4 +- .../controls/VirtualPadAnalogStick.cs | 84 ++++++------------- .../controls/components/AnalogStickPanel.cs | 60 ++++++------- .../tools/VirtualPads/schema/ColecoSchema.cs | 9 +- .../tools/VirtualPads/schema/IntvSchema.cs | 9 +- .../tools/VirtualPads/schema/N64Schema.cs | 9 +- .../tools/VirtualPads/schema/PSXSchema.cs | 17 ++-- .../tools/VirtualPads/schema/PadSchema.cs | 6 ++ .../tools/VirtualPads/schema/SaturnSchema.cs | 35 +++----- .../tools/VirtualPads/schema/SnesSchema.cs | 9 +- .../tools/VirtualPads/schema/VECSchema.cs | 9 +- .../ControllerDefinition.cs | 70 +++++++++------- .../Atari/2600/Atari2600Controllers.cs | 4 +- .../Atari/A7800Hawk/A7800HawkControllers.cs | 2 +- .../Consoles/Belogic/Uzem.cs | 6 +- .../Consoles/Coleco/ColecoControllers.cs | 4 +- .../GCE/Vectrex/VectrexHawkControllers.cs | 2 +- .../Controllers/IntellivisionControllers.cs | 2 +- .../Consoles/NEC/PCFX/TstControllerDeck.cs | 6 +- .../Consoles/Nintendo/GBA/GBA.cs | 11 +-- .../Nintendo/GBHawk/GBHawkControllers.cs | 2 +- .../Consoles/Nintendo/N64/N64Input.cs | 23 ++--- .../Consoles/Nintendo/NES/NES.Core.cs | 2 +- .../Consoles/Nintendo/NES/NESControllers.cs | 14 ++-- .../Nintendo/SNES/LibsnesControllerDeck.cs | 31 +++---- .../Consoles/Nintendo/SNES9X/Snes9x.cs | 20 +---- .../Consoles/Nintendo/SubGBHawk/SubGBHawk.cs | 2 +- .../Consoles/Sega/SMS/SMS.IEmulator.cs | 2 +- .../Consoles/Sega/SMS/SMS.Input.cs | 24 +++--- .../Sega/Saturn/SaturnusControllerDeck.cs | 28 +++++-- .../Sega/gpgx64/GPGXControlConverter.cs | 6 +- .../Consoles/Sony/PSP/PSP.cs | 22 ++--- .../Consoles/Sony/PSX/Octoshock.cs | 21 ++--- .../Libretro/LibretroCore.cs | 3 +- 38 files changed, 256 insertions(+), 373 deletions(-) diff --git a/BizHawk.Client.Common/Controller.cs b/BizHawk.Client.Common/Controller.cs index 3b4a0537fa..883e977694 100644 --- a/BizHawk.Client.Common/Controller.cs +++ b/BizHawk.Client.Common/Controller.cs @@ -28,7 +28,7 @@ namespace BizHawk.Client.Common private readonly WorkingDictionary> _bindings = new WorkingDictionary>(); private readonly WorkingDictionary _buttons = new WorkingDictionary(); private readonly WorkingDictionary _floatButtons = new WorkingDictionary(); - private readonly Dictionary _floatRanges = new WorkingDictionary(); + private readonly Dictionary _floatRanges = new WorkingDictionary(); private readonly Dictionary _floatBinds = new Dictionary(); /// don't do this @@ -79,7 +79,7 @@ namespace BizHawk.Client.Common // zero 09-mar-2015 - not sure if adding + 1 here is correct.. but... maybe? float output; - if (range.Max < range.Min) + if (range.IsReversed) { output = (((input * multiplier) + 10000.0f) * (range.Min - range.Max + 1) / 20000.0f) + range.Max; } @@ -90,22 +90,8 @@ namespace BizHawk.Client.Common // zero 09-mar-2015 - at this point, we should only have integers, since that's all 100% of consoles ever see // if this becomes a problem we can add flags to the range and update GUIs to be able to display floats - output = (int)output; - float lowerBound = Math.Min(range.Min, range.Max); - float upperBound = Math.Max(range.Min, range.Max); - - if (output < lowerBound) - { - output = lowerBound; - } - - if (output > upperBound) - { - output = upperBound; - } - - _floatButtons[outKey] = output; + _floatButtons[outKey] = output.ConstrainWithin(range.FloatRange); } } } diff --git a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index 6f9f0317ed..ef62ee5618 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -90,7 +90,7 @@ namespace BizHawk.Client.Common { int val; int i = _source.Definition.FloatControls.IndexOf(button); - int mid = (int)_source.Definition.FloatRanges[i].Mid; + var mid = _source.Definition.FloatRanges[i].Mid; if (createEmpty) { diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index 418f0b9b28..91569ff2c7 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using BizHawk.Emulation.Common; using BizHawk.Common.NumberExtensions; using BizHawk.Client.Common; +using BizHawk.Common; namespace BizHawk.Client.EmuHawk { @@ -338,9 +339,9 @@ namespace BizHawk.Client.EmuHawk if (column.Type == ColumnType.Float) { // feos: this could be cached, but I don't notice any slowdown this way either - ControllerDefinition.FloatRange range = ControllerType.FloatRanges + ControllerDefinition.AxisRange range = ControllerType.FloatRanges [ControllerType.FloatControls.IndexOf(columnName)]; - if (text == range.Mid.ToString()) + if (text == ((float) range.Mid).ToString()) { text = ""; } @@ -1190,29 +1191,7 @@ namespace BizHawk.Client.EmuHawk return; } - float value = _floatPaintState + increment; - ControllerDefinition.FloatRange range = ControllerType.FloatRanges - [ControllerType.FloatControls.IndexOf(_floatEditColumn)]; - - // Range for N64 Y axis has max -128 and min 127. That should probably be fixed in ControllerDefinition.cs. - // SuuperW: I really don't think changing it would break anything, but adelikat isn't so sure. - float rMax = range.Max; - float rMin = range.Min; - if (rMax < rMin) - { - rMax = range.Min; - rMin = range.Max; - } - - if (value > rMax) - { - value = rMax; - } - else if (value < rMin) - { - value = rMin; - } - + var value = (_floatPaintState + increment).ConstrainWithin(ControllerType.FloatRanges[ControllerType.FloatControls.IndexOf(_floatEditColumn)].FloatRange); CurrentTasMovie.SetFloatState(_floatEditRow, _floatEditColumn, value); _floatTypedValue = value.ToString(); @@ -1285,23 +1264,13 @@ namespace BizHawk.Client.EmuHawk float prev = value; string prevTyped = _floatTypedValue; - ControllerDefinition.FloatRange range = ControllerType.FloatRanges - [ControllerType.FloatControls.IndexOf(_floatEditColumn)]; - - float rMax = range.Max; - float rMin = range.Min; - - // Range for N64 Y axis has max -128 and min 127. That should probably be fixed ControllerDefinition.cs, but I'll put a quick fix here anyway. - if (rMax < rMin) - { - rMax = range.Min; - rMin = range.Max; - } + var range = ControllerType.FloatRanges[ControllerType.FloatControls.IndexOf(_floatEditColumn)]; + var (rMin, rMax) = range.FloatRange; // feos: typing past max digits overwrites existing value, not touching the sign // but doesn't handle situations where the range is like -50 through 100, where minimum is negative and has less digits // it just uses 3 as maxDigits there too, leaving room for typing impossible values (that are still ignored by the game and then clamped) - int maxDigits = range.MaxDigits(); + int maxDigits = range.MaxDigits; int curDigits = _floatTypedValue.Length; string curMinus; if (_floatTypedValue.StartsWith("-")) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index f564cf2030..617365c6cd 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -427,10 +427,10 @@ namespace BizHawk.Client.EmuHawk int digits; if (ControllerType.FloatControls.Contains(kvp.Key)) { - ControllerDefinition.FloatRange range = ControllerType.FloatRanges + ControllerDefinition.AxisRange range = ControllerType.FloatRanges [ControllerType.FloatControls.IndexOf(kvp.Key)]; type = ColumnType.Float; - digits = Math.Max(kvp.Value.Length, range.MaxDigits()); + digits = Math.Max(kvp.Value.Length, range.MaxDigits); } else { diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs index b8d2103c93..87a151ae26 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs @@ -78,8 +78,8 @@ namespace BizHawk.Client.EmuHawk SecondaryName = (button.SecondaryNames != null && button.SecondaryNames.Any()) ? button.SecondaryNames[0] : "", Location = UIHelper.Scale(button.Location), Size = UIHelper.Scale(new Size(180 + 79, 200 + 9)), - RangeX = new float[] { button.MinValue, button.MidValue, button.MaxValue }, - RangeY = new float[] { button.MinValueSec, button.MidValueSec, button.MaxValueSec }, + RangeX = button.AxisRange ?? throw new Exception(), + RangeY = button.SecondaryAxisRange ?? throw new Exception() }); break; case PadSchema.PadInputType.TargetedPair: diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs index 6dc252a411..f5a91a5311 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs @@ -11,22 +11,8 @@ namespace BizHawk.Client.EmuHawk { public partial class VirtualPadAnalogStick : UserControl, IVirtualPadControl { - /// for coordinate transformation when non orthogonal (like PSX for example) - private int rangeAverageX; - - /// - private int rangeAverageY; - - private Range _rangeX = AnalogStickPanel.DefaultRange; - - private Range _rangeY = AnalogStickPanel.DefaultRange; - private bool _readonly; - private bool _reverseX; - - private bool _reverseY; - private bool _updatingFromAnalog; private bool _updatingFromPolar; @@ -44,45 +30,25 @@ namespace BizHawk.Client.EmuHawk manualTheta.ValueChanged += PolarNumeric_Changed; } - public float[] RangeX - { - set - { - if (value.Length != 3) throw new ArgumentException("must be float[3]", nameof(value)); -#if false - _midX = (int) value[1]; -#endif - _reverseX = value[2] < value[0]; - _rangeX = _reverseX ? ((int) value[2]).RangeTo((int) value[0]) : ((int) value[0]).RangeTo((int) value[2]); - } - } + public ControllerDefinition.AxisRange RangeX { get; set; } - public float[] RangeY - { - set - { - if (value.Length != 3) throw new ArgumentException("must be float[3]", nameof(value)); -#if false - _midY = (int) value[1]; -#endif - _reverseY = value[2] < value[0]; - _rangeY = _reverseY ? ((int) value[2]).RangeTo((int) value[0]) : ((int) value[0]).RangeTo((int) value[2]); - } - } + public ControllerDefinition.AxisRange RangeY { get; set; } public string? SecondaryName { get; set; } private void VirtualPadAnalogStick_Load(object sender, EventArgs e) { - AnalogStick.XName = AnalogStick.Name = Name; - AnalogStick.SetRangeX(_rangeX); - AnalogStick.YName = !string.IsNullOrEmpty(SecondaryName) ? SecondaryName : Name.Replace("X", "Y"); - AnalogStick.SetRangeY(_rangeY); + AnalogStick.Init( + Name, + RangeX, + !string.IsNullOrEmpty(SecondaryName) ? SecondaryName : Name.Replace("X", "Y"), + RangeY + ); - ManualX.Minimum = _rangeX.Start; - ManualX.Maximum = _rangeX.EndInclusive; - ManualY.Minimum = _rangeY.Start; - ManualY.Maximum = _rangeY.EndInclusive; + ManualX.Minimum = RangeX.Min; + ManualX.Maximum = RangeX.Max; + ManualY.Minimum = RangeY.Min; + ManualY.Maximum = RangeY.Max; MaxXNumeric.Minimum = 1; MaxXNumeric.Maximum = 100; MaxYNumeric.Minimum = 1; @@ -91,9 +57,6 @@ namespace BizHawk.Client.EmuHawk // these trigger Change events that set the analog stick's values too MaxXNumeric.Value = 100; MaxYNumeric.Value = 100; - - rangeAverageX = (_rangeX.Start + _rangeX.EndInclusive) / 2; - rangeAverageY = (_rangeY.Start + _rangeY.EndInclusive) / 2; } public void UpdateValues() @@ -168,14 +131,19 @@ namespace BizHawk.Client.EmuHawk public void SetPrevious(IController previous) => AnalogStick.SetPrevious(previous); + private (ushort R, ushort Θ) RectToPolarHelper(int x, int y) => PolarRectConversion.RectToPolarLookup( + (sbyte) (RangeX.IsReversed ? RangeX.Mid - x : x - RangeX.Mid), + (sbyte) (RangeY.IsReversed ? RangeY.Mid - y : y - RangeY.Mid) + ); + private void ManualXY_ValueChanged(object sender, EventArgs e) { if (_updatingFromAnalog || _updatingFromPolar) return; _updatingFromXY = true; - var x = (sbyte) ManualX.Value; - var y = (sbyte) ManualY.Value; - var (r, θ) = PolarRectConversion.RectToPolarLookup(x, y); + var x = (int) ManualX.Value; + var y = (int) ManualY.Value; + var (r, θ) = RectToPolarHelper(x, y); SetAnalog(x, y); SetPolar(r, θ); @@ -183,7 +151,7 @@ namespace BizHawk.Client.EmuHawk } private void MaxManualXY_ValueChanged(object sender, EventArgs e) - => AnalogStick.SetUserRange(_reverseX ? -MaxXNumeric.Value : MaxXNumeric.Value, _reverseY ? -MaxYNumeric.Value : MaxYNumeric.Value); + => AnalogStick.SetUserRange((int) MaxXNumeric.Value, (int) MaxYNumeric.Value); private void PolarNumeric_Changed(object sender, EventArgs e) { @@ -191,8 +159,8 @@ namespace BizHawk.Client.EmuHawk _updatingFromPolar = true; var (x, y) = PolarRectConversion.PolarToRectLookup((ushort) manualR.Value, (ushort) manualTheta.Value); - var x1 = (rangeAverageX + x).ConstrainWithin(_rangeX); - var y1 = (rangeAverageY + y).ConstrainWithin(_rangeY); + 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); SetAnalog(x1, y1); SetXY(x1, y1); @@ -227,9 +195,9 @@ namespace BizHawk.Client.EmuHawk if (AnalogStick.HasValue) { - var x = AnalogStick.X - rangeAverageX; - var y = AnalogStick.Y - rangeAverageY; - var (r, θ) = PolarRectConversion.RectToPolarLookup((sbyte) x, (sbyte) y); + var x = AnalogStick.X; + var y = AnalogStick.Y; + var (r, θ) = RectToPolarHelper(x, y); SetPolar(r, θ); SetXY(x, y); } diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs index f2985163ef..252b0e2f85 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs @@ -37,59 +37,53 @@ namespace BizHawk.Client.EmuHawk public bool HasValue; public bool ReadOnly { private get; set; } - public string XName = string.Empty; - public string YName = string.Empty; + public string XName { get; private set; } = string.Empty; + public string YName { get; private set; } = string.Empty; private IController _previous; - private sbyte _userRangePercentageX = 100; - private sbyte _userRangePercentageY = 100; + private int _userRangePercentageX = 100; + private int _userRangePercentageY = 100; - public void SetUserRange(decimal rx, decimal ry) + public void SetUserRange(int rx, int ry) { - _userRangePercentageX = (sbyte) rx; - _userRangePercentageY = (sbyte) ry; + _userRangePercentageX = rx.ConstrainWithin(PercentRange); + _userRangePercentageY = ry.ConstrainWithin(PercentRange); Rerange(); Refresh(); } - public void SetRangeX(Range range) + public void Init(string nameX, ControllerDefinition.AxisRange rangeX, string nameY, ControllerDefinition.AxisRange rangeY) { - _actualRangeX = range; + Name = XName = nameX; + _fullRangeX = rangeX; + YName = nameY; + _fullRangeY = rangeY; Rerange(); } - public void SetRangeY(Range range) - { - _actualRangeY = range; - Rerange(); - } - - private Range _rangeX = DefaultRange; - private Range _rangeY = DefaultRange; - private Range _actualRangeX = DefaultRange; - private Range _actualRangeY = DefaultRange; + private Range _rangeX = 0.RangeTo(0); + private Range _rangeY = 0.RangeTo(0); + private ControllerDefinition.AxisRange _fullRangeX; + private ControllerDefinition.AxisRange _fullRangeY; private bool _reverseX; private bool _reverseY; private void Rerange() { - _reverseX = _userRangePercentageX < 0; - _reverseY = _userRangePercentageY < 0; + _reverseX = _fullRangeX.IsReversed ^ _userRangePercentageX < 0; + _reverseY = _fullRangeY.IsReversed ^ _userRangePercentageY < 0; - var midX = (_actualRangeX.Start + _actualRangeX.EndInclusive) / 2.0; - var halfRangeX = (_reverseX ? -1 : 1) * (_actualRangeX.EndInclusive - _actualRangeX.Start) * _userRangePercentageX / 200.0; - _rangeX = ((int) (midX - halfRangeX)).RangeTo((int) (midX + halfRangeX)); + _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); - var midY = (_actualRangeY.Start + _actualRangeY.EndInclusive) / 2.0; - var halfRangeY = (_reverseY ? -1 : 1) * (_actualRangeY.EndInclusive - _actualRangeY.Start) * _userRangePercentageY / 200.0; - _rangeY = ((int) (midY - halfRangeY)).RangeTo((int) (midY + halfRangeY)); - - // re-constrain after changing ranges - X = X; - Y = Y; + _x = _x.ConstrainWithin(_rangeX); + _y = _y.ConstrainWithin(_rangeY); + SetAnalog(); } /// @@ -104,7 +98,7 @@ namespace BizHawk.Client.EmuHawk /// private int MaybeReversedInX(int i) => _reverseX ? _rangeX.Start + _rangeX.EndInclusive - i : i; /// - private int MaybeReversedInY(int i) => _reverseY ? _rangeY.Start + _rangeY.EndInclusive - i : i; + private int MaybeReversedInY(int i) => _reverseY ? i : _rangeY.Start + _rangeY.EndInclusive - i; private int PixelSizeX => (int)(_rangeX.Count() * ScaleX); private int PixelSizeY => (int)(_rangeY.Count() * ScaleY); @@ -286,6 +280,6 @@ namespace BizHawk.Client.EmuHawk Refresh(); } - internal static readonly Range DefaultRange = (-128).RangeTo(127); + private static readonly Range PercentRange = 0.RangeTo(100); } } diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs index d1f07fcbe0..a2487ccdab 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs @@ -185,6 +185,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema TurboController(int controller) { + var controllerDefRanges = new ColecoTurboController(controller).Definition.FloatRanges; return new PadSchema { IsConsole = false, @@ -194,12 +195,8 @@ namespace BizHawk.Client.EmuHawk new PadSchema.ButtonSchema { Name = $"P{controller} Disc X", - MinValue = -127, - MidValue = 0, - MaxValue = 127, - MinValueSec = 127, - MidValueSec = 0, - MaxValueSec = -127, + AxisRange = controllerDefRanges[0], + SecondaryAxisRange = controllerDefRanges[1], DisplayName = "", Location = new Point(6, 14), Type = PadSchema.PadInputType.AnalogStick diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs index 03ae9682ef..4a995c166c 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs @@ -283,6 +283,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema AnalogController(int controller) { + var controllerDefRanges = new FakeAnalogController(controller).Definition.FloatRanges; return new PadSchema { DisplayName = $"Player {controller}", @@ -407,12 +408,8 @@ namespace BizHawk.Client.EmuHawk new PadSchema.ButtonSchema { Name = $"P{controller} Disc X", - MinValue = -127, - MidValue = 0, - MaxValue = 127, - MinValueSec = 127, - MidValueSec = 0, - MaxValueSec = -127, + AxisRange = controllerDefRanges[0], + SecondaryAxisRange = controllerDefRanges[1], DisplayName = "", Location = new Point(1, 121), Type = PadSchema.PadInputType.AnalogStick diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/N64Schema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/N64Schema.cs index 02e23df50d..d2bca3752e 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/N64Schema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/N64Schema.cs @@ -24,6 +24,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema StandardController(int controller) { + var controllerDefRanges = N64Input.N64ControllerDefinition.FloatRanges; return new PadSchema { IsConsole = false, @@ -135,12 +136,8 @@ namespace BizHawk.Client.EmuHawk new PadSchema.ButtonSchema { Name = $"P{controller} X Axis", - MinValue = -128, - MidValue = 0, - MaxValue = 127, - MinValueSec = 127, - MidValueSec = 0, - MaxValueSec = -128, + AxisRange = controllerDefRanges[0], + SecondaryAxisRange = controllerDefRanges[1], DisplayName = "", Location = new Point(6, 14), Type = PadSchema.PadInputType.AnalogStick diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PSXSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PSXSchema.cs index bde01748d0..0fcb77867c 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PSXSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PSXSchema.cs @@ -46,6 +46,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema DualShockController(int controller) { + var stickRanges = Octoshock.DualShockStickRanges; return new PadSchema { IsConsole = false, @@ -176,12 +177,8 @@ namespace BizHawk.Client.EmuHawk new PadSchema.ButtonSchema { Name = $"P{controller} LStick X", - MinValue = 0, - MidValue = 128, - MaxValue = 255, - MinValueSec = 0, - MidValueSec = 128, - MaxValueSec = 255, + AxisRange = stickRanges[0], + SecondaryAxisRange = stickRanges[1], DisplayName = "", Location = new Point(3, 120), Type = PadSchema.PadInputType.AnalogStick @@ -189,12 +186,8 @@ namespace BizHawk.Client.EmuHawk new PadSchema.ButtonSchema { Name = $"P{controller} RStick X", - MinValue = 0, - MidValue = 128, - MaxValue = 255, - MinValueSec = 0, - MidValueSec = 128, - MaxValueSec = 255, + AxisRange = stickRanges[0], + SecondaryAxisRange = stickRanges[1], DisplayName = "", Location = new Point(260, 120), Type = PadSchema.PadInputType.AnalogStick diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs index c67fcfa1f8..4724ec9fff 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs @@ -2,6 +2,8 @@ using System.Drawing; using System.Windows.Forms; +using BizHawk.Emulation.Common; + namespace BizHawk.Client.EmuHawk { public class PadSchema @@ -40,6 +42,10 @@ namespace BizHawk.Client.EmuHawk public object OwnerEmulator { get; set; } public Orientation Orientation { get; set; } // For Single Float controls + + // for Analog Stick controls + public ControllerDefinition.AxisRange? AxisRange { get; set; } + public ControllerDefinition.AxisRange? SecondaryAxisRange { get; set; } } } } diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs index 91bb96c84f..c40842083b 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SaturnSchema.cs @@ -175,6 +175,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema ThreeDeeController(int controller) { + var axisRanges = SaturnusControllerDeck.ThreeDeeAxisRanges; return new PadSchema { IsConsole = false, @@ -266,12 +267,8 @@ namespace BizHawk.Client.EmuHawk { Name = $"P{controller} Stick Horizontal", SecondaryNames = new[] { $"P{controller} Stick Vertical" }, - MinValue = 0, - MidValue = 127, - MaxValue = 255, - MinValueSec = 0, - MidValueSec = 127, - MaxValueSec = 255, + AxisRange = axisRanges[0], + SecondaryAxisRange = axisRanges[1], DisplayName = "", Location = new Point(6, 74), Type = PadSchema.PadInputType.AnalogStick @@ -440,6 +437,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema MissionControl(int controller) { + var axisRanges = SaturnusControllerDeck.MissionAxisRanges; return new PadSchema { DisplayName = "Mission", @@ -514,12 +512,8 @@ namespace BizHawk.Client.EmuHawk { Name = $"P{controller} Stick Horizontal", SecondaryNames = new[] { $"P{controller} Stick Vertical" }, - MinValue = 0, - MidValue = 127, - MaxValue = 255, - MinValueSec = 0, - MidValueSec = 127, - MaxValueSec = 255, + AxisRange = axisRanges[0], + SecondaryAxisRange = axisRanges[1], DisplayName = "", Location = new Point(185, 13), Type = PadSchema.PadInputType.AnalogStick @@ -541,6 +535,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema DualMissionControl(int controller) { + var axisRanges = SaturnusControllerDeck.DualMissionAxisRanges; return new PadSchema { DisplayName = "Dual Mission", @@ -552,12 +547,8 @@ namespace BizHawk.Client.EmuHawk { Name = $"P{controller} Left Stick Horizontal", SecondaryNames = new[] { $"P{controller} Left Stick Vertical" }, - MinValue = 0, - MidValue = 127, - MaxValue = 255, - MinValueSec = 0, - MidValueSec = 127, - MaxValueSec = 255, + AxisRange = axisRanges[3], + SecondaryAxisRange = axisRanges[4], DisplayName = "", Location = new Point(58, 13), Type = PadSchema.PadInputType.AnalogStick @@ -577,12 +568,8 @@ namespace BizHawk.Client.EmuHawk { Name = $"P{controller} Right Stick Horizontal", SecondaryNames = new[] { $"P{controller} Right Stick Vertical" }, - MinValue = 0, - MidValue = 127, - MaxValue = 255, - MinValueSec = 0, - MidValueSec = 127, - MaxValueSec = 255, + AxisRange = axisRanges[0], + SecondaryAxisRange = axisRanges[1], DisplayName = "", Location = new Point(400, 13), Type = PadSchema.PadInputType.AnalogStick diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs index 74808314bc..28158753f8 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs @@ -212,6 +212,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema Mouse(int controller) { + var controllerDefRanges = new SnesMouseController().Definition.FloatRanges; return new PadSchema { IsConsole = false, @@ -221,12 +222,8 @@ namespace BizHawk.Client.EmuHawk new PadSchema.ButtonSchema { Name = $"P{controller} Mouse X", - MinValue = -128, - MidValue = 0, - MaxValue = 127, - MinValueSec = 127, - MidValueSec = 0, - MaxValueSec = -128, + AxisRange = controllerDefRanges[0], + SecondaryAxisRange = controllerDefRanges[1], DisplayName = "", Location = new Point(6, 14), Type = PadSchema.PadInputType.AnalogStick diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs index 85cc5c8b4d..e7c6b71c67 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs @@ -107,6 +107,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema AnalogController(int controller) { + var controllerDefRanges = new AnalogControls(controller).Definition.FloatRanges; return new PadSchema { IsConsole = false, @@ -145,12 +146,8 @@ namespace BizHawk.Client.EmuHawk { Name = $"P{controller} Stick X", Location = new Point(2, 80), - MinValue = 127, - MidValue = 0, - MaxValue = -128, - MinValueSec = -128, - MidValueSec = 0, - MaxValueSec = 127, + AxisRange = controllerDefRanges[0], + SecondaryAxisRange = controllerDefRanges[1], Type = PadSchema.PadInputType.AnalogStick, SecondaryNames = new[] { diff --git a/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index 45fc28e4a3..984bbc66eb 100644 --- a/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using BizHawk.Common; + namespace BizHawk.Emulation.Common { /// @@ -45,7 +47,7 @@ namespace BizHawk.Emulation.Common /// Gets a list of all float ranges for each float control (must be one to one with FloatControls) /// FloatRanges include the min/max/default values /// - public List FloatRanges { get; } = new List(); + public List FloatRanges { get; set; } = new List(); /// /// Gets the axis constraints that apply artificial constraints to float values @@ -100,44 +102,50 @@ namespace BizHawk.Emulation.Common } } - public struct FloatRange + public readonly struct AxisRange { - public readonly float Min; - public readonly float Max; + public readonly bool IsReversed; - /// - /// default position - /// - public readonly float Mid; + public readonly int Max; - public FloatRange(float min, float mid, float max) + /// used as default/neutral/unset + public readonly int Mid; + + public readonly int Min; + + public Range FloatRange => ((float) Min).RangeTo(Max); + + /// maximum decimal digits analog input can occupy with no-args ToString + /// 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 Range Range => Min.RangeTo(Max); + + public AxisRange(int min, int mid, int max, bool isReversed = false) { - Min = min; - Mid = mid; + const string ReversedBoundsExceptionMessage = nameof(AxisRange) + " must not have " + nameof(max) + " < " + nameof(min) + ". pass " + nameof(isReversed) + ": true to ctor instead, or use " + nameof(CreateAxisRangePair); + if (max < min) throw new ArgumentOutOfRangeException(nameof(max), max, ReversedBoundsExceptionMessage); + IsReversed = isReversed; Max = max; + Mid = mid; + Min = min; } + } - /// for terse construction - /// length is not 3 - public static implicit operator FloatRange(float[] f) - { - if (f.Length != 3) - { - throw new ArgumentException(); - } + public static List CreateAxisRangePair(int min, int mid, int max, AxisPairOrientation pDir) => new List + { + new AxisRange(min, mid, max, ((byte) pDir & 2) != 0), + new AxisRange(min, mid, max, ((byte) pDir & 1) != 0) + }; - return new FloatRange(f[0], f[1], f[2]); - } - - /// - /// Gets maximum decimal digits analog input can occupy. Discards negative sign and possible fractional part (analog devices don't use floats anyway). - /// - public int MaxDigits() - { - return Math.Max( - Math.Abs((int)Min).ToString().Length, - Math.Abs((int)Max).ToString().Length); - } + /// represents the direction of (+, +) + /// docs of individual controllers are being collected in comments of https://github.com/TASVideos/BizHawk/issues/1200 + public enum AxisPairOrientation : byte + { + RightAndUp = 0, + RightAndDown = 1, + LeftAndUp = 2, + LeftAndDown = 3 } public enum AxisConstraintType diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs index a66018fb87..0ee2d29e96 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -121,7 +121,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 .Select(b => $"P{PortNum} " + b) .ToList(), FloatControls = { "P" + PortNum + " Paddle X 1" , "P" + PortNum + " Paddle X 2" }, - FloatRanges = { new[] { -127.0f, 0, 127.0f }, new[] { -127.0f, 0, 127.0f } } + FloatRanges = { new ControllerDefinition.AxisRange(-127, 0, 127), new ControllerDefinition.AxisRange(-127, 0, 127) } }; } @@ -238,7 +238,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 .Select(b => $"P{PortNum} " + b) .ToList(), FloatControls = { "P" + PortNum + " Wheel X 1", "P" + PortNum + " Wheel X 2" }, - FloatRanges = { new[] { -127.0f, 0, 127.0f }, new[] { -127.0f, 0, 127.0f } } + FloatRanges = { new ControllerDefinition.AxisRange(-127, 0, 127), new ControllerDefinition.AxisRange(-127, 0, 127) } }; } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllers.cs b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllers.cs index 813f492afe..4168c4ad70 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllers.cs @@ -276,7 +276,7 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk .Select(b => "P" + PortNum + " " + b) .ToList(), FloatControls = { "P" + PortNum + " X", "P" + PortNum + " Y" }, - FloatRanges = { new[] { 1.0f, 160, 320.0f }, new[] { 1.0f, 121, 242.0f } } + FloatRanges = { new ControllerDefinition.AxisRange(1, 160, 320), new ControllerDefinition.AxisRange(1, 121, 242) } }; } diff --git a/BizHawk.Emulation.Cores/Consoles/Belogic/Uzem.cs b/BizHawk.Emulation.Cores/Consoles/Belogic/Uzem.cs index b82d2d494b..3de7021fc4 100644 --- a/BizHawk.Emulation.Cores/Consoles/Belogic/Uzem.cs +++ b/BizHawk.Emulation.Cores/Consoles/Belogic/Uzem.cs @@ -65,11 +65,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Belogic { "P1 Mouse X", "P1 Mouse Y" }, - FloatRanges = - { - new[] { -127f, 0f, 127f }, - new[] { -127f, 0f, 127f } - } + FloatRanges = ControllerDefinition.CreateAxisRangePair(-127, 0, 127, ControllerDefinition.AxisPairOrientation.RightAndUp) //TODO verify direction against hardware }; private static readonly string[] PadBits = diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs index 3c1ad6ece7..f5989a2a23 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs @@ -136,7 +136,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision .Select(b => "P" + PortNum + " " + b) .ToList(), FloatControls = { "P" + PortNum + " Disc X", "P" + PortNum + " Disc Y" }, - FloatRanges = { new[] { -127.0f, 0, 127.0f }, new[] { -127.0f, 0, 127.0f } } + FloatRanges = ControllerDefinition.CreateAxisRangePair(-127, 0, 127, ControllerDefinition.AxisPairOrientation.RightAndUp) //TODO verify direction against hardware }; } @@ -241,7 +241,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision .Select(b => "P" + PortNum + " " + b) .ToList(), FloatControls = { "P" + PortNum + " Disc X", "P" + PortNum + " Disc Y" }, - FloatRanges = { new[] { -127.0f, 0, 127.0f }, new[] { -127.0f, 0, 127.0f } } + FloatRanges = ControllerDefinition.CreateAxisRangePair(-127, 0, 127, ControllerDefinition.AxisPairOrientation.RightAndUp) //TODO verify direction against hardware }; } diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllers.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllers.cs index 872442ed4b..a3545860e7 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllers.cs @@ -82,7 +82,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex .Select(b => "P" + PortNum + " " + b) .ToList(), FloatControls = { "P" + PortNum + " Stick X", "P" + PortNum + " Stick Y" }, - FloatRanges = { new[] { -128.0f, 0, 127.0f }, new[] { -128.0f, 0, 127.0f } } + FloatRanges = ControllerDefinition.CreateAxisRangePair(-128, 0, 127, ControllerDefinition.AxisPairOrientation.RightAndUp) }; } diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllers.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllers.cs index e450c0ca4d..517d568007 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllers.cs @@ -145,7 +145,7 @@ namespace BizHawk.Emulation.Cores.Intellivision .Select(b => "P" + PortNum + " " + b) .ToList(), FloatControls = { "P" + PortNum + " Disc X", "P" + PortNum + " Disc Y" }, - FloatRanges = { new[] { -127.0f, 0, 127.0f }, new[] { -127.0f, 0, 127.0f } } + FloatRanges = ControllerDefinition.CreateAxisRangePair(-127, 0, 127, ControllerDefinition.AxisPairOrientation.RightAndUp) //TODO verify direction against hardware }; } diff --git a/BizHawk.Emulation.Cores/Consoles/NEC/PCFX/TstControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/NEC/PCFX/TstControllerDeck.cs index b5a03c1e43..22344fdd8c 100644 --- a/BizHawk.Emulation.Cores/Consoles/NEC/PCFX/TstControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/NEC/PCFX/TstControllerDeck.cs @@ -140,11 +140,7 @@ namespace BizHawk.Emulation.Cores.Consoles.NEC.PCFX { BoolButtons = { "0Mouse Left", "0Mouse Right" }, FloatControls = { "0X", "0Y" }, - FloatRanges = - { - new[] { -127f, 0f, 127f }, - new[] { -127f, 0f, 127f } - } + FloatRanges = ControllerDefinition.CreateAxisRangePair(-127, 0, 127, ControllerDefinition.AxisPairOrientation.RightAndUp) //TODO verify direction against hardware }; public ControllerDefinition Definition => _definition; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/GBA.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/GBA.cs index f2733da900..f1c7fdd96e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/GBA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/GBA.cs @@ -4,6 +4,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA { public static class GBA { + private static readonly ControllerDefinition.AxisRange TiltRange = new ControllerDefinition.AxisRange(-32767, 0, 32767); + public static readonly ControllerDefinition GBAController = new ControllerDefinition { Name = "GBA Controller", @@ -13,14 +15,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA }, FloatControls = { - "Tilt X", "Tilt Y", "Tilt Z", "Light Sensor" + "Tilt X", "Tilt Y", "Tilt Z", + "Light Sensor" }, FloatRanges = { - new[] { -32767f, 0f, 32767f }, - new[] { -32767f, 0f, 32767f }, - new[] { -32767f, 0f, 32767f }, - new[] { 0f, 100f, 200f }, + TiltRange, TiltRange, TiltRange, + new ControllerDefinition.AxisRange(0, 100, 200), } }; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs index e0f1e59368..8048e71afe 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs @@ -118,7 +118,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk .Select(b => "P" + PortNum + " " + b) .ToList(), FloatControls = { "P" + PortNum + " Tilt X", "P" + PortNum + " Tilt Y" }, - FloatRanges = { new[] { -45.0f, 0, 45.0f }, new[] { -45.0f, 0, 45.0f } } + FloatRanges = ControllerDefinition.CreateAxisRangePair(-45, 0, 45, ControllerDefinition.AxisPairOrientation.RightAndUp) //TODO verify direction against hardware }; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs index 7fb31a5a36..6a792d5789 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs @@ -1,9 +1,12 @@ -using BizHawk.Emulation.Common; +using System.Collections.Generic; +using System.Linq; + +using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Nintendo.N64.NativeApi; namespace BizHawk.Emulation.Cores.Nintendo.N64 { - internal class N64Input + public class N64Input { private readonly mupen64plusInputApi _api; public CoreComm CoreComm { get; } @@ -13,6 +16,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 public bool ThisFrameInputPolled { get; set; } public ControllerDefinition ControllerDefinition => N64ControllerDefinition; + private static readonly List AnalogStickRanges = ControllerDefinition.CreateAxisRangePair(-128, 0, 127, ControllerDefinition.AxisPairOrientation.RightAndUp); + public static readonly ControllerDefinition N64ControllerDefinition = new ControllerDefinition { Name = "Nintendo 64 Controller", @@ -25,17 +30,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 { "P1 X Axis", "P1 Y Axis", }, - FloatRanges = - { - new[] {-128.0f, 0.0f, 127.0f}, - new[] {127.0f, 0.0f, -128.0f}, - new[] {-128.0f, 0.0f, 127.0f}, - new[] {127.0f, 0.0f, -128.0f}, - new[] {-128.0f, 0.0f, 127.0f}, - new[] {127.0f, 0.0f, -128.0f}, - new[] {-128.0f, 0.0f, 127.0f}, - new[] {127.0f, 0.0f, -128.0f} - }, + FloatRanges = AnalogStickRanges.Concat(AnalogStickRanges).Concat(AnalogStickRanges).Concat(AnalogStickRanges).ToList(), //TODO is this supposed to be duplicated? docs say FloatRanges.Count should equal FloatControls.Count --yoshi AxisConstraints = { new ControllerDefinition.AxisConstraint { Class = "Natural Circle", Type = ControllerDefinition.AxisConstraintType.Circular, Params = new object[] {"P1 X Axis", "P1 Y Axis", 127.0f} } @@ -44,7 +39,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 private readonly IInputPollable _emuCore; - public N64Input(IInputPollable emuCore, mupen64plusApi core, CoreComm comm, N64SyncSettings.N64ControllerSettings[] controllerSettings) + internal N64Input(IInputPollable emuCore, mupen64plusApi core, CoreComm comm, N64SyncSettings.N64ControllerSettings[] controllerSettings) { _emuCore = emuCore; _api = new mupen64plusInputApi(core); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs index 4c20eb580e..6d9fa22f8f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -171,7 +171,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES if (using_reset_timing && ControllerDefinition.FloatControls.Count == 0) { ControllerDefinition.FloatControls.Add("Reset Cycle"); - ControllerDefinition.FloatRanges.Add(new ControllerDefinition.FloatRange(0, 0, 500000)); + ControllerDefinition.FloatRanges.Add(new ControllerDefinition.AxisRange(0, 0, 500000)); } // don't replace the magicSoundProvider on reset, as it's not needed diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs index 76c0eda438..88a1304cc1 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs @@ -185,6 +185,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES Right.SyncState(ser); ser.EndSection(); } + + internal static readonly ControllerDefinition.AxisRange ArkanoidPaddleRange = new ControllerDefinition.AxisRange(0, 80, 160); + + internal static readonly List ZapperRanges = new List { new ControllerDefinition.AxisRange(0, 128, 255), new ControllerDefinition.AxisRange(0, 120, 239) }; } public class UnpluggedNES : INesPort @@ -392,7 +396,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { BoolButtons = { "0Fire" }, FloatControls = { "0Paddle" }, - FloatRanges = { new[] { 0.0f, 80.0f, 160.0f } } + FloatRanges = { NesDeck.ArkanoidPaddleRange } }; public void Strobe(StrobeInfo s, IController c) @@ -557,7 +561,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { BoolButtons = { "0Fire" }, FloatControls = { "0Zapper X", "0Zapper Y" }, - FloatRanges = { new[] { 0.0f, 128.0f, 255.0f }, new[] { 0.0f, 120.0f, 239.0f } } + FloatRanges = NesDeck.ZapperRanges }; public void Strobe(StrobeInfo s, IController c) @@ -610,7 +614,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { BoolButtons = { "0Fire" }, FloatControls = { "0Zapper X", "0Zapper Y" }, - FloatRanges = { new[] { 0.0f, 128.0f, 255.0f }, new[] { 0.0f, 120.0f, 239.0f } } + FloatRanges = NesDeck.ZapperRanges }; void Latch(IController c) @@ -752,7 +756,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { BoolButtons = { "0Fire" }, FloatControls = { "0Paddle" }, - FloatRanges = { new[] { 0.0f, 80.0f, 160.0f } } + FloatRanges = { NesDeck.ArkanoidPaddleRange } }; public void Strobe(StrobeInfo s, IController c) @@ -1012,7 +1016,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { BoolButtons = { "0Click", "0Touch" }, FloatControls = { "0Pen X", "0Pen Y" }, - FloatRanges = { new[] { 0.0f, 128.0f, 255.0f }, new[] { 0.0f, 120.0f, 239.0f } } + FloatRanges = NesDeck.ZapperRanges // why would a tablet have the same resolution as a CRT monitor? --yoshi }; bool resetting; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs index f878fb43b8..7fd223d0ed 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs @@ -20,6 +20,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES Payload } + /// + /// problem: when you're in 240 line mode, the limit on Y needs to be 240. when you're in 224 mode, it needs to be 224. + /// perhaps the deck needs to account for this... + /// for reference Snes9x is always in 224 mode + /// + public static readonly List LightGunRanges = new List { new ControllerDefinition.AxisRange(0, 128, 256), new ControllerDefinition.AxisRange(0, 0, 240) }; + private static ILibsnesController Factory(ControllerType t, LibsnesCore.SnesSyncSettings ss) { switch (t) @@ -284,11 +291,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES "0Mouse X", "0Mouse Y" }, - FloatRanges = - { - new[] { -127f, 0f, 127f }, - new[] { -127f, 0f, 127f } - } + FloatRanges = ControllerDefinition.CreateAxisRangePair(-127, 0, 127, ControllerDefinition.AxisPairOrientation.RightAndUp) //TODO verify direction against hardware }; public ControllerDefinition Definition => _definition; @@ -343,13 +346,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES "0Scope X", "0Scope Y" }, - FloatRanges = - { - // problem: when you're in 240 line mode, the limit on Y needs to be 240. - // when you're in 224 mode, it needs to be 224. perhaps the deck needs to account for this... - new[] { 0f, 128f, 256f }, - new[] { 0f, 0f, 240f } - } + FloatRanges = LibsnesControllerDeck.LightGunRanges }; public ControllerDefinition Definition => _definition; @@ -398,15 +395,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES "1Justifier X", "1Justifier Y", }, - FloatRanges = - { - // problem: when you're in 240 line mode, the limit on Y needs to be 240. - // when you're in 224 mode, it needs to be 224. perhaps the deck needs to account for this... - new[] { 0f, 128f, 256f }, - new[] { 0f, 0f, 240f }, - new[] { 0f, 128f, 256f }, - new[] { 0f, 0f, 240f } - } + FloatRanges = LibsnesControllerDeck.LightGunRanges.Concat(LibsnesControllerDeck.LightGunRanges).ToList() }; public ControllerDefinition Definition => _definition; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs index 1b862a7399..693eeb9ae8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs @@ -214,11 +214,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X "0Mouse X", "0Mouse Y" }, - FloatRanges = - { - new[] { -127f, 0f, 127f }, - new[] { -127f, 0f, 127f } - } + FloatRanges = ControllerDefinition.CreateAxisRangePair(-127, 0, 127, ControllerDefinition.AxisPairOrientation.RightAndUp) //TODO verify direction against hardware }; public override ControllerDefinition Definition => _definition; @@ -240,12 +236,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X "0Scope X", "0Scope Y" }, - FloatRanges = - { - // snes9x is always in 224 mode - new[] { 0f, 128f, 256f }, - new[] { 0f, 0f, 240f } - } + FloatRanges = SNES.LibsnesControllerDeck.LightGunRanges }; public override ControllerDefinition Definition => _definition; @@ -265,12 +256,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X "0Justifier X", "0Justifier Y", }, - FloatRanges = - { - // snes9x is always in 224 mode - new[] { 0f, 128f, 256f }, - new[] { 0f, 0f, 240f }, - } + FloatRanges = SNES.LibsnesControllerDeck.LightGunRanges }; public override ControllerDefinition Definition => _definition; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs index 65744e8f7f..478204326e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs @@ -44,7 +44,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubGBHawk ser.Register(_tracer); _GBCore.ControllerDefinition.FloatControls.Add("Input Cycle"); - _GBCore.ControllerDefinition.FloatRanges.Add(new ControllerDefinition.FloatRange(0, 70224, 70224)); + _GBCore.ControllerDefinition.FloatRanges.Add(new ControllerDefinition.AxisRange(0, 70224, 70224)); } public GBHawk.GBHawk _GBCore; diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IEmulator.cs index d5a790e844..aa5c80d230 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IEmulator.cs @@ -25,7 +25,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem return SMSPaddleController; case SmsSyncSettings.ControllerTypes.LightPhaser: // scale the vertical to the display mode - SMSLightPhaserController.FloatRanges[1] = new ControllerDefinition.FloatRange(0, Vdp.FrameHeight / 2, Vdp.FrameHeight - 1); + SMSLightPhaserController.FloatRanges[1] = new ControllerDefinition.AxisRange(0, Vdp.FrameHeight / 2, Vdp.FrameHeight - 1); return SMSLightPhaserController; case SmsSyncSettings.ControllerTypes.SportsPad: diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.Input.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.Input.cs index fcb2fd00b4..cfd99e1316 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.Input.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.Input.cs @@ -1,4 +1,7 @@ -using BizHawk.Emulation.Common; +using System.Collections.Generic; +using System.Linq; + +using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Sega.MasterSystem { @@ -41,8 +44,8 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem }, FloatRanges = { - new ControllerDefinition.FloatRange(0, 128, 255), - new ControllerDefinition.FloatRange(0, 128, 255) + new ControllerDefinition.AxisRange(0, 128, 255), + new ControllerDefinition.AxisRange(0, 128, 255) } }; @@ -60,11 +63,14 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem }, FloatRanges = { - new ControllerDefinition.FloatRange(0, 64, 127), - new ControllerDefinition.FloatRange(0, 500, 1000) + new ControllerDefinition.AxisRange(0, 64, 127), + new ControllerDefinition.AxisRange(0, 500, 1000) } }; + /// TODO verify direction against hardware + private static readonly List SportsPadTrackballRanges = ControllerDefinition.CreateAxisRangePair(-64, 0, 63, ControllerDefinition.AxisPairOrientation.RightAndUp); + public static readonly ControllerDefinition SMSSportsPadController = new ControllerDefinition { Name = "SMS Sports Pad Controller", @@ -79,13 +85,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem "P1 X", "P1 Y", "P2 X", "P2 Y" }, - FloatRanges = - { - new ControllerDefinition.FloatRange(-64, 0, 63), - new ControllerDefinition.FloatRange(-64, 0, 63), - new ControllerDefinition.FloatRange(-64, 0, 63), - new ControllerDefinition.FloatRange(-64, 0, 63) - } + FloatRanges = SportsPadTrackballRanges.Concat(SportsPadTrackballRanges).ToList() }; public static readonly ControllerDefinition SMSKeyboardController = new ControllerDefinition diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/SaturnusControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/SaturnusControllerDeck.cs index 176b5cf8ab..de7b534499 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/SaturnusControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/SaturnusControllerDeck.cs @@ -61,6 +61,17 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn return _data; } + /// TODO verify direction against hardware + private static readonly List AnalogStickRanges = CreateAxisRangePair(0, 128, 255, AxisPairOrientation.RightAndDown); + + private static readonly AxisRange MiscAxisRange = new AxisRange(0, 128, 255); + + public static readonly List MissionAxisRanges = AnalogStickRanges.Concat(new List { MiscAxisRange }).ToList(); + + public static readonly List DualMissionAxisRanges = MissionAxisRanges.Concat(MissionAxisRanges).ToList(); + + public static readonly List ThreeDeeAxisRanges = AnalogStickRanges.Concat(new List { new AxisRange(0, 0, 255), new AxisRange(0, 0, 255) }).ToList(); + public enum Device { None, @@ -95,8 +106,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn private abstract class ButtonedDevice : IDevice { - private static readonly FloatRange AnalogFloatRange = new FloatRange(0, 128, 255); - protected ButtonedDevice() { _bakedButtonNames = ButtonNames.Select(s => s != null ? "0" + s : null).ToArray(); @@ -115,7 +124,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn .Select((s, i) => new { s, i }) .OrderBy(a => AnalogOrdinal(AnalogNames[a.i])) .Select(a => a.s)); - Definition.FloatRanges.AddRange(_bakedAnalogNames.Select(s => AnalogFloatRange)); + Definition.FloatRanges.AddRange(_bakedAnalogNames.Select(s => MiscAxisRange)); } private readonly string[] _bakedButtonNames; @@ -233,8 +242,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn public ThreeDeeGamepad() { - Definition.FloatRanges[2] = new FloatRange(0, 0, 255); - Definition.FloatRanges[3] = new FloatRange(0, 0, 255); + Definition.FloatRanges = ThreeDeeAxisRanges; } public override void Update(IController controller, byte[] dest, int offset) @@ -358,6 +366,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn protected override string[] AnalogNames => _analogNames; protected override int AnalogByteOffset => 4; + public Mission() + { + Definition.FloatRanges = MissionAxisRanges; + } + protected override int ButtonOrdinal(string name) { switch (name) @@ -397,6 +410,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn }; protected override string[] AnalogNames => _analogNames; + + public DualMission() + { + Definition.FloatRanges = DualMissionAxisRanges; + } } private class Keyboard : ButtonedDevice diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs index 5b7cde8d0a..65b6136d11 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs @@ -93,12 +93,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx new CName("XE E2", LibGPGX.INPUT_KEYS.INPUT_XE_E2), }; - private static readonly ControllerDefinition.FloatRange MouseRange = new ControllerDefinition.FloatRange(-256, 0, 255); + private static readonly ControllerDefinition.AxisRange MouseRange = new ControllerDefinition.AxisRange(-256, 0, 255); // lightgun needs to be transformed to match the current screen resolution - private static readonly ControllerDefinition.FloatRange LightgunRange = new ControllerDefinition.FloatRange(0, 5000, 10000); + private static readonly ControllerDefinition.AxisRange LightgunRange = new ControllerDefinition.AxisRange(0, 5000, 10000); - private static readonly ControllerDefinition.FloatRange Xea1PRange = new ControllerDefinition.FloatRange(-128, 0, 127); + private static readonly ControllerDefinition.AxisRange Xea1PRange = new ControllerDefinition.AxisRange(-128, 0, 127); private LibGPGX.InputData _target; private IController _source; diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSP/PSP.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSP/PSP.cs index 4c636a5b68..aa8bc8a6a1 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSP/PSP.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSP/PSP.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using BizHawk.Emulation.Common; @@ -40,6 +41,12 @@ namespace BizHawk.Emulation.Cores.Sony.PSP attachedcore = this; } + /// TODO + private static readonly List AnalogStickRanges = ControllerDefinition.CreateAxisRangePair(-1, 0, 1, ControllerDefinition.AxisPairOrientation.RightAndUp); + + /// TODO + private static readonly ControllerDefinition.AxisRange TriggerRange = new ControllerDefinition.AxisRange(-1, 0, 1); + public static readonly ControllerDefinition PSPController = new ControllerDefinition { Name = "PSP Controller", @@ -51,17 +58,12 @@ namespace BizHawk.Emulation.Cores.Sony.PSP }, FloatControls = { - "Left Stick X", "Left Stick Y", "Right Stick X", "Right Stick Y", "Left Trigger", "Right Trigger" + "Left Stick X", "Left Stick Y", + "Right Stick X", "Right Stick Y", + "Left Trigger", + "Right Trigger" }, - FloatRanges = // TODO - { - new[] {-1.0f, 0.0f, 1.0f}, - new[] {-1.0f, 0.0f, 1.0f}, - new[] {-1.0f, 0.0f, 1.0f}, - new[] {-1.0f, 0.0f, 1.0f}, - new[] {-1.0f, 0.0f, 1.0f}, - new[] {-1.0f, 0.0f, 1.0f}, - } + FloatRanges = AnalogStickRanges.Concat(AnalogStickRanges).Concat(new List { TriggerRange, TriggerRange }).ToList() }; public ControllerDefinition ControllerDefinition => PSPController; diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs index f1ebdccb54..3ceb4575c0 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs @@ -15,6 +15,7 @@ using System.ComponentModel; using System.Runtime.InteropServices; using System.IO; using System.Collections.Generic; +using System.Linq; using System.Text; using Newtonsoft.Json; @@ -216,6 +217,8 @@ namespace BizHawk.Emulation.Cores.Sony.PSX public string SystemId => "PSX"; + public static readonly IReadOnlyList DualShockStickRanges = ControllerDefinition.CreateAxisRangePair(0, 128, 255, ControllerDefinition.AxisPairOrientation.RightAndDown); + public static ControllerDefinition CreateControllerDefinition(SyncSettings syncSettings) { var definition = new ControllerDefinition { Name = "PSX Front Panel" }; @@ -249,10 +252,11 @@ namespace BizHawk.Emulation.Cores.Sony.PSX "P" + pnum + " L" }); - definition.FloatRanges.Add(new[] { 0.0f, 128.0f, 255.0f }); - definition.FloatRanges.Add(new[] { 0.0f, 128.0f, 255.0f }); - definition.FloatRanges.Add(new[] { 0.0f, 128.0f, 255.0f }); - definition.FloatRanges.Add(new[] { 0.0f, 128.0f, 255.0f }); + var axisRange = new ControllerDefinition.AxisRange(0, 128, 255); + definition.FloatRanges.Add(axisRange); + definition.FloatRanges.Add(axisRange); + definition.FloatRanges.Add(axisRange); + definition.FloatRanges.Add(axisRange); } else { @@ -289,10 +293,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX "P" + pnum + " RStick Y" }); - definition.FloatRanges.Add(new[] { 0.0f, 128.0f, 255.0f }); - definition.FloatRanges.Add(new[] { 255.0f, 128.0f, 0.0f }); - definition.FloatRanges.Add(new[] { 0.0f, 128.0f, 255.0f }); - definition.FloatRanges.Add(new[] { 255.0f, 128.0f, 0.0f }); + definition.FloatRanges.AddRange(DualShockStickRanges.Concat(DualShockStickRanges).ToList()); } } } @@ -307,9 +308,9 @@ namespace BizHawk.Emulation.Cores.Sony.PSX definition.FloatControls.Add("Disc Select"); definition.FloatRanges.Add( - //new[] {-1f,-1f,-1f} //this is carefully chosen so that we end up with a -1 disc by default (indicating that it's never been set) + //new ControllerDefinition.AxisRange(-1, -1, -1) //this is carefully chosen so that we end up with a -1 disc by default (indicating that it's never been set) //hmm.. I don't see why this wouldn't work - new[] { 0f, 1f, 1f } + new ControllerDefinition.AxisRange(0, 1, 1) ); return definition; diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs index 15e764e7ab..a5db111597 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs @@ -260,8 +260,7 @@ namespace BizHawk.Emulation.Cores.Libretro definition.BoolButtons.Add("Pointer Pressed"); //TODO: this isnt showing up in the binding panel. I don't want to find out why. definition.FloatControls.Add("Pointer X"); definition.FloatControls.Add("Pointer Y"); - definition.FloatRanges.Add(new ControllerDefinition.FloatRange(-32767, 0, 32767)); - definition.FloatRanges.Add(new ControllerDefinition.FloatRange(-32767, 0, 32767)); + definition.FloatRanges.AddRange(ControllerDefinition.CreateAxisRangePair(-32767, 0, 32767, ControllerDefinition.AxisPairOrientation.RightAndUp)); foreach (var key in new[]{ "Key Backspace", "Key Tab", "Key Clear", "Key Return", "Key Pause", "Key Escape",