From 5f809d8e24dd383e67c560fbcdf9905882196bab Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 15 Jun 2020 13:02:01 +1000 Subject: [PATCH] Cleanup N64 controller def init and re-init --- .../Consoles/Nintendo/N64/N64.ISettable.cs | 56 +++++++------------ .../Consoles/Nintendo/N64/N64.cs | 2 +- .../Consoles/Nintendo/N64/N64Input.cs | 27 +-------- 3 files changed, 21 insertions(+), 64 deletions(-) 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 a1aefe2773..97b89799ff 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs @@ -1,5 +1,7 @@ using BizHawk.Emulation.Common; +using static BizHawk.Emulation.Common.ControllerDefinition; + namespace BizHawk.Emulation.Cores.Nintendo.N64 { public partial class N64 : ISettable @@ -29,47 +31,27 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 private void SetControllerButtons() { + 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 } + }); + } + ControllerDefinition.BoolButtons.Clear(); ControllerDefinition.AxisControls.Clear(); + ControllerDefinition.AxisRanges.Clear(); + ControllerDefinition.AxisConstraints.Clear(); - ControllerDefinition.BoolButtons.AddRange(new[] + ControllerDefinition.BoolButtons.AddRange(new[] { "Reset", "Power" }); + for (var i = 1; i <= 4; i++) { - "Reset", - "Power" - }); - - for (int i = 0; i < 4; i++) - { - if (_syncSettings.Controllers[i].IsConnected) - { - ControllerDefinition.BoolButtons.AddRange(new[] - { - "P" + (i + 1) + " A Up", - "P" + (i + 1) + " A Down", - "P" + (i + 1) + " A Left", - "P" + (i + 1) + " A Right", - "P" + (i + 1) + " DPad U", - "P" + (i + 1) + " DPad D", - "P" + (i + 1) + " DPad L", - "P" + (i + 1) + " DPad R", - "P" + (i + 1) + " Start", - "P" + (i + 1) + " Z", - "P" + (i + 1) + " B", - "P" + (i + 1) + " A", - "P" + (i + 1) + " C Up", - "P" + (i + 1) + " C Down", - "P" + (i + 1) + " C Right", - "P" + (i + 1) + " C Left", - "P" + (i + 1) + " L", - "P" + (i + 1) + " R", - }); - - ControllerDefinition.AxisControls.AddRange(new[] - { - "P" + (i + 1) + " X Axis", - "P" + (i + 1) + " Y Axis", - }); - } + if (_syncSettings.Controllers[i - 1].IsConnected) AddN64StandardController(ControllerDefinition, i); } } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs index e1cd654b17..042b5361a6 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs @@ -259,7 +259,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 public DisplayType Region => _display_type; - public ControllerDefinition ControllerDefinition => _inputProvider.ControllerDefinition; + public ControllerDefinition ControllerDefinition { get; } = new ControllerDefinition { Name = "Nintendo 64 Controller" }; public void ResetCounters() { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs index 2d6d4bc563..da9b5f13be 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.Linq; - -using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Nintendo.N64.NativeApi; namespace BizHawk.Emulation.Cores.Nintendo.N64 @@ -13,28 +10,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 public bool LastFrameInputPolled { get; set; } 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", - BoolButtons = - { - "P1 A Up", "P1 A Down", "P1 A Left", "P1 A Right", "P1 DPad U", "P1 DPad D", "P1 DPad L", "P1 DPad R", "P1 Start", "P1 Z", "P1 B", "P1 A", "P1 C Up", "P1 C Down", "P1 C Right", "P1 C Left", "P1 L", "P1 R", - "Reset", "Power" - }, - AxisControls = - { - "P1 X Axis", "P1 Y Axis", - }, - AxisRanges = AnalogStickRanges.Concat(AnalogStickRanges).Concat(AnalogStickRanges).Concat(AnalogStickRanges).ToList(), //TODO is this supposed to be duplicated? docs say AxisRanges.Count should equal AxisControls.Count --yoshi - AxisConstraints = - { - new ControllerDefinition.AxisConstraint { Class = "Natural Circle", Type = ControllerDefinition.AxisConstraintType.Circular, Params = new object[] {"P1 X Axis", "P1 Y Axis", 127.0f} } - } - }; private readonly IInputPollable _emuCore;