Table of Contents

Interface INetworkTime

Namespace
Coherence
Assembly
Coherence.Core.dll
public interface INetworkTime

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.

bool AccountForPing { get; set; }

Property Value

bool

ClientFixedSimulationFrame

Similar to ClientSimulationFrame but quantized to FixedTimeStep.

AbsoluteSimulationFrame ClientFixedSimulationFrame { get; }

Property Value

AbsoluteSimulationFrame

ClientSimulationFrame

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

AbsoluteSimulationFrame ClientSimulationFrame { get; }

Property Value

AbsoluteSimulationFrame

ConnectionSimulationFrame

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

AbsoluteSimulationFrame ConnectionSimulationFrame { get; }

Property Value

AbsoluteSimulationFrame

FixedTimeStep

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

double FixedTimeStep { get; set; }

Property Value

double

IsTimeSynced

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

bool IsTimeSynced { get; }

Property Value

bool

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

bool MultiClientMode { get; set; }

Property Value

bool

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. TargetTimeScale is calculated during SetServerSimulationFrame(AbsoluteSimulationFrame, Ping) based on the current client/server frame diff, and NetworkTimeScale will smoothly approach this value over time.

float NetworkTimeScale { get; }

Property Value

float

NetworkTimeScaleAsDouble

Similar to NetworkTimeScale with double precision.

double NetworkTimeScaleAsDouble { get; }

Property Value

double

Pause

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

bool Pause { get; set; }

Property Value

bool

ServerSimulationFrame

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

AbsoluteSimulationFrame ServerSimulationFrame { get; }

Property Value

AbsoluteSimulationFrame

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 Reset(AbsoluteSimulationFrame, bool).

float SessionTime { get; }

Property Value

float

SessionTimeAsDouble

Similar to SessionTime but with double precision.

double SessionTimeAsDouble { get; }

Property Value

double

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 NetworkTimeScale towards TargetTimeScale.

bool SmoothTimeScaleChange { get; set; }

Property Value

bool

TargetTimeScale

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

double TargetTimeScale { get; }

Property Value

double

TimeAsDouble

Monotonic clock that increases with each call to Step(double) 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 Reset(AbsoluteSimulationFrame, bool).

double TimeAsDouble { get; }

Property Value

double

Methods

Reset(AbsoluteSimulationFrame, bool)

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

The new frame value that will be applied to both ClientSimulationFrame and ServerSimulationFrame. Default is frame zero.
void Reset(AbsoluteSimulationFrame newClientAndServerFrame = default, bool notify = true)

Parameters

newClientAndServerFrame AbsoluteSimulationFrame
notify bool

Step(double)

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

void Step(double currentTime)

Parameters

currentTime double

The current game time, usually just Time.time. Must be non-zero for OnFixedNetworkUpdate to be invoked.

Events

OnFixedNetworkUpdate

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

event Action OnFixedNetworkUpdate

Event Type

Action

OnLateFixedNetworkUpdate

Similar to OnFixedNetworkUpdate but guaranteed to be called later.

event Action OnLateFixedNetworkUpdate

Event Type

Action

OnServerSimulationFrameReceived

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

event Action<AbsoluteSimulationFrame, AbsoluteSimulationFrame> OnServerSimulationFrameReceived

Event Type

Action<AbsoluteSimulationFrame, AbsoluteSimulationFrame>

OnTimeReset

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

event Action OnTimeReset

Event Type

Action