Notes / game-engineering

Three Clocks in an Interactive Simulation

Updated 7 min read

  • game-engineering
  • simulation
  • timing

I'm developing a psychological horror game, and part of the engineering work involves timing-sensitive interactions. I want to reproduce the decisions the game makes and still be able to investigate differences in what players actually see or hear. A normal state log only covers part of that.

The story and specific gameplay ideas are staying private for now. The timing problem is useful without them.

An event has more than one timestamp

Suppose an interaction is accepted at simulation time t. The presentation system schedules a response for t + δ. The output is actually rendered at t + δ + ε, where ε is the delivery error relative to the requested time.

Simulation decision, scheduled response and actual rendering occur at distinct timesFull size

Here, δ belongs to the presentation policy. ε depends on the actual execution path: frame timing, audio buffering, thread scheduling or the availability of an asset. Replaying identical game-state inputs can reproduce t and δ without producing the same ε on every run.

The distinction matters most when an output is time-sensitive. There is a difference between deciding to play something, requesting its playback and determining when the engine actually rendered it.

Sample accuracy and an ordinary frame callback are different tools

Consider an engine running game logic at 60 frames per second. Its frame interval is about 16.7 milliseconds, before accounting for scheduling variation. A callback asking to play a sound on the next frame provides no guarantee that the audio render thread consumes that command at the exact game-thread timestamp. Audio is processed in sample buffers, and the command may arrive just before or just after a render boundary.

For scale, 2,048 samples at 48,000 samples per second span roughly 42.7 milliseconds. The number is a hypothetical buffer duration, not a measurement of this game's audio output. It shows how two playback commands with similar game-thread timestamps can land on different audio processing boundaries. On top of that are device and output-chain delays that a game-thread timer does not measure.

Unreal Engine's Quartz documentation explains scheduling against the audio render timeline, including commands placed at boundaries within a buffer. That is useful when a presentation decision requires tight timing. It does not make the game thread, audio render thread and physical output device share one perfectly observable clock.

A trace should state which timestamp it reports. requested_at might be game-thread time; scheduled_for might be the intended audio-render time; render_observed_at might come from instrumentation closer to the audio pipeline. Recording them together under a single field named event_time hides the difference the experiment is supposed to measure.

This problem appears outside games. Distributed tracing distinguishes when a client sends a request, when a server starts work and when a response is observed. Audio introduces tighter timing tolerances, but the need to identify which clock produced a measurement is familiar.

Replay the decision, measure the presentation

For deterministic simulation logic, I want a test record that includes the initial state, ordered inputs, random seed and emitted decisions. If the same inputs produce different decisions, something unrecorded is affecting the simulation: perhaps wall-clock time, an unordered collection or state retained from a previous run.

Presentation requires a different measurement. Record the requested output time and the observed execution time at the engine boundary. Those timestamps let us distinguish a scheduling discrepancy from a simulation that emitted the wrong event. Measurements farther down the audio or display pipeline require additional instrumentation; a callback timestamp alone should not be reported as the moment a player perceived the result.

A reproducible event trace and a successful presentation-timing test establish two different properties. For example, changing a render setting can alter output timing while leaving the simulation trace unchanged. If both are logged as a single "event time," that discrepancy becomes hard to diagnose.

What deterministic replay needs to record

A seed by itself is not a replay mechanism. If one subsystem reads wall-clock time, iteration order changes between runs, or asynchronous completion affects a branch, two executions with the same seed can still diverge. For a meaningful replay, the record needs initial state, ordered input events, the seed and the decisions emitted by the simulation. The order of inputs matters as much as their values.

For example, imagine two user inputs occur in the same frame. A log containing only their timestamps may not tell us which input the simulation processed first. If that order affects the next state, replay requires a stable sequence number or another explicit ordering rule. Likewise, a random generator should have a clear owner: an unrelated visual effect shouldn't consume the next random value and change a gameplay decision by accident.

One useful test is to run the same recorded input sequence twice without rendering and compare the emitted decision stream. A mismatch points toward nondeterministic simulation state. A matching decision stream doesn't prove that the presentation timing matches. That's a second test, using the actual output path or targeted instrumentation.

The separation is valuable when an experiment fails. A mismatch in simulated event selection suggests a state or replay defect. A consistent selection with different delivered timing suggests a scheduling or performance issue. A consistent delivered signal that players interpret differently is evidence about perception, not automatically an engine bug. This classification prevents a team from changing a gameplay rule to compensate for a buffer or rendering problem.

Evaluating what players perceive

Neither trace explains how a new player interpreted the interaction. The engine could choose the intended event and deliver it exactly on schedule, while a player attributes the result to a glitch or misses it entirely.

The design of that test is consequential. Asking people directly whether they noticed unusual timing primes them to search for it. A player who explains the event as an ordinary glitch, a player who investigates and one who misses it altogether provide different evidence about how the experience was communicated.

Testing interpretation without showing the design in the question

Because the game relies partly on expectation, the test setup can contaminate the result. A participant told to watch for an unusual delay will search for one. The same participant entering a scene with no hint may interpret the identical timing as ordinary engine behavior. Both observations are real, but they answer different questions.

I would separate a technical timing test from a player interpretation test. The technical one controls input, schedules a known event and records execution timestamps across repeated runs and different system loads. The perception test uses an unprimed participant, keeps most of the surrounding interaction constant and changes one presentation parameter at a time. Ask the participant what they noticed before mentioning latency, synchronization or horror.

The result should retain disagreement. If one player calls it a bug, another ignores it and a third investigates, replacing those descriptions with an average score discards useful information. The design question may depend on why they reacted differently, whether an expected pattern had been established and whether they could reproduce what they saw. That is the part no deterministic unit test can answer.

These are proposed measurement and evaluation methods, not claims of completed playtests. The actual game mechanics and narrative context remain private.

For this game, the useful artifact is a record that can answer three questions separately: which event was chosen, when it was presented, and how the player described it. If an experiment fails to communicate the intended effect, those records provide somewhere concrete to start investigating instead of rewriting the simulation blindly.

Daniel MayaEngineering / Notes