From 711298e2744b1e66ca3b455e9a1dea0066bf3506 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 9 Jul 2021 23:42:18 +0200 Subject: [PATCH] skeleton: use SDL_GetPerformanceCounter insted of SDL_GetTicks --- skeleton/sdl2.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/skeleton/sdl2.cpp b/skeleton/sdl2.cpp index 86d71e6..80a9f05 100644 --- a/skeleton/sdl2.cpp +++ b/skeleton/sdl2.cpp @@ -224,7 +224,8 @@ main(int argc, char *argv[]) if(EventHandler(RWINITIALIZE, nil) == EVENTERROR) return 0; - float lastTime = SDL_GetTicks(); + Uint64 lastTicks = SDL_GetPerformanceCounter(); + const float tickPeriod = 1.f / SDL_GetPerformanceFrequency(); SDL_Event event; int mouseButtons = 0; @@ -297,12 +298,12 @@ main(int argc, char *argv[]) } } } - float currTime = SDL_GetTicks(); - float timeDelta = (currTime - lastTime) * 0.001f; + Uint64 currTicks = SDL_GetPerformanceCounter(); + float timeDelta = (currTicks - lastTicks) * tickPeriod; EventHandler(IDLE, &timeDelta); - lastTime = currTime; + lastTicks = currTicks; } SDL_StopTextInput();