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:
10
src/timer.c
10
src/timer.c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user