1
Fork 0

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.
This commit is contained in:
Joshua Goins 2022-10-03 21:56:02 -04:00
parent 4ef38faada
commit 605c6030a5

View file

@ -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) {