Expose GetTime() function to users
Monotonic time since InitWindow() could be retrieved with this function.
This commit is contained in:
parent
a7de5bf6d9
commit
5290390494
3 changed files with 33 additions and 32 deletions
57
src/core.c
57
src/core.c
|
@ -150,11 +150,11 @@
|
||||||
#include <GLFW/glfw3native.h> // which are required for hiding mouse
|
#include <GLFW/glfw3native.h> // which are required for hiding mouse
|
||||||
#endif
|
#endif
|
||||||
//#include <GL/gl.h> // OpenGL functions (GLFW3 already includes gl.h)
|
//#include <GL/gl.h> // OpenGL functions (GLFW3 already includes gl.h)
|
||||||
//#define GLFW_DLL // Using GLFW DLL on Windows -> No, we use static version!
|
|
||||||
|
|
||||||
#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32)
|
#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32)
|
||||||
__stdcall unsigned int timeBeginPeriod(unsigned int uPeriod);
|
// NOTE: Those functions require linking with winmm library
|
||||||
__stdcall unsigned int timeEndPeriod(unsigned int uPeriod);
|
unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
|
||||||
|
unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -351,7 +351,6 @@ extern void UnloadDefaultFont(void); // [Module: text] Unloads default fo
|
||||||
static void InitGraphicsDevice(int width, int height); // Initialize graphics device
|
static void InitGraphicsDevice(int width, int height); // Initialize graphics device
|
||||||
static void SetupFramebufferSize(int displayWidth, int displayHeight);
|
static void SetupFramebufferSize(int displayWidth, int displayHeight);
|
||||||
static void InitTimer(void); // Initialize timer
|
static void InitTimer(void); // Initialize timer
|
||||||
static double GetTime(void); // Returns time since InitTimer() was run
|
|
||||||
static void Wait(float ms); // Wait for some milliseconds (stop program execution)
|
static void Wait(float ms); // Wait for some milliseconds (stop program execution)
|
||||||
static bool GetKeyStatus(int key); // Returns if a key has been pressed
|
static bool GetKeyStatus(int key); // Returns if a key has been pressed
|
||||||
static bool GetMouseButtonStatus(int button); // Returns if a mouse button has been pressed
|
static bool GetMouseButtonStatus(int button); // Returns if a mouse button has been pressed
|
||||||
|
@ -421,6 +420,9 @@ void InitWindow(int width, int height, void *data)
|
||||||
|
|
||||||
// Init graphics device (display device and OpenGL context)
|
// Init graphics device (display device and OpenGL context)
|
||||||
InitGraphicsDevice(width, height);
|
InitGraphicsDevice(width, height);
|
||||||
|
|
||||||
|
// Init hi-res timer
|
||||||
|
InitTimer();
|
||||||
|
|
||||||
#if defined(SUPPORT_DEFAULT_FONT)
|
#if defined(SUPPORT_DEFAULT_FONT)
|
||||||
// Load default font
|
// Load default font
|
||||||
|
@ -428,9 +430,6 @@ void InitWindow(int width, int height, void *data)
|
||||||
LoadDefaultFont();
|
LoadDefaultFont();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Init hi-res timer
|
|
||||||
InitTimer();
|
|
||||||
|
|
||||||
#if defined(PLATFORM_RPI)
|
#if defined(PLATFORM_RPI)
|
||||||
// Init raw input system
|
// Init raw input system
|
||||||
InitMouse(); // Mouse init
|
InitMouse(); // Mouse init
|
||||||
|
@ -786,7 +785,7 @@ void ClearBackground(Color color)
|
||||||
// Setup canvas (framebuffer) to start drawing
|
// Setup canvas (framebuffer) to start drawing
|
||||||
void BeginDrawing(void)
|
void BeginDrawing(void)
|
||||||
{
|
{
|
||||||
currentTime = GetTime(); // Number of elapsed seconds since InitTimer() was called
|
currentTime = GetTime(); // Number of elapsed seconds since InitTimer()
|
||||||
updateTime = currentTime - previousTime;
|
updateTime = currentTime - previousTime;
|
||||||
previousTime = currentTime;
|
previousTime = currentTime;
|
||||||
|
|
||||||
|
@ -1060,6 +1059,24 @@ float GetFrameTime(void)
|
||||||
return (float)frameTime;
|
return (float)frameTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get elapsed time measure in seconds since InitTimer()
|
||||||
|
// NOTE: On PLATFORM_DESKTOP InitTimer() is called on InitWindow()
|
||||||
|
// NOTE: On PLATFORM_DESKTOP, timer is initialized on glfwInit()
|
||||||
|
double GetTime(void)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
|
return glfwGetTime(); // Elapsed time since glfwInit()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
uint64_t time = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
|
||||||
|
|
||||||
|
return (double)(time - baseTime)*1e-9; // Elapsed time since InitTimer()
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Converts Color to float array and normalizes
|
// Converts Color to float array and normalizes
|
||||||
float *ColorToFloat(Color color)
|
float *ColorToFloat(Color color)
|
||||||
{
|
{
|
||||||
|
@ -2118,22 +2135,6 @@ static void InitTimer(void)
|
||||||
previousTime = GetTime(); // Get time as double
|
previousTime = GetTime(); // Get time as double
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get elapsed time measure (in seconds)
|
|
||||||
static double GetTime(void)
|
|
||||||
{
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
|
||||||
return glfwGetTime(); // Elapsed time since glfwInit()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
|
||||||
struct timespec ts;
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
uint64_t time = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
|
|
||||||
|
|
||||||
return (double)(time - baseTime)*1e-9; // Elapsed time since InitTimer()
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for some milliseconds (stop program execution)
|
// Wait for some milliseconds (stop program execution)
|
||||||
// NOTE: Sleep() granularity could be around 10 ms, it means, Sleep() could
|
// NOTE: Sleep() granularity could be around 10 ms, it means, Sleep() could
|
||||||
// take longer than expected... for that reason we use the busy wait loop
|
// take longer than expected... for that reason we use the busy wait loop
|
||||||
|
@ -2602,6 +2603,9 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||||
{
|
{
|
||||||
// Init graphics device (display device and OpenGL context)
|
// Init graphics device (display device and OpenGL context)
|
||||||
InitGraphicsDevice(screenWidth, screenHeight);
|
InitGraphicsDevice(screenWidth, screenHeight);
|
||||||
|
|
||||||
|
// Init hi-res timer
|
||||||
|
InitTimer();
|
||||||
|
|
||||||
#if defined(SUPPORT_DEFAULT_FONT)
|
#if defined(SUPPORT_DEFAULT_FONT)
|
||||||
// Load default font
|
// Load default font
|
||||||
|
@ -2624,9 +2628,6 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Init hi-res timer
|
|
||||||
InitTimer();
|
|
||||||
|
|
||||||
// raylib logo appearing animation (if enabled)
|
// raylib logo appearing animation (if enabled)
|
||||||
if (showLogo)
|
if (showLogo)
|
||||||
{
|
{
|
||||||
|
|
|
@ -522,7 +522,7 @@ static double GetCurrentTime(void)
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
unsigned long long int clockFrequency, currentTime;
|
unsigned long long int clockFrequency, currentTime;
|
||||||
|
|
||||||
QueryPerformanceFrequency(&clockFrequency);
|
QueryPerformanceFrequency(&clockFrequency); // BE CAREFUL: Costly operation!
|
||||||
QueryPerformanceCounter(¤tTime);
|
QueryPerformanceCounter(¤tTime);
|
||||||
|
|
||||||
time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds
|
time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds
|
||||||
|
@ -538,8 +538,8 @@ static double GetCurrentTime(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
//#define CLOCK_REALTIME CALENDAR_CLOCK
|
//#define CLOCK_REALTIME CALENDAR_CLOCK // returns UTC time since 1970-01-01
|
||||||
//#define CLOCK_MONOTONIC SYSTEM_CLOCK
|
//#define CLOCK_MONOTONIC SYSTEM_CLOCK // returns the time since boot time
|
||||||
|
|
||||||
clock_serv_t cclock;
|
clock_serv_t cclock;
|
||||||
mach_timespec_t now;
|
mach_timespec_t now;
|
||||||
|
|
|
@ -722,7 +722,7 @@ RLAPI Matrix GetCameraMatrix(Camera camera); // Returns cam
|
||||||
RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum)
|
RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum)
|
||||||
RLAPI int GetFPS(void); // Returns current FPS
|
RLAPI int GetFPS(void); // Returns current FPS
|
||||||
RLAPI float GetFrameTime(void); // Returns time in seconds for last frame drawn
|
RLAPI float GetFrameTime(void); // Returns time in seconds for last frame drawn
|
||||||
//RLAPI double GetCurrentTime(void); // Return current time in seconds
|
RLAPI double GetTime(void); // Returns elapsed time in seconds since InitWindow()
|
||||||
|
|
||||||
// Color-related functions
|
// Color-related functions
|
||||||
RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color
|
RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue