From 4faa49d42c55250250c0c45dddce013897305cc5 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 10 Aug 2022 15:19:15 +1000 Subject: [PATCH] System: Fix framerate spike after pausing in debugger --- src/core/system.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/core/system.cpp b/src/core/system.cpp index 050128842..0b86258af 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -2078,6 +2078,17 @@ void System::ResetThrottler() void System::Throttle() { + // If we're running too slow, advance the next frame time based on the time we lost. Effectively skips + // running those frames at the intended time, because otherwise if we pause in the debugger, we'll run + // hundreds of frames when we resume. + const Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); + if (current_time > s_next_frame_time) + { + const Common::Timer::Value diff = static_cast(current_time) - static_cast(s_next_frame_time); + s_next_frame_time += (diff / s_frame_period) * s_frame_period; + return; + } + Common::Timer::SleepUntil(s_next_frame_time, true); }