Skip to content

Commit

Permalink
Actually fix GenOrderedControls invariant, dropping Libretro hack
Browse files Browse the repository at this point in the history
fixes a836884 and 3384ce8
  • Loading branch information
YoshiRulz committed Dec 22, 2024
1 parent 1eb8433 commit b091344
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
12 changes: 3 additions & 9 deletions src/BizHawk.Client.Common/display/InputDisplayGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@vadosnaprimer

vadosnaprimer Dec 22, 2024

Contributor

So what happens when player 0 doesn't exist?
Looked at the other comment.

foreach ((string buttonName, AxisSpec? axisSpec) in playersNewOrder.SelectMany(static x => x))
{
if (axisSpec.HasValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private void AssertMutable()
if (!_mutable) throw new InvalidOperationException(ERR_MSG);
}

/// <remarks>implementors should include empty lists for empty players, including "player 0", to match this base implementation</remarks>
protected virtual IReadOnlyList<IReadOnlyList<(string Name, AxisSpec? AxisSpec)>> GenOrderedControls()
{
var ret = new List<(string, AxisSpec?)>[PlayerCount + 1];
Expand Down
23 changes: 0 additions & 23 deletions src/BizHawk.Emulation.Cores/Libretro/Libretro.IEmulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,6 @@ public LibretroControllerDef()

MakeImmutable();
}

protected override IReadOnlyList<IReadOnlyList<(string Name, AxisSpec? AxisSpec)>> 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; }
Expand Down

0 comments on commit b091344

Please sign in to comment.