Unit 1 · Game loops and real-time systems
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.
1. At 60 updates per second, what is the fixed step?
0.01667 seconds, calculated as 1 / 60.2. What happens when the accumulator is at least one step?
3. What is the spiral of death?
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.