diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 1975a7bfe..9b6881d40 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1179,6 +1179,7 @@ void SwapScreenBuffer(void) double GetTime(void) { double time = glfwGetTime(); // Elapsed time since glfwInit() + return time; } diff --git a/src/platforms/rcore_desktop_rgfw.c b/src/platforms/rcore_desktop_rgfw.c index b091215ed..b92775592 100755 --- a/src/platforms/rcore_desktop_rgfw.c +++ b/src/platforms/rcore_desktop_rgfw.c @@ -174,7 +174,6 @@ extern "C" { // Types and Structures Definition //---------------------------------------------------------------------------------- typedef struct { - double startTime; RGFW_window *window; // Native display device (physical screen connection) RGFW_monitor *monitor; mg_gamepads minigamepad; @@ -1127,7 +1126,9 @@ void SwapScreenBuffer(void) // Get elapsed time measure in seconds since InitTimer() double GetTime(void) { - return get_time_seconds() - platform.startTime; + double time = get_time_seconds() - CORE.Time.base; + + return time; } // Open URL with default system browser (if available) @@ -1628,7 +1629,7 @@ int InitPlatform(void) RGFW_setGlobalHints_OpenGL(hints); platform.window = RGFW_createWindow((CORE.Window.title != 0)? CORE.Window.title : " ", 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, flags | RGFW_windowOpenGL); - platform.startTime = get_time_seconds(); + CORE.Time.base = get_time_seconds(); #ifndef PLATFORM_WEB_RGFW i32 screenSizeWidth; diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 11c83c72c..5cd93ebd7 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -1276,7 +1276,9 @@ void SwapScreenBuffer(void) // Get elapsed time measure in seconds double GetTime(void) { - return (double)SDL_GetPerformanceCounter() / SDL_GetPerformanceFrequency(); + double time = (double)(SDL_GetPerformanceCounter()/SDL_GetPerformanceFrequency()) - CORE.Time.base; + + return time; } // Open URL with default system browser (if available) @@ -2122,12 +2124,14 @@ int InitPlatform(void) // Initialize timing system //---------------------------------------------------------------------------- - // NOTE: No need to call InitTimer(), let SDL manage it internally - CORE.Time.previous = GetTime(); // Get time as double - + // Get base time from window initialization + CORE.Time.base = (double)(SDL_GetPerformanceCounter()/SDL_GetPerformanceFrequency()); + #if defined(_WIN32) && SUPPORT_WINMM_HIGHRES_TIMER && !SUPPORT_BUSY_WAIT_LOOP SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "1"); // SDL equivalent of timeBeginPeriod() and timeEndPeriod() #endif + + // NOTE: No need to call InitTimer(), let SDL manage it internally //---------------------------------------------------------------------------- // Initialize storage system diff --git a/src/platforms/rcore_desktop_win32.c b/src/platforms/rcore_desktop_win32.c index a56a7f090..1cf8826aa 100644 --- a/src/platforms/rcore_desktop_win32.c +++ b/src/platforms/rcore_desktop_win32.c @@ -1238,9 +1238,12 @@ void SwapScreenBuffer(void) // Get elapsed time measure in seconds double GetTime(void) { + double time = 0.0; LARGE_INTEGER now = { 0 }; QueryPerformanceCounter(&now); - return (double)(now.QuadPart - CORE.Time.base)/(double)platform.timerFrequency.QuadPart; + time = (double)(now.QuadPart - CORE.Time.base)/(double)platform.timerFrequency.QuadPart; + + return time; } // Open URL with default system browser (if available) diff --git a/src/platforms/rcore_template.c b/src/platforms/rcore_template.c index 40a1922e7..368dd3e77 100644 --- a/src/platforms/rcore_template.c +++ b/src/platforms/rcore_template.c @@ -341,7 +341,6 @@ void SwapScreenBuffer(void) double GetTime(void) { double time = 0.0; - struct timespec ts = { 0 }; clock_gettime(CLOCK_MONOTONIC, &ts); unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec; diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index ae847d8c9..62b2afda9 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -986,6 +986,7 @@ void SwapScreenBuffer(void) double GetTime(void) { double time = glfwGetTime(); // Elapsed time since glfwInit() + return time; } diff --git a/src/platforms/rcore_web_emscripten.c b/src/platforms/rcore_web_emscripten.c index df3234217..60b647f60 100644 --- a/src/platforms/rcore_web_emscripten.c +++ b/src/platforms/rcore_web_emscripten.c @@ -962,14 +962,7 @@ void SwapScreenBuffer(void) // Get elapsed time measure in seconds since InitTimer() double GetTime(void) { - double time = 0.0; - /* - struct timespec ts = { 0 }; - clock_gettime(CLOCK_MONOTONIC, &ts); - unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec; - time = (double)(nanoSeconds - CORE.Time.base)*1e-9; // Elapsed time since InitTimer() - */ - time = emscripten_get_now()*1000.0; + double time = emscripten_get_now()*1000.0; return time; }