game/src/net/input.rs#
Source: lib/game/src/net/input.rs
input -- what a client sends every tick, the redundancy that makes a lost datagram cost nothing, and
the server's buffer that hands each tick its input
NetInput one tick's input, quantised: held buttons (the game's bits), two axes, yaw, pitch and
the view time for lag compensation (how far behind the tick the client's picture of
the others was, in 1/256 ticks)
write_inputs the newest input whole, every older one against the next newer (1 bit when it is the
same); read_inputs the inverse (None when malformed)
InputBuffer the server's: put what arrives (late and far-future ticks are refused), take(tick)
hands the tick its input or repeats the last one (a missed input), have() says up to
which tick the inputs are complete (the client resends from there), the margin says
how early inputs arrive (the client steers its clock by it)
Ticks are u32 and wrap; every comparison goes through tick_diff.
/// inputs a packet carries at most (the newest and the 15 before it)
MAX_REDUNDANT: usize = 16
/// ticks the server's buffer looks ahead (inputs further in the future are refused)
BUFFER: usize = 64
struct NetInputone tick's input (see the module header)buttons: u16-- the buttons held (the game's bits; edges come from comparing with the previous tick)move_x: i8-- right (+) and left (-), quant::axis_qmove_z: i8-- forward (+) and back (-), quant::axis_qyaw: u16-- the view's yaw, quant::angle_qpitch: i16-- the view's pitch, quant::pitch_qview: u16-- how far the client's picture of the other entities lagged behind this tick, in 1/256 ticks (the lag compensation's view time is tick - view / 256)
fn write_inputs(w: &mut BitWriter, newest: u32, inputs: &[NetInput])writeinputs(the newest first, at most MAX_REDUNDANT) whose newest is for ticknewestfn read_inputs(r: &mut BitReader) -> Option<(u32, Vec<NetInput>)>read what write_inputs wrote -> (the newest tick, the inputs newest first); None when malformedstruct InputStatswhat an input buffer countedreceived: u64-- inputs taken in (each tick once)repeated: u64-- inputs that came again (redundancy)late: u64-- inputs for ticks already simulatedearly: u64-- inputs too far in the future (refused)missed: u64-- ticks simulated without the client's input (the last one repeated)
struct InputBufferthe server's inputs of one client (see the module header)
impl InputBuffer
fn new(next: u32) -> InputBuffera buffer whose first tick isnextfn put_packet(&mut self, newest: u32, inputs: &[NetInput])a packet's inputs (newest first, the newest for ticknewest)fn put(&mut self, tick: u32, input: NetInput) -> boolone input fortick; false when refused (late, too far ahead, or already there)fn take(&mut self, tick: u32) -> (NetInput, bool)the input oftick(the buffer moves past it) and whether it is the client's own (false: missed, the last one repeated)fn have(&self) -> u32the newest tick up to which every input from the next one on is here (next - 1 when the next is missing)fn take_margin(&mut self) -> Option<i32>the smallest margin since the last call (None: no packet came)fn next(&self) -> u32the next tick take() hands outfn stats(&self) -> InputStatswhat it counted