From 605c6030a557965fba95150c2cfe73f312bbe726 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 3 Oct 2022 21:56:02 -0400 Subject: [PATCH] Fix broken sync_framerate_with_timer For some reason their implementation is broken, and will randomly speed up and down. This fixes it and now it properly syncs the framerate if you need to fallback to this method. --- src/pc/gfx/gfx_sdl2.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 65d7b4e..923d264 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -274,13 +274,14 @@ static bool gfx_sdl_start_frame(void) { static void sync_framerate_with_timer(void) { // Number of milliseconds a frame should take (30 fps) - const Uint32 FRAME_TIME = 1000 / 30; - static Uint32 last_time; - Uint32 elapsed = SDL_GetTicks() - last_time; + const Uint64 FRAME_TIME = 1000 / 30; + static Uint64 last_time; + Uint64 elapsed = SDL_GetTicks64() - last_time; if (elapsed < FRAME_TIME) SDL_Delay(FRAME_TIME - elapsed); - last_time += FRAME_TIME; + + last_time = SDL_GetTicks64(); } static void gfx_sdl_swap_buffers_begin(void) {