From 81b6c2793ce0e61fbb75c4d8de22505781620317 Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Wed, 25 Sep 2024 18:26:17 +0200 Subject: [PATCH] Respect AutoFireLagFrames config setting in sticky controllers Previously, there was no way to configure this and sticky autofire controls would always adjust to lag. --- .../controllers/StickyControllers.cs | 12 +++++++----- src/BizHawk.Client.EmuHawk/config/AutofireConfig.cs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/BizHawk.Client.Common/controllers/StickyControllers.cs b/src/BizHawk.Client.Common/controllers/StickyControllers.cs index 7a54cb59dd..0d8bf2eac7 100644 --- a/src/BizHawk.Client.Common/controllers/StickyControllers.cs +++ b/src/BizHawk.Client.Common/controllers/StickyControllers.cs @@ -90,6 +90,7 @@ namespace BizHawk.Client.Common // Probably would have slightly lower performance, but it seems weird to have such a similar class that is only used once. private int _onFrames; private int _offFrames; + private bool _respectLag; private readonly Dictionary _boolPatterns = [ ]; private readonly Dictionary _axisPatterns = [ ]; @@ -98,10 +99,10 @@ namespace BizHawk.Client.Common public IReadOnlyCollection CurrentAutofires => _boolPatterns.Keys; // the callsite doesn't care about sticky axes - public StickyAutofireController(ControllerDefinition definition, int onFrames = 1, int offFrames = 1) + public StickyAutofireController(ControllerDefinition definition, int onFrames = 1, int offFrames = 1, bool respectLag = true) { Definition = definition; - SetDefaultOnOffPattern(onFrames, offFrames); + UpdateDefaultPatternSettings(onFrames, offFrames, respectLag); } public bool IsPressed(string button) @@ -117,17 +118,18 @@ namespace BizHawk.Client.Common public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => throw new NotSupportedException(); public void SetHapticChannelStrength(string name, int strength) => throw new NotSupportedException(); - public void SetDefaultOnOffPattern(int onFrames, int offFrames) + public void UpdateDefaultPatternSettings(int onFrames, int offFrames, bool respectLag) { _onFrames = Math.Max(onFrames, 1); _offFrames = Math.Max(offFrames, 1); + _respectLag = respectLag; } public void SetButtonAutofire(string button, bool enabled, AutoPatternBool pattern = null) { if (enabled) { - pattern ??= new AutoPatternBool(_onFrames, _offFrames); + pattern ??= new AutoPatternBool(_onFrames, _offFrames, _respectLag); _boolPatterns[button] = pattern; } else @@ -140,7 +142,7 @@ namespace BizHawk.Client.Common { if (value.HasValue) { - pattern ??= new AutoPatternAxis(value.Value, _onFrames, Definition.Axes[name].Neutral, _offFrames); + pattern ??= new AutoPatternAxis(value.Value, _onFrames, Definition.Axes[name].Neutral, _offFrames, _respectLag); _axisPatterns[name] = pattern; } else diff --git a/src/BizHawk.Client.EmuHawk/config/AutofireConfig.cs b/src/BizHawk.Client.EmuHawk/config/AutofireConfig.cs index 8947be714b..e5f66ea647 100644 --- a/src/BizHawk.Client.EmuHawk/config/AutofireConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/AutofireConfig.cs @@ -57,7 +57,7 @@ namespace BizHawk.Client.EmuHawk _autoFireController.On = _config.AutofireOn = (int)nudPatternOn.Value; _autoFireController.Off = _config.AutofireOff = (int)nudPatternOff.Value; _config.AutofireLagFrames = cbConsiderLag.Checked; - _stickyAutofireController.SetDefaultOnOffPattern(_config.AutofireOn, _config.AutofireOff); + _stickyAutofireController.UpdateDefaultPatternSettings(_config.AutofireOn, _config.AutofireOff, _config.AutofireLagFrames); DialogResult = DialogResult.OK; Close();