Tutorial 3: Timing and Fixed Updates

Unit 1 · Game loops and real-time systems

Objectives

Variable versus fixed time

A variable-step update receives the measured delta each frame and is simple for many arcade games. Physics and deterministic simulations often benefit from a fixed step, such as 1/60 second, so the same rules run with the same interval.

double accumulator = 0.0;
final double step = 1.0 / 60.0;

accumulator += Math.min(deltaSeconds, 0.25);
while (accumulator >= step) {
    updateWorld(step);
    accumulator -= step;
}
render();

The cap prevents a long pause from demanding thousands of updates. The loop may still fall behind if each update costs more than the time it represents: this is the spiral of death. Measure update cost and keep simulation work bounded.

Exercises

  1. Calculate how many fixed updates are needed for a 0.05-second frame.
  2. Trace an accumulator through three frames: 0.010, 0.020, and 0.040 seconds.
  3. List one system suited to fixed updates and one suited to variable updates.

Self-check

  1. Why use a fixed simulation step?
  2. What does the accumulator store?
  3. Why cap delta time after a pause?

Self-Check Quiz

1. At 60 updates per second, what is the fixed step?

AnswerApproximately 0.01667 seconds, calculated as 1 / 60.

2. What happens when the accumulator is at least one step?

AnswerThe simulation performs one fixed update and subtracts one step from the accumulator.

3. What is the spiral of death?

AnswerA feedback loop in which falling behind requires more catch-up work, causing the program to fall further behind.

Homework

  1. Implement an accumulator-based simulation and log update count per rendered frame.
  2. Compare variable and fixed movement over the same total elapsed time.
  3. Design a policy for long pauses and justify its maximum delta.
Sample answer

Use a fixed step of 1.0 / 60.0, add capped delta to an accumulator, and run updates while enough time remains. The cap might be 0.25 seconds to avoid a huge catch-up burst. Both methods should produce similar movement for simple motion, but fixed updates give more predictable simulation timing.

👤