From b0913448966d65cc5c19a7b72168cea0d540fa5e Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 23 Dec 2024 02:37:56 +1000 Subject: [PATCH] Actually fix `GenOrderedControls` invariant, dropping Libretro hack fixes a8368849a and 3384ce862 --- .../display/InputDisplayGenerator.cs | 12 +++------- .../ControllerDefinition.cs | 1 + .../Libretro/Libretro.IEmulator.cs | 23 ------------------- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/src/BizHawk.Client.Common/display/InputDisplayGenerator.cs b/src/BizHawk.Client.Common/display/InputDisplayGenerator.cs index ed53992d24e..ff713e91911 100644 --- a/src/BizHawk.Client.Common/display/InputDisplayGenerator.cs +++ b/src/BizHawk.Client.Common/display/InputDisplayGenerator.cs @@ -16,15 +16,9 @@ public static string Generate(IController source) throw new InvalidOperationException("Can't generate input display string with empty mnemonics cache"); var sb = new StringBuilder(); - var controls = source.Definition.ControlsOrdered.ToList(); - // index 0 is for controls that don't belong to any indexed player - if (controls.ElementAtOrDefault(0) != null) - { - controls.Add(controls[0]); - controls.RemoveAt(0); - } - - foreach ((string buttonName, AxisSpec? axisSpec) in controls.SelectMany(x => x)) + var players = source.Definition.ControlsOrdered; + var playersNewOrder = players.Skip(1).Concat(players.Take(1)); // move first ("player 0") to end + foreach ((string buttonName, AxisSpec? axisSpec) in playersNewOrder.SelectMany(static x => x)) { if (axisSpec.HasValue) { diff --git a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index 999ba29d813..f676f2f036e 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -114,6 +114,7 @@ private void AssertMutable() if (!_mutable) throw new InvalidOperationException(ERR_MSG); } + /// implementors should include empty lists for empty players, including "player 0", to match this base implementation protected virtual IReadOnlyList> GenOrderedControls() { var ret = new List<(string, AxisSpec?)>[PlayerCount + 1]; diff --git a/src/BizHawk.Emulation.Cores/Libretro/Libretro.IEmulator.cs b/src/BizHawk.Emulation.Cores/Libretro/Libretro.IEmulator.cs index fd05f8c14e2..75a7441d631 100644 --- a/src/BizHawk.Emulation.Cores/Libretro/Libretro.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Libretro/Libretro.IEmulator.cs @@ -111,29 +111,6 @@ public LibretroControllerDef() MakeImmutable(); } - - protected override IReadOnlyList> GenOrderedControls() - { - // all this is to remove the keyboard buttons from P0 and put them in P3 so they appear at the end of the input display - var players = base.GenOrderedControls().ToList(); - List<(string, AxisSpec?)> retroKeyboard = new(); - var p0 = (List<(string, AxisSpec?)>) players[0]; - for (var i = 0; i < p0.Count; /* incremented in body */) - { - (string ButtonName, AxisSpec?) button = p0[i]; - if (CategoryLabels.TryGetValue(button.ButtonName, out var v) && v is CAT_KEYBOARD) - { - retroKeyboard.Add(button); - p0.RemoveAt(i); - } - else - { - i++; - } - } - players.Add(retroKeyboard); - return players; - } } public ControllerDefinition ControllerDefinition { get; }