diff options
| author | Ray <[email protected]> | 2021-03-12 17:18:48 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2021-03-12 17:18:48 +0100 |
| commit | 08723659386e463219d60447ef83ebdc5cf3f2f9 (patch) | |
| tree | 81c88aa4db04b8625a97a357749568a754c32fc3 /src | |
| parent | 755ed388b2c9f1355d765e83c6dce5372e8e16d6 (diff) | |
| download | raylib-08723659386e463219d60447ef83ebdc5cf3f2f9.tar.gz raylib-08723659386e463219d60447ef83ebdc5cf3f2f9.zip | |
Add config flag: SUPPORT_WINMM_HIGHRES_TIMER #1641
Useful to avoid WinMM requirement and useful to avoid possible performance issues.
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.h | 3 | ||||
| -rw-r--r-- | src/core.c | 18 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/config.h b/src/config.h index d0c8cfdd..aecff8e5 100644 --- a/src/config.h +++ b/src/config.h @@ -40,6 +40,9 @@ #define SUPPORT_SSH_KEYBOARD_RPI 1 // Draw a mouse pointer on screen #define SUPPORT_MOUSE_CURSOR_NATIVE 1 +// Setting a higher resolution can improve the accuracy of time-out intervals in wait functions. +// However, it can also reduce overall system performance, because the thread scheduler switches tasks more often. +#define SUPPORT_WINMM_HIGHRES_TIMER 1 // Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used //#define SUPPORT_BUSY_WAIT_LOOP 1 // Use a half-busy wait loop, in this case frame sleeps for some time and runs a busy-wait-loop at the end @@ -197,7 +197,7 @@ #define GLFW_EXPOSE_NATIVE_WIN32 #include "GLFW/glfw3native.h" // WARNING: It requires customization to avoid windows.h inclusion! - #if !defined(SUPPORT_BUSY_WAIT_LOOP) + #if defined(SUPPORT_WINMM_HIGHRES_TIMER) && !defined(SUPPORT_BUSY_WAIT_LOOP) // NOTE: Those functions require linking with winmm library unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod); unsigned int __stdcall timeEndPeriod(unsigned int uPeriod); @@ -575,7 +575,7 @@ static int FindNearestConnectorMode(const drmModeConnector *connector, uint widt #endif // PLATFORM_RPI || PLATFORM_DRM #if defined(_WIN32) - // NOTE: We include Sleep() function signature here to avoid windows.h inclusion + // NOTE: We include Sleep() function signature here to avoid windows.h inclusion (kernel32 lib) void __stdcall Sleep(unsigned long msTimeout); // Required for Wait() #endif @@ -819,7 +819,7 @@ void CloseWindow(void) glfwTerminate(); #endif -#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32) && !defined(PLATFORM_UWP) +#if defined(_WIN32) && defined(SUPPORT_WINMM_HIGHRES_TIMER) && !defined(SUPPORT_BUSY_WAIT_LOOP) && !defined(PLATFORM_UWP) timeEndPeriod(1); // Restore time period #endif @@ -4204,10 +4204,14 @@ static void SetupFramebuffer(int width, int height) // Initialize hi-resolution timer static void InitTimer(void) { - srand((unsigned int)time(NULL)); // Initialize random seed + srand((unsigned int)time(NULL)); // Initialize random seed -#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32) && !defined(PLATFORM_UWP) - timeBeginPeriod(1); // Setup high-resolution timer to 1ms (granularity of 1-2 ms) +// Setting a higher resolution can improve the accuracy of time-out intervals in wait functions. +// However, it can also reduce overall system performance, because the thread scheduler switches tasks more often. +// High resolutions can also prevent the CPU power management system from entering power-saving modes. +// Setting a higher resolution does not improve the accuracy of the high-resolution performance counter. +#if defined(_WIN32) && defined(SUPPORT_WINMM_HIGHRES_TIMER) && !defined(SUPPORT_BUSY_WAIT_LOOP) && !defined(PLATFORM_UWP) + timeBeginPeriod(1); // Setup high-resolution timer to 1ms (granularity of 1-2 ms) #endif #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(PLATFORM_DRM) @@ -4220,7 +4224,7 @@ static void InitTimer(void) else TRACELOG(LOG_WARNING, "TIMER: Hi-resolution timer not available"); #endif - CORE.Time.previous = GetTime(); // Get time as double + CORE.Time.previous = GetTime(); // Get time as double } // Wait for some milliseconds (stop program execution) |
