Photon Quantum 3.0.0

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

The user implementation of FrameBase that resides in the project quantum_state and has access to all user relevant classes. More...

Classes

struct  FrameSignals
 The Quantum signal API consist of core and user-defined code-generated signals. More...
 

Public Member Functions

 Frame (FrameContext context, SystemBase[] systemsAll, SystemBase[] systemsRoots, DeterministicSessionConfig sessionConfig, RuntimeConfig runtimeConfig, SimulationConfig simulationConfig, FP deltaTime)
 Create a new frame object. More...
 
PlayerRef[] ActorIdToAllPlayers (Int32 actorId)
 Returns all players with a certain ActorId (Photon client id). More...
 
PlayerRefActorIdToFirstPlayer (Int32 actorId)
 Returns the first player that is using a certain ActorId (Photon client id). More...
 
sealed override UInt64 CalculateChecksum ()
 Calculates a checksum for the current game state. If the game is not started with QuantumGameFlags.DisableSharedChecksumSerializer flag, this method is not thread-safe, i.e. calling it from multiple threads for frames from the same simulation is going to break. More...
 
UInt64 CalculateChecksum (bool useSharedSerializer)
 Calculates a checksum for the current game state. More...
 
sealed override String DumpFrame (int dumpFlags=0)
 Dump the frame in human readable form into a string. More...
 
RuntimePlayer GetPlayerData (PlayerRef player)
 Gets the runtime player configuration data for a certain player. More...
 
Boolean InPredictionArea (FPVector2 position)
 See InPredictionArea(FPVector3). More...
 
Boolean InPredictionArea (FPVector3 position)
 Test is a position is inside the prediction area. More...
 
Int32? PlayerToActorId (PlayerRef player)
 Converts a Quantum PlayerRef to an ActorId (Photon client id). More...
 
override Byte[] Serialize (DeterministicFrameSerializeMode mode)
 Serializes the frame using a temporary buffer (20MB). More...
 
ArraySegment< byte > Serialize (DeterministicFrameSerializeMode mode, byte[] buffer, int offset=0, bool allocOutput=false)
 Serializes the frame using buffer as a buffer for temporary data. More...
 
void SetPredictionArea (FPVector2 position, FP radius)
 See SetPredictionArea(FPVector3, FP). More...
 
void SetPredictionArea (FPVector3 position, FP radius)
 Set the prediction area. More...
 
void SystemDisable< T > ()
 Disables a system. More...
 
void SystemEnable< T > ()
 Enable a system. More...
 
Boolean SystemIsEnabledSelf< T > ()
 Test if a system is enabled. More...
 

Static Public Member Functions

static void InitStatic ()
 Initialized Quantum static type registry. More...
 

Public Attributes

FrameEvents Events
 Access the Quantum event API. More...
 
FrameSignals Signals
 Access the Quantum signal API. More...
 

Static Public Attributes

const int DumpFlag_AssetDBCheckums = 1 << 10
 If set the frame dump will print Asset DB checksums. More...
 
const int DumpFlag_ComponentChecksums = 1 << 9
 If set the frame dump will print component checksums. More...
 
const int DumpFlag_NoDeterministicSessionConfig = 1 << 4
 If set the DeterministicSessionConfig will not be printed in the frame dump during DumpFrame(int). More...
 
const int DumpFlag_NoDynamicDB = 1 << 6
 If set the Dynamic Asset DB will not be printed in the frame dump during DumpFrame(int). More...
 
const int DumpFlag_NoIsVerified = 1 << 11
 Is set the frame dump will not print the IsVerified information. More...
 
const int DumpFlag_NoRuntimeConfig = 1 << 3
 If set the Quantum.RuntimeConfig will not be printed in the frame dump during DumpFrame(int). More...
 
const int DumpFlag_NoRuntimePlayers = 1 << 5
 If set the RuntimePlayers will not be printed in the frame dump during DumpFrame(int). More...
 
const int DumpFlag_NoSimulationConfig = 1 << 1
 If set the Quantum.SimulationConfig will not be printed in the frame dump during DumpFrame(int). More...
 
const int DumpFlag_PrintRawValues = 1 << 8
 If set the frame dump will print more raw values like pointers. More...
 
const int DumpFlag_ReadableDynamicDB = 1 << 7
 If set the Dynamic Asset DB will be dumped in readable form during DumpFrame(int). More...
 

Protected Member Functions

sealed override void Copy (DeterministicFrame frame)
 Copies the complete frame memory. More...
 

Properties

override PhysicsEngineState * _physicsState2D [get]
 Returns the physics 2D engine state. More...
 
override PhysicsEngineState * _physicsState3D [get]
 Returns the physics 3d engine state. More...
 
override CommitCommandsModes CommitCommandsMode [get]
 Returns the mode that commands are committed to the simulation. More...
 
new FrameContextUser Context [get]
 The frame user context More...
 
override FP DeltaTime [get, set]
 Delta time in seconds. Can be set during run-time. More...
 
override FrameMetaData * FrameMetaData [get]
 Returns the frame meta data. More...
 
_globals_ * Global [get]
 Access the global read and write struct with generated variables by the Quantum DSL compiler. More...
 
override sealed Map Map [get, set]
 Retrieves the Quantum map asset. Can be set during run-time. More...
 
AssetRef< MapMapAssetRef [get, set]
 Get or set the map asset reference. Can be set during run-time. More...
 
override NavMeshRegionMaskNavMeshRegionMask [get]
 Returns the global navmesh region mask that controls toggling on/off regions. More...
 
sealed override PhysicsSceneSettings * PhysicsSceneSettings [get]
 Globally access the physics settings which are taken from the SimulationConfig during the Frame constructor. More...
 
Int32 PlayerConnectedCount [get]
 Returns the number of players that are currently connected, requires the PlayerConnectedSystem. More...
 
Int32 PlayerCount [get]
 Returns the max player count that the simulation was started with DeterministicSessionConfig.PlayerCount. More...
 
RNGSessionRNG [get]
 The randomization session started with the seed from the RuntimeConfig used to start the simulation with. More...
 
RuntimeConfig RuntimeConfig [get]
 The deserialized RuntimeConfig used for this session. More...
 
DeterministicSessionConfig SessionConfig [get]
 The DeterministicSessionConfig used for this session. More...
 
SimulationConfig SimulationConfig [get]
 The SimulationConfig used for this session. More...
 
SystemBase[] SystemsAll [get]
 All systems running in the session. More...
 
override int UpdateRate [get]
 See DeterministicSession.SimulationRate. This getter acquires the value from the SessionConfig though. More...
 

Detailed Description

The user implementation of FrameBase that resides in the project quantum_state and has access to all user relevant classes.

Constructor & Destructor Documentation

◆ Frame()

Quantum.Frame.Frame ( FrameContext  context,
SystemBase[]  systemsAll,
SystemBase[]  systemsRoots,
DeterministicSessionConfig  sessionConfig,
RuntimeConfig  runtimeConfig,
SimulationConfig  simulationConfig,
FP  deltaTime 
)
inline

Create a new frame object.

Member Function Documentation

◆ SetPredictionArea() [1/2]

void Quantum.Frame.SetPredictionArea ( FPVector3  position,
FP  radius 
)
inline

Set the prediction area.

Parameters
positionCenter of the prediction area
radiusRadius of the prediction area

This can be safely called from the main-thread.

Prediction Culling allows developers to save CPU time in games where the player has only a partial view of the game scene. Quantum prediction and rollbacks, which are time consuming, will only run for important entities that are visible to the local player(s). Leaving anything outside that area to be simulated only once per tick with no rollbacks as soon as the inputs are confirmed from server. It is safe and simple to activate and, depending on the game, the performance difference can be quite large.Imagine a 30Hz game to constantly rollback ten ticks for every confirmed input (with more players, the predictor eventually misses at least for one of them). This requires the game simulation to be lightweight to be able to run at almost 300Hz(because of the rollbacks). With Prediction Culling enabled the full frames will be simulated at the expected 30Hz all the time while the much smaller prediction area is the only one running within the prediction buffer.

◆ SetPredictionArea() [2/2]

void Quantum.Frame.SetPredictionArea ( FPVector2  position,
FP  radius 
)
inline

See SetPredictionArea(FPVector3, FP).

Parameters
position
radius

◆ InPredictionArea() [1/2]

Boolean Quantum.Frame.InPredictionArea ( FPVector3  position)
inline

Test is a position is inside the prediction area.

Parameters
positionPosition
Returns
True if the position is inside the prediction area.

◆ InPredictionArea() [2/2]

Boolean Quantum.Frame.InPredictionArea ( FPVector2  position)
inline

See InPredictionArea(FPVector3).

Parameters
position
Returns

◆ Serialize() [1/2]

override Byte [] Quantum.Frame.Serialize ( DeterministicFrameSerializeMode  mode)
inline

Serializes the frame using a temporary buffer (20MB).

Parameters
mode
Returns

◆ Serialize() [2/2]

ArraySegment<byte> Quantum.Frame.Serialize ( DeterministicFrameSerializeMode  mode,
byte[]  buffer,
int  offset = 0,
bool  allocOutput = false 
)
inline

Serializes the frame using buffer as a buffer for temporary data.

If allocOutput is set to false, then buffer is also used for the final data - use offset and count from the result to access the part of buffer where serialized frame is stored.

If allocOutput is set to true then a new array is allocated for the result.

Despite accepting a buffer, this method still allocates a few small temporary objects. IAssetSerializer.SerializeAssets(Stream, AssetObject[]) is also going to allocate when serializing DynamicAssetDB, but how much depends on the serializer itself and the number of dynamic assets.

Parameters
mode
buffer
offset
allocOutput
Returns
Segment of buffer where the serialized frame is stored

Do not serialize during GameStart callback because systems have not been initialized, yet. Rather use CallbackSimulateFinished to wait for the first update.

◆ DumpFrame()

sealed override String Quantum.Frame.DumpFrame ( int  dumpFlags = 0)
inline

Dump the frame in human readable form into a string.

Parameters
dumpFlagsFlags to control the output for example DumpFlag_AssetDBCheckums.
Returns
Frame string representation.

◆ CalculateChecksum() [1/2]

sealed override UInt64 Quantum.Frame.CalculateChecksum ( )
inline

Calculates a checksum for the current game state. If the game is not started with QuantumGameFlags.DisableSharedChecksumSerializer flag, this method is not thread-safe, i.e. calling it from multiple threads for frames from the same simulation is going to break.

◆ CalculateChecksum() [2/2]

UInt64 Quantum.Frame.CalculateChecksum ( bool  useSharedSerializer)
inline

Calculates a checksum for the current game state.

Parameters
useSharedSerializerTrue - use shared checksum serializer to avoid allocs (not thread-safe).
Returns

◆ Copy()

sealed override void Quantum.Frame.Copy ( DeterministicFrame  frame)
inlineprotected

Copies the complete frame memory.

Parameters
frameInput frame object

◆ SystemIsEnabledSelf< T >()

Boolean Quantum.Frame.SystemIsEnabledSelf< T > ( )
inline

Test if a system is enabled.

Template Parameters
TSystem type
Returns
True if the system is enabled

Logs an error if the system type is not found.

Type Constraints
T :SystemBase 

◆ SystemEnable< T >()

void Quantum.Frame.SystemEnable< T > ( )
inline

Enable a system.

Template Parameters
TSystem type

Logs an error if the system type is not found.

Type Constraints
T :SystemBase 

◆ SystemDisable< T >()

void Quantum.Frame.SystemDisable< T > ( )
inline

Disables a system.

Template Parameters
TSystem type

Logs an error if the system type is not found.

// test for a certain asset and disable the system during its OnInit method
public override void OnInit(Frame f) {
var testSettings = f.FindAsset<NavMeshAgentsSettings>(f.Map.UserAsset.Id);
if (testSettings == null) {
f.SystemDisable<NavMeshAgentTestSystem>();
return;
}
//..
}
Type Constraints
T :SystemBase 

◆ InitStatic()

static void Quantum.Frame.InitStatic ( )
inlinestatic

Initialized Quantum static type registry.

◆ GetPlayerData()

RuntimePlayer Quantum.Frame.GetPlayerData ( PlayerRef  player)
inline

Gets the runtime player configuration data for a certain player.

Parameters
playerPlayer ref
Returns
Player config or null if player was not found

◆ PlayerToActorId()

Int32? Quantum.Frame.PlayerToActorId ( PlayerRef  player)
inline

Converts a Quantum PlayerRef to an ActorId (Photon client id).

Parameters
playerPlayer reference
Returns
ActorId or null if payer was not found

◆ ActorIdToFirstPlayer()

PlayerRef? Quantum.Frame.ActorIdToFirstPlayer ( Int32  actorId)
inline

Returns the first player that is using a certain ActorId (Photon client id).

Parameters
actorIdActor id
Returns
Player reference or null if actor id was not found

The first player because multiple players from the same Photon client can join.

◆ ActorIdToAllPlayers()

PlayerRef [] Quantum.Frame.ActorIdToAllPlayers ( Int32  actorId)
inline

Returns all players with a certain ActorId (Photon client id).

Parameters
actorIdActor id
Returns
Array of player references

Member Data Documentation

◆ DumpFlag_NoSimulationConfig

const int Quantum.Frame.DumpFlag_NoSimulationConfig = 1 << 1
static

If set the Quantum.SimulationConfig will not be printed in the frame dump during DumpFrame(int).

◆ DumpFlag_NoRuntimeConfig

const int Quantum.Frame.DumpFlag_NoRuntimeConfig = 1 << 3
static

If set the Quantum.RuntimeConfig will not be printed in the frame dump during DumpFrame(int).

◆ DumpFlag_NoDeterministicSessionConfig

const int Quantum.Frame.DumpFlag_NoDeterministicSessionConfig = 1 << 4
static

If set the DeterministicSessionConfig will not be printed in the frame dump during DumpFrame(int).

◆ DumpFlag_NoRuntimePlayers

const int Quantum.Frame.DumpFlag_NoRuntimePlayers = 1 << 5
static

If set the RuntimePlayers will not be printed in the frame dump during DumpFrame(int).

◆ DumpFlag_NoDynamicDB

const int Quantum.Frame.DumpFlag_NoDynamicDB = 1 << 6
static

If set the Dynamic Asset DB will not be printed in the frame dump during DumpFrame(int).

◆ DumpFlag_ReadableDynamicDB

const int Quantum.Frame.DumpFlag_ReadableDynamicDB = 1 << 7
static

If set the Dynamic Asset DB will be dumped in readable form during DumpFrame(int).

◆ DumpFlag_PrintRawValues

const int Quantum.Frame.DumpFlag_PrintRawValues = 1 << 8
static

If set the frame dump will print more raw values like pointers.

◆ DumpFlag_ComponentChecksums

const int Quantum.Frame.DumpFlag_ComponentChecksums = 1 << 9
static

If set the frame dump will print component checksums.

◆ DumpFlag_AssetDBCheckums

const int Quantum.Frame.DumpFlag_AssetDBCheckums = 1 << 10
static

If set the frame dump will print Asset DB checksums.

◆ DumpFlag_NoIsVerified

const int Quantum.Frame.DumpFlag_NoIsVerified = 1 << 11
static

Is set the frame dump will not print the IsVerified information.

◆ Signals

FrameSignals Quantum.Frame.Signals

Access the Quantum signal API.

Signals are function signatures used as a decoupled inter-system communication API similar to a publisher/subscriber API or observer pattern.

Custom signals are defined in the DSL.

◆ Events

FrameEvents Quantum.Frame.Events

Access the Quantum event API.

Events are a fine-grained solution to communicate from the simulation to the view.

Events should never be used to modify/update part of the game state.

Custom events are defined in the DSL.

Property Documentation

◆ Global

_globals_* Quantum.Frame.Global
get

Access the global read and write struct with generated variables by the Quantum DSL compiler.

Globals can be declared in any .qtn file by using the global scope.

Like all things DSL-defined, global variables are part of the state and are fully compatible with the predict-rollback system.

An alternative to global variables are the Singleton Components.

global {
FPVector3 Foo;
}

◆ RNG

RNGSession* Quantum.Frame.RNG
get

The randomization session started with the seed from the RuntimeConfig used to start the simulation with.

Supports determinism under roll-backs.

If random is used in conjunction with the prediction area feature the session needs to be stored on the entities themselves.

◆ PlayerCount

Int32 Quantum.Frame.PlayerCount
get

Returns the max player count that the simulation was started with DeterministicSessionConfig.PlayerCount.

◆ PlayerConnectedCount

Int32 Quantum.Frame.PlayerConnectedCount
get

Returns the number of players that are currently connected, requires the PlayerConnectedSystem.

◆ NavMeshRegionMask

override NavMeshRegionMask* Quantum.Frame.NavMeshRegionMask
get

Returns the global navmesh region mask that controls toggling on/off regions.

◆ FrameMetaData

override FrameMetaData* Quantum.Frame.FrameMetaData
get

Returns the frame meta data.

◆ _physicsState2D

override PhysicsEngineState* Quantum.Frame._physicsState2D
getprotected

Returns the physics 2D engine state.

◆ _physicsState3D

override PhysicsEngineState* Quantum.Frame._physicsState3D
getprotected

Returns the physics 3d engine state.

◆ CommitCommandsMode

override CommitCommandsModes Quantum.Frame.CommitCommandsMode
get

Returns the mode that commands are committed to the simulation.

◆ Context

new FrameContextUser Quantum.Frame.Context
get

The frame user context

◆ RuntimeConfig

RuntimeConfig Quantum.Frame.RuntimeConfig
get

The deserialized RuntimeConfig used for this session.

◆ SimulationConfig

SimulationConfig Quantum.Frame.SimulationConfig
get

The SimulationConfig used for this session.

◆ SessionConfig

DeterministicSessionConfig Quantum.Frame.SessionConfig
get

The DeterministicSessionConfig used for this session.

◆ SystemsAll

SystemBase [] Quantum.Frame.SystemsAll
get

All systems running in the session.

◆ UpdateRate

override int Quantum.Frame.UpdateRate
get

See DeterministicSession.SimulationRate. This getter acquires the value from the SessionConfig though.

◆ PhysicsSceneSettings

sealed override PhysicsSceneSettings* Quantum.Frame.PhysicsSceneSettings
get

Globally access the physics settings which are taken from the SimulationConfig during the Frame constructor.

◆ DeltaTime

override FP Quantum.Frame.DeltaTime
getset

Delta time in seconds. Can be set during run-time.

◆ Map

override sealed Map Quantum.Frame.Map
getset

Retrieves the Quantum map asset. Can be set during run-time.

If assigned value is different than the current one, signal ISignalOnMapChanged is raised.

◆ MapAssetRef

AssetRef<Map> Quantum.Frame.MapAssetRef
getset

Get or set the map asset reference. Can be set during run-time.

If assigned value is different than the current one, signal ISignalOnMapChanged is raised.

Quantum.Frame.Frame
Frame(FrameContext context, SystemBase[] systemsAll, SystemBase[] systemsRoots, DeterministicSessionConfig sessionConfig, RuntimeConfig runtimeConfig, SimulationConfig simulationConfig, FP deltaTime)
Create a new frame object.
Definition: Frame.cs:291