Skip to content

Commit 062df0e

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 b871bef commit 062df0e

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,
@@ -157,6 +146,8 @@ private static AutofireController BindToDefinitionAF(
157146
/// caller if the input didn't alrady do something else.</param>
158147
public void ProcessInput(IInputSource source, Func<string, bool> processHotkey, Config config, Action<InputEvent> processUnboundInput)
159148
{
149+
List<string> oldPressedButtons = ActiveController.PressedButtons;
150+
160151
// loop through all available events
161152
InputEvent ie;
162153
while ((ie = source.DequeueEvent()) != null)
@@ -230,13 +221,25 @@ public void ProcessInput(IInputSource source, Func<string, bool> processHotkey,
230221
ActiveController.ApplyAxisConstraints("Natural Circle");
231222
}
232223

233-
if (ClientControls["Autohold"])
234-
{
235-
ToggleStickies();
236-
}
237-
else if (ClientControls["Autofire"])
224+
if (ClientControls["Autohold"] || ClientControls["Autofire"])
238225
{
239-
ToggleAutoStickies();
226+
List<string> newPressedButtons = ActiveController.PressedButtons;
227+
List<string> justPressedButtons = new();
228+
foreach (string button in newPressedButtons)
229+
{
230+
if (!oldPressedButtons.Contains(button)) justPressedButtons.Add(button);
231+
}
232+
if (justPressedButtons.Count != 0)
233+
{
234+
if (ClientControls["Autohold"])
235+
{
236+
StickyHoldController.MassToggleStickyState(justPressedButtons);
237+
}
238+
else
239+
{
240+
StickyAutofireController.MassToggleStickyState(justPressedButtons);
241+
}
242+
}
240243
}
241244

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

0 commit comments

Comments
 (0)