Added handling for uclock() returning earlier time

On some systems the call to uclock() would sometimes return a slightly
earlier time than the previous call, this would result in a negative
delta time. This is now checked for and uclock() is now called
repeatedly until we have a valid delta time.
This commit is contained in:
rxi
2014-06-23 19:53:17 +01:00
parent 3b100b4c9b
commit 68664405d2

View File

@@ -23,8 +23,14 @@ double timer_avgTimer;
int l_timer_step(lua_State *L) {
/* Do delta */
long long now = uclock();
timer_lastDt = (now - timer_lastStep) / (double)UCLOCKS_PER_SEC;
long long now;
/* Sometimes a call to uclock() will return a slightly earlier time than the
* previous call, resulting in a negative delta time. The below loop keeps
* trying for a proper value if this occurs. */
do {
now = uclock();
timer_lastDt = (now - timer_lastStep) / (double)UCLOCKS_PER_SEC;
} while (timer_lastDt < 0);
timer_lastStep = now;
/* Do average */
timer_avgAcc += timer_lastDt;