From 69862fef70e8c6a6af522400457a84e716c5d1bd Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Sun, 23 Mar 2025 15:20:09 +0100 Subject: [PATCH] simplify frame advance bool logic this now also prevents _runloopFrameProgress from potentially getting stuck after rewinding and fixes some other obscure interactions with frame advance and rewind. - added 2 bugs --- src/BizHawk.Client.EmuHawk/MainForm.cs | 47 +++++++++++--------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 46543c759a..e115c2f399 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -2991,20 +2991,21 @@ namespace BizHawk.Client.EmuHawk double frameAdvanceTimestampDeltaMs = (double)(currentTimestamp - _frameAdvanceTimestamp) / Stopwatch.Frequency * 1000.0; bool frameProgressTimeElapsed = frameAdvanceTimestampDeltaMs >= Config.FrameProgressDelayMs; - if (Config.SkipLagFrame && Emulator.CanPollInput() && Emulator.AsInputPollable().IsLagFrame && frameProgressTimeElapsed && Emulator.Frame > 0) + // TODO technically this should only force run frames if the frame advance key has been used + if (Config.SkipLagFrame && Emulator.CanPollInput() && Emulator.AsInputPollable().IsLagFrame && Emulator.Frame > 0) { runFrame = true; } RA?.Update(); - bool oldFrameAdvanceCondition = InputManager.ClientControls["Frame Advance"] || PressFrameAdvance || HoldFrameAdvance; + bool frameAdvance = InputManager.ClientControls["Frame Advance"] || PressFrameAdvance || HoldFrameAdvance; if (FrameInch) { FrameInch = false; - if (EmulatorPaused || oldFrameAdvanceCondition) + if (EmulatorPaused) { - oldFrameAdvanceCondition = true; + frameAdvance = true; } else { @@ -3012,42 +3013,34 @@ namespace BizHawk.Client.EmuHawk } } - bool frameAdvance = oldFrameAdvanceCondition || FrameInch; - if (!frameAdvance && _runloopFrameAdvance && _runloopFrameProgress) - { - // handle release of frame advance - _runloopFrameProgress = false; - PauseEmulator(); - } - - _runloopFrameAdvance = frameAdvance; if (frameAdvance) { - FrameInch = false; - - // handle the initial trigger of a frame advance - if (_frameAdvanceTimestamp == 0) + if (!_runloopFrameAdvance) { - PauseEmulator(); + // handle the initial trigger of a frame advance runFrame = true; _frameAdvanceTimestamp = currentTimestamp; + PauseEmulator(); } - else + else if (frameProgressTimeElapsed) { - // handle the timed transition from countdown to FrameProgress - if (frameProgressTimeElapsed) - { - runFrame = true; - _runloopFrameProgress = true; - UnpauseEmulator(); - } + runFrame = true; + _runloopFrameProgress = true; + UnpauseEmulator(); } } else { - _frameAdvanceTimestamp = 0; + if (_runloopFrameAdvance) + { + // handle release of frame advance + PauseEmulator(); + } + _runloopFrameProgress = false; } + _runloopFrameAdvance = frameAdvance; + #if BIZHAWKBUILD_SUPERHAWK if (!EmulatorPaused && (!Config.SuperHawkThrottle || InputManager.ClientControls.AnyInputHeld)) #else