This document is about: QUANTUM 2
SWITCH TO

Simulation Context

The SimulationContext is a container holding all information related to a single Quantum simulation instance. It also contains a list of SimulationContextService instances which operate on top of simulation state or are otherwise bound to the simulation. The purpose of this is to strictly isolate multiple simulations and all their dependencies running at the same time.

This separation is key for implementing features such as replays.

A Note on Scene Services

All scene services (e.g.: SceneUI and SceneCamera) are prepared for SimulationContext switching; they accept a single SimulationContext instance and synchronize with it, after which they forward all important events to their children.

By default, the SimulationContext is registered to all scene services. Each service decides for themself whether to use and/or forward the information provided to them. For example, SceneUI forwards the simulation context instance to its children UIView, but you can override it by registering a custom SimulationContext on a specific view.

fps template - handling of different simulation contexts by scene services
Handling of different simulation contexts by scene services in the View.

Context Switching Pattern - Replay Example

A replay is just another instance of SimulationContext holding identical data which starts the simulation from a snapshot at a specific time offset and applies recorded inputs to it. This means a game using replays will be applying the context switching pattern as follows:

  1. At the beginning of the game the main SimulationContext is registered to all scene services at the start of the game.
  2. When a replay is started, a new replay SimulationContext is created and registered to all scene services. N.B.: The main SimulationContext remains alive and continues behind the scenes.
  3. When the replay is over, the main SimulationContext is swapped back to the scene services and the replay SimulationContext is destroyed.
fps template replay context switch
Simulation context switching example for Replay purposes.
Back to top