Photon Fusion 2.0.3

Classes | Public Member Functions | Protected Member Functions | Properties | List of all members
Simulation Class Referenceabstract

Main simulation class More...

Inherits ILogSource, and INetPeerGroupCallbacks.

Classes

struct  AreaOfInterest
 Static access to AreaOfInterest for backwards compatibility More...
 
struct  AreaOfInterestState
 Area of Interest Definition More...
 

Public Member Functions

void GetAreaOfInterestGizmoData (List<(Vector3 center, Vector3 size, int playerCount, int objectCount)> result)
 Clears the provided list and populates it with data about the current Area of Interest (AOI) cells. Each tuple in the list represents one AOI cell, containing its center, size, player count, and object count. More...
 
PlayerRef GetInputAuthority (NetworkObject networkObject)
 Get the Input Authority PlayerRef for a NetworkObject More...
 
SimulationInput GetInputForPlayer (PlayerRef player)
 Get the Simulation Input for a specific Player More...
 
void GetObjectsAndPlayersInAreaOfInterestCell (int cellKey, List< PlayerRef > players, List< NetworkId > objects)
 Used by RunnerAOIGizmos component. Supplies data about current active AOI cells. More...
 
List< NetworkIdGetObjectsInAreaOfInterestForPlayer (PlayerRef player)
 Retrieves a list of network object IDs that are in the area of interest for the specified player. More...
 
PlayerRef GetStateAuthority (NetworkObject networkObject)
 Get the State Authority PlayerRef for a NetworkObject More...
 
bool HasAnyActiveConnections ()
 Signal if the Server has any Active Connection with any number of Clients. More...
 
bool IsInputAuthority (NetworkObject networkObject, PlayerRef playerRef)
 Check if a Player is the Input Authority over an NetworkObject More...
 
bool? IsInterestedIn (NetworkObject obj, PlayerRef player)
 Check if a NetworkObject is interested by a specific Player More...
 
bool IsLocalSimulationInputAuthority (NetworkObject obj)
 Check if the Local Player is the Input Authority over a NetworkObject More...
 
bool IsLocalSimulationStateAuthority (NetworkId id)
 Check if a Player is the State Authority over a NetworkObject by NetworkId More...
 
bool IsLocalSimulationStateAuthority (NetworkObject obj)
 Check if the Local Player is the State Authority over a NetworkObject More...
 
bool IsLocalSimulationStateOrInputSource (NetworkObject obj)
 Check if the Local Player is the State Authority or Input Authority over a NetworkObject More...
 
bool IsStateAuthority (NetworkObject networkObject, PlayerRef playerRef)
 Check if a Player is the State Authority over a NetworkObject More...
 
bool IsStateAuthority (PlayerRef stateSource, PlayerRef playerRef)
 Check if a Player is the State Authority in relation to another Player More...
 
bool TryGetHostPlayer (out PlayerRef player)
 Try to get the Host Player More...
 
int Update (double dt)
 Forwards the Simulation based on the Delta Time More...
 

Protected Member Functions

virtual void AfterSimulation ()
 Callback invoked after the Simulation Update More...
 
virtual void AfterUpdate ()
 Callback invoked After the Simulation Update More...
 
virtual void BeforeFirstTick ()
 Callback invoked before the First Tick More...
 
virtual int BeforeSimulation ()
 Callback invoked before the Simulation Loop More...
 
virtual void BeforeUpdate ()
 Callback invoked before the Simulation Update More...
 
virtual void NetworkConnected (NetConnection *connection)
 Callback invoked on the Connected More...
 
virtual void NetworkDisconnected (NetConnection *connection, NetDisconnectReason reason)
 Callback invoked on the Disconnected More...
 
virtual void NetworkReceiveDone ()
 Callback invoked when the Network Receive is completed More...
 
virtual void NoSimulation ()
 Callback invoked when there is no simulation More...
 

Properties

virtual IEnumerable< PlayerRefActivePlayers [get]
 List of Active players in the Simulation More...
 
SimulationConfig Config [get]
 The SimulationConfig file used by this Simulation. More...
 
float DeltaTime [get]
 Gets the fixed tick time interval. Derived from the SimulationRuntimeConfig.TickRate. More...
 
int InputCount [get]
 The current input collection size More...
 
bool IsClient [get]
 If this peer is a client. True for client peers in Server/Client topologies, and true for all peers in Shared Mode. More...
 
bool IsFirstTick [get]
 Use in conjunction with IsResimulation/IsForward inside of FixedUpdateNetwork to determine if the current tick being simulated is the first tick of the resimulation or forward phase of the simulation loop. More...
 
bool IsForward [get]
 Use inside of FixedUpdateNetwork to determine if the tick currently being simulated has NOT previously been simulated locally. More...
 
bool IsLastTick [get]
 Use in conjunction with IsResimulation/IsForward inside of FixedUpdateNetwork to determine if the current tick being simulated is the last tick of the resimulation or forward phase of the simulation loop. More...
 
bool IsLocalPlayerFirstExecution [get]
 True if the current stage of the simulation loop is Forward. False during resimulations. More...
 
bool IsMasterClient [get]
 Only valid in Shared Mode. Indicates if this peer is flagged as the MasterClient, which means it is default StateAuthority More...
 
bool IsPlayer [get]
 True for any peer that represents a human player. This is true for all peers except a dedicated server. More...
 
bool IsResimulation [get]
 Use inside of FixedUpdateNetwork to determine if the tick currently being simulated has previously been simulated locally. Resimulation occurs in client prediction when new states arrive from the StateAuthority. Networked objects are set to the most current authority state tick, and simulations are repeated from that tick to the local current tick. More...
 
bool IsRunning [get]
 Signal if the Simulation is currently running More...
 
bool IsServer [get]
 If this peer is the server. True for the Server or Host peer in Server/Client topologies, and always false for all peers in Shared Mode (the relay is the server). More...
 
bool IsShutdown [get]
 
bool IsSinglePlayer [get]
 Indicates that this simulation is operating in Single Player mode, which is a Host that accepts no connections. More...
 
abstract Tick LatestServerTick [get]
 latest tick on server we are aware of More...
 
NetAddress LocalAddress [get]
 Bound Address of the internal socket More...
 
float LocalAlpha [get]
 
abstract PlayerRef LocalPlayer [get]
 Get LocalPlayer PlayerRef More...
 
SimulationModes Mode [get]
 Gets the SimulationModes flags for The type of network peer this simulation represents. More...
 
NetConfigNetConfigPointer [get]
 Current NetConfig More...
 
int ObjectCount [get]
 Returns the number of objects in the simulation. More...
 
Dictionary< NetworkId, NetworkObjectMetaObjects [get]
 Returns a map of all objects in the simulation. More...
 
NetworkProjectConfig ProjectConfig [get]
 The NetworkProjectConfig file used by this Simulation. More...
 
float RemoteAlpha [get]
 Remote Interpolation Alpha More...
 
Tick RemoteTick [get]
 Remote Tick More...
 
Tick RemoteTickPrevious [get]
 Remote previous Tick More...
 
double SendDelta [get]
 The packet send delta time More...
 
int SendRate [get]
 The packet send rate More...
 
SimulationStages Stage [get]
 Gets the current SimulationStages value. More...
 
Tick Tick [get]
 The tick associated with the current state of networked objects, or the current simulation tick being processed (when evaluated during FixedUpdateNetwork). More...
 
double TickDeltaDouble [get]
 The delta time of each tick as a double More...
 
float TickDeltaFloat [get]
 The delta time of each tick as a float More...
 
Tick TickPrevious [get]
 The previous tick More...
 
int TickRate [get]
 The current tick rate of the simulation More...
 
int TickStride [get]
 How large the ticks the current simulation takes are More...
 
double Time [get]
 The current simulation time in seconds More...
 
Topologies Topology [get]
 Indicates if a Server/Client or Shared Mode (relay server) topology is being used. More...
 

Detailed Description

Main simulation class

Member Function Documentation

◆ AfterSimulation()

virtual void AfterSimulation ( )
protectedvirtual

Callback invoked after the Simulation Update

◆ AfterUpdate()

virtual void AfterUpdate ( )
protectedvirtual

Callback invoked After the Simulation Update

◆ BeforeFirstTick()

virtual void BeforeFirstTick ( )
protectedvirtual

Callback invoked before the First Tick

◆ BeforeSimulation()

virtual int BeforeSimulation ( )
protectedvirtual

Callback invoked before the Simulation Loop

Returns
Total number of re-simulations

◆ BeforeUpdate()

virtual void BeforeUpdate ( )
protectedvirtual

Callback invoked before the Simulation Update

◆ GetAreaOfInterestGizmoData()

void GetAreaOfInterestGizmoData ( List<(Vector3 center, Vector3 size, int playerCount, int objectCount)>  result)

Clears the provided list and populates it with data about the current Area of Interest (AOI) cells. Each tuple in the list represents one AOI cell, containing its center, size, player count, and object count.

Parameters
resultThe list to be populated with AOI cell data.

◆ GetInputAuthority()

PlayerRef GetInputAuthority ( NetworkObject  networkObject)

Get the Input Authority PlayerRef for a NetworkObject

Parameters
networkObjectNetworkObject to check
Returns
PlayerRef of the Input Authority for the NetworkObject

◆ GetInputForPlayer()

SimulationInput GetInputForPlayer ( PlayerRef  player)

Get the Simulation Input for a specific Player

Parameters
playerPlayer to check for the Simulation Input
Returns
Simulation Input for a specific Player


◆ GetObjectsAndPlayersInAreaOfInterestCell()

void GetObjectsAndPlayersInAreaOfInterestCell ( int  cellKey,
List< PlayerRef players,
List< NetworkId objects 
)

Used by RunnerAOIGizmos component. Supplies data about current active AOI cells.

◆ GetObjectsInAreaOfInterestForPlayer()

List<NetworkId> GetObjectsInAreaOfInterestForPlayer ( PlayerRef  player)

Retrieves a list of network object IDs that are in the area of interest for the specified player.

Parameters
playerThe player for whom the area of interest is being queried.
Returns
A list of network object IDs in the area of interest for the player.

◆ GetStateAuthority()

PlayerRef GetStateAuthority ( NetworkObject  networkObject)

Get the State Authority PlayerRef for a NetworkObject

Parameters
networkObjectNetworkObject to check
Returns
PlayerRef of the State Authority for the NetworkObject

◆ HasAnyActiveConnections()

bool HasAnyActiveConnections ( )

Signal if the Server has any Active Connection with any number of Clients.

Returns
True, if at least one connection is active, false otherwise.

◆ IsInputAuthority()

bool IsInputAuthority ( NetworkObject  networkObject,
PlayerRef  playerRef 
)

Check if a Player is the Input Authority over an NetworkObject

Parameters
networkObjectNetworkObject to check
playerRefPlayer to check
Returns
True if the Player is the Input Authority over the NetworkObject, false otherwise

◆ IsInterestedIn()

bool? IsInterestedIn ( NetworkObject  obj,
PlayerRef  player 
)

Check if a NetworkObject is interested by a specific Player

Parameters
objNetworkObject to check
playerPlayer to check
Returns
True if the Player is interested in the NetworkObject, false otherwise

◆ IsLocalSimulationInputAuthority()

bool IsLocalSimulationInputAuthority ( NetworkObject  obj)

Check if the Local Player is the Input Authority over a NetworkObject

Parameters
objNetworkObject to check
Returns
True if the Player is the Input Authority, false otherwise

◆ IsLocalSimulationStateAuthority() [1/2]

bool IsLocalSimulationStateAuthority ( NetworkId  id)

Check if a Player is the State Authority over a NetworkObject by NetworkId

Parameters
idNetworkId of the NetworkObject to check
Returns
True if the Player is the State Authority, false otherwise

◆ IsLocalSimulationStateAuthority() [2/2]

bool IsLocalSimulationStateAuthority ( NetworkObject  obj)

Check if the Local Player is the State Authority over a NetworkObject

Parameters
objNetworkObject to check
Returns
True if the Player is the State Authority, false otherwise

◆ IsLocalSimulationStateOrInputSource()

bool IsLocalSimulationStateOrInputSource ( NetworkObject  obj)

Check if the Local Player is the State Authority or Input Authority over a NetworkObject

Parameters
objNetworkObject to check
Returns
True if the Player is the State Authority or Input Authority, false otherwise

◆ IsStateAuthority() [1/2]

bool IsStateAuthority ( NetworkObject  networkObject,
PlayerRef  playerRef 
)

Check if a Player is the State Authority over a NetworkObject

Parameters
networkObjectNetworkObject to check
playerRefPlayer to check
Returns
True if the Player is the State Authority, false otherwise

◆ IsStateAuthority() [2/2]

bool IsStateAuthority ( PlayerRef  stateSource,
PlayerRef  playerRef 
)

Check if a Player is the State Authority in relation to another Player

Parameters
stateSourceState Source Player
playerRefPlayer to check
Returns
True if the Player is the State Authority, false otherwise

◆ NetworkConnected()

virtual void NetworkConnected ( NetConnection connection)
protectedvirtual

Callback invoked on the Connected

Parameters
connectionConnection that was connected

◆ NetworkDisconnected()

virtual void NetworkDisconnected ( NetConnection connection,
NetDisconnectReason  reason 
)
protectedvirtual

Callback invoked on the Disconnected

Parameters
connectionConnection that was disconnected
reasonReason for the disconnection

◆ NetworkReceiveDone()

virtual void NetworkReceiveDone ( )
protectedvirtual

Callback invoked when the Network Receive is completed

◆ NoSimulation()

virtual void NoSimulation ( )
protectedvirtual

Callback invoked when there is no simulation

◆ TryGetHostPlayer()

bool TryGetHostPlayer ( out PlayerRef  player)

Try to get the Host Player

Parameters
playerHost Player
Returns
True if the Host Player was found, false otherwise

◆ Update()

int Update ( double  dt)

Forwards the Simulation based on the Delta Time

Parameters
dtDelta Time used to forward the simulation
Returns
How many Ticks executed on this Update

Property Documentation

◆ ActivePlayers

virtual IEnumerable<PlayerRef> ActivePlayers
get

List of Active players in the Simulation

◆ Config

SimulationConfig Config
get

The SimulationConfig file used by this Simulation.

◆ DeltaTime

float DeltaTime
get

Gets the fixed tick time interval. Derived from the SimulationRuntimeConfig.TickRate.

◆ InputCount

int InputCount
get

The current input collection size

◆ IsClient

bool IsClient
get

If this peer is a client. True for client peers in Server/Client topologies, and true for all peers in Shared Mode.

◆ IsFirstTick

bool IsFirstTick
get

Use in conjunction with IsResimulation/IsForward inside of FixedUpdateNetwork to determine if the current tick being simulated is the first tick of the resimulation or forward phase of the simulation loop.

'Resimulation' describes simulating a tick that has been previously been simulated.
'Forward' describes simulating a tick that is being simulated for the first time locally.
'Prediction' describes simulating ticks higher than the most current known StateAuthority snapshot tick.

◆ IsForward

bool IsForward
get

Use inside of FixedUpdateNetwork to determine if the tick currently being simulated has NOT previously been simulated locally.

◆ IsLastTick

bool IsLastTick
get

Use in conjunction with IsResimulation/IsForward inside of FixedUpdateNetwork to determine if the current tick being simulated is the last tick of the resimulation or forward phase of the simulation loop.

'Resimulation' describes simulating a tick that has been previously been simulated.
'Forward' describes simulating a tick that is being simulated for the first time locally.
'Prediction' describes simulating ticks higher than the most current known StateAuthority snapshot tick.

◆ IsLocalPlayerFirstExecution

bool IsLocalPlayerFirstExecution
get

True if the current stage of the simulation loop is Forward. False during resimulations.

'Resimulation' describes simulating a tick that has been previously been simulated.
'Forward' describes simulating a tick that is being simulated for the first time locally.
'Prediction' describes simulating ticks higher than the most current known StateAuthority snapshot tick.

◆ IsMasterClient

bool IsMasterClient
get

Only valid in Shared Mode. Indicates if this peer is flagged as the MasterClient, which means it is default StateAuthority

◆ IsPlayer

bool IsPlayer
get

True for any peer that represents a human player. This is true for all peers except a dedicated server.

◆ IsResimulation

bool IsResimulation
get

Use inside of FixedUpdateNetwork to determine if the tick currently being simulated has previously been simulated locally. Resimulation occurs in client prediction when new states arrive from the StateAuthority. Networked objects are set to the most current authority state tick, and simulations are repeated from that tick to the local current tick.

◆ IsRunning

bool IsRunning
get

Signal if the Simulation is currently running

◆ IsServer

bool IsServer
get

If this peer is the server. True for the Server or Host peer in Server/Client topologies, and always false for all peers in Shared Mode (the relay is the server).

◆ IsShutdown

bool IsShutdown
get

◆ IsSinglePlayer

bool IsSinglePlayer
get

Indicates that this simulation is operating in Single Player mode, which is a Host that accepts no connections.

◆ LatestServerTick

abstract Tick LatestServerTick
get

latest tick on server we are aware of

◆ LocalAddress

NetAddress LocalAddress
get

Bound Address of the internal socket

◆ LocalAlpha

float LocalAlpha
get

◆ LocalPlayer

abstract PlayerRef LocalPlayer
get

Get LocalPlayer PlayerRef

◆ Mode

SimulationModes Mode
get

Gets the SimulationModes flags for The type of network peer this simulation represents.

◆ NetConfigPointer

NetConfig* NetConfigPointer
get

Current NetConfig

◆ ObjectCount

int ObjectCount
get

Returns the number of objects in the simulation.

◆ Objects

Dictionary<NetworkId, NetworkObjectMeta> Objects
get

Returns a map of all objects in the simulation.

◆ ProjectConfig

NetworkProjectConfig ProjectConfig
get

The NetworkProjectConfig file used by this Simulation.

◆ RemoteAlpha

float RemoteAlpha
get

Remote Interpolation Alpha

◆ RemoteTick

Tick RemoteTick
get

Remote Tick

◆ RemoteTickPrevious

Tick RemoteTickPrevious
get

Remote previous Tick

◆ SendDelta

double SendDelta
get

The packet send delta time

◆ SendRate

int SendRate
get

The packet send rate

◆ Stage

SimulationStages Stage
get

Gets the current SimulationStages value.

◆ Tick

Tick Tick
get

The tick associated with the current state of networked objects, or the current simulation tick being processed (when evaluated during FixedUpdateNetwork).

◆ TickDeltaDouble

double TickDeltaDouble
get

The delta time of each tick as a double

◆ TickDeltaFloat

float TickDeltaFloat
get

The delta time of each tick as a float

◆ TickPrevious

Tick TickPrevious
get

The previous tick

◆ TickRate

int TickRate
get

The current tick rate of the simulation

◆ TickStride

int TickStride
get

How large the ticks the current simulation takes are

◆ Time

double Time
get

The current simulation time in seconds

◆ Topology

Topologies Topology
get

Indicates if a Server/Client or Shared Mode (relay server) topology is being used.