Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • GameTime

Index

Constructors

Properties

_time: { clientTime: number; serverTime: number; worldTime: number }

The most recently synchronized timestamps retrieved from the server.

Type declaration

  • clientTime: number
  • serverTime: number
  • worldTime: number
_dt: number

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

_dts: number[]

The most recent five synchronization durations

SYNC_INTERVAL_MS: number = ...

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

Accessors

  • get serverTime(): number
  • The current server time based on the last synchronization point and the approximated one-way latency.

    Returns number

  • get worldTime(): number
  • The current World time based on the last recorded value of the core.time setting

    Returns number

Methods

  • advance(seconds: number, options: any): Promise<number>
  • Advance the game time by a certain number of seconds

    Parameters

    • seconds: number

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

    • options: any

    Returns Promise<number>

    The new game time

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

    Parameters

    • socket: Socket

      The connected server Socket instance

    Returns Promise<GameTime>

  • onUpdateWorldTime(worldTime: number, options: any, userId: string): void
  • Handle follow-up actions when the official World time is changed

    Parameters

    • worldTime: number

      The new canonical World time.

    • options: any

      Options passed from the requesting client where the change was made

    • userId: string

      The ID of the User who advanced the time

    Returns void