diff options
| author | Ray <[email protected]> | 2021-06-24 11:01:44 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2021-06-24 11:01:44 +0200 |
| commit | 4e9afac2a55cd3d7b347d9e3706e0dd370386ff7 (patch) | |
| tree | 8699743f5839fb36eeddbc49652d83bdaf6648d6 | |
| parent | 2cce5a24c90321df0eed83a1f5e45131a2fe27ee (diff) | |
| download | raylib-4e9afac2a55cd3d7b347d9e3706e0dd370386ff7.tar.gz raylib-4e9afac2a55cd3d7b347d9e3706e0dd370386ff7.zip | |
REVIEWED: WaitTime() #1841
Avoid global variables dependency, now the function is self-contained.
| -rw-r--r-- | src/core.c | 32 |
1 files changed, 15 insertions, 17 deletions
@@ -4716,29 +4716,23 @@ static void InitTimer(void) // Ref: http://www.geisswerks.com/ryan/FAQS/timing.html --> All about timming on Win32! void WaitTime(float ms) { -#if defined(PLATFORM_UWP) - UWPGetSleepFunc()(ms/1000); - return; -#endif - #if defined(SUPPORT_BUSY_WAIT_LOOP) - double prevTime = GetTime(); - double nextTime = 0.0; + double previousTime = GetTime(); + double currentTime = 0.0; // Busy wait loop - while ((nextTime - prevTime) < ms/1000.0f) nextTime = GetTime(); + while ((currentTime - previousTime) < ms/1000.0f) currentTime = GetTime(); #else #if defined(SUPPORT_PARTIALBUSY_WAIT_LOOP) - #define DEFAULT_PARTIALBUSY_WAIT_TIME 4 - #define PARTIALBUSY_WAIT_FACTOR 0.95 - - double halfWait = DEFAULT_PARTIALBUSY_WAIT_TIME; - if (CORE.Time.target > 0) halfWait = CORE.Time.target*PARTIALBUSY_WAIT_FACTOR; - - double destTime = GetTime() + ms/1000; - if (ms > halfWait) ms -= (float)halfWait; + double busyWait = ms*0.05; // NOTE: We are using a busy wait of 5% of the time + ms -= (float)busyWait; #endif + // System halt functions + #if defined(PLATFORM_UWP) + UWPGetSleepFunc()(ms/1000); + return; + #endif #if defined(_WIN32) Sleep((unsigned int)ms); #endif @@ -4757,7 +4751,11 @@ void WaitTime(float ms) #endif #if defined(SUPPORT_PARTIALBUSY_WAIT_LOOP) - while (GetTime() < destTime) { } + double previousTime = GetTime(); + double currentTime = 0.0; + + // Partial busy wait loop (only a fraction of the total wait time) + while ((currentTime - previousTime) < busyWait/1000.0f) currentTime = GetTime(); #endif #endif } |
