Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

GameClock

Beider edited this page Jun 23, 2020 · 2 revisions

Introduction

The GameClock keeps track of game ticks, each game tick represents one physics frame. The game clock will use ping updates from the GameSynchronizer to ensure all clients are at the same game tick.

In addition it tracks how far behind we need to run nodes that we are not the master of based on the ping of the other players. For instance if the ping to other players is 160 all nodes owned by other players will be run 10~ game ticks behind assuming a physics frame rate of 60 physics frames per second.


Events

OnGameTick(uint Tick)

This event happens every time there is a new game tick. Will also happen on skipped game ticks.

  • Tick - The current tick.

OnLocalSkippedTick(uint Tick)

If for some reason we end up being behind the server or a physics frame is dropped this event will trigger and notify about a game tick being skipped.

  • Tick - The skipped tick.

OnRemoteSkippedTick(uint Tick)

This happens when we need to skip a remote tick to adjust the remote offset between clients. Will happen if ping between clients decreases.

  • Tick - The skipped tick.

OnGameTickChanged(uint Tick)

Triggers when ticks are adjusted from the outside, such as when you join a game in progress.

  • Tick - The new tick we are at.

Public Methods

void SetCurrentTick(uint Tick)

Sets the current tick to the given tick. Will trigger an OnGameTickChanged event.

  • Tick - The new tick we should be adjusted to.

uint GetTick()

Get the current local tick

  • Return - The current tick we are at.

uint GetRemoteTick()

Get the current remote tick we are using for remote nodes. Will be slightly behind GetTick() based on the current ping between players and the server.

  • Return - The current remote tick.

long GetTimeOfTick(uint Tick)

Get time in milliseconds (OS.GetTickMsec() format) until the tick or since the tick.

  • Tick - The tick we want the time of.
  • Return - The time until / since the tick.

uint GetTickAtTimeOffset(long Offset)

Returns the tick that we will be in at the given offset (msec).

  • Offset - The time offset in milliseconds from the current time (eg. If you want the tick 2 seconds from now this would be 2000).
  • Return - The tick that we will be at / were at based on offset time.

void CheckSynch(long EstimateTime, long EstimatedTick)

This method is used by the GameSynchronizer and it is adviced not to use it unless you know what you are doing. Clients recieve this from the server as a way to attempt to keep them in synch in case they or the server freeze for any reason.


Configuration

Currently there is no configuration for the GameClock