back to the school
docs/001-fixed-timestep.md
1 # ADR 001: advance the game at a fixed step
2
3 Status: accepted
4
5 ## Decision
6
7 `advance` in `update.ts` adds elapsed frame time to an accumulator and calls `step` with `FIXED_STEP` until the accumulator is spent. Each step moves the ball a known distance.
8
9 ## Reason
10
11 The ball travels at a constant speed in world units. A variable `dt` makes the same two frames land at different places on a 60 Hz screen and a 144 Hz screen, so a bounce can miss a paddle on one machine and hit it on another. A fixed step makes the physics repeatable and keeps `step` free of wall-clock reads.
12
13 The accumulator is capped. `FRAME_TIME_CAP` bounds a long pause and `MAX_STEPS_PER_FRAME` stops a catch-up loop from freezing the frame after the window is restored.
14
15 ## Consequences
16
17 `step` never needs to know how fast the monitor refreshes. The draw call can happen at any rate and reads the same state. A reader who changes `FIXED_STEP` changes the feel of bounces, so that constant stays in one place.
18