JFLib

game/src/net/lagcomp.rs#

Source: lib/game/src/net/lagcomp.rs

lagcomp -- hits with lag compensation: the server keeps where the figures were over the last ticks and,
for a shot, puts them back to the time the shooter saw them, at most 300 ms back unless set (the interpolation's
100 ms and 200 ms beyond them, the user's decision of 2026-11-19)

  view_time(tick, view, max_back)   the shooter's view time from its input (NetInput::view: the lag of
                                    its picture in 1/256 ticks), clamped to max_back ticks before tick
  HitHistory      the centres of the figures' hit volumes per tick (a ring); rewind(view time) blends the
                  two recorded ticks around it as a client blends two snapshots
  hitscan         a ray against the map (physics::World::ray_cast) and the rewound figures
                  (physics::query::ray against each capsule): the nearest hit, the shooter left out

What the client saw and what the server rewinds differ by the quantisation of the snapshots (under a
millimetre) and, when a figure turns within a snapshot's interval, by blending ticks one apart where
the client blended snapshots two apart (docs/NETCODE.md, "Treffer").
  • fn view_time(tick: u32, view: u16, max_back: u32) -> (u32, f64) the view time (a tick and the fraction towards the next) of an input of tick whose picture lagged view / 256 ticks, at most max_back ticks back

  • struct HitHistory the figures' hit volumes over the last ticks (see the module header)

impl HitHistory

  • fn new(cap: usize) -> HitHistory remember cap ticks

  • fn record(&mut self, tick: u32, figures: &[(u16, Vec3)]) where the figures (id, centre of the hit volume) are after tick; ids ascending

  • fn span(&self) -> Option<(u32, u32)> the oldest and newest tick remembered

  • fn rewind(&self, tick: u32, frac: f64, out: &mut Vec<(u16, Vec3)>) -> bool the figures at view time (tick, frac): blended between tick and tick + 1 where both have them, clamped to the ticks remembered; false when nothing is remembered

  • enum Hit what a shot hit

    • Figure { id: u16, t: f64, point: Vec3 } -- a figure: its id, the distance along the ray and the point
    • World { t: f64, point: Vec3 } -- the map
  • fn hitscan(map: &physics::World, figures: &[(u16, Vec3)], shape: &Shape, shooter: u16, origin: Vec3, dir: Vec3, max_t: f64) -> Option<Hit> a ray from origin along dir (unit length) up to max_t against the map and the figures (shape at each centre), the figure shooter left out: the nearest hit

Source: docs/API.md in the JFLib repository.