GameTime

GameTime

A singleton class game#time which keeps the official Server and World time stamps. Uses a basic implementation of https://www.geeksforgeeks.org/cristians-algorithm/ for synchronization.

Constructor

new GameTime()

Members

_dt :number

The average one-way latency across the most recent 5 trips

Type:
  • number

_dts :Array.<number>

The most recent five synchronization durations

Type:

_time :Object

The most recently synchronized timestamps retrieved from the server.

Type:
  • Object

serverTime

The current server time based on the last synchronization point and the approximated one-way latency.

SYNC_INTERVAL_MS :number

The amount of time to delay before re-syncing the official server time.

Type:
  • number

worldTime

The current World time based on the last recorded value of the core.time setting

Methods

(async) advance(seconds) → {Promise.<number>}

Advance the game time by a certain number of seconds

Parameters:
Name Type Description
seconds number

The number of seconds to advance (or rewind if negative) by

Returns:

The new game time

Type
Promise.<number>

onUpdateWorldTime(worldTime)

Handle follow-up actions when the official World time is changed

Parameters:
Name Type Description
worldTime number

The new canonical World time.

(async) sync() → {Promise.<GameTime>}

Synchronize the local client game time with the official time kept by the server

Returns:
Type
Promise.<GameTime>