Skip to content

Commit

Permalink
Loop|Client|Server: Advance a single tic if app has been stuck for a …
Browse files Browse the repository at this point in the history
…long time

This addresses the problem where Doomsday would remain stuck running
a massive number of tics after wall time has skipped (e.g., app hung,
clock change).
  • Loading branch information
skyjake committed May 9, 2015
1 parent 5ae247a commit 71d6067
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doomsday/apps/client/src/dd_loop.cpp
Expand Up @@ -57,6 +57,13 @@
*/
#define MAX_FRAME_TIME (1.0/MIN_TIC_RATE)

/**
* If the loop is stuck for more than this number of seconds, the elapsed time is
* ignored. The assumption is that the app was suspended or was not able to run,
* so no point in running tics.
*/
#define MAX_ELAPSED_TIME 5

float frameTimePos; // 0...1: fractional part for sharp game tics.

int maxFrameRate = 120; // Zero means 'unlimited'.
Expand Down Expand Up @@ -393,6 +400,11 @@ void Loop_RunTics(void)
// Let's see how much time has passed. This is affected by "settics".
nowTime = Timer_Seconds();
elapsedTime = nowTime - lastRunTicsTime;
if(elapsedTime > MAX_ELAPSED_TIME)
{
// It was too long ago, no point in running individual ticks. Just do one.
elapsedTime = MAX_FRAME_TIME;
}

// Remember when this frame started.
lastRunTicsTime = nowTime;
Expand Down

0 comments on commit 71d6067

Please sign in to comment.