promptsandmore.com

Click. Tweak. Observe. Understand.

Time & Simulation

Fixed vs variable timestep, event queues, and determinism

System Overview

Fixed timestep updates simulation at constant intervals (e.g., 60 FPS), ensuring deterministic, frame-rate independent behavior. Variable timestep uses actual frame time, simpler but non-deterministic and frame-rate dependent.

The accumulator pattern allows fixed timestep to handle variable frame rates: accumulate frame time, update in fixed steps until accumulator is depleted. This maintains determinism while adapting to performance variations.

Why Include Gravity?

Gravity (acceleration) is included in this demo for several important reasons:

Try it yourself: Set gravity to 0 and watch how the desync becomes minimal. Then increase gravity and observe how quickly the two simulations diverge. This demonstrates why fixed timestep is essential for physics-heavy games.

Why Games Use This

Key Parameters

Failure Modes

Scaling Behavior

Fixed timestep performance depends on update frequency and complexity. If frame time exceeds timestep, multiple updates occur per frame. Worst case: frame takes longer than timestep, causing spiral of death.

Variable timestep is O(1) per frame but non-deterministic. Fixed timestep is O(n) where n = frame_time / timestep.

Related Algorithms

Free Tools & Libraries

System-Thinking Prompts