Skip to content

Commit 18bf16c

Browse files
committed
Fix: autofire/autohold hotkeys would sometimes activate buttons that were already being held when the hotkey was pressed.
passes test AutofireHotkeyDoesNotRespondToAlreadyHeldButton
1 parent 6eecdd2 commit 18bf16c

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

src/BizHawk.Client.Common/controllers/StickyControllers.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using System.Linq;
32

43
using BizHawk.Common.CollectionExtensions;
54
using BizHawk.Emulation.Common;
@@ -60,16 +59,12 @@ public void ClearStickies()
6059
_axisHolds.Clear();
6160
}
6261

63-
private List<string> _justPressed = [ ];
64-
6562
public void MassToggleStickyState(List<string> buttons)
6663
{
67-
foreach (var button in buttons.Where(button => !_justPressed.Contains(button)))
64+
foreach (var button in buttons)
6865
{
6966
_ = _buttonHolds.ToggleMembership(button);
7067
}
71-
72-
_justPressed = buttons;
7368
}
7469
}
7570

@@ -158,16 +153,12 @@ public void IncrementLoops(bool lagged)
158153
foreach (var v in _axisPatterns.Values) v.GetNextValue(lagged);
159154
}
160155

161-
private List<string> _justPressed = [ ];
162-
163156
public void MassToggleStickyState(List<string> buttons)
164157
{
165-
foreach (var button in buttons.Where(button => !_justPressed.Contains(button)))
158+
foreach (var button in buttons)
166159
{
167160
SetButtonAutofire(button, !_boolPatterns.ContainsKey(button));
168161
}
169-
170-
_justPressed = buttons;
171162
}
172163
}
173164
}

src/BizHawk.Client.Common/inputAdapters/InputManager.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ public void SyncControls(IEmulator emulator, IMovieSession session, Config confi
7777
ControllerOutput.Source = session.MovieOut;
7878
}
7979

80-
public void ToggleStickies()
81-
{
82-
StickyHoldController.MassToggleStickyState(ActiveController.PressedButtons);
83-
StickyAutofireController.MassToggleStickyState(AutoFireController.PressedButtons); // does this even make sense?
84-
}
85-
86-
public void ToggleAutoStickies()
87-
{
88-
StickyAutofireController.MassToggleStickyState(ActiveController.PressedButtons);
89-
}
90-
9180
private static Controller BindToDefinition(
9281
ControllerDefinition def,
9382
IDictionary<string, Dictionary<string, string>> allBinds,
@@ -233,6 +222,8 @@ public void RunControllerChain(Config config)
233222
ClientControls.LatchFromPhysical(_hotkeyCoalescer);
234223

235224
// controller, which actually has a chain
225+
List<string> oldPressedButtons = ActiveController.PressedButtons;
226+
236227
ActiveController.LatchFromPhysical(ControllerInputCoalescer);
237228
ActiveController.OR_FromLogical(ClickyVirtualPadController);
238229
AutoFireController.LatchFromPhysical(ControllerInputCoalescer);
@@ -242,13 +233,25 @@ public void RunControllerChain(Config config)
242233
ActiveController.ApplyAxisConstraints("Natural Circle");
243234
}
244235

245-
if (ClientControls["Autohold"])
246-
{
247-
ToggleStickies();
248-
}
249-
else if (ClientControls["Autofire"])
236+
if (ClientControls["Autohold"] || ClientControls["Autofire"])
250237
{
251-
ToggleAutoStickies();
238+
List<string> newPressedButtons = ActiveController.PressedButtons;
239+
List<string> justPressedButtons = new();
240+
foreach (string button in newPressedButtons)
241+
{
242+
if (!oldPressedButtons.Contains(button)) justPressedButtons.Add(button);
243+
}
244+
if (justPressedButtons.Count != 0)
245+
{
246+
if (ClientControls["Autohold"])
247+
{
248+
StickyHoldController.MassToggleStickyState(justPressedButtons);
249+
}
250+
else
251+
{
252+
StickyAutofireController.MassToggleStickyState(justPressedButtons);
253+
}
254+
}
252255
}
253256

254257
// autohold/autofire must not be affected by the following inputs

0 commit comments

Comments
 (0)