Skip to content

Commit

Permalink
Use variable timestep for SDL_Delay
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
InfoTeddy committed Jul 21, 2024
1 parent 487e0c6 commit 6930bde
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions desktop_version/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 6930bde

Please sign in to comment.