Table of Contents

INetworkTime

interface in Coherence
Properties
AccountForPing

If true, the server frame will be adjusted by ping, resulting in the client frame matching the server frame as it is on the Replication Server the moment packet is received. If false, the client frame will aim to match the server frame as it was at the moment of being sent from the Replication Server.

ClientFixedSimulationFrame

Similar to Coherence.Core.NetworkTime.ClientSimulationFrame but quantized to Coherence.Core.NetworkTime.FixedTimeStep.

ClientSimulationFrame

ClientSimulationFrame is the current network time quantized to 60hz. It is used to timestamp outgoing packets.

ConnectionSimulationFrame

The first ServerSimulationFrame received from the replication server. Used as a baseline for calculating Coherence.Core.NetworkTime.SessionTime.

FixedTimeStep

The rate at which which Coherence.Core.NetworkTime.OnFixedNetworkUpdate is invoked. Should normally be set to Time.fixedTimeStep. If set to zero, Coherence.Core.NetworkTime.OnFixedNetworkUpdate will not be invoked.

IsTimeSynced

IsTimeSynced will be set to true the first time Coherence.Core.NetworkTime.SetServerSimulationFrame(Coherence.SimulationFrame.AbsoluteSimulationFrame, Coherence.Common.Ping) is called (usually when connecting). IsTimeSynced will be reset back to false by Coherence.Core.NetworkTime.Reset(Coherence.SimulationFrame.AbsoluteSimulationFrame, bool).

MaximumDeltaTime

Limits time incremented in Coherence.Core.NetworkTime.Step(double, bool) in case of cpu spikes. Should normally be set to Unity's Time.maximumDeltaTime.

MultiClientMode

Allows multiple CoherenceBridge instances within one application to maintain independent time scales. This is useful for testing multiple connections within the Unity editor without making standalone builds. Instead of adapting Time.timeScale to catch up with server clock, it applies the frequency of Coherence.Core.NetworkTime.OnFixedNetworkUpdate.

NetworkTimeScale

The recommended time scale that should be applied to Time.timeScale for the client clock to smoothly catch up/slow down to server clock. Coherence.Core.NetworkTime.TargetTimeScale is calculated during Coherence.Core.NetworkTime.SetServerSimulationFrame(Coherence.SimulationFrame.AbsoluteSimulationFrame, Coherence.Common.Ping) based on the current client/server frame diff, and NetworkTimeScale will smoothly approach this value over time.

NetworkTimeScaleAsDouble

Similar to Coherence.Core.NetworkTime.NetworkTimeScale with double precision.

Pause

Pauses updating the client simulation frame. When set to true any calls to Coherence.Core.NetworkTime.Step(double, bool) will have no effect on the simulation frame and fixed simulation frame.

ServerSimulationFrame

The last ServerSimulationFrame received from the replication server. Used for calculating Coherence.Core.NetworkTime.TargetTimeScale in order to synchronize client with server.

SessionTime

Monotonic clock that only increases when connected to a replication server and that resets back to zero on disconnect. Value will jump considerably during time reset as client network time adapts to server time, see Coherence.Core.NetworkTime.Reset(Coherence.SimulationFrame.AbsoluteSimulationFrame, bool).

SessionTimeAsDouble

Similar to Coherence.Core.NetworkTime.SessionTime but with double precision.

SmoothTimeScaleChange

Enables smoothing time scale changes, i.e. if there is a big gap between client and server simulation frames, instead of sudden jumps in time scale it will smoothly transition Coherence.Core.NetworkTime.NetworkTimeScale towards Coherence.Core.NetworkTime.TargetTimeScale.

TargetTimeScale

The time scale that Coherence.Core.NetworkTime.NetworkTimeScale is smoothly approaching over time. When Coherence.Core.NetworkTime.SmoothTimeScaleChange is set to false, TargetTimeScale and Coherence.Core.NetworkTime.NetworkTimeScale are always equal.

TimeAsDouble

Monotonic clock that increases with each call to Coherence.Core.NetworkTime.Step(double, bool) regardless if connected to a replication server or not. Value will jump considerably during connect, disconnect and time reset as client network time adapts to server time, see Coherence.Core.NetworkTime.Reset(Coherence.SimulationFrame.AbsoluteSimulationFrame, bool).

Methods
Reset

Resets client and server frames to the given value. Happens on connect, disconnect and when client/server frames are too far apart. Sets Coherence.Core.NetworkTime.IsTimeSynced to false, causing Coherence.Core.NetworkTime.SessionTime to reset back to zero. Triggers Coherence.Core.NetworkTime.OnTimeReset.

The new frame value that will be applied to both Coherence.Core.NetworkTime.ClientSimulationFrame and Coherence.Core.NetworkTime.ServerSimulationFrame. Default is frame zero.
Step

Updates the Coherence.Core.NetworkTime.ClientSimulationFrame using the current game time, advancing one frame every 1/60 second. The Coherence.Core.NetworkTime.NetworkTimeScale is smoothly interpolated towards TargetTimeScale with each call. With multiClientMode enabled, however, the callback trigger rate is scaled by Coherence.Core.NetworkTime.NetworkTimeScale.

Events
OnFixedNetworkUpdate

With Coherence.Core.NetworkTime.MultiClientMode enabled it is recommended to put simulation code in OnFixedNetworkUpdate event handlers instead of FixedUpdate. This allows multiple connected clients within the application to execute at different frequencies for correct network synchronization. The Time.fixedDeltaTime should be applied similar to how it is normally used in FixedUpdate.

OnLateFixedNetworkUpdate

Similar to Coherence.Core.NetworkTime.OnFixedNetworkUpdate but guaranteed to be called later.

OnServerSimulationFrameReceived

Triggered in response to Coherence.Core.NetworkTime.SetServerSimulationFrame(Coherence.SimulationFrame.AbsoluteSimulationFrame, Coherence.Common.Ping) after Coherence.Core.NetworkTime.TargetTimeScale has been recalculated. The first parameter is the server simulation frame. The second parameter is the client simulation frame.

OnTimeReset

Triggered the first time Coherence.Core.NetworkTime.SetServerSimulationFrame(Coherence.SimulationFrame.AbsoluteSimulationFrame, Coherence.Common.Ping) is called and at any subsequent call if Coherence.Core.NetworkTime.ClientSimulationFrame and Coherence.Core.NetworkTime.ServerSimulationFrame have drifter too far apart.