REVIEWED: GetTime(), make it consistent between platforms, consider window initialization base time

This commit is contained in:
Ray
2026-03-15 20:39:57 +01:00
parent 29280971be
commit 1d9e24eb58
7 changed files with 19 additions and 17 deletions

View File

@@ -1179,6 +1179,7 @@ void SwapScreenBuffer(void)
double GetTime(void)
{
double time = glfwGetTime(); // Elapsed time since glfwInit()
return time;
}

View File

@@ -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;

View File

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

View File

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

View File

@@ -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;

View File

@@ -986,6 +986,7 @@ void SwapScreenBuffer(void)
double GetTime(void)
{
double time = glfwGetTime(); // Elapsed time since glfwInit()
return time;
}

View File

@@ -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;
}