mirror of
https://github.com/raysan5/raylib.git
synced 2026-04-10 01:09:10 -04:00
REVIEWED: GetTime(), make it consistent between platforms, consider window initialization base time
This commit is contained in:
@ -1179,6 +1179,7 @@ void SwapScreenBuffer(void)
|
|||||||
double GetTime(void)
|
double GetTime(void)
|
||||||
{
|
{
|
||||||
double time = glfwGetTime(); // Elapsed time since glfwInit()
|
double time = glfwGetTime(); // Elapsed time since glfwInit()
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -174,7 +174,6 @@ extern "C" {
|
|||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
typedef struct {
|
typedef struct {
|
||||||
double startTime;
|
|
||||||
RGFW_window *window; // Native display device (physical screen connection)
|
RGFW_window *window; // Native display device (physical screen connection)
|
||||||
RGFW_monitor *monitor;
|
RGFW_monitor *monitor;
|
||||||
mg_gamepads minigamepad;
|
mg_gamepads minigamepad;
|
||||||
@ -1127,7 +1126,9 @@ void SwapScreenBuffer(void)
|
|||||||
// Get elapsed time measure in seconds since InitTimer()
|
// Get elapsed time measure in seconds since InitTimer()
|
||||||
double GetTime(void)
|
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)
|
// Open URL with default system browser (if available)
|
||||||
@ -1628,7 +1629,7 @@ int InitPlatform(void)
|
|||||||
|
|
||||||
RGFW_setGlobalHints_OpenGL(hints);
|
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.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
|
#ifndef PLATFORM_WEB_RGFW
|
||||||
i32 screenSizeWidth;
|
i32 screenSizeWidth;
|
||||||
|
|||||||
@ -1276,7 +1276,9 @@ void SwapScreenBuffer(void)
|
|||||||
// Get elapsed time measure in seconds
|
// Get elapsed time measure in seconds
|
||||||
double GetTime(void)
|
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)
|
// Open URL with default system browser (if available)
|
||||||
@ -2122,12 +2124,14 @@ int InitPlatform(void)
|
|||||||
|
|
||||||
// Initialize timing system
|
// Initialize timing system
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// NOTE: No need to call InitTimer(), let SDL manage it internally
|
// Get base time from window initialization
|
||||||
CORE.Time.previous = GetTime(); // Get time as double
|
CORE.Time.base = (double)(SDL_GetPerformanceCounter()/SDL_GetPerformanceFrequency());
|
||||||
|
|
||||||
#if defined(_WIN32) && SUPPORT_WINMM_HIGHRES_TIMER && !SUPPORT_BUSY_WAIT_LOOP
|
#if defined(_WIN32) && SUPPORT_WINMM_HIGHRES_TIMER && !SUPPORT_BUSY_WAIT_LOOP
|
||||||
SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "1"); // SDL equivalent of timeBeginPeriod() and timeEndPeriod()
|
SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "1"); // SDL equivalent of timeBeginPeriod() and timeEndPeriod()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// NOTE: No need to call InitTimer(), let SDL manage it internally
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize storage system
|
// Initialize storage system
|
||||||
|
|||||||
@ -1238,9 +1238,12 @@ void SwapScreenBuffer(void)
|
|||||||
// Get elapsed time measure in seconds
|
// Get elapsed time measure in seconds
|
||||||
double GetTime(void)
|
double GetTime(void)
|
||||||
{
|
{
|
||||||
|
double time = 0.0;
|
||||||
LARGE_INTEGER now = { 0 };
|
LARGE_INTEGER now = { 0 };
|
||||||
QueryPerformanceCounter(&now);
|
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)
|
// Open URL with default system browser (if available)
|
||||||
|
|||||||
@ -341,7 +341,6 @@ void SwapScreenBuffer(void)
|
|||||||
double GetTime(void)
|
double GetTime(void)
|
||||||
{
|
{
|
||||||
double time = 0.0;
|
double time = 0.0;
|
||||||
|
|
||||||
struct timespec ts = { 0 };
|
struct timespec ts = { 0 };
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
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;
|
unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec;
|
||||||
|
|||||||
@ -986,6 +986,7 @@ void SwapScreenBuffer(void)
|
|||||||
double GetTime(void)
|
double GetTime(void)
|
||||||
{
|
{
|
||||||
double time = glfwGetTime(); // Elapsed time since glfwInit()
|
double time = glfwGetTime(); // Elapsed time since glfwInit()
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -962,14 +962,7 @@ void SwapScreenBuffer(void)
|
|||||||
// Get elapsed time measure in seconds since InitTimer()
|
// Get elapsed time measure in seconds since InitTimer()
|
||||||
double GetTime(void)
|
double GetTime(void)
|
||||||
{
|
{
|
||||||
double time = 0.0;
|
double time = emscripten_get_now()*1000.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;
|
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user