summaryrefslogtreecommitdiffhomepage
path: root/src/core.c
diff options
context:
space:
mode:
authorRay San <[email protected]>2017-12-19 14:06:54 +0100
committerRay San <[email protected]>2017-12-19 14:06:54 +0100
commit5290390494c23055c689c183aea6d88039b0d5fb (patch)
tree17de956653f0da54ed558cf58585a4590468b3d1 /src/core.c
parenta7de5bf6d9b707c20b95b6cff56aaf4f2c009857 (diff)
downloadraylib-5290390494c23055c689c183aea6d88039b0d5fb.tar.gz
raylib-5290390494c23055c689c183aea6d88039b0d5fb.zip
Expose GetTime() function to users
Monotonic time since InitWindow() could be retrieved with this function.
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/core.c b/src/core.c
index 8a2e40b3..6468539f 100644
--- a/src/core.c
+++ b/src/core.c
@@ -150,11 +150,11 @@
#include <GLFW/glfw3native.h> // which are required for hiding mouse
#endif
//#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)
- __stdcall unsigned int timeBeginPeriod(unsigned int uPeriod);
- __stdcall unsigned int timeEndPeriod(unsigned int uPeriod);
+ // NOTE: Those functions require linking with winmm library
+ unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
+ unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
#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 SetupFramebufferSize(int displayWidth, int displayHeight);
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 bool GetKeyStatus(int key); // Returns if a key 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)
InitGraphicsDevice(width, height);
+
+ // Init hi-res timer
+ InitTimer();
#if defined(SUPPORT_DEFAULT_FONT)
// Load default font
@@ -428,9 +430,6 @@ void InitWindow(int width, int height, void *data)
LoadDefaultFont();
#endif
- // Init hi-res timer
- InitTimer();
-
#if defined(PLATFORM_RPI)
// Init raw input system
InitMouse(); // Mouse init
@@ -786,7 +785,7 @@ void ClearBackground(Color color)
// Setup canvas (framebuffer) to start drawing
void BeginDrawing(void)
{
- currentTime = GetTime(); // Number of elapsed seconds since InitTimer() was called
+ currentTime = GetTime(); // Number of elapsed seconds since InitTimer()
updateTime = currentTime - previousTime;
previousTime = currentTime;
@@ -1060,6 +1059,24 @@ float GetFrameTime(void)
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
float *ColorToFloat(Color color)
{
@@ -2118,22 +2135,6 @@ static void InitTimer(void)
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)
// 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
@@ -2602,6 +2603,9 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
{
// Init graphics device (display device and OpenGL context)
InitGraphicsDevice(screenWidth, screenHeight);
+
+ // Init hi-res timer
+ InitTimer();
#if defined(SUPPORT_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)
if (showLogo)
{