Class WorldClock
World time, carried forward by FishNet's synchronised tick and anchored to one reference clock.
public sealed class WorldClock
- Inheritance
-
WorldClock
- Inherited Members
Remarks
Every scene server measures its offset from the database server's clock and publishes an anchor. Clients never read their own wall clock: they take the anchor and advance it with the server tick FishNet already keeps in step, so every client in a scene agrees to within a tick or two, and every scene server agrees with every other.
A correction is never a jump. A new anchor replaces the old one over SlewTicks, and
both are shipped, so the blend is a pure function of the tick: a client that joins mid-slew
computes the same value as one that was there when it began.
The tick drives it; the anchor says what time it is. FishNet's tick never changes pace; an admin who sets the time, holds it or races it (the world clock control, adopted by every scene server) publishes a new anchor at the tick it happens on — the time it has reached and the new pace — so nothing drifts out of line and every client computes the same moment. Such a change is instant (Override(uint, double, double, bool)); a correction of the clock's own drift is eased.
Fields
JumpThresholdSeconds
An outright change of the time by more than this is a jump (Jumps): a set, not a pace change.
public const double JumpThresholdSeconds = 2
Field Value
RepublishThresholdSeconds
An error below this is left alone. A quarter second moves a 6-hour sun by 0.004°.
public const double RepublishThresholdSeconds = 0.25
Field Value
Shared
The process-wide clock. The server publishes into it; the client adopts into it.
public static readonly WorldClock Shared
Field Value
SlewSeconds
How long a correction is eased in over.
public const double SlewSeconds = 10
Field Value
WarnThresholdSeconds
An error above this is worth a warning: something is wrong with a host clock.
public const double WarnThresholdSeconds = 5
Field Value
Properties
Current
public WorldClockAnchor Current { get; }
Property Value
HasAnchor
public bool HasAnchor { get; }
Property Value
HasPrevious
public bool HasPrevious { get; }
Property Value
Jumps
Counts the times the clock was set outright to another moment — an admin's set, the bed's, or the first anchor a client gets — as opposed to held, raced or eased onto its reference. Whatever eases what it shows toward the weather of the moment compares this with the count it last saw, and on a change shows the new moment at once: a set is meant to land everything there, not to fade toward it.
public uint Jumps { get; }
Property Value
LastMeasuredError
The most recent measured error, in seconds (reference − clock). Diagnostics only.
public double LastMeasuredError { get; }
Property Value
Previous
public WorldClockAnchor Previous { get; }
Property Value
Rate
World seconds per second of ticks now: 1 the world's own pace, 0 held, more raced. 1 without an anchor.
public double Rate { get; }
Property Value
SlewTicks
public uint SlewTicks { get; }
Property Value
TickDelta
Seconds per tick. Set from the TimeManager before use.
public double TickDelta { get; set; }
Property Value
Methods
Adopt(WorldClockAnchor, WorldClockAnchor, bool, uint)
Adopts an anchor published by the server.
public void Adopt(WorldClockAnchor anchor, WorldClockAnchor previousAnchor, bool hasPreviousAnchor, uint slew)
Parameters
anchorWorldClockAnchorpreviousAnchorWorldClockAnchorhasPreviousAnchorboolslewuint
Override(uint, double, double, bool)
Sets the clock outright: at tick the world reads worldSeconds
and runs at rate from there. Instant — no easing — because it is a decision
(an admin's, a test bed's), not a correction: the new time is exact from that tick on.
public void Override(uint tick, double worldSeconds, double rate, bool verified)
Parameters
Propose(uint, double, bool)
Offers a fresh reading of the reference clock. Publishes (and returns true) only when there is no anchor yet, the error exceeds RepublishThresholdSeconds, or the reading verifies an unverified anchor.
public bool Propose(uint tick, double referenceWorldSeconds, bool verified)
Parameters
Returns
Reset()
Forgets everything. Used on disconnect and by tests.
public void Reset()
TickAt(double)
The (fractional) tick at which the clock reads worldSeconds, by the current
anchor; while the clock is held, the anchor's own tick (every tick reads the same moment).
public double TickAt(double worldSeconds)
Parameters
worldSecondsdouble
Returns
WorldHoursAt(double)
Real hours since the epoch at a tick.
public double WorldHoursAt(double tick)
Parameters
tickdouble
Returns
WorldSecondsAt(double)
World seconds at a (possibly fractional) server tick.
public double WorldSecondsAt(double tick)
Parameters
tickdouble
Returns
WorldSecondsFromUnixMilliseconds(long, long)
Seconds since the epoch for Unix milliseconds.
public static double WorldSecondsFromUnixMilliseconds(long unixMilliseconds, long epochUnixSeconds)
Parameters
Returns
WorldSecondsFromUtc(DateTime, long)
Seconds since the epoch for a UTC instant.
public static double WorldSecondsFromUtc(DateTime utc, long epochUnixSeconds)
Parameters
Returns
Events
OnAnchorChanged
Raised whenever a new anchor is published or adopted.
public event Action<WorldClock> OnAnchorChanged