From 6930bde91be89640c6b510d22e82d3b1a31042ac Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 13 Jul 2024 13:01:20 -0700 Subject: [PATCH] Use variable timestep for `SDL_Delay` This fixes a bug where fast-forward wouldn't work in 30-FPS-only mode. This is because the 30-FPS-only code has a hardcoded check for the number 34, as in 34 milliseconds must pass before the next frame can advance. This is why slowdown still worked, because slowdown means you're waiting longer than 34 ms anyways, but fast-forward tries to wait for only 1 ms, which wouldn't work if the 34 limit was still enforced. So instead, swap out the 34 with game.get_timestep() and this will be fixed. Fixes #1185. --- desktop_version/src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index cdae341f..c3672eb4 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -866,9 +866,10 @@ int main(int argc, char *argv[]) f_time = SDL_GetTicks64(); const Uint64 f_timetaken = f_time - f_timePrev; - if (!game.over30mode && f_timetaken < 34) + const int timestep = game.get_timestep(); + if (!game.over30mode && f_timetaken < (Uint64) timestep) { - const volatile Uint64 f_delay = 34 - f_timetaken; + const volatile Uint64 f_delay = timestep - f_timetaken; SDL_Delay((Uint32) f_delay); f_time = SDL_GetTicks64(); }