Class WeatherExposureTick
Converts a prediction replicate's tick into the tick the weather timeline is evaluated at.
public static class WeatherExposureTick
- Inheritance
-
WeatherExposureTick
- Inherited Members
Remarks
Two clocks, and they are not the same one. The weather timeline is anchored in the
SYNCHRONISED tick (TimeManager.Tick): WeatherTimeline.WorldSecondsAt
measures from WorldSecondsTick, which the scene server stamps from its own
TimeManager.Tick and broadcasts. A replicate's input.GetTick(), however, is the
OWNING CLIENT's unsynchronised LocalTick — a counter that restarts at zero on every
connect — so on the server the two differ by an arbitrary per-connection constant. Feeding an
input tick straight to the weather would read the forecast for some other hour entirely, and
would read a DIFFERENT wrong hour on the client than on the server, so the reconcile would
fight the prediction for ever.
The mapping. FishNet hands us the pairing it reconciled on: ClientStateTick is
the local tick of the last reconcile and ServerStateTick is the server tick of that
same reconcile. The difference between them is the constant, so
FishNet 4.7 publishes that pairing only WHILE it reconciles — PredictionManager resets
both to UNSET_TICK after every reconcile, where 4.6 left them standing until the next.
Read raw, live prediction would then fall back to the client's synchronised estimate while
replay used the pairing, and the two would disagree by however far the estimate is off. So
WeatherExposureTick.ReconcilePairing remembers the pairing of the last reconcile per
PredictionManager (from OnPreReconcile), and live prediction and replay read the same
numbers again. It is forgotten when the client connection stops, because LocalTick restarts.
weatherTick = ServerStateTick + (inputTick − ClientStateTick)
and this one line is correct both live and in replay. In replay it is provably so: FishNet
walks ClientReplayTick and ServerReplayTick forward together from
ClientStateTick + 1 and ServerStateTick + 1 (PredictionManager, the
while (ClientReplayTick < localTick) loop), so for the replicate being replayed at
client tick t the server's tick is exactly what the formula returns. That identity is
what Resolve(bool, uint, uint, uint, uint, uint) asserts against when a replay tick is supplied, and what the
closed-loop tests pin.
On the server the input tick is not used at all. The server IS the authority on when
"now" is; its own TimeManager.Tick is the weather's tick, and the client's counter is
only a label for matching inputs to reconciles.
Pure arithmetic on purpose: everything here takes plain numbers, so the whole mapping can be tested without a NetworkManager, a connection or a running scene.
Fields
Unset
FishNet's "no tick" sentinel, repeated so callers need not reference TimeManager.
public const uint Unset = 0
Field Value
Methods
FromReplayCounters(uint)
What Resolve(bool, uint, uint, uint, uint, uint) must return while FishNet is replaying, from FishNet's own replay counters. Equal to the formula by construction — see the remarks on this class — so it exists to be asserted against rather than to be used in its place.
public static uint FromReplayCounters(uint serverReplayTick)
Parameters
serverReplayTickuint
Returns
Remarks
Not used by the controller. Taking the replay counter directly would work, but it is only valid inside a replay, so the controller would need two code paths where one will do — and a second path is a second thing to get wrong.
ReplayAgrees(uint, uint, uint, uint)
True when the formula and FishNet's replay counter agree for one replayed step. The closed-loop check, in one place, for tests and for a debug assertion.
public static bool ReplayAgrees(uint clientStateTick, uint serverStateTick, uint clientReplayTick, uint serverReplayTick)
Parameters
Returns
Resolve(NetworkBehaviour, uint)
Resolve(bool, uint, uint, uint, uint, uint) for a behaviour on a predicted object, reading the clocks off its own managers. Every predicted thing that reads the weather goes through this, so there is one place the two tick domains are reconciled and one place to get it wrong.
public static uint Resolve(NetworkBehaviour behaviour, uint inputTick)
Parameters
behaviourNetworkBehaviourThe behaviour being replicated.
inputTickuintThe replicate's own tick, in the owning client's domain.
Returns
Resolve(bool, uint, uint, uint, uint, uint)
The synchronised tick to evaluate the weather at for one replicate step.
public static uint Resolve(bool isServer, uint serverTick, uint clientSyncTick, uint clientStateTick, uint serverStateTick, uint inputTick)
Parameters
isServerboolTrue when this peer is the server, which owns the clock.
serverTickuintThe server's own
TimeManager.Tick. Used only whenisServer.clientSyncTickuintThe client's estimate of the synchronised tick (
TimeManager.Tick), used only before a first reconcile has established the pairing.clientStateTickuintThe last reconcile's client tick (WeatherExposureTick.ReconcilePairing), or Unset.
serverStateTickuintThe last reconcile's server tick (WeatherExposureTick.ReconcilePairing), or Unset.
inputTickuintThe replicate's own tick, in the owning client's domain.
Returns
- uint
A tick in the weather timeline's (synchronised) domain. Zero is a real answer — it is the first tick of the timeline, which is where a mapping that would fall below it is clamped — and is also what Unset happens to be, since FishNet's sentinel is literally zero. Nothing downstream needs to tell the two apart: both mean "read the oldest weather".