A game loop is the simulation step of a realm — a realm is, by definition, the region served by a single one. Each iteration turns the realm’s input streams into its output streams:
- Record the current position of every input stream, so the whole iteration reads a consistent snapshot of its inputs.
- Run AI.
- Move objects.
- Generate sounds.
- Compute output deltas and append them to the output streams.
- Repeat.
Why the shape matters#
Reading inputs at a recorded stream position, and emitting deltas appended to a stream, is what makes the loop a state machine over the log: two nodes that begin in the same state and consume the same inputs in the same order end in the same state. That is the property the peer-to-peer network leans on in place of an authoritative server — convergence follows from determinism rather than from anyone being in charge.
Determinism is demanding in practice. It rules out reading a wall clock or un-seeded randomness mid-iteration, and it requires that floating-point results agree across machines and browsers. A fixed timestep for simulation, decoupled from a variable-rate render, is the standard way to keep the loop reproducible while still drawing as fast as the display allows.
External links#
Similar concepts and prior art:
- Game structure on Wikipedia
- Game Loop in Game Programming Patterns
- Fix Your Timestep! and Deterministic Lockstep — Gaffer on Games
- State machine replication on Wikipedia
See also#
- Realm · The Log · Parameter Stream · Node