diff --git a/src/rcore.c b/src/rcore.c index ece265144..eb8fbae42 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -686,6 +686,10 @@ static void RecordAutomationEvent(unsigned int frame); // Record frame even static void PlayAutomationEvent(unsigned int frame); // Play frame events (from internal events array) #endif +#if defined(SUPPORT_BUSY_WAIT_LOOP) || defined(SUPPORT_PARTIALBUSY_WAIT_LOOP) +static void BusyWaitUntil(double destinationTime); +#endif + #if defined(_WIN32) // NOTE: We declare Sleep() function symbol to avoid including windows.h (kernel32.lib linkage required) void __stdcall Sleep(unsigned long msTimeout); // Required for: WaitTime() @@ -4826,15 +4830,14 @@ static void InitTimer(void) // Ref: http://www.geisswerks.com/ryan/FAQS/timing.html --> All about timming on Win32! void WaitTime(double seconds) { -#if defined(SUPPORT_BUSY_WAIT_LOOP) - double previousTime = GetTime(); - double currentTime = 0.0; +#if defined(SUPPORT_BUSY_WAIT_LOOP) || defined(SUPPORT_PARTIALBUSY_WAIT_LOOP) + double destinationTime = GetTime() + seconds; +#endif - // Busy wait loop - while ((currentTime - previousTime) < seconds) currentTime = GetTime(); +#if defined(SUPPORT_BUSY_WAIT_LOOP) + BusyWaitUntil(destinationTime); #else #if defined(SUPPORT_PARTIALBUSY_WAIT_LOOP) - double destinationTime = GetTime() + seconds; double sleepSeconds = seconds - seconds*0.05; // NOTE: We reserve a percentage of the time for busy waiting #else double sleepSeconds = seconds; @@ -4859,11 +4862,18 @@ void WaitTime(double seconds) #endif #if defined(SUPPORT_PARTIALBUSY_WAIT_LOOP) - while (GetTime() < destinationTime) { } + BusyWaitUntil(destinationTime); #endif #endif } +#if defined(SUPPORT_BUSY_WAIT_LOOP) || defined(SUPPORT_PARTIALBUSY_WAIT_LOOP) +static void BusyWaitUntil(double destinationTime) +{ + while (GetTime() < destinationTime) { } +} +#endif + // Swap back buffer with front buffer (screen drawing) void SwapScreenBuffer(void) {