HTML and CSS Reference
Figure 20-1. Render and game clock (arrows represent renders/updates, and the line is the current time)
Interpolation requires that the game keep the two most recent game states, and the renderer interpolates
between the two states. This is done in code as follows:
renderTransform(frame, x) = transform(state) * (x) + transform(state) * (1.0 - x);
The render transform is interpolated between the transform at state and the transform at state , resulting
in a smooth motion even if a render occurs between game state updates.
Extrapolation can be used by factoring in object velocity:
renderTransform(frame, x) = transform(state) + integrate(velocity(state), x);
The extrapolated transformation may end up being wrong. For example, the object may disappear from the scene
before it gets to the extrapolated position. Extrapolation has the added benefit of only requiring a single snapshot of
the game state.
Whether the renderer uses stale, interpolated, or extrapolated object transforms depends on the game and
rendering engine. Generally a game looks better, because animations will be smoother, if it compensates for the
discrepancy between the game clock and the renderer clock.
User Input Processing
User input processing is game-specific, but the main loop can provide generalized input type support for mapping
from raw input events to game input events, along with chord (multiple simultaneous buttons down or up) detection
and sequence (a specific sequence of input events) detection.