Photon Quantum 3.0.0

Public Member Functions | Public Attributes | Properties | List of all members
Photon.Deterministic.DeterministicSession Class Reference

Represents a Quantum runtime match, holding the references to Game, its Frames (game state) and Simulator, and implements (together with Simulator) the predict/rollback logic, time control and input management. Single use, so whenever a Session is shutdown (or disconnected), it can't be reused anymore and a new one must be instantiated. More...

Public Member Functions

 DeterministicSession (DeterministicSessionArgs args)
 Validates a few conditions to assert the session object has coherent settings. After construction, session is ready to Join/Start a game. More...
 
void AddPlayer (int playerSlot, Byte[] data)
 Attempts to add a local player slot to have input controlled by the session. Fails is local slot is already used, or if the server/plugin does not have an available PlayerRef. More...
 
void ApplyTimeOffset (Double time)
 Legacy method to manually add time to the internal Simulator. Not used anymore by the standard SDK, but available to legacy projects. More...
 
void Destroy ()
 Terminates the game/session, Disposing all buffers and objects. More...
 
void GetLocalConfigs (out DeterministicSessionConfig sessionConfig, out Byte[] runtimeConfig)
 Retrieves the local copies of the main configs. More...
 
Boolean IsFrameVerified (int frame)
 true if the latest confirmed/verified frame is equals or larger then this. More...
 
Boolean IsLocalPlayer (PlayerRef player)
 true if this global PlayerRef is controlled by the local session. More...
 
bool IsPlayerLocal (PlayerRef player)
 Tests whereas this PlayerRef is controlled by this local client/session. More...
 
bool IsPlayerSlotLocal (int playerSlot)
 Checks if this local player slot is currently in use (local slots can be added/removed dynamically). More...
 
void Join (String id)
 Sends the Join protocol message to server/plugin. If successful, a start protocol message (and optionally a snapshot) will be received and the session will start to be updated. Sessions are always joined as spectators (starting on Quantum 3.0), and adding local players that can have input polled for is a dynamic operation done after session start. More...
 
void RemovePlayer (Int32 playerSlot)
 Attempts to remove a local player slot from the session. Fails is local slot is not currently in use. More...
 
void ResetReplay (DeterministicFrame frame)
 Resets the session to the specified frame for replay purposes. More...
 
void Resync (Byte[] frameData, Int32 frameNumber)
 Resynchronizes the session based on the provided frame data and frame number. More...
 
void Resync (DeterministicFrame frame)
 Resynchronizes the session to the specified frame. More...
 
DeterministicCommandSendResult SendCommand (Int32 playerSlot, DeterministicCommand command)
 Includes command for local prediction, and sends to server (in online games) for confirmation. Fails if this slot is not in use by the local session/client. Server protects against all forms of spoofing in online games. More...
 
void SendGameResult (Byte[] data)
 Supports sending one game result during one session per client. Send this based on timing and simulation data of a verified frame to make results be comparable. Data can be any format but the size must be below Protocol.GameResult.MaxSize. Zip compress Json for example to reduce the size. More...
 
void SetPlayerData (int playerSlot, Byte[] data)
 Previously could be called multiple times to send custom data relative to a player. AddPlayer replaces it, and can only be called once for a specific slot. More...
 
bool TryGetLocalPlayer (int playerSlot, out PlayerRef player)
 Returns true and fills in the corresponding global PlayerRef if playerSlot is a valid local slot, for which the session can send input. More...
 
void Update (Double? deltaTime=null)
 Called to move the simulation forward (poll local input, decode confirmed, simulate verified and predicted frames). When passing a delta time, the internal Stopwatch is ignored. More...
 

Public Attributes

bool IsRunning => State == DeterministicSessionState.Running
 true if local session is started and active. More...
 
List< PlayerRefLocalPlayers => _localPlayerMap.Players
 The collection of PlayerRefs the local client has control of (sends input for). More...
 
List< Int32 > LocalPlayerSlots => _localPlayerMap.PlayerSlots
 The collection of local-indexed (0-n) players the local client has control of (sends input for). More...
 

Properties

Double AccumulatedTime [get]
 Remaining accumulated time after all frames forward (both verified and predicted) have been simulated. Usually less than a full delta-time (defined by update rate), and used to compute the interpolation alpha. Can be above delta-time if the current session is temporarily lagging behind and can not simulate forward the full prediction (depending on settings). More...
 
DeterministicCommandSerializer CommandSerializer [get]
 Local instance of specialized serializer that can pack/unpack DeterministicCommands to/from byte[]s. More...
 
FP DeltaTime [get]
 Fixed-point delta-time as defined by DeterministicConfig's UpdateFPS (1/UpdateFPS). More...
 
Double DeltaTimeDouble [get]
 Double version of delta-time as defined by DeterministicConfig's UpdateFPS (1/UpdateFPS). More...
 
DeterministicFrameFramePredicted [get]
 Quick accessor to the latest locally predicted copy of the game state. More...
 
DeterministicFrameFramePredictedPrevious [get]
 Quick accessor to the second latest locally predicted copy of the game state. Used for accurate visual interpolation of transforms (or any other data) between this and the Predicted frame. More...
 
DeterministicFrameFrameVerified [get]
 Quick accessor to the forward-only verified data (simulated with confirmed inputs from server in online games). Can be used as source of truth, as this does not include predicted data. More...
 
IDeterministicGame Game [get]
 The matching game instance, which holds the Frames (game state) and other accessory logic entry points for a predict/rollback match. More...
 
DeterministicGameMode GameMode [get]
 Possible modes are online/multiplayer, local or replay. More...
 
Int32 InitialTick [get]
 Normally zero (0) for most game clients. Can be set to a specific value if a local copy for initial frame snapshot data is provided (normally used occasionally in case of quick rejoinining a room). More...
 
DeterministicTickInput.Pool InputPool [get]
 Accessor to the pool of input objects. More...
 
byte[] IntitialFrameData [get]
 Serialized local copy for initial frame snapshot data, if provided when starting a new session (normally used occasionally in case of quick rejoinining a room). More...
 
Boolean IsInterpolatable [get]
 If the session provides previous states for interpolation. More...
 
Boolean IsLocal [get]
 true for replays and local games (single player or split screen/couch-local). false for online games. More...
 
Boolean IsLockstep [get]
 Legacy mode in which frames are only simulated forward with input delay, and no prediction is ever performed. In the past this was the default approach for classic RTS games. More...
 
Boolean IsOnline [get]
 true for online games. false for replays and local games (single player or split screen/couch-local). More...
 
Boolean IsPaused [get]
 Temporarily true only for a session that has just been started (Start message arrived from server) while waiting for a snapshot to arrive. More...
 
Boolean IsPredicted [get]
 true when not using legacy lockstep mode. Means frames will be predicted and rolled back. More...
 
Boolean IsReplay [get]
 true when GameMode is Replay (input comes from replay provider). More...
 
Boolean IsReplayFinished [get]
 true when the final input in the replay stream has been consumed to simulate forward a verified frame. More...
 
Boolean IsSpectating [get]
 Always true once session is started. false if at least one player is controlled by the local session. More...
 
Boolean IsStalling [get]
 true if simulation is being clamped at max prediction (rollback window). Happens normally when input confirmations from server are disrupted (network loss or very high ping times). More...
 
Int32 LocalInputOffset [get]
 Current value for the dynamically-adjusted input delay (independent for each client). Starts at the initial offset on DeterministicConfig (defaults to 0), and grows with RTT. More...
 
Int32 MaxVerifiedTicksPerUpdate [get, set]
 Limit the maximum number of verified ticks computed per update. Default is int.MaxValue. More...
 
DeterministicPlatformInfo PlatformInfo [get]
 Cached info about the local device platform (some OS and hardware available specs). More...
 
Int32 PlayerCount [get]
 Total/max number of PlayerRefs this particular session instance comprises of. This is not the number of connected players, but rather the total number. More...
 
Int32 PredictedFrames [get]
 Stats: Number of predicted frames simulated during the last call to Update(). More...
 
DeterministicFramePreviousUpdateFramePredicted [get]
 Quick accessor to the latest simulated copy of the Frame that was last-Predicted during the previous main session update. Used to calculate transform view error for smoothed correction. More...
 
IDeterministicReplayProvider ReplayProvider [get]
 When running replays, input comes from the provider/container. Replay input streams can com from file, memory, or a network stream (custom). More...
 
Int32 RollbackWindow [get]
 Max number of frames/ticks the session is allowed to predict. Can be set at DeterministicConfig. More...
 
IDisposable Runner [get, set]
 Runner is the wrapper for session/game that can be attached to Unity, a .Net console app, or a Quantum Custom Server Plugin. More...
 
Byte[] RuntimeConfig [get]
 Serialized local copy of the game/session custom RuntimeConfig instance (received from the photon server). Since this has been received from server, it's the same in all instances. More...
 
DeterministicSessionConfig SessionConfig [get]
 Local copy of the server-provided main set of settings, controlling update rate, input adjustment and other important control values. Since this has been received from server, it's the same set of values in all instances. More...
 
Int32 SimulationRate [get]
 Fixed rate at which the game is simulated (verified frames). Can be set at DeterministicConfig. More...
 
Double SimulationTimeElasped [get]
 Stats: Precise time in seconds used by the last call to Update(). Includes all session internal input handling, rollbacks, verified and predicted frames simulation. More...
 
double SpectatingOffsetSec [get, set]
 Specify the offset in sec that the simulation will run behind in Spectator mode. Value must be negative or 0. Default is -1 sec. More...
 
DeterministicStats Stats [get]
 Copy of local runtime stats (stores the last Update values for simulation time, number of frames simulated, etc). Used by the QuantumStatsUI to show these in runtime on Unity. More...
 
Double TimeScale [get]
 Current time-dilation delta-time scale. Tf time-dilation settings allow it, server will reduce this to slow down games when some clients have very high ping (reducing the number of predictions). More...
 

Detailed Description

Represents a Quantum runtime match, holding the references to Game, its Frames (game state) and Simulator, and implements (together with Simulator) the predict/rollback logic, time control and input management. Single use, so whenever a Session is shutdown (or disconnected), it can't be reused anymore and a new one must be instantiated.

Constructor & Destructor Documentation

◆ DeterministicSession()

Photon.Deterministic.DeterministicSession.DeterministicSession ( DeterministicSessionArgs  args)
inline

Validates a few conditions to assert the session object has coherent settings. After construction, session is ready to Join/Start a game.

Member Function Documentation

◆ IsPlayerLocal()

bool Photon.Deterministic.DeterministicSession.IsPlayerLocal ( PlayerRef  player)
inline

Tests whereas this PlayerRef is controlled by this local client/session.

◆ TryGetLocalPlayer()

bool Photon.Deterministic.DeterministicSession.TryGetLocalPlayer ( int  playerSlot,
out PlayerRef  player 
)
inline

Returns true and fills in the corresponding global PlayerRef if playerSlot is a valid local slot, for which the session can send input.

◆ IsPlayerSlotLocal()

bool Photon.Deterministic.DeterministicSession.IsPlayerSlotLocal ( int  playerSlot)
inline

Checks if this local player slot is currently in use (local slots can be added/removed dynamically).

◆ GetLocalConfigs()

void Photon.Deterministic.DeterministicSession.GetLocalConfigs ( out DeterministicSessionConfig  sessionConfig,
out Byte[]  runtimeConfig 
)
inline

Retrieves the local copies of the main configs.

◆ IsFrameVerified()

Boolean Photon.Deterministic.DeterministicSession.IsFrameVerified ( int  frame)
inline

true if the latest confirmed/verified frame is equals or larger then this.

◆ IsLocalPlayer()

Boolean Photon.Deterministic.DeterministicSession.IsLocalPlayer ( PlayerRef  player)
inline

true if this global PlayerRef is controlled by the local session.

◆ SendCommand()

DeterministicCommandSendResult Photon.Deterministic.DeterministicSession.SendCommand ( Int32  playerSlot,
DeterministicCommand  command 
)
inline

Includes command for local prediction, and sends to server (in online games) for confirmation. Fails if this slot is not in use by the local session/client. Server protects against all forms of spoofing in online games.

◆ SetPlayerData()

void Photon.Deterministic.DeterministicSession.SetPlayerData ( int  playerSlot,
Byte[]  data 
)
inline

Previously could be called multiple times to send custom data relative to a player. AddPlayer replaces it, and can only be called once for a specific slot.

◆ AddPlayer()

void Photon.Deterministic.DeterministicSession.AddPlayer ( int  playerSlot,
Byte[]  data 
)
inline

Attempts to add a local player slot to have input controlled by the session. Fails is local slot is already used, or if the server/plugin does not have an available PlayerRef.

◆ RemovePlayer()

void Photon.Deterministic.DeterministicSession.RemovePlayer ( Int32  playerSlot)
inline

Attempts to remove a local player slot from the session. Fails is local slot is not currently in use.

◆ SendGameResult()

void Photon.Deterministic.DeterministicSession.SendGameResult ( Byte[]  data)
inline

Supports sending one game result during one session per client. Send this based on timing and simulation data of a verified frame to make results be comparable. Data can be any format but the size must be below Protocol.GameResult.MaxSize. Zip compress Json for example to reduce the size.

Parameters
dataSerialized game result

◆ Join()

void Photon.Deterministic.DeterministicSession.Join ( String  id)
inline

Sends the Join protocol message to server/plugin. If successful, a start protocol message (and optionally a snapshot) will be received and the session will start to be updated. Sessions are always joined as spectators (starting on Quantum 3.0), and adding local players that can have input polled for is a dynamic operation done after session start.

◆ ApplyTimeOffset()

void Photon.Deterministic.DeterministicSession.ApplyTimeOffset ( Double  time)
inline

Legacy method to manually add time to the internal Simulator. Not used anymore by the standard SDK, but available to legacy projects.

◆ Destroy()

void Photon.Deterministic.DeterministicSession.Destroy ( )
inline

Terminates the game/session, Disposing all buffers and objects.

◆ Update()

void Photon.Deterministic.DeterministicSession.Update ( Double?  deltaTime = null)
inline

Called to move the simulation forward (poll local input, decode confirmed, simulate verified and predicted frames). When passing a delta time, the internal Stopwatch is ignored.

◆ ResetReplay()

void Photon.Deterministic.DeterministicSession.ResetReplay ( DeterministicFrame  frame)
inline

Resets the session to the specified frame for replay purposes.

Parameters
frameThe frame to reset the session to.

◆ Resync() [1/2]

void Photon.Deterministic.DeterministicSession.Resync ( DeterministicFrame  frame)
inline

Resynchronizes the session to the specified frame.

Parameters
frameThe frame to reset to.

◆ Resync() [2/2]

void Photon.Deterministic.DeterministicSession.Resync ( Byte[]  frameData,
Int32  frameNumber 
)
inline

Resynchronizes the session based on the provided frame data and frame number.

Parameters
frameDataThe frame data to use for resynchronization.
frameNumberThe frame number to resynchronize with.

Member Data Documentation

◆ LocalPlayers

List<PlayerRef> Photon.Deterministic.DeterministicSession.LocalPlayers => _localPlayerMap.Players

The collection of PlayerRefs the local client has control of (sends input for).

◆ LocalPlayerSlots

List<Int32> Photon.Deterministic.DeterministicSession.LocalPlayerSlots => _localPlayerMap.PlayerSlots

The collection of local-indexed (0-n) players the local client has control of (sends input for).

◆ IsRunning

bool Photon.Deterministic.DeterministicSession.IsRunning => State == DeterministicSessionState.Running

true if local session is started and active.

Property Documentation

◆ MaxVerifiedTicksPerUpdate

Int32 Photon.Deterministic.DeterministicSession.MaxVerifiedTicksPerUpdate
getset

Limit the maximum number of verified ticks computed per update. Default is int.MaxValue.

◆ SpectatingOffsetSec

double Photon.Deterministic.DeterministicSession.SpectatingOffsetSec
getset

Specify the offset in sec that the simulation will run behind in Spectator mode. Value must be negative or 0. Default is -1 sec.

◆ RuntimeConfig

Byte [] Photon.Deterministic.DeterministicSession.RuntimeConfig
get

Serialized local copy of the game/session custom RuntimeConfig instance (received from the photon server). Since this has been received from server, it's the same in all instances.

◆ Stats

DeterministicStats Photon.Deterministic.DeterministicSession.Stats
get

Copy of local runtime stats (stores the last Update values for simulation time, number of frames simulated, etc). Used by the QuantumStatsUI to show these in runtime on Unity.

◆ Game

IDeterministicGame Photon.Deterministic.DeterministicSession.Game
get

The matching game instance, which holds the Frames (game state) and other accessory logic entry points for a predict/rollback match.

◆ FramePredicted

DeterministicFrame? Photon.Deterministic.DeterministicSession.FramePredicted
get

Quick accessor to the latest locally predicted copy of the game state.

◆ FramePredictedPrevious

DeterministicFrame? Photon.Deterministic.DeterministicSession.FramePredictedPrevious
get

Quick accessor to the second latest locally predicted copy of the game state. Used for accurate visual interpolation of transforms (or any other data) between this and the Predicted frame.

◆ FrameVerified

DeterministicFrame? Photon.Deterministic.DeterministicSession.FrameVerified
get

Quick accessor to the forward-only verified data (simulated with confirmed inputs from server in online games). Can be used as source of truth, as this does not include predicted data.

◆ PreviousUpdateFramePredicted

DeterministicFrame? Photon.Deterministic.DeterministicSession.PreviousUpdateFramePredicted
get

Quick accessor to the latest simulated copy of the Frame that was last-Predicted during the previous main session update. Used to calculate transform view error for smoothed correction.

◆ SessionConfig

DeterministicSessionConfig Photon.Deterministic.DeterministicSession.SessionConfig
get

Local copy of the server-provided main set of settings, controlling update rate, input adjustment and other important control values. Since this has been received from server, it's the same set of values in all instances.

◆ AccumulatedTime

Double Photon.Deterministic.DeterministicSession.AccumulatedTime
get

Remaining accumulated time after all frames forward (both verified and predicted) have been simulated. Usually less than a full delta-time (defined by update rate), and used to compute the interpolation alpha. Can be above delta-time if the current session is temporarily lagging behind and can not simulate forward the full prediction (depending on settings).

◆ InitialTick

Int32 Photon.Deterministic.DeterministicSession.InitialTick
get

Normally zero (0) for most game clients. Can be set to a specific value if a local copy for initial frame snapshot data is provided (normally used occasionally in case of quick rejoinining a room).

◆ IntitialFrameData

byte [] Photon.Deterministic.DeterministicSession.IntitialFrameData
get

Serialized local copy for initial frame snapshot data, if provided when starting a new session (normally used occasionally in case of quick rejoinining a room).

◆ TimeScale

Double Photon.Deterministic.DeterministicSession.TimeScale
get

Current time-dilation delta-time scale. Tf time-dilation settings allow it, server will reduce this to slow down games when some clients have very high ping (reducing the number of predictions).

◆ PlayerCount

Int32 Photon.Deterministic.DeterministicSession.PlayerCount
get

Total/max number of PlayerRefs this particular session instance comprises of. This is not the number of connected players, but rather the total number.

◆ SimulationRate

Int32 Photon.Deterministic.DeterministicSession.SimulationRate
get

Fixed rate at which the game is simulated (verified frames). Can be set at DeterministicConfig.

◆ RollbackWindow

Int32 Photon.Deterministic.DeterministicSession.RollbackWindow
get

Max number of frames/ticks the session is allowed to predict. Can be set at DeterministicConfig.

◆ LocalInputOffset

Int32 Photon.Deterministic.DeterministicSession.LocalInputOffset
get

Current value for the dynamically-adjusted input delay (independent for each client). Starts at the initial offset on DeterministicConfig (defaults to 0), and grows with RTT.

◆ PredictedFrames

Int32 Photon.Deterministic.DeterministicSession.PredictedFrames
get

Stats: Number of predicted frames simulated during the last call to Update().

◆ SimulationTimeElasped

Double Photon.Deterministic.DeterministicSession.SimulationTimeElasped
get

Stats: Precise time in seconds used by the last call to Update(). Includes all session internal input handling, rollbacks, verified and predicted frames simulation.

◆ DeltaTime

FP Photon.Deterministic.DeterministicSession.DeltaTime
get

Fixed-point delta-time as defined by DeterministicConfig's UpdateFPS (1/UpdateFPS).

◆ DeltaTimeDouble

Double Photon.Deterministic.DeterministicSession.DeltaTimeDouble
get

Double version of delta-time as defined by DeterministicConfig's UpdateFPS (1/UpdateFPS).

◆ GameMode

DeterministicGameMode Photon.Deterministic.DeterministicSession.GameMode
get

Possible modes are online/multiplayer, local or replay.

◆ IsLocal

Boolean Photon.Deterministic.DeterministicSession.IsLocal
get

true for replays and local games (single player or split screen/couch-local). false for online games.

◆ IsOnline

Boolean Photon.Deterministic.DeterministicSession.IsOnline
get

true for online games. false for replays and local games (single player or split screen/couch-local).

◆ IsSpectating

Boolean Photon.Deterministic.DeterministicSession.IsSpectating
get

Always true once session is started. false if at least one player is controlled by the local session.

◆ IsStalling

Boolean Photon.Deterministic.DeterministicSession.IsStalling
get

true if simulation is being clamped at max prediction (rollback window). Happens normally when input confirmations from server are disrupted (network loss or very high ping times).

◆ IsPaused

Boolean Photon.Deterministic.DeterministicSession.IsPaused
get

Temporarily true only for a session that has just been started (Start message arrived from server) while waiting for a snapshot to arrive.

◆ IsLockstep

Boolean Photon.Deterministic.DeterministicSession.IsLockstep
get

Legacy mode in which frames are only simulated forward with input delay, and no prediction is ever performed. In the past this was the default approach for classic RTS games.

◆ IsPredicted

Boolean Photon.Deterministic.DeterministicSession.IsPredicted
get

true when not using legacy lockstep mode. Means frames will be predicted and rolled back.

◆ IsReplay

Boolean Photon.Deterministic.DeterministicSession.IsReplay
get

true when GameMode is Replay (input comes from replay provider).

◆ IsInterpolatable

Boolean Photon.Deterministic.DeterministicSession.IsInterpolatable
get

If the session provides previous states for interpolation.

◆ IsReplayFinished

Boolean Photon.Deterministic.DeterministicSession.IsReplayFinished
get

true when the final input in the replay stream has been consumed to simulate forward a verified frame.

◆ ReplayProvider

IDeterministicReplayProvider Photon.Deterministic.DeterministicSession.ReplayProvider
get

When running replays, input comes from the provider/container. Replay input streams can com from file, memory, or a network stream (custom).

◆ PlatformInfo

DeterministicPlatformInfo Photon.Deterministic.DeterministicSession.PlatformInfo
get

Cached info about the local device platform (some OS and hardware available specs).

◆ CommandSerializer

DeterministicCommandSerializer Photon.Deterministic.DeterministicSession.CommandSerializer
get

Local instance of specialized serializer that can pack/unpack DeterministicCommands to/from byte[]s.

◆ Runner

IDisposable Photon.Deterministic.DeterministicSession.Runner
getset

Runner is the wrapper for session/game that can be attached to Unity, a .Net console app, or a Quantum Custom Server Plugin.

◆ InputPool

DeterministicTickInput.Pool Photon.Deterministic.DeterministicSession.InputPool
get

Accessor to the pool of input objects.