Photon Fusion 2.0.0

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

Main simulation class. More...

Inherits ILogSourceProxy, and INetPeerGroupCallbacks.

Classes

struct  AreaOfInterest
 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.
 
PlayerRef GetInputAuthority (NetworkObject networkObject)
 Get the Input Authority PlayerRef for a NetworkObject.
 
SimulationInput GetInputForPlayer (PlayerRef player)
 Get the Simulation Input for a specific Player.
 
void GetObjectsAndPlayersInAreaOfInterestCell (int cellKey, List< PlayerRef > players, List< NetworkId > objects)
 Used by RunnerAOIGizmos component. Supplies data about current active AOI cells.
 
PlayerRef GetStateAuthority (NetworkObject networkObject)
 Get the State Authority PlayerRef for a NetworkObject.
 
bool HasAnyActiveConnections ()
 Signal if the Server has any Active Connection with any number of Clients.
 
bool IsInputAuthority (NetworkObject networkObject, PlayerRef playerRef)
 Check if a Player is the Input Authority over an NetworkObject.
 
bool? IsInterestedIn (NetworkObject obj, PlayerRef player)
 Check if a NetworkObject is interested by a specific Player.
 
bool IsLocalSimulationInputAuthority (NetworkObject obj)
 Check if the Local Player is the Input Authority over a NetworkObject.
 
bool IsLocalSimulationStateAuthority (NetworkId id)
 Check if a Player is the State Authority over a NetworkObject by NetworkId.
 
bool IsLocalSimulationStateAuthority (NetworkObject obj)
 Check if the Local Player is the State Authority over a NetworkObject.
 
bool IsLocalSimulationStateOrInputSource (NetworkObject obj)
 Check if the Local Player is the State Authority or Input Authority over a NetworkObject.
 
bool IsStateAuthority (NetworkObject networkObject, PlayerRef playerRef)
 Check if a Player is the State Authority over a NetworkObject.
 
bool IsStateAuthority (PlayerRef stateSource, PlayerRef playerRef)
 Check if a Player is the State Authority in relation to another Player.
 
bool TryGetHostPlayer (out PlayerRef player)
 Try to get the Host Player.
 
int Update (double dt)
 Forwards the Simulation based on the Delta Time.
 

Protected Member Functions

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

Properties

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

Detailed Description

Main simulation class.

Member Function Documentation

◆ BeforeSimulation()

virtual int BeforeSimulation ( )
protectedvirtual

Callback invoked before the Simulation Loop.

Returns
Total number of re-simulations

◆ 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


◆ 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

◆ 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

◆ 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.

◆ 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.