Photon Quantum 2.1.9

Public Member Functions | 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...

Inheritance diagram for Quantum.Frame:
Quantum.Core.FrameBase

Public Member Functions

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...
 
- Public Member Functions inherited from Quantum.Core.FrameBase
AddResult Add (EntityRef entity, int componentIndex, out void *result)
 Adds a component of default value to an entity and returns a pointer to the added component. More...
 
AddResult Add (EntityRef entity, int componentIndex, void *value)
 Adds a component of defined value to an entity More...
 
AddResult Add (EntityRef entity, int componentIndex, void *value, out void *result)
 Adds a component of defined value to an entity and returns a pointer to the added component. More...
 
AddResult Add< T > (EntityRef entity)
 Adds a default component to an entity. More...
 
AddResult Add< T > (EntityRef entity, out T *result)
 Adds a component of default value to an entity and returns a pointer to the added component. More...
 
AddResult Add< T > (EntityRef entity, T value)
 Adds a component to an entity. More...
 
AddResult Add< T > (EntityRef entity, T value, out T *result)
 Adds a component of defined value to an entity and returns a pointer to the added component. More...
 
AssetGuid AddAsset (AssetObject asset)
 Adds a dynamic asset to the frame. Dynamic Asset DB generates and assigns Guids for dynamic assets, so asset can not have AssetObject.Guid set before calling this method. More...
 
bool AddOrGet (EntityRef entity, int componentIndex, out void *result)
 Adds a component of default value to an entity (if it does not have that component yet) and gets a pointer to the component. More...
 
bool AddOrGet< T > (EntityRef entity, out T *result)
 Adds a component of default value to an entity (if it does not have that component yet) and gets a pointer to the component. More...
 
void ClearAllNavMeshRegions ()
 If a navmesh region is toggled on/off is saved here. Call this method to reset every region state to be enabled again. More...
 
void ClearCulledState ()
 Marks all entities as not culled. More...
 
int ComponentCount (int componentIndex, bool includePendingRemoval=false)
 Gets the total count of components of a given index. See ComponentTypeId and ComponentTypeId<T> to have access to component types metadata. More...
 
int ComponentCount< T > (bool includePendingRemoval=false)
 Gets the total count of T components More...
 
EntityRef Create ()
 Creates an entity that is saved in the game state. More...
 
EntityRef Create (AssetRefEntityPrototype prototype)
 Creates an entity from a prototype asset. This process is also reffered to as "prototype materialization". More...
 
EntityRef Create (EntityPrototype prototype)
 Creates an entity from a prototype. This process is also reffered to as "prototype materialization". More...
 
void Create (EntityPrototypeContainer[] prototypes, Map parentAsset)
 Creates (materializes) map prototypes. The difference between this method and calling Create(EntityPrototype) repeatedly is that EntityRef fields get resolved and that MapEntityLink components are added implicitly. More...
 
void Cull (EntityRef entityRef)
 Marks a cullable and existing entity as culled. If the entity does not Exist or is not cullable, nothing is done. More...
 
bool Culled (EntityRef entityRef)
 If the entity is prediction-culled. More...
 
bool Destroy (EntityRef entityRef)
 Destroys the entity and all components that were added to it. More...
 
bool DestroyPending (EntityRef entityRef)
 Check if a destroy is pending for this entity More...
 
bool DisposeAsset (AssetGuid guid)
 Disposes an asset. More...
 
void DisposeAsset (string path, DatabaseType dbType=DatabaseType.Default)
 Disposes an asset. More...
 
bool Exists (EntityRef entityRef)
 Checks if an entity is still valid. More...
 
FindAsset< T > (AssetGuid guid)
 Retrieves an asset either from the asset database or as an dynamic asset. In case of a missing asset logs a warning. More...
 
FindAsset< T > (AssetRef assetRef)
 Retrieves an asset either from the asset database or as an dynamic asset. In case of a missing asset logs a warning. More...
 
bool FindAsset< T > (AssetRef assetRef, out T asset)
 Retrieves an asset either from the asset database or as an dynamic asset. In case of a missing asset logs a warning. More...
 
FindAsset< T > (string path, DatabaseType dbType=DatabaseType.Default)
 Retrieves an asset by path from selected databases. In case of a missing asset logs a warning. More...
 
ComponentPrototype FindPrototype (ComponentPrototypeRef prototypeRef)
 
EntityPrototypeContainer FindPrototype (EntityPrototypeRef prototypeRef)
 
Get< T > (EntityRef entityRef)
 Gets a component from an entity. More...
 
ComponentIterator< T > GetComponentIterator< T > ()
 Create a component iterator for all components of one type. More...
 
ComponentSet GetComponentSet (EntityRef entityRef)
 Gets a set of all component types that were added to the entity. More...
 
bool Has (EntityRef entityRef, ComponentSet set)
 Checks if the entity contains a whole set of components. More...
 
bool Has< T > (EntityRef entityRef)
 Checks if an entity has a component. More...
 
bool IsCullable (EntityRef entity)
 If an entity can be culled during simulation. For instance, used by the prediction culling systems to cull entities outside of the prediction area. More...
 
bool IsCulled (EntityRef entityRef)
 If an entity is currently culled from the simulation, regardless of the frame state (Predicted or Verified). More...
 
bool LoadAsset (AssetGuid guid)
 Loads an asset asynchronously into memory. More...
 
bool Remove (EntityRef entityRef, int componentIndex)
 Removes a component from an entity. More...
 
bool Remove (EntityRef entityRef, Type componentType)
 Removes a component from an entity. More...
 
bool Remove< T > (EntityRef entityRef)
 Removes a component from an entity. More...
 
void ReplaceAsset (AssetGuid guid, AssetObject asset)
 Replaces a dynamic asset in the frame. Asset asset can not have AssetObject.Path or AssetObject.Guid set as it inherits both from the original asset. More...
 
SetResult Set (EntityRef entity, AssetRefEntityPrototype prototype)
 Adds (materializes) components to an already existing entity. More...
 
SetResult Set (EntityRef entity, AssetRefEntityPrototype prototype, out ComponentSet overwrittenComponents)
 Adds (materializes) components to an already existing entity. More...
 
SetResult Set (EntityRef entity, EntityPrototype prototype)
 Adds (materializes) components to an already existing entity. If a component already exists, it will get completely overwritten, but an error message will be logged. To avoid errors in such case use Set(EntityRef, EntityPrototype, out ComponentSet) instead. More...
 
SetResult Set (EntityRef entity, EntityPrototype prototype, out ComponentSet overwrittenComponents)
 Adds (materializes) components to an already existing entity. If a component already exists, it will get completely overwritten. More...
 
SetResult Set (EntityRef entity, int componentIndex, void *value)
 Sets a component on an entity. More...
 
SetResult Set< T > (EntityRef entity, T value)
 Sets a component on an entity. More...
 
void SetCullable (EntityRef entityRef, bool cullable)
 Sets if an existing entity is cullable or not. More...
 
bool TryFindAsset< T > (AssetGuid guid, out T asset)
 Retrieves an asset either from the asset database or as an dynamic asset. More...
 
bool TryFindAsset< T > (AssetRef assetRef, out T asset)
 Retrieves an asset either from the asset database or as an dynamic asset. More...
 
bool TryFindAsset< T > (string path, out T asset, DatabaseType dbType=DatabaseType.Default)
 Retrieves an asset by path from selected databases. More...
 
bool TryFindAsset< TAssetRef, T > (TAssetRef assetRef, out T asset)
 Retrieves an asset either from the asset database or as an dynamic asset. More...
 
bool TryGet< T > (EntityRef entityRef, out T value)
 Gets a component from an entity. Does not throw when the component does not exist. More...
 
bool TryGetComponentSet (EntityRef entityRef, out ComponentSet set)
 Gets a set of all component types that were added to the entity. More...
 

Public Attributes

FrameAssets Assets
 Access to the assets API More...
 
FrameEvents Events
 Access the event API.
Events are a fine-grained solution to communicate things that happen inside the simulation to the rendering engine (they should never be used to modify/update part of the game state). More...
 
FrameSignals Signals
 Access the signal API.
Signals are function signatures used as a decoupled inter-system communication API (a bit like a publisher/subscriber API or observer pattern). More...
 
- Public Attributes inherited from Quantum.Core.FrameBase
Physics2D.PhysicsEngine2D.Api Physics2D
 Access to the Physics2D API. More...
 
Physics3D.PhysicsEngine3D.Api Physics3D
 Access to the Physics3D API. More...
 

Protected Member Functions

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

Properties

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...
 
_globals_ * Global [get]
 Access the global struct with generated values from the DSL. More...
 
sealed override Map Map [get, set]
 Retrieves the Quantum map asset. Can be set during run-time. More...
 
sealed override PhysicsSceneSettings * PhysicsSceneSettings [get]
 Globally access the physics settings which are taken from the SimulationConfig during the Frame constructor. More...
 
Int32 PlayerCount [get]
 Defines the amount of player in this Quantum session. More...
 
RNGSessionRNG [get]
 The randomization session started with the seed from the RuntimeConfig used to start the simulation with. More...
 
RuntimeConfig RuntimeConfig [get]
 The 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 SimulationRate. This getter acquires the value from the SessionConfig though. More...
 
- Properties inherited from Quantum.Core.FrameBase
Navigation Navigation [get]
 Access to the Navigation API. More...
 

Detailed Description

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

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

The Prediction Culling feature must be explicitly enabled in SimulationConfig.UsePredictionArea.

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(System.Collections.Generic.IEnumerable<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.

Returns
Frame 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 

◆ 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

◆ Signals

FrameSignals Quantum.Frame.Signals

Access the signal API.
Signals are function signatures used as a decoupled inter-system communication API (a bit like a publisher/subscriber API or observer pattern).

Custom signals are defined in the DSL.

◆ Events

FrameEvents Quantum.Frame.Events

Access the event API.
Events are a fine-grained solution to communicate things that happen inside the simulation to the rendering engine (they should never be used to modify/update part of the game state).

Custom events are defined in the DSL.

◆ Assets

FrameAssets Quantum.Frame.Assets

Access to the assets API

Property Documentation

◆ Global

_globals_* Quantum.Frame.Global
get

Access the global struct with generated values from the DSL.

◆ 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

Defines the amount of player in this Quantum session.

The value is takes from the Deterministic session config.

◆ Context

new FrameContextUser Quantum.Frame.Context
get

The frame user context

◆ RuntimeConfig

RuntimeConfig Quantum.Frame.RuntimeConfig
get

The 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 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

sealed override 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.