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()

Source:

Members

(static) SYNC_INTERVAL_MS :number

Source:

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

Type:
  • number

_dt :number

Source:

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

Type:
  • number

_dts :Array.<number>

Source:

The most recent five synchronization durations

Type:

_time :Object

Source:

The most recently synchronized timestamps retrieved from the server.

Type:
  • Object

serverTime

Source:

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

worldTime

Source:

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

Methods

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

Source:

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)

Source:

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>}

Source:

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

Returns:
Type
Promise.<GameTime>