game/src/net/clock.rs#
Source: lib/game/src/net/clock.rs
clock -- a client's two clocks: the ticks it predicts and sends inputs for (ahead of the server by the
trip of its inputs plus a margin), and the time it shows the other entities at (behind the newest
snapshot by an interpolation delay); both run on time from outside, like FixedTick
SteeredClock the prediction's ticks. The server reports how early the client's inputs arrive (the
smallest margin per snapshot, in ticks); the clock runs up to 10 % faster or slower to
hold the margin at its target (2 ticks unless set), jumps ahead when far too late and
holds still when far too early. All in integers: the speed in ppm, the accumulator in
ns x rate x ppm
InterpClock the picture of the others: a render time in server ticks (a tick and a fraction, so it
survives the wrap of u32), interp_ticks behind the newest snapshot, steered by up to
10 % towards that place at every snapshot, snapped when it is far off, never past the
newest snapshot (it holds)
The two are separate from the tick interpolation of Pose (that blends the last two predicted ticks of
the own figure); docs/NETCODE.md, "Zeit".
struct SteeredClockthe prediction's clock (see the module header)
impl SteeredClock
fn new(rate: u32, target: f64) -> SteeredClockrateticks a second, holding the margin of the inputs attargetticksfn set_tick(&mut self, tick: u32)start attick(the next tick advance hands out)fn advance(&mut self, now_ns: u64) -> u32the clock stands at now_ns -> the ticks due (take each with next_tick)fn next_tick(&mut self) -> u32the tick to run now (call once per tick advance returned)fn tick(&self) -> u32the next tick next_tick hands outfn alpha(&self) -> f64how far the clock is into the next tick, in [0, 1) (a frame blends the last two predicted states)fn on_margin(&mut self, m: i32)the server's report: the smallest margin of the client's inputs (ticks they arrived early)fn speed_ppm(&self) -> u32the speed now in ppm (1 000 000: nominal)fn margin(&self) -> Option<f64>the smoothed margin (None before the first report)fn jumps(&self) -> u32how often it jumped or heldstruct InterpClockthe time the others are shown at (see the module header)
impl InterpClock
fn new(rate: u32, delay: f64) -> InterpClockrateticks a second,delayticks behind the newest snapshotfn on_snapshot(&mut self, tick: u32)a snapshot oftickcame (older ones than the newest only count as nothing)fn advance(&mut self, now_ns: u64)the clock stands at now_nsfn time(&self) -> Option<(u32, f64)>the render time: a tick and the fraction towards the next (None before the first snapshot)fn behind(&self) -> f64how far the render time is behind the newest snapshot, in ticks