Fixed Timestep Game Loops & Frame Pacing
Fixed Timestep Game Loops & Frame Pacing
A game loop coordinates input, simulation, and rendering. The important distinction is that render frames do not need to run at the same rate as simulation updates. A fixed simulation step makes physics and gameplay updates easier to reason about when frame time varies.
Variable vs. Fixed Timestep
A variable timestep passes the measured frame duration directly into simulation:
position += velocity * frame_delta
This is simple, but a slow frame produces a large simulation step. Collision behavior, integration error, and gameplay feel can change with frame rate.
A fixed timestep advances simulation using a constant interval, such as 1/60 second. Rendering can still run at any rate.
Accumulator Pattern
Accumulate elapsed real time, then run as many fixed updates as needed to catch up:
accumulator += frame_time
while accumulator >= fixed_dt:
previous_state = current_state
simulate(fixed_dt)
accumulator -= fixed_dt
alpha = accumulator / fixed_dt
render(interpolate(previous_state, current_state, alpha))
The interpolation factor alpha is between 0 and 1. Rendering between the previous and current simulation states avoids visibly stepping at the lower simulation frequency. This introduces up to one simulation-step of visual delay, which is usually preferable to jitter.
Practical Loop
fixed_dt :: 1.0 / 60.0
max_frame_dt :: 0.25
max_steps_per_frame :: 8
accumulator := 0.0
previous := current
for running {
frame_dt := min(clock_delta(), max_frame_dt)
accumulator += frame_dt
process_input()
steps := 0
for accumulator >= fixed_dt && steps < max_steps_per_frame {
previous = current
simulate(fixed_dt)
accumulator -= fixed_dt
steps += 1
}
// Avoid an unbounded catch-up spiral after a severe stall.
if steps == max_steps_per_frame && accumulator >= fixed_dt {
accumulator = mod(accumulator, fixed_dt)
}
alpha := accumulator / fixed_dt
render_interpolated(previous, current, alpha)
}
This is an architectural sketch: adapt clock, state-copy, and interpolation functions to the engine. Some games prefer to retain accumulated time and slow rendering rather than discard simulation time; choose deliberately based on whether responsiveness or strict simulation-time preservation matters more.
Why the Step Limit Matters
If a frame takes too long, the accumulator may demand many simulation updates. Those updates make the next frame even slower, which creates more accumulated time: the spiral of death. Clamp unusually large frame deltas and cap catch-up work so one stall cannot consume the entire frame budget.
Do not silently discard time in systems where every simulation tick must be preserved. For deterministic lockstep or authoritative server simulation, define an explicit overload policy and monitor missed deadlines.
Input, Physics, and Networking
- Sample device input once per render frame, then queue commands for the next simulation tick. Keep edge-triggered actions (pressed/released) so a short tap is not lost between ticks.
- Apply forces and integrate physics using the fixed
dt. See Physics Solvers & Numerical Integration. - Multiplayer commands should identify the simulation tick or sequence number they belong to. A fixed step helps clients and servers agree on update cadence, but does not make a simulation deterministic by itself. Floating-point differences, iteration order, random seeds, and engine behavior still matter.
- Keep visual-only animation, UI, and camera smoothing independent where appropriate; they do not all need to run at the physics rate.
Choosing a Tick Rate
60 Hz (about 16.67 ms per step) is a common starting point, not a universal rule. Higher rates improve temporal resolution but increase CPU cost and network traffic. Lower rates may suit slower simulations. Profile the complete workload and choose a rate that fits the game.
Related Notes
- Physics Solvers & Numerical Integration — Integration methods and collision solving.
- Game Networking Basics — Network update rates and transport.
- Client-Side Prediction & Server Reconciliation — Tick-based input history and replay.
- Odin Engine Architecture — A custom engine's frame-loop structure.