_NetworkTimeSynchronizer
Inherits: Node
Continuously synchronizes time to the host's remote clock.
Description
Make sure to read the NetworkTimeSynchronizer Guide to understand the different clocks that the class docs refer to.
Tutorials
Properties
| Type | Name | Default |
|---|---|---|
| float | sync_interval | |
| int | sync_samples | |
| int | adjust_steps | |
| float | panic_threshold | |
| float | rtt | |
| float | rtt_jitter | |
| float | remote_offset |
Methods
| Return Type | Name |
|---|---|
| void | start() |
| void | stop() |
| float | get_time() |
Signals
on_initial_sync ( )
Emitted after the initial time sync. At the start of the game, clients request an initial timestamp to kickstart their time sync loop. This event is emitted once that initial timestamp is received.
on_panic ( float offset )
Emitted when clocks get overly out of sync and a time sync panic occurs. Panic means that the difference between clocks is too large. The time sync will reset the clock to the remote clock's time and restart the time sync loop from there.
Use this event in case you need to react to clock changes in your game.
Constants
MIN_SYNC_INTERVAL = 0.1
The minimum time in seconds between two sync samples. See sync_interval
Property Descriptions
float sync_interval
Time between sync samples, in seconds. Cannot be less than MIN_SYNC_INTERVAL
read-only, you can change this in the Netfox project settings
int sync_samples
Number of measurements ( samples ) to use for time synchronization.
read-only, you can change this in the Netfox project settings
int adjust_steps
Number of iterations to nudge towards the host's remote clock. Lower values result in more aggressive changes in clock and may be more sensitive to jitter. Larger values may end up approaching the remote clock too slowly.
read-only, you can change this in the Netfox project settings
float panic_threshold
Largest tolerated offset from the host's remote clock before panicking. Once this threshold is reached, the clock will be reset to the remote clock's value, and the nudge process will start from scratch.
read-only, you can change this in the Netfox project settings
float rtt
Measured roundtrip time measured to the host. This value is calculated from multiple samples. The actual roundtrip times can be anywhere in the rtt +/- rtt_jitter range.
read-only
float rtt_jitter
Measured jitter in the roundtrip time to the host remote. This value is calculated from multiple samples. The actual roundtrip times can be anywhere in the rtt +/- rtt_jitter range.
read-only
float remote_offset
Estimated offset from the host's remote clock. Positive values mean that the host's remote clock is ahead of ours, while negative values mean that our clock is behind the host's remote.
read-only
Method Descriptions
void start ( )
Start the time synchronization loop. Starting multiple times has no effect.
void stop ( )
Stop the time synchronization loop.
float get_time ( )
Get the current time from the reference clock. Returns a timestamp in seconds, with a fractional part for extra precision.