Quantum 3 3.1.0

Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
Quantum.Testing.FrameEmulator Class Reference

Creates and steps a single verified Frame without a QuantumGame or a DeterministicSession, running only the systems passed in Args.Systems. Meant for tests, benchmarks and tools. More...

Inherits IDisposable.

Classes

struct  Args
 The FrameEmulator creation arguments. More...
 

Public Member Functions

 FrameEmulator (in Args args)
 Creates the frame context and the frame and initializes the systems. More...
 
void AddCommand (PlayerRef player, DeterministicCommand command)
 Adds a command of a player to the next step. The emulator takes the ownership of the command. More...
 
void AddPlayer (PlayerRef player, RuntimePlayer data)
 Marks the player as present (connected) and sets its runtime player data during the next step, which raises ISignalOnPlayerAdded. The actor id of the player is its index + 1. More...
 
T CreateAndAddAsset< T > (Action< T > init=null)
 Creates an asset, invokes the optional action and adds the asset to the resource manager. If the action does not set a valid guid, the next free one starting at DefaultAssetGuids.Max is assigned. More...
 
void Dispose ()
 Frees the frame, disposes the frame context and unloads the assets of the emulator's resource manager. More...
 
void RemovePlayer (PlayerRef player)
 Marks the player as not present (disconnected) and raises ISignalOnPlayerRemoved during the next step. Like in a session, the runtime player data is kept. Cancels an AddPlayer that was not stepped yet. More...
 
void SetInput (PlayerRef player, Input input)
 Sets the input of a player. The input is kept for all following steps until it is set again. More...
 
void Step (Int32 ticks=1)
 Emulates ticks ticks. More...
 

Static Public Member Functions

static FrameEmulator Create (Map map, params SystemBase[] systems)
 Creates an emulator with map that runs systems with the config from CreateSimulationConfig. More...
 
static FrameEmulator Create (params SystemBase[] systems)
 Creates an emulator without a map that runs systems with the config from CreateSimulationConfig. More...
 
static SimulationConfig CreateSimulationConfig ()
 Creates a simulation config with default settings, see SimulationConfig.InitMissingDefaults. More...
 

Public Attributes

IReadOnlyList< EventBase > Events => _events
 The events raised during the last Step, or during the system initialization if no step has been executed yet. The event objects are pooled and only valid until the next Step. More...
 

Properties

Frame Frame [get]
 The emulated verified frame. More...
 

Detailed Description

Creates and steps a single verified Frame without a QuantumGame or a DeterministicSession, running only the systems passed in Args.Systems. Meant for tests, benchmarks and tools.

Uses the same system initialization and scheduling code as QuantumGame, but does not cover what the session does: prediction and rollbacks, input prediction, delta compressed input, checksums, snapshots, event confirmation and the RuntimePlayer serialization.

Exceptions thrown by the simulation code (systems, signals, tasks) are not caught, unlike in a session that logs them. They are thrown from the constructor (system initialization) or Step after all systems of the stage ran, see ExceptionUtils.ThrowIfAny: a single exception as is, several as an AggregateException. The frame should not be stepped anymore afterwards.

using var emulator = new FrameEmulator(new FrameEmulator.Args {
Systems = new SystemBase[] { new MySystem() },
SimulationConfig = simulationConfig,
});
var entity = emulator.Frame.Create();
emulator.SetInput(0, new Input { Up = true });
emulator.Step(10);

Constructor & Destructor Documentation

◆ FrameEmulator()

Quantum.Testing.FrameEmulator.FrameEmulator ( in Args  args)
inline

Creates the frame context and the frame and initializes the systems.

Parameters
argsCreation arguments.

Member Function Documentation

◆ CreateAndAddAsset< T >()

T Quantum.Testing.FrameEmulator.CreateAndAddAsset< T > ( Action< T >  init = null)
inline

Creates an asset, invokes the optional action and adds the asset to the resource manager. If the action does not set a valid guid, the next free one starting at DefaultAssetGuids.Max is assigned.

The systems have already been initialized, assets they need in SystemBase.OnInit have to be passed in Args.Assets. Must not be called while the emulator is stepping.

Type Constraints
T :AssetObject 

◆ CreateSimulationConfig()

static SimulationConfig Quantum.Testing.FrameEmulator.CreateSimulationConfig ( )
inlinestatic

Creates a simulation config with default settings, see SimulationConfig.InitMissingDefaults.

◆ Create() [1/2]

static FrameEmulator Quantum.Testing.FrameEmulator.Create ( params SystemBase[]  systems)
inlinestatic

Creates an emulator without a map that runs systems with the config from CreateSimulationConfig.

Parameters
systemsThe root systems in schedule order.

◆ Create() [2/2]

static FrameEmulator Quantum.Testing.FrameEmulator.Create ( Map  map,
params SystemBase[]  systems 
)
inlinestatic

Creates an emulator with map that runs systems with the config from CreateSimulationConfig.

Parameters
mapThe map, see Args.Map.
systemsThe root systems in schedule order, including the physics systems if needed.

◆ SetInput()

void Quantum.Testing.FrameEmulator.SetInput ( PlayerRef  player,
Input  input 
)
inline

Sets the input of a player. The input is kept for all following steps until it is set again.

Parameters
playerPlayer
inputInput

◆ AddCommand()

void Quantum.Testing.FrameEmulator.AddCommand ( PlayerRef  player,
DeterministicCommand  command 
)
inline

Adds a command of a player to the next step. The emulator takes the ownership of the command.

Parameters
playerPlayer
commandCommand

◆ AddPlayer()

void Quantum.Testing.FrameEmulator.AddPlayer ( PlayerRef  player,
RuntimePlayer  data 
)
inline

Marks the player as present (connected) and sets its runtime player data during the next step, which raises ISignalOnPlayerAdded. The actor id of the player is its index + 1.

Parameters
playerPlayer
dataRuntime player data

◆ RemovePlayer()

void Quantum.Testing.FrameEmulator.RemovePlayer ( PlayerRef  player)
inline

Marks the player as not present (disconnected) and raises ISignalOnPlayerRemoved during the next step. Like in a session, the runtime player data is kept. Cancels an AddPlayer that was not stepped yet.

Parameters
playerPlayer

◆ Step()

void Quantum.Testing.FrameEmulator.Step ( Int32  ticks = 1)
inline

Emulates ticks ticks.

Parameters
ticksNumber of ticks to emulate.

◆ Dispose()

void Quantum.Testing.FrameEmulator.Dispose ( )
inline

Frees the frame, disposes the frame context and unloads the assets of the emulator's resource manager.

Member Data Documentation

◆ Events

IReadOnlyList<EventBase> Quantum.Testing.FrameEmulator.Events => _events

The events raised during the last Step, or during the system initialization if no step has been executed yet. The event objects are pooled and only valid until the next Step.

Property Documentation

◆ Frame

Frame Quantum.Testing.FrameEmulator.Frame
get

The emulated verified frame.

Quantum.Testing.FrameEmulator.FrameEmulator
FrameEmulator(in Args args)
Creates the frame context and the frame and initializes the systems.
Definition: FrameEmulator.cs:110