skip to content

How would you set a physics determinism policy for replays when a replay recorded on one platform diverges on another?

level: principalimportance: should knowfreq 30%

answer

  1. three strengths of determinism
  2. insertion order and thread count
  3. cross-platform mode costs speed
  4. record inputs or record states
  5. checksums find the first bad step

basics

~20 s

Decide first whether replays must play across platforms. If so, either enable the middleware's cross-platform determinism and enforce identical inputs, order and versions, or record body states instead of inputs; checksums per step locate divergence.

solid answer

~40 s

Physics determinism comes in three strengths: same build on the same machine, independent of thread count and unrelated bodies, and identical across CPUs and compilers. Most middleware give the first if you feed a fixed step and create bodies in the same order; the second and third usually need an explicit mode or build option that costs performance. A policy answers: do replays cross platforms or patches, which bodies matter to the outcome, and what storage is acceptable? Input replays are tiny but break on any divergence, so they need the cross-platform mode, pinned middleware versions, full state capture including solver caches, and per-step checksums. Recording transforms of gameplay-relevant bodies is larger but always plays back. Many teams use a hybrid: inputs plus periodic state keyframes, with cosmetic debris excluded.

code

pseudocode · 17 lines
pseudocode
// recording: one hash per fixed physics step
for step in recording:
    applyRecordedInputs(step)
    physicsWorld.step(fixedStepLength)
    hash = 0
    for body in gameplayBodies sorted by stableId:
        hash = combine(hash, bitsOf(body.position), bitsOf(body.linearVelocity))
    recording.hashes[step] = hash

// playback on another platform
for step in recording:
    applyRecordedInputs(step)
    physicsWorld.step(fixedStepLength)
    if hashOfGameplayBodies() != recording.hashes[step]:
        report("first divergence at step", step)
        dumpBodies(step)
        stop

go deeper

for a junior

Recall that replaying recorded inputs only works if the physics produces exactly the same result every time.

for a middle

Explain what breaks same-machine determinism: variable step lengths, creation order, and forces applied per rendered frame.

for a senior

Diagnose a divergent replay with per-step checksums and identify the first step and the body where the runs disagree.

for a principal

Choose between input replays, state recordings and a hybrid by weighing cross-platform needs, storage, patch survival and the cost of a determinism mode.

## The symptom A match replay recorded on a desktop plays fine there, but on a handheld built from the same game version a tumbling barrel lands a few centimetres to the left, a door it was meant to block stays open, and by the end the replay shows a different winner. The replay stored only player inputs and relied on the physics running the same way twice. On the second platform it did not. ## Three strengths of determinism 1. **Same build, same machine, same inputs.** Most middleware produce the same results if they get the same fixed step length, the same bodies created in the same order and the same calls in the same order. A variable step, iterating a hash map to create bodies, or applying forces in frame-rate-dependent amounts already breaks this level. 2. **Independent of scheduling and unrelated bodies.** Multithreaded solvers may process islands or constraints in an order that depends on thread count or timing, and adding a body in one corner of the level can reorder work elsewhere. Some middleware offer a mode that sorts work so results do not depend on either, at some performance cost. 3. **Across platforms.** Different CPUs, compilers and math libraries can round differently. Middleware that support this usually do it through a build option or mode that avoids instructions and optimisations whose results differ, and uses their own implementations of functions like sine and arctangent. It is slower, and every line of the game's own code that feeds the simulation must follow the same rules. The floating-point causes themselves are a separate numerical subject. ## What the game must also guarantee - The **same middleware version and build options** on every platform. A patch to the library can change results; replays recorded before it diverge after it. - **Full state** when a replay starts mid-session: positions and velocities are not enough. Solver caches used for warm starting, contact caches, sleep timers and broad-phase ordering also shape the next step. Either save and restore them, or start replays from a state where both sides reset caches in the same way. - **Deterministic gameplay inputs**: forces applied per physics step, not per rendered frame, and in a fixed order. ## The policy options | Approach | Replay size | Survives divergence | Main cost | |---|---|---|---| | Record inputs, re-simulate | tiny | no: any difference grows | determinism mode, version pinning, engineering discipline | | Record transforms of relevant bodies | large | yes: playback is exact | storage and bandwidth; cannot re-simulate alternatives | | Inputs plus periodic state keyframes | medium | partly: corrects at each keyframe | complexity of two systems | Questions that decide between them: - **Do replays cross platforms, cross-play matches or patches?** A single-player kill-cam replayed on the device that recorded it can live with level 1; uploaded replays watched on any device cannot. - **Which bodies matter?** Separate gameplay-relevant physics (the barrel that blocks the door) from cosmetic debris. Cosmetic bodies can be non-deterministic and excluded from checksums and recordings. - **How long are replays?** Recording 50 bodies' transforms at 30 samples per second for a 3-minute match is 270,000 samples, several megabytes at full precision before compression; recording 5,000 debris pieces is not viable, which pushes towards inputs plus a deterministic subset. - **Is lockstep networking planned?** If the same simulation must also agree between machines live, cross-platform determinism stops being optional, and some teams write a small deterministic simulation of their own, sometimes in fixed point, rather than depend on general middleware. ## Detecting and locating divergence Build the tool before the bug report arrives: - Hash the positions and velocities of gameplay-relevant bodies every step, in a fixed order, and store the hashes with the recording. - On playback, compare hashes and stop at the **first divergent step**; dump both sides' bodies at that step. - Run nightly checks that replay recorded sessions on every target platform. The first divergent step usually points straight at the cause: a body created in a different order, a force applied from render-rate code, a library built with different options, or a thread-count-dependent solve. ## A reasonable default For most games: record transforms for short kill-cams, run input replays only on the platform that recorded them, and invest in the cross-platform mode, pinned versions and checksums only when shared replays or lockstep are part of the product. The lead's job is to make that choice explicitly, because retrofitting determinism after launch is far more expensive than designing for it.

  • Why can a replay diverge even on the same platform after restoring a saved state?
    Positions and velocities are only part of the simulation state. Warm-starting caches, contact caches, sleep timers and broad-phase ordering also influence the next step. If the save omitted them, the restored run solves from different starting guesses and drifts; save them too, or reset them identically in both runs.
  • Why exclude cosmetic debris from replay checksums?
    Debris that never affects the outcome does not need to match, and including it makes every harmless difference look like a desync. Keeping it out of checksums and recordings also lets it run in a faster, non-deterministic configuration.
  • When would a team write its own deterministic simulation instead of using middleware?
    When lockstep or cross-platform replays are central, the simulated objects are few and simple, and the available middleware's deterministic mode is too slow or not offered. A small custom simulation, sometimes in fixed point, is easier to make bit-identical than a general-purpose library.

  • Same inputs always give the same physics result anywhere
  • Saving positions and velocities fully restores a simulation
  • Updating the physics library cannot break old replays
  • Every debris piece must be in the replay checksum
  • Multithreading never changes results if inputs are identical