Cleanup N64 controller def init and re-init

This commit is contained in:
YoshiRulz 2020-06-15 13:02:01 +10:00
parent e5e4983464
commit 5f809d8e24
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 21 additions and 64 deletions

View File

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

View File

@ -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()
{

View File

@ -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<ControllerDefinition.AxisRange> 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;