REVIEWED: WaitTime() #1841
Avoid global variables dependency, now the function is self-contained.
This commit is contained in:
parent
2cce5a24c9
commit
4e9afac2a5
1 changed files with 15 additions and 17 deletions
32
src/core.c
32
src/core.c
|
@ -4716,29 +4716,23 @@ static void InitTimer(void)
|
||||||
// Ref: http://www.geisswerks.com/ryan/FAQS/timing.html --> All about timming on Win32!
|
// Ref: http://www.geisswerks.com/ryan/FAQS/timing.html --> All about timming on Win32!
|
||||||
void WaitTime(float ms)
|
void WaitTime(float ms)
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_UWP)
|
|
||||||
UWPGetSleepFunc()(ms/1000);
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_BUSY_WAIT_LOOP)
|
#if defined(SUPPORT_BUSY_WAIT_LOOP)
|
||||||
double prevTime = GetTime();
|
double previousTime = GetTime();
|
||||||
double nextTime = 0.0;
|
double currentTime = 0.0;
|
||||||
|
|
||||||
// Busy wait loop
|
// Busy wait loop
|
||||||
while ((nextTime - prevTime) < ms/1000.0f) nextTime = GetTime();
|
while ((currentTime - previousTime) < ms/1000.0f) currentTime = GetTime();
|
||||||
#else
|
#else
|
||||||
#if defined(SUPPORT_PARTIALBUSY_WAIT_LOOP)
|
#if defined(SUPPORT_PARTIALBUSY_WAIT_LOOP)
|
||||||
#define DEFAULT_PARTIALBUSY_WAIT_TIME 4
|
double busyWait = ms*0.05; // NOTE: We are using a busy wait of 5% of the time
|
||||||
#define PARTIALBUSY_WAIT_FACTOR 0.95
|
ms -= (float)busyWait;
|
||||||
|
|
||||||
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;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// System halt functions
|
||||||
|
#if defined(PLATFORM_UWP)
|
||||||
|
UWPGetSleepFunc()(ms/1000);
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
Sleep((unsigned int)ms);
|
Sleep((unsigned int)ms);
|
||||||
#endif
|
#endif
|
||||||
|
@ -4757,7 +4751,11 @@ void WaitTime(float ms)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SUPPORT_PARTIALBUSY_WAIT_LOOP)
|
#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
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue