From 6cb60aa9fdca7e851f359559405f13b0c8ffd5fd Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 22 Jun 2020 06:38:57 +1000 Subject: [PATCH] Merge AxisControls, AxisRanges, and AxisConstraints into a single dict --- src/BizHawk.Client.Common/Controller.cs | 6 +- .../display/IInputDisplayGenerator.cs | 7 +- .../inputAdapters/InputManager.cs | 2 +- .../movie/bk2/Bk2Controller.cs | 8 +- .../movie/bk2/Bk2LogEntryGenerator.cs | 8 +- .../movie/import/DsmImport.cs | 7 +- .../movie/tasproj/TasMovie.cs | 2 +- .../Api/Libraries/JoypadApi.cs | 2 +- .../config/ControllerConfig.cs | 4 +- .../tools/Lua/Libraries/TAStudioLuaLibrary.cs | 2 +- .../tools/Macros/MacroInput.ButtonSelect.cs | 8 +- .../tools/Macros/MovieZone.cs | 15 +-- .../tools/TAStudio/PatternsForm.cs | 8 +- .../tools/TAStudio/TAStudio.ListView.cs | 22 ++-- .../tools/TAStudio/TAStudio.cs | 10 +- .../tools/TAStudio/TAStudioClipboard.cs | 2 +- .../tools/VirtualPads/VirtualpadsTool.cs | 6 +- .../tools/VirtualPads/schema/ColecoSchema.cs | 6 +- .../tools/VirtualPads/schema/IntvSchema.cs | 6 +- .../tools/VirtualPads/schema/SnesSchema.cs | 6 +- .../tools/VirtualPads/schema/VECSchema.cs | 6 +- .../ControllerDefinition.cs | 109 +++++++++++++----- .../ControllerDefinitionMerger.cs | 9 +- src/BizHawk.Emulation.Common/Extensions.cs | 53 ++++----- .../SaveController.cs | 2 +- .../Atari/2600/Atari2600ControllerDeck.cs | 7 +- .../Atari/2600/Atari2600Controllers.cs | 20 ++-- .../A7800Hawk/A7800HawkControllerDeck.cs | 7 +- .../Atari/A7800Hawk/A7800HawkControllers.cs | 4 +- .../Consoles/Coleco/ColecoControllerDeck.cs | 7 +- .../Consoles/Coleco/ColecoControllers.cs | 16 +-- .../GCE/Vectrex/VectrexHawkControllerDeck.cs | 7 +- .../IntellivisionControllerDeck.cs | 7 +- .../Controllers/IntellivisionControllers.cs | 4 +- .../Magnavox/Odyssey2/O2HawkControllerDeck.cs | 4 +- .../Nintendo/GBHawk/GBHawkControllerDeck.cs | 4 +- .../Nintendo/GBHawk/GBHawkControllers.cs | 4 +- .../Consoles/Nintendo/N64/N64.ISettable.cs | 24 ++-- .../Consoles/Nintendo/NES/NES.Core.cs | 5 +- .../Consoles/Nintendo/NES/NESControllers.cs | 20 +--- .../Consoles/Nintendo/SNES9X/Snes9x.cs | 2 +- .../Consoles/Nintendo/SubGBHawk/SubGBHawk.cs | 3 +- .../Consoles/PC Engine/PceControllerDeck.cs | 17 +-- .../Consoles/Sega/SMS/SMS.IEmulator.cs | 7 +- .../Consoles/Sega/SMS/SMS.Input.cs | 13 +-- .../Consoles/Sony/PSX/Octoshock.cs | 24 +--- .../Waterbox/NymaCore.Controller.cs | 33 ++---- 47 files changed, 259 insertions(+), 296 deletions(-) diff --git a/src/BizHawk.Client.Common/Controller.cs b/src/BizHawk.Client.Common/Controller.cs index 7e1f815f90..7fe0411e77 100644 --- a/src/BizHawk.Client.Common/Controller.cs +++ b/src/BizHawk.Client.Common/Controller.cs @@ -12,10 +12,10 @@ namespace BizHawk.Client.Common public Controller(ControllerDefinition definition) { Definition = definition; - for (int i = 0; i < Definition.AxisControls.Count; i++) + foreach (var kvp in Definition.Axes) { - _axes[Definition.AxisControls[i]] = Definition.AxisRanges[i].Mid; - _axisRanges[Definition.AxisControls[i]] = Definition.AxisRanges[i]; + _axes[kvp.Key] = kvp.Value.Range.Mid; + _axisRanges[kvp.Key] = kvp.Value.Range; } } diff --git a/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs b/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs index 528de1bef5..685c1611db 100644 --- a/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs +++ b/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs @@ -37,14 +37,11 @@ namespace BizHawk.Client.Common { foreach (var button in group) { - if (_source.Definition.AxisControls.Contains(button)) + if (_source.Definition.Axes.TryGetValue(button, out var range)) { - int i = _source.Definition.AxisControls.IndexOf(button); - var mid = _source.Definition.AxisRanges[i].Mid; - var val = (int)_source.AxisValue(button); - if (val == mid) + if (val == range.Range.Mid) { sb.Append(" "); } diff --git a/src/BizHawk.Client.Common/inputAdapters/InputManager.cs b/src/BizHawk.Client.Common/inputAdapters/InputManager.cs index eccf2f3cf8..13d3dc9267 100644 --- a/src/BizHawk.Client.Common/inputAdapters/InputManager.cs +++ b/src/BizHawk.Client.Common/inputAdapters/InputManager.cs @@ -89,7 +89,7 @@ namespace BizHawk.Client.Common if (analogBinds.TryGetValue(def.Name, out var aBinds)) { - foreach (var btn in def.AxisControls) + foreach (var btn in def.Axes.Keys) { if (aBinds.TryGetValue(btn, out var bind)) { diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs index d472862570..10315d8579 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs @@ -36,7 +36,7 @@ namespace BizHawk.Client.Common { Name = c, IsBool = _type.BoolButtons.Contains(c), - IsAxis = _type.AxisControls.Contains(c) + IsAxis = _type.Axes.ContainsKey(c) }) .ToList(); } @@ -53,7 +53,7 @@ namespace BizHawk.Client.Common _myBoolButtons[button] = source.IsPressed(button); } - foreach (var name in Definition.AxisControls) + foreach (var name in Definition.Axes.Keys) { _myAxisControls[name] = source.AxisValue(name); } @@ -67,9 +67,9 @@ namespace BizHawk.Client.Common } // axes don't have sticky logic, so latch default value - for (int i = 0; i < Definition.AxisControls.Count; i++) + foreach (var kvp in Definition.Axes) { - _myAxisControls[Definition.AxisControls[i]] = Definition.AxisRanges[i].Mid; + _myAxisControls[kvp.Key] = kvp.Value.Range.Mid; } } diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index 8f22b6c66b..08af150c8a 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -51,7 +51,7 @@ namespace BizHawk.Client.Common { dict.Add(button, Bk2MnemonicLookup.Lookup(button, _systemId).ToString()); } - else if (_source.Definition.AxisControls.Contains(button)) + else if (_source.Definition.Axes.ContainsKey(button)) { dict.Add(button, Bk2MnemonicLookup.LookupAxis(button, _systemId)); } @@ -73,15 +73,13 @@ namespace BizHawk.Client.Common { foreach (var button in group) { - if (_source.Definition.AxisControls.Contains(button)) + if (_source.Definition.Axes.TryGetValue(button, out var range)) { int val; - int i = _source.Definition.AxisControls.IndexOf(button); - var mid = _source.Definition.AxisRanges[i].Mid; if (createEmpty) { - val = mid; + val = range.Range.Mid; } else { diff --git a/src/BizHawk.Client.Common/movie/import/DsmImport.cs b/src/BizHawk.Client.Common/movie/import/DsmImport.cs index ccc88e8e83..ddfed42262 100644 --- a/src/BizHawk.Client.Common/movie/import/DsmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/DsmImport.cs @@ -88,14 +88,9 @@ namespace BizHawk.Client.Common "Right", "Left", "Down", "Up", "Start", "Select", "B", "A", "X", "Y", "L", "R", "LidOpen", "LidClose", "Touch" } - } + }.AddXYPair("Touch{0}", ControllerDefinition.AxisPairOrientation.RightAndUp, (0, 128, 255), (0, 96, 191)) //TODO verify direction against hardware }; - controller.Definition.AxisControls.Add("TouchX"); - controller.Definition.AxisRanges.Add(new ControllerDefinition.AxisRange(0, 128, 255)); - controller.Definition.AxisControls.Add("TouchY"); - controller.Definition.AxisRanges.Add(new ControllerDefinition.AxisRange(0, 96, 191)); - controller["LidOpen"] = false; controller["LidOpen"] = false; diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 59041ccfb9..14cc82eb6d 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -146,7 +146,7 @@ namespace BizHawk.Client.Common : ""; } - if (adapter.Definition.AxisControls.Contains(buttonName)) + if (adapter.Definition.Axes.ContainsKey(buttonName)) { return adapter.AxisValue(buttonName).ToString(); } diff --git a/src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs b/src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs index 01b377f754..2a3d3569a8 100644 --- a/src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs +++ b/src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs @@ -39,7 +39,7 @@ namespace BizHawk.Client.EmuHawk return; } foreach (var button in controller.Definition.BoolButtons) GlobalWin.InputManager.ButtonOverrideAdapter.SetButton(button, controller.IsPressed(button)); - foreach (var axis in controller.Definition.AxisControls) GlobalWin.InputManager.ButtonOverrideAdapter.SetAxis(axis, controller.AxisValue(axis)); + foreach (var axis in controller.Definition.Axes.Keys) GlobalWin.InputManager.ButtonOverrideAdapter.SetAxis(axis, controller.AxisValue(axis)); } public void Set(Dictionary buttons, int? controller = null) diff --git a/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs b/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs index 46ba6f42d6..341ffdcc0c 100644 --- a/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs @@ -90,7 +90,7 @@ namespace BizHawk.Client.EmuHawk private static readonly Regex ButtonMatchesPlayer = new Regex("^P(\\d+)\\s"); - private void LoadToPanel(Control dest, string controllerName, IList controllerButtons, Dictionary categoryLabels, IDictionary> settingsBlock, T defaultValue, PanelCreator createPanel) + private void LoadToPanel(Control dest, string controllerName, IReadOnlyCollection controllerButtons, Dictionary categoryLabels, IDictionary> settingsBlock, T defaultValue, PanelCreator createPanel) { if (!settingsBlock.TryGetValue(controllerName, out var settings)) { @@ -193,7 +193,7 @@ namespace BizHawk.Client.EmuHawk { LoadToPanel(NormalControlsTab, _emulator.ControllerDefinition.Name, _emulator.ControllerDefinition.BoolButtons, _emulator.ControllerDefinition.CategoryLabels, normal, "", CreateNormalPanel); LoadToPanel(AutofireControlsTab, _emulator.ControllerDefinition.Name, _emulator.ControllerDefinition.BoolButtons, _emulator.ControllerDefinition.CategoryLabels, autofire, "", CreateNormalPanel); - LoadToPanel(AnalogControlsTab, _emulator.ControllerDefinition.Name, _emulator.ControllerDefinition.AxisControls, _emulator.ControllerDefinition.CategoryLabels, analog, new AnalogBind("", 1.0f, 0.1f), CreateAnalogPanel); + LoadToPanel(AnalogControlsTab, _emulator.ControllerDefinition.Name, _emulator.ControllerDefinition.Axes.Keys.ToList(), _emulator.ControllerDefinition.CategoryLabels, analog, new AnalogBind("", 1.0f, 0.1f), CreateAnalogPanel); if (AnalogControlsTab.Controls.Count == 0) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index 7e5762a826..602a35d612 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -385,7 +385,7 @@ namespace BizHawk.Client.EmuHawk table[button] = controller.IsPressed(button); } - foreach (var button in controller.Definition.AxisControls) + foreach (var button in controller.Definition.Axes.Keys) { table[button] = controller.AxisValue(button); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.ButtonSelect.cs b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.ButtonSelect.cs index e3a926a5bb..9bae454334 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.ButtonSelect.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.ButtonSelect.cs @@ -10,18 +10,18 @@ namespace BizHawk.Client.EmuHawk private void SetUpButtonBoxes() { var def = Emulator.ControllerDefinition; - int count = def.BoolButtons.Count + def.AxisControls.Count; + int count = def.BoolButtons.Count + def.Axes.Count; _buttonBoxes = new CheckBox[count]; - for (int i = 0; i < def.AxisControls.Count; i++) + for (int i = 0; i < def.Axes.Count; i++) { - var box = new CheckBox { Text = def.AxisControls[i] }; + var box = new CheckBox { Text = def.Axes[i] }; _buttonBoxes[i] = box; } for (int i = 0; i < def.BoolButtons.Count; i++) { var box = new CheckBox { Text = def.BoolButtons[i] }; - _buttonBoxes[i + def.AxisControls.Count] = box; + _buttonBoxes[i + def.Axes.Count] = box; } foreach (var box in _buttonBoxes) diff --git a/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs b/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs index e2b080e803..e6fee9aa8f 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs @@ -49,9 +49,7 @@ namespace BizHawk.Client.EmuHawk } else { - d.AxisControls.Add(k); - int rangeIndex = _emulator.ControllerDefinition.AxisControls.IndexOf(k); - d.AxisRanges.Add(_emulator.ControllerDefinition.AxisRanges[rangeIndex]); + d.Axes.Add(k, _emulator.ControllerDefinition.Axes[k]); } } @@ -104,7 +102,7 @@ namespace BizHawk.Client.EmuHawk } else { - d.AxisControls.Add(key); + d.Axes.Add(key, _emulator.ControllerDefinition.Axes[key]); } } @@ -268,7 +266,7 @@ namespace BizHawk.Client.EmuHawk } else { - d.AxisControls.Add(k); + d.Axes.Add(k, _emulator.ControllerDefinition.Axes[key]); } } @@ -282,7 +280,7 @@ namespace BizHawk.Client.EmuHawk latching.SetBool(button, source.IsPressed(button)); } - foreach (string name in source.Definition.AxisControls) + foreach (string name in source.Definition.Axes.Keys) { latching.SetAxis(name, source.AxisValue(name)); } @@ -295,11 +293,10 @@ namespace BizHawk.Client.EmuHawk latching.SetBool(button, latching.IsPressed(button) | source.IsPressed(button)); } - foreach (string name in latching.Definition.AxisControls) + foreach (string name in latching.Definition.Axes.Keys) { var axisValue = source.AxisValue(name); - int indexRange = source.Definition.AxisControls.IndexOf(name); - if (axisValue == source.Definition.AxisRanges[indexRange].Mid) + if (axisValue == source.Definition.Axes[name].Range.Mid) { latching.SetAxis(name, axisValue); } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/PatternsForm.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/PatternsForm.cs index 0a7855d42f..7489f2b2f2 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/PatternsForm.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/PatternsForm.cs @@ -30,7 +30,7 @@ namespace BizHawk.Client.EmuHawk ButtonBox.Items.Add(button); } - foreach (var button in _tastudio.MovieSession.MovieController.Definition.AxisControls) + foreach (var button in _tastudio.MovieSession.MovieController.Definition.Axes.Keys) { ButtonBox.Items.Add(button); } @@ -203,7 +203,7 @@ namespace BizHawk.Client.EmuHawk } else { - index = _tastudio.MovieSession.MovieController.Definition.AxisControls.IndexOf(SelectedButton); + index = _tastudio.MovieSession.MovieController.Definition.Axes.IndexOf(SelectedButton); } LagBox.Checked = _tastudio.AxisPatterns[index].SkipsLag; @@ -249,7 +249,7 @@ namespace BizHawk.Client.EmuHawk } else { - index = _tastudio.MovieSession.MovieController.Definition.AxisControls.IndexOf(SelectedButton); + index = _tastudio.MovieSession.MovieController.Definition.Axes.IndexOf(SelectedButton); } var p = new List(); @@ -311,7 +311,7 @@ namespace BizHawk.Client.EmuHawk } else { - index = _tastudio.MovieSession.MovieController.Definition.AxisControls.IndexOf(SelectedButton); + index = _tastudio.MovieSession.MovieController.Definition.Axes.IndexOf(SelectedButton); } var p = _tastudio.AxisPatterns[index].Pattern; diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index 0bcd81b99a..89be7e9c97 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -358,9 +358,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 - ControllerDefinition.AxisRange range = ControllerType.AxisRanges - [ControllerType.AxisControls.IndexOf(columnName)]; - if (text == ((float) range.Mid).ToString()) + if (text == ((float) ControllerType.Axes[columnName].Range.Mid).ToString()) { text = ""; } @@ -487,11 +485,11 @@ namespace BizHawk.Client.EmuHawk { if (index == 0) { - index = ControllerType.AxisControls.IndexOf(button); + index = ControllerType.Axes.IndexOf(button); } else { - index += ControllerType.AxisControls.Count - 1; + index += ControllerType.Axes.Count - 1; } int? value = null; @@ -690,8 +688,8 @@ namespace BizHawk.Client.EmuHawk if (applyPatternToPaintedInputToolStripMenuItem.Checked && (!onlyOnAutoFireColumnsToolStripMenuItem.Checked || TasView.CurrentCell.Column.Emphasis)) { - AxisPatterns[ControllerType.AxisControls.IndexOf(buttonName)].Reset(); - CurrentTasMovie.SetAxisState(frame, buttonName, AxisPatterns[ControllerType.AxisControls.IndexOf(buttonName)].GetNextValue()); + AxisPatterns[ControllerType.Axes.IndexOf(buttonName)].Reset(); + CurrentTasMovie.SetAxisState(frame, buttonName, AxisPatterns[ControllerType.Axes.IndexOf(buttonName)].GetNextValue()); _patternPaint = true; } else @@ -1173,7 +1171,7 @@ namespace BizHawk.Client.EmuHawk } else { - setVal = AxisPatterns[ControllerType.AxisControls.IndexOf(_startAxisDrawColumn)].GetNextValue(); + setVal = AxisPatterns[ControllerType.Axes.IndexOf(_startAxisDrawColumn)].GetNextValue(); } } @@ -1203,7 +1201,7 @@ namespace BizHawk.Client.EmuHawk return; } - var value = (_axisPaintState + increment).ConstrainWithin(ControllerType.AxisRanges[ControllerType.AxisControls.IndexOf(_axisEditColumn)].Range); + var value = (_axisPaintState + increment).ConstrainWithin(ControllerType.Axes[_axisEditColumn].Range.Range); CurrentTasMovie.SetAxisState(_axisEditRow, _axisEditColumn, value); _axisTypedValue = value.ToString(); @@ -1276,13 +1274,13 @@ namespace BizHawk.Client.EmuHawk float prev = value; string prevTyped = _axisTypedValue; - var range = ControllerType.AxisRanges[ControllerType.AxisControls.IndexOf(_axisEditColumn)]; - var (rMin, rMax) = range.FloatRange; + var range = ControllerType.Axes[_axisEditColumn]; + var (rMin, rMax) = range.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.Range.MaxDigits; int curDigits = _axisTypedValue.Length; string curMinus; if (_axisTypedValue.StartsWith("-")) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 2d2c383e51..aac533b3f7 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -421,12 +421,10 @@ namespace BizHawk.Client.EmuHawk { ColumnType type; int digits; - if (ControllerType.AxisControls.Contains(kvp.Key)) + if (ControllerType.Axes.TryGetValue(kvp.Key, out var range)) { - var range = ControllerType.AxisRanges - [ControllerType.AxisControls.IndexOf(kvp.Key)]; type = ColumnType.Axis; - digits = Math.Max(kvp.Value.Length, range.MaxDigits); + digits = Math.Max(kvp.Value.Length, range.Range.MaxDigits); } else { @@ -490,14 +488,14 @@ namespace BizHawk.Client.EmuHawk if (BoolPatterns == null) { BoolPatterns = new AutoPatternBool[ControllerType.BoolButtons.Count + 2]; - AxisPatterns = new AutoPatternAxis[ControllerType.AxisControls.Count + 2]; + AxisPatterns = new AutoPatternAxis[ControllerType.Axes.Count + 2]; } else { bStart = BoolPatterns.Length - 2; fStart = AxisPatterns.Length - 2; Array.Resize(ref BoolPatterns, ControllerType.BoolButtons.Count + 2); - Array.Resize(ref AxisPatterns, ControllerType.AxisControls.Count + 2); + Array.Resize(ref AxisPatterns, ControllerType.Axes.Count + 2); } for (int i = bStart; i < BoolPatterns.Length - 2; i++) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudioClipboard.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudioClipboard.cs index b30149f35d..ae4d2c0dcc 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudioClipboard.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudioClipboard.cs @@ -35,7 +35,7 @@ namespace BizHawk.Client.EmuHawk GlobalWin.InputManager.ButtonOverrideAdapter.SetButton(button, controller.IsPressed(button)); } - foreach (var axisName in controller.Definition.AxisControls) + foreach (var axisName in controller.Definition.Axes.Keys) { GlobalWin.InputManager.ButtonOverrideAdapter.SetAxis(axisName, controller.AxisValue(axisName)); } diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs index 18bb99c90d..f080654fcd 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs @@ -90,14 +90,14 @@ namespace BizHawk.Client.EmuHawk if (VersionInfo.DeveloperBuild) { var buttonControls = Emulator.ControllerDefinition.BoolButtons; - var axisControls = Emulator.ControllerDefinition.AxisControls; + var axisControls = Emulator.ControllerDefinition.Axes; foreach (var schema in padSchemata) foreach (var controlSchema in schema.Buttons) { Predicate searchSetContains = controlSchema switch { ButtonSchema _ => buttonControls.Contains, - DiscManagerSchema _ => s => buttonControls.Contains(s) || axisControls.Contains(s), - _ => axisControls.Contains + DiscManagerSchema _ => s => buttonControls.Contains(s) || axisControls.ContainsKey(s), + _ => axisControls.ContainsKey }; if (!searchSetContains(controlSchema.Name)) { diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs index f32562b8b7..e98b4e6b25 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/ColecoSchema.cs @@ -48,7 +48,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema TurboController(int controller) { - var controllerDefRanges = new ColecoTurboController(controller).Definition.AxisRanges; + var defAxes = new ColecoTurboController(controller).Definition.Axes; return new PadSchema { Size = new Size(275, 260), @@ -56,8 +56,8 @@ namespace BizHawk.Client.EmuHawk { new AnalogSchema(6, 14, $"P{controller} Disc X") { - AxisRange = controllerDefRanges[0], - SecondaryAxisRange = controllerDefRanges[1] + AxisRange = defAxes.SpecAtIndex(0).Range, + SecondaryAxisRange = defAxes.SpecAtIndex(1).Range }, new ButtonSchema(6, 224, controller, "Pedal") } diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs index ca01c11334..4ff17d8dce 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/IntvSchema.cs @@ -70,7 +70,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema AnalogController(int controller) { - var controllerDefRanges = new FakeAnalogController(controller).Definition.AxisRanges; + var defAxes = new FakeAnalogController(controller).Definition.Axes; return new PadSchema { DisplayName = $"Player {controller}", @@ -79,8 +79,8 @@ namespace BizHawk.Client.EmuHawk { new AnalogSchema(1, 121, $"P{controller} Disc X") { - AxisRange = controllerDefRanges[0], - SecondaryAxisRange = controllerDefRanges[1] + AxisRange = defAxes.SpecAtIndex(0).Range, + SecondaryAxisRange = defAxes.SpecAtIndex(1).Range } }) }; diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs index ffd4b5302b..e20fa7823e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/SnesSchema.cs @@ -159,7 +159,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema Mouse(int controller) { - var controllerDefRanges = new SnesMouseController().Definition.AxisRanges; + var defAxes = new SnesMouseController().Definition.Axes; return new PadSchema { Size = new Size(345, 225), @@ -167,8 +167,8 @@ namespace BizHawk.Client.EmuHawk { new AnalogSchema(6, 14, $"P{controller} Mouse X") { - AxisRange = controllerDefRanges[0], - SecondaryAxisRange = controllerDefRanges[1] + AxisRange = defAxes.SpecAtIndex(0).Range, + SecondaryAxisRange = defAxes.SpecAtIndex(1).Range }, new ButtonSchema(275, 15, controller, "Mouse Left") { diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs index 92522b6568..33c031a797 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/VECSchema.cs @@ -60,7 +60,7 @@ namespace BizHawk.Client.EmuHawk private static PadSchema AnalogController(int controller) { - var controllerDefRanges = new AnalogControls(controller).Definition.AxisRanges; + var defAxes = new AnalogControls(controller).Definition.Axes; return new PadSchema { Size = new Size(280, 300), @@ -72,8 +72,8 @@ namespace BizHawk.Client.EmuHawk Button(146, 34, controller, 4), new AnalogSchema(2, 80, $"P{controller} Stick X") { - AxisRange = controllerDefRanges[0], - SecondaryAxisRange = controllerDefRanges[1] + AxisRange = defAxes.SpecAtIndex(0).Range, + SecondaryAxisRange = defAxes.SpecAtIndex(1).Range } } }; diff --git a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index ab8770ba5c..13d48ef30a 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -22,9 +23,7 @@ namespace BizHawk.Emulation.Common { Name = source.Name; BoolButtons.AddRange(source.BoolButtons); - AxisControls.AddRange(source.AxisControls); - AxisRanges.AddRange(source.AxisRanges); - AxisConstraints.AddRange(source.AxisConstraints); + foreach (var kvp in source.Axes) Axes.Add(kvp); CategoryLabels = source.CategoryLabels; } @@ -38,23 +37,76 @@ namespace BizHawk.Emulation.Common /// public List BoolButtons { get; set; } = new List(); - /// - /// Gets a list of all non-boolean types, that can be represented by a numerical value (such as analog controls, stylus coordinates, etc - /// - public List AxisControls { get; } = new List(); + public sealed class AxisDict : IReadOnlyDictionary + { + private readonly IList _keys = new List(); - /// - /// Gets a list of all axis ranges for each axis control (must be one to one with AxisControls) - /// AxisRanges include the min/max/default values - /// - public List AxisRanges { get; set; } = new List(); + private readonly IDictionary _specs = new Dictionary(); - /// - /// Gets the axis constraints that apply artificial constraints to float values - /// For instance, a N64 controller's analog range is actually larger than the amount allowed by the plastic that artificially constrains it to lower values - /// Axis constraints provide a way to technically allow the full range but have a user option to constrain down to typical values that a real control would have - /// - public List AxisConstraints { get; } = new List(); + public int Count => _keys.Count; + + public bool HasContraints { get; private set; } + + public IEnumerable Keys => _keys; + + public IEnumerable Values => _specs.Values; + + public string this[int index] => _keys[index]; + + public AxisSpec this[string index] + { + get => _specs[index]; + set => _specs[index] = value; + } + + public void Add(string key, AxisSpec value) + { + _keys.Add(key); + _specs.Add(key, value); + if (value.Constraint != null) HasContraints = true; + } + + public void Add(KeyValuePair item) => Add(item.Key, item.Value); + + public void Clear() + { + _keys.Clear(); + _specs.Clear(); + HasContraints = false; + } + + public bool ContainsKey(string key) => _keys.Contains(key); + + public IEnumerator> GetEnumerator() => _specs.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public int IndexOf(string key) => _keys.IndexOf(key); + + public AxisSpec SpecAtIndex(int index) => this[_keys[index]]; + + public bool TryGetValue(string key, out AxisSpec value) => _specs.TryGetValue(key, out value); + } + + public readonly AxisDict Axes = new AxisDict(); + + public readonly struct AxisSpec + { + /// + /// Gets the axis constraints that apply artificial constraints to float values + /// For instance, a N64 controller's analog range is actually larger than the amount allowed by the plastic that artificially constrains it to lower values + /// Axis constraints provide a way to technically allow the full range but have a user option to constrain down to typical values that a real control would have + /// + public readonly AxisConstraint? Constraint; + + public readonly AxisRange Range; + + public AxisSpec(AxisRange range, AxisConstraint? constraint = null) + { + Constraint = constraint; + Range = range; + } + } /// /// Gets the category labels. These labels provide a means of categorizing controls in various controller display and config screens @@ -63,17 +115,14 @@ namespace BizHawk.Emulation.Common public void ApplyAxisConstraints(string constraintClass, IDictionary axes) { - if (AxisConstraints == null) - { - return; - } + if (!Axes.HasContraints) return; - foreach (var constraint in AxisConstraints) + foreach (var kvp in Axes) { - if (constraint.Class != constraintClass) - { - continue; - } + if (kvp.Value.Constraint == null) continue; + var constraint = kvp.Value.Constraint.Value; + + if (constraint.Class != constraintClass) continue; switch (constraint.Type) { @@ -168,7 +217,7 @@ namespace BizHawk.Emulation.Common { get { - var list = new List(AxisControls); + var list = new List(Axes.Keys); list.AddRange(BoolButtons); // starts with console buttons, then each player's buttons individually @@ -201,7 +250,7 @@ namespace BizHawk.Emulation.Common { get { - var allNames = AxisControls.Concat(BoolButtons).ToList(); + var allNames = Axes.Keys.Concat(BoolButtons).ToList(); var player = allNames .Select(PlayerNumber) .DefaultIfEmpty(0) @@ -219,7 +268,7 @@ namespace BizHawk.Emulation.Common public bool Any() { - return BoolButtons.Any() || AxisControls.Any(); + return BoolButtons.Any() || Axes.Any(); } } } diff --git a/src/BizHawk.Emulation.Common/ControllerDefinitionMerger.cs b/src/BizHawk.Emulation.Common/ControllerDefinitionMerger.cs index 7522442d98..4c1a533c89 100644 --- a/src/BizHawk.Emulation.Common/ControllerDefinitionMerger.cs +++ b/src/BizHawk.Emulation.Common/ControllerDefinitionMerger.cs @@ -40,14 +40,13 @@ namespace BizHawk.Emulation.Common remaps[s] = r; } - foreach (string s in def.AxisControls) + foreach (var kvp in def.Axes) { - string r = Allocate(s, ref plr, ref playerNext); - ret.AxisControls.Add(r); - remaps[s] = r; + string r = Allocate(kvp.Key, ref plr, ref playerNext); + ret.Axes.Add(r, kvp.Value); + remaps[kvp.Key] = r; } - ret.AxisRanges.AddRange(def.AxisRanges); plr = playerNext; unmergers.Add(new ControlDefUnMerger(remaps)); } diff --git a/src/BizHawk.Emulation.Common/Extensions.cs b/src/BizHawk.Emulation.Common/Extensions.cs index 17b0edad12..7456919b52 100644 --- a/src/BizHawk.Emulation.Common/Extensions.cs +++ b/src/BizHawk.Emulation.Common/Extensions.cs @@ -335,10 +335,10 @@ namespace BizHawk.Emulation.Common /// public static List ToAxisControlNameList(this IController controller, int? controllerNum = null) { - return ToControlNameList(controller.Definition.AxisControls, controllerNum); + return ToControlNameList(controller.Definition.Axes.Keys, controllerNum); } - private static List ToControlNameList(List buttonList, int? controllerNum = null) + private static List ToControlNameList(IEnumerable buttonList, int? controllerNum = null) { var buttons = new List(); foreach (var button in buttonList) @@ -372,7 +372,7 @@ namespace BizHawk.Emulation.Common buttons[sub] = controller.IsPressed($"P{controllerNum} {sub}"); } } - foreach (var button in controller.Definition.AxisControls) + foreach (var button in controller.Definition.Axes.Keys) { if (controllerNum == null) { @@ -404,27 +404,32 @@ namespace BizHawk.Emulation.Common /// Adds an axis to the receiver , and returns it. /// The new axis will appear after any that were previously defined. /// + /// 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, int min, int mid, int max, bool isReversed = false) + public static ControllerDefinition AddAxis(this ControllerDefinition def, string name, AxisRange range, AxisConstraint? constraint = null) { - def.AxisControls.Add(name); - def.AxisRanges.Add(new AxisRange(min, mid, max, isReversed)); + def.Axes.Add(name, new AxisSpec(range, constraint)); return def; } + /// + /// Adds an axis to the receiver , and returns it. + /// The new axis will appear after any that were previously defined. + /// + /// 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, int min, int mid, int max, bool isReversed = false, AxisConstraint? constraint = null) + => def.AddAxis(name, new AxisRange(min, mid, max, isReversed), constraint); + /// /// Adds an X/Y pair of axes to the receiver , and returns it. /// The new axes will appear after any that were previously defined. /// /// 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, int minBoth, int midBoth, int maxBoth) - { - def.AxisControls.Add(string.Format(nameFormat, "X")); - def.AxisControls.Add(string.Format(nameFormat, "Y")); - def.AxisRanges.AddRange(CreateAxisRangePair(minBoth, midBoth, maxBoth, pDir)); - return def; - } + public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, (int Min, int Mid, int Max) rangeX, (int Min, int Mid, int Max) rangeY, AxisConstraint? constraint = null) + => def.AddAxis(string.Format(nameFormat, "X"), rangeX.Min, rangeX.Mid, rangeX.Max, ((byte) pDir & 2) != 0, constraint) + .AddAxis(string.Format(nameFormat, "Y"), rangeY.Min, rangeY.Mid, rangeY.Max, ((byte) pDir & 1) != 0); /// /// Adds an X/Y pair of axes to the receiver , and returns it. @@ -432,14 +437,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, (int Min, int Mid, int Max) rangeX, (int Min, int Mid, int Max) rangeY) - { - def.AxisControls.Add(string.Format(nameFormat, "X")); - def.AxisControls.Add(string.Format(nameFormat, "Y")); - def.AxisRanges.Add(new AxisRange(rangeX.Min, rangeX.Mid, rangeX.Max, ((byte) pDir & 2) != 0)); - def.AxisRanges.Add(new AxisRange(rangeY.Min, rangeY.Mid, rangeY.Max, ((byte) pDir & 1) != 0)); - return def; - } + public static ControllerDefinition AddXYPair(this ControllerDefinition def, string nameFormat, AxisPairOrientation pDir, int minBoth, int midBoth, int maxBoth, AxisConstraint? constraint = null) + => def.AddXYPair(nameFormat, pDir, (minBoth, midBoth, maxBoth), (minBoth, midBoth, maxBoth), constraint); /// /// Adds an X/Y/Z triple of axes to the receiver , and returns it. @@ -449,14 +448,12 @@ namespace BizHawk.Emulation.Common /// identical reference to ; the object is mutated public static ControllerDefinition AddXYZTriple(this ControllerDefinition def, string nameFormat, int minAll, int midAll, int maxAll) { - def.AxisControls.Add(string.Format(nameFormat, "X")); - def.AxisControls.Add(string.Format(nameFormat, "Y")); - def.AxisControls.Add(string.Format(nameFormat, "Z")); var range = new AxisRange(minAll, midAll, maxAll); - def.AxisRanges.Add(range); - def.AxisRanges.Add(range); - def.AxisRanges.Add(range); - return def; + return def.AddAxis(string.Format(nameFormat, "X"), range) + .AddAxis(string.Format(nameFormat, "Y"), range) + .AddAxis(string.Format(nameFormat, "Z"), range); } + + public static AxisSpec With(this in AxisSpec spec, AxisRange range) => new AxisSpec(range, spec.Constraint); } } \ No newline at end of file diff --git a/src/BizHawk.Emulation.Common/SaveController.cs b/src/BizHawk.Emulation.Common/SaveController.cs index 27a8ce5e00..01340c79cd 100644 --- a/src/BizHawk.Emulation.Common/SaveController.cs +++ b/src/BizHawk.Emulation.Common/SaveController.cs @@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Common _buttons.Add(k, source.IsPressed(k) ? 1 : 0); } - foreach (var k in Definition.AxisControls) + foreach (var k in Definition.Axes.Keys) { if (_buttons.Keys.Contains(k)) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs index 9e400968f4..d393dfa52f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs @@ -37,11 +37,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 .ToList() }; - Definition.AxisControls.AddRange(Port1.Definition.AxisControls); - Definition.AxisControls.AddRange(Port2.Definition.AxisControls); - - Definition.AxisRanges.AddRange(Port1.Definition.AxisRanges); - Definition.AxisRanges.AddRange(Port2.Definition.AxisRanges); + foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); + foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs index 3069aa0b95..0453b29d7c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -119,10 +119,9 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { BoolButtons = BaseDefinition .Select(b => $"P{PortNum} " + b) - .ToList(), - AxisControls = { "P" + PortNum + " Paddle X 1" , "P" + PortNum + " Paddle X 2" }, - AxisRanges = { new ControllerDefinition.AxisRange(-127, 0, 127), new ControllerDefinition.AxisRange(-127, 0, 127) } - }; + .ToList() + }.AddAxis($"P{PortNum} Paddle X 1", -127, 0, 127) + .AddAxis($"P{PortNum} Paddle X 2", -127, 0, 127); } public int PortNum { get; } @@ -152,7 +151,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 public int Read_Pot(IController c, int pot) { - int x = (int)c.AxisValue(Definition.AxisControls[pot]); + int x = (int)c.AxisValue(Definition.Axes[pot]); x = -x; x += 127; @@ -236,10 +235,9 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { BoolButtons = BaseDefinition .Select(b => $"P{PortNum} " + b) - .ToList(), - AxisControls = { "P" + PortNum + " Wheel X 1", "P" + PortNum + " Wheel X 2" }, - AxisRanges = { new ControllerDefinition.AxisRange(-127, 0, 127), new ControllerDefinition.AxisRange(-127, 0, 127) } - }; + .ToList() + }.AddAxis($"P{PortNum} Wheel X 1", -127, 0, 127) + .AddAxis($"P{PortNum} Wheel X 2", -127, 0, 127); } public int PortNum { get; } @@ -262,8 +260,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if (c.IsPressed($"P{PortNum} Button")) { result &= 0xF7; } - float x = c.AxisValue(Definition.AxisControls[0]); - float y = c.AxisValue(Definition.AxisControls[1]); + float x = c.AxisValue(Definition.Axes[0]); + float y = c.AxisValue(Definition.Axes[1]); float angle = CalcDirection(x, y); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllerDeck.cs index f479c03141..96cf583efc 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllerDeck.cs @@ -43,11 +43,8 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk .ToList() }; - Definition.AxisControls.AddRange(Port1.Definition.AxisControls); - Definition.AxisControls.AddRange(Port2.Definition.AxisControls); - - Definition.AxisRanges.AddRange(Port1.Definition.AxisRanges); - Definition.AxisRanges.AddRange(Port2.Definition.AxisRanges); + foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); + foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllers.cs index 60d1cc701d..7404f654b8 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllers.cs @@ -313,8 +313,8 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk public bool Is_LightGun(IController c, out float x, out float y) { - x = c.AxisValue(Definition.AxisControls[0]); - y = c.AxisValue(Definition.AxisControls[1]); + x = c.AxisValue(Definition.Axes[0]); + y = c.AxisValue(Definition.Axes[1]); return true; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs index 017c3713e3..0ba3671694 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs @@ -37,11 +37,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision .ToList() }; - Definition.AxisControls.AddRange(Port1.Definition.AxisControls); - Definition.AxisControls.AddRange(Port2.Definition.AxisControls); - - Definition.AxisRanges.AddRange(Port1.Definition.AxisRanges); - Definition.AxisRanges.AddRange(Port2.Definition.AxisRanges); + foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); + foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); } public float wheel1; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs index 4c7e1dde60..bffb93d022 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs @@ -148,8 +148,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision if (c.IsPressed(Definition.BoolButtons[0])) retVal &= 0x3F; - float x = c.AxisValue(Definition.AxisControls[0]); - float y = c.AxisValue(Definition.AxisControls[1]); + float x = c.AxisValue(Definition.Axes[0]); + float y = c.AxisValue(Definition.Axes[1]); var angle = updateWheel ? wheelAngle : CalcDirection(x, y); @@ -219,8 +219,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision public float UpdateWheel(IController c) { - float x = c.AxisValue(Definition.AxisControls[0]); - float y = c.AxisValue(Definition.AxisControls[1]); + float x = c.AxisValue(Definition.Axes[0]); + float y = c.AxisValue(Definition.Axes[1]); return CalcDirection(x, y); } } @@ -250,8 +250,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision if (c.IsPressed(Definition.BoolButtons[3])) retVal &= 0xF7; if (c.IsPressed(Definition.BoolButtons[4])) retVal &= 0x3F; - float x = c.AxisValue(Definition.AxisControls[0]); - float y = c.AxisValue(Definition.AxisControls[1]); + float x = c.AxisValue(Definition.Axes[0]); + float y = c.AxisValue(Definition.Axes[1]); var angle = updateWheel ? wheelAngle : CalcDirection(x, y); @@ -348,8 +348,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision public float UpdateWheel(IController c) { - float x = c.AxisValue(Definition.AxisControls[0]); - float y = c.AxisValue(Definition.AxisControls[1]); + float x = c.AxisValue(Definition.Axes[0]); + float y = c.AxisValue(Definition.Axes[1]); return CalcDirection(x, y); } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs index ffed17267a..c4d953cd47 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs @@ -38,11 +38,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex .ToList() }; - Definition.AxisControls.AddRange(Port1.Definition.AxisControls); - Definition.AxisControls.AddRange(Port2.Definition.AxisControls); - - Definition.AxisRanges.AddRange(Port1.Definition.AxisRanges); - Definition.AxisRanges.AddRange(Port2.Definition.AxisRanges); + foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); + foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs index f38fdf082d..4b33ade67b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs @@ -38,11 +38,8 @@ namespace BizHawk.Emulation.Cores.Intellivision .ToList() }; - Definition.AxisControls.AddRange(Port1.Definition.AxisControls); - Definition.AxisControls.AddRange(Port2.Definition.AxisControls); - - Definition.AxisRanges.AddRange(Port1.Definition.AxisRanges); - Definition.AxisRanges.AddRange(Port2.Definition.AxisRanges); + foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); + foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllers.cs index 3e6e5095a6..039169c381 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllers.cs @@ -160,8 +160,8 @@ namespace BizHawk.Emulation.Cores.Intellivision } } - int x = (int)c.AxisValue(Definition.AxisControls[0]); - int y = (int)c.AxisValue(Definition.AxisControls[1]); + int x = (int)c.AxisValue(Definition.Axes[0]); + int y = (int)c.AxisValue(Definition.Axes[1]); result |= CalcDirection(x, y); return result; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllerDeck.cs index a2043fe5e2..15c12be537 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllerDeck.cs @@ -43,9 +43,7 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk .ToList() }; - Definition.AxisControls.AddRange(Port1.Definition.AxisControls); - - Definition.AxisRanges.AddRange(Port1.Definition.AxisRanges); + foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllerDeck.cs index e003e61593..990dadd16a 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllerDeck.cs @@ -26,9 +26,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk .ToList() }; - Definition.AxisControls.AddRange(Port1.Definition.AxisControls); - - Definition.AxisRanges.AddRange(Port1.Definition.AxisRanges); + foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs index 787305d914..94c4b08881 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllers.cs @@ -173,8 +173,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk theta_prev = theta; phi_prev = phi; - theta = (float)(c.AxisValue(Definition.AxisControls[1]) * Math.PI / 180.0); - phi = (float)(c.AxisValue(Definition.AxisControls[0]) * Math.PI / 180.0); + theta = (float)(c.AxisValue(Definition.Axes[1]) * Math.PI / 180.0); + phi = (float)(c.AxisValue(Definition.Axes[0]) * Math.PI / 180.0); float temp = (float)(Math.Cos(theta) * Math.Sin(phi)); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs index 97b89799ff..24ae808ea2 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs @@ -34,19 +34,23 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 static void AddN64StandardController(ControllerDefinition def, int player) { def.BoolButtons.AddRange(new[] { $"P{player} A Up", $"P{player} A Down", $"P{player} A Left", $"P{player} A Right", $"P{player} DPad U", $"P{player} DPad D", $"P{player} DPad L", $"P{player} DPad R", $"P{player} Start", $"P{player} Z", $"P{player} B", $"P{player} A", $"P{player} C Up", $"P{player} C Down", $"P{player} C Right", $"P{player} C Left", $"P{player} L", $"P{player} R" }); - def.AddXYPair($"P{player} {{0}} Axis", AxisPairOrientation.RightAndUp, -128, 0, 127); - def.AxisConstraints.Add(new AxisConstraint - { - Class = "Natural Circle", - Type = AxisConstraintType.Circular, - Params = new object[] { $"P{player} X Axis", $"P{player} Y Axis", 127.0f } - }); + def.AddXYPair( + $"P{player} {{0}} Axis", + AxisPairOrientation.RightAndUp, + -128, + 0, + 127, + new AxisConstraint + { + Class = "Natural Circle", + Type = AxisConstraintType.Circular, + Params = new object[] { $"P{player} X Axis", $"P{player} Y Axis", 127.0f } + } + ); } ControllerDefinition.BoolButtons.Clear(); - ControllerDefinition.AxisControls.Clear(); - ControllerDefinition.AxisRanges.Clear(); - ControllerDefinition.AxisConstraints.Clear(); + ControllerDefinition.Axes.Clear(); ControllerDefinition.BoolButtons.AddRange(new[] { "Reset", "Power" }); for (var i = 1; i <= 4; i++) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs index 81070fe682..5ae760b67a 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -160,10 +160,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } // Add in the reset timing axis for subneshawk - if (using_reset_timing && ControllerDefinition.AxisControls.Count == 0) + if (using_reset_timing && ControllerDefinition.Axes.Count == 0) { - ControllerDefinition.AxisControls.Add("Reset Cycle"); - ControllerDefinition.AxisRanges.Add(new ControllerDefinition.AxisRange(0, 0, 500000)); + ControllerDefinition.AddAxis("Reset Cycle", 0, 0, 500000); } // don't replace the magicSoundProvider on reset, as it's not needed diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs index a97519f7ea..28c6c84fc8 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs @@ -183,8 +183,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES Right.SyncState(ser); ser.EndSection(); } - - internal static readonly AxisRange ArkanoidPaddleRange = new AxisRange(0, 80, 160); } public class UnpluggedNES : INesPort @@ -388,12 +386,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES bool resetting = false; byte latchedvalue = 0x54 ^ 0xff; - static ControllerDefinition Definition = new ControllerDefinition - { - BoolButtons = { "0Fire" }, - AxisControls = { "0Paddle" }, - AxisRanges = { NesDeck.ArkanoidPaddleRange } - }; + private static readonly ControllerDefinition Definition + = new ControllerDefinition { BoolButtons = { "0Fire" } } + .AddAxis("0Paddle", 0, 80, 160); public void Strobe(StrobeInfo s, IController c) { @@ -746,12 +741,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES bool resetting = false; byte latchedvalue = 0x54 ^ 0xff; - static ControllerDefinition Definition = new ControllerDefinition - { - BoolButtons = { "0Fire" }, - AxisControls = { "0Paddle" }, - AxisRanges = { NesDeck.ArkanoidPaddleRange } - }; + private static readonly ControllerDefinition Definition + = new ControllerDefinition { BoolButtons = { "0Fire" } } + .AddAxis("0Paddle", 0, 80, 160); public void Strobe(StrobeInfo s, IController c) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs index a6fe42c822..50cc2b6c0e 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs @@ -197,7 +197,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X public void ApplyState(IController controller, short[] input, int offset) { - foreach (var s in Definition.AxisControls) + foreach (var s in Definition.Axes.Keys) input[offset++] = (short)(controller.AxisValue(s)); foreach (var s in Definition.BoolButtons) input[offset++] = (short)(controller.IsPressed(s) ? 1 : 0); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs index 3c88e98461..2b1596ae78 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs @@ -41,8 +41,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubGBHawk _tracer = new TraceBuffer { Header = _GBCore.cpu.TraceHeader }; ser.Register(_tracer); - _GBCore.ControllerDefinition.AxisControls.Add("Input Cycle"); - _GBCore.ControllerDefinition.AxisRanges.Add(new ControllerDefinition.AxisRange(0, 70224, 70224)); + _GBCore.ControllerDefinition.AddAxis("Input Cycle", 0, 70224, 70224); } public GBHawk.GBHawk _GBCore; diff --git a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs index b57cdf890d..b765942f48 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs @@ -43,18 +43,11 @@ namespace BizHawk.Emulation.Cores.PCEngine .Concat(_port5.Definition.BoolButtons) .ToList() }; - - Definition.AxisControls.AddRange(_port1.Definition.AxisControls); - Definition.AxisControls.AddRange(_port2.Definition.AxisControls); - Definition.AxisControls.AddRange(_port3.Definition.AxisControls); - Definition.AxisControls.AddRange(_port4.Definition.AxisControls); - Definition.AxisControls.AddRange(_port5.Definition.AxisControls); - - Definition.AxisRanges.AddRange(_port1.Definition.AxisRanges); - Definition.AxisRanges.AddRange(_port2.Definition.AxisRanges); - Definition.AxisRanges.AddRange(_port3.Definition.AxisRanges); - Definition.AxisRanges.AddRange(_port4.Definition.AxisRanges); - Definition.AxisRanges.AddRange(_port5.Definition.AxisRanges); + foreach (var kvp in _port1.Definition.Axes) Definition.Axes.Add(kvp); + foreach (var kvp in _port2.Definition.Axes) Definition.Axes.Add(kvp); + foreach (var kvp in _port3.Definition.Axes) Definition.Axes.Add(kvp); + foreach (var kvp in _port4.Definition.Axes) Definition.Axes.Add(kvp); + foreach (var kvp in _port5.Definition.Axes) Definition.Axes.Add(kvp); } private readonly IPort _port1; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IEmulator.cs index 9917d8dfe9..fae7fc2312 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IEmulator.cs @@ -1,5 +1,7 @@ using BizHawk.Emulation.Common; +using static BizHawk.Emulation.Common.ControllerDefinition; + namespace BizHawk.Emulation.Cores.Sega.MasterSystem { public partial class SMS : IEmulator @@ -24,8 +26,9 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem return SMSPaddleController; case SmsSyncSettings.ControllerTypes.LightPhaser: // scale the vertical to the display mode - SMSLightPhaserController.AxisRanges[1] = new ControllerDefinition.AxisRange(0, Vdp.FrameHeight / 2, Vdp.FrameHeight - 1); - + var axisName = SMSLightPhaserController.Axes[1]; + SMSLightPhaserController.Axes[axisName] = SMSLightPhaserController.Axes[axisName] + .With(range: new AxisRange(0, Vdp.FrameHeight / 2, Vdp.FrameHeight - 1)); return SMSLightPhaserController; case SmsSyncSettings.ControllerTypes.SportsPad: return SMSSportsPadController; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.Input.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.Input.cs index 6e630c67dc..86be8e5143 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.Input.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.Input.cs @@ -38,18 +38,9 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem "Reset", "Pause", "P1 Left", "P1 Right", "P1 B1", "P2 Left", "P2 Right", "P2 B1", - }, - AxisControls = - { - "P1 Paddle", - "P2 Paddle" - }, - AxisRanges = - { - new AxisRange(0, 128, 255), - new AxisRange(0, 128, 255) } - }; + }.AddAxis("P1 Paddle", 0, 128, 255) + .AddAxis("P2 Paddle", 0, 128, 255); public static readonly ControllerDefinition SMSLightPhaserController = new ControllerDefinition { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs b/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs index aef100eb59..6af791ccb4 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs @@ -272,19 +272,11 @@ namespace BizHawk.Emulation.Cores.Sony.PSX "P" + pnum + " A", }); - definition.AxisControls.AddRange(new[] - { - "P" + pnum + " Twist", - "P" + pnum + " 1", - "P" + pnum + " 2", - "P" + pnum + " L" - }); - var axisRange = new AxisRange(0, 128, 255); - definition.AxisRanges.Add(axisRange); - definition.AxisRanges.Add(axisRange); - definition.AxisRanges.Add(axisRange); - definition.AxisRanges.Add(axisRange); + definition.AddAxis($"P{pnum} Twist", axisRange); + definition.AddAxis($"P{pnum} 1", axisRange); + definition.AddAxis($"P{pnum} 2", axisRange); + definition.AddAxis($"P{pnum} L", axisRange); } else { @@ -325,13 +317,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX "Reset" }); - definition.AxisControls.Add("Disc Select"); - - definition.AxisRanges.Add( - //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 AxisRange(0, 1, 1) - ); + definition.AddAxis("Disc Select", new AxisRange(0, 1, 1)); return definition; } diff --git a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs index 780a83d147..5e7563feef 100644 --- a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs +++ b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs @@ -4,6 +4,8 @@ using System.IO; using System.Linq; using BizHawk.Emulation.Common; using NymaTypes; + +using static BizHawk.Emulation.Common.ControllerDefinition; using static BizHawk.Emulation.Cores.Waterbox.LibNymaCore; namespace BizHawk.Emulation.Cores.Waterbox @@ -176,11 +178,8 @@ namespace BizHawk.Emulation.Cores.Waterbox var data = input.Extra.AsAxis(); var fullName = $"{name} {overrideName(data.NameNeg)} / {overrideName(data.NamePos)}"; - ret.AxisControls.Add(fullName); + ret.AddAxis(fullName, new AxisRange(0, 0x8000, 0xFFFF, (input.Flags & AxisFlags.InvertCo) != 0)); ret.CategoryLabels[fullName] = category; - ret.AxisRanges.Add(new ControllerDefinition.AxisRange( - 0, 0x8000, 0xffff, (input.Flags & AxisFlags.InvertCo) != 0 - )); _thunks.Add((c, b) => { var val = c.AxisValue(fullName); @@ -194,15 +193,12 @@ namespace BizHawk.Emulation.Cores.Waterbox var data = input.Extra.AsAxis(); var fullName = $"{name} {input.Extra.AsAxis().NameNeg} / {input.Extra.AsAxis().NamePos}"; - ret.AxisControls.Add(fullName); + // TODO: Mednafen docs say this range should be [-32768, 32767], and inspecting the code + // reveals that a 16 bit value is read, but using anywhere near this full range makes + // PCFX mouse completely unusable. Maybe this is some TAS situation where average users + // will want a 1/400 multiplier on sensitivity but TASers might want one frame screenwide movement? + ret.AddAxis(fullName, new AxisRange(-127, 0, 127, (input.Flags & AxisFlags.InvertCo) != 0)); ret.CategoryLabels[fullName] = category; - ret.AxisRanges.Add(new ControllerDefinition.AxisRange( - // TODO: Mednafen docs say this range should be [-32768, 32767], and inspecting the code - // reveals that a 16 bit value is read, but using anywhere near this full range makes - // PCFX mouse completely unusable. Maybe this is some TAS situation where average users - // will want a 1/400 multiplier on sensitivity but TASers might want one frame screenwide movement? - -127, 0, 127, (input.Flags & AxisFlags.InvertCo) != 0 - )); _thunks.Add((c, b) => { var val = c.AxisValue(fullName); @@ -214,9 +210,7 @@ namespace BizHawk.Emulation.Cores.Waterbox case InputType.PointerX: { // I think the core expects to be sent some sort of 16 bit integer, but haven't investigated much - ret.AxisControls.Add(name); - ret.AxisRanges.Add(new ControllerDefinition.AxisRange( - systemInfo.PointerOffsetX, systemInfo.PointerOffsetX, systemInfo.PointerScaleX)); + ret.AddAxis(name, new AxisRange(systemInfo.PointerOffsetX, systemInfo.PointerOffsetX, systemInfo.PointerScaleX)); _thunks.Add((c, b) => { var val = c.AxisValue(name); @@ -228,9 +222,7 @@ namespace BizHawk.Emulation.Cores.Waterbox case InputType.PointerY: { // I think the core expects to be sent some sort of 16 bit integer, but haven't investigated much - ret.AxisControls.Add(name); - ret.AxisRanges.Add(new ControllerDefinition.AxisRange( - systemInfo.PointerOffsetY, systemInfo.PointerOffsetY, systemInfo.PointerScaleY)); + ret.AddAxis(name, new AxisRange(systemInfo.PointerOffsetY, systemInfo.PointerOffsetY, systemInfo.PointerScaleY)); _thunks.Add((c, b) => { var val = c.AxisValue(name); @@ -241,11 +233,8 @@ namespace BizHawk.Emulation.Cores.Waterbox } case InputType.ButtonAnalog: { - ret.AxisControls.Add(name); + ret.AddAxis(name, new AxisRange(0, 0, 0xFFFF)); ret.CategoryLabels[name] = category; - ret.AxisRanges.Add(new ControllerDefinition.AxisRange( - 0, 0, 0xffff, false - )); _thunks.Add((c, b) => { var val = c.AxisValue(name);