group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
server::lagcomp Namespace Reference

Pure (dependency-free) lag-compensation rewind math. More...

Functions

constexpr std::uint32_t msToTicks (std::uint32_t ms, std::uint32_t tickRateHz)
 Round a millisecond duration to the nearest whole physics tick.
std::uint32_t computeRewindTicks (std::uint16_t rttMs, std::uint16_t interpDelayMs, std::uint8_t interpDelaySnapshots, std::uint32_t snapshotEveryNTicks, std::uint32_t tickRateHz, std::uint32_t maxLagCompTicks)
 Compute the lag-compensation rewind depth (in physics ticks) for a shooter from their last-reported net state.

Detailed Description

Pure (dependency-free) lag-compensation rewind math.

Lives in its own header so it can be unit-tested in isolation — ServerGame includes it from the hot path in updateLagCompTargets.

Function Documentation

◆ computeRewindTicks()

std::uint32_t server::lagcomp::computeRewindTicks ( std::uint16_t rttMs,
std::uint16_t interpDelayMs,
std::uint8_t interpDelaySnapshots,
std::uint32_t snapshotEveryNTicks,
std::uint32_t tickRateHz,
std::uint32_t maxLagCompTicks )
inline

Compute the lag-compensation rewind depth (in physics ticks) for a shooter from their last-reported net state.

PR-31: prefer the client's measured render delay in milliseconds (interpDelayMs, derived client-side from an EMA of observed snapshot-apply intervals) whenever it is non-zero. The measured value tracks the real snapshot cadence — including the drift introduced by a highly jittery link and the post-join warm-up window before the EMA converges — so the server rewinds to exactly the render time the client actually displayed when it fired.

Falls back to the legacy snapshot-count estimate (interpDelaySnapshots × snapshotEveryNTicks) when interpDelayMs == 0, i.e. render-delay interpolation is disabled (cl_interp 0) or the client predates the ms field. That path uses the server's nominal fixed cadence, which can diverge from the client's true render delay under jitter — exactly the mismatch the ms field eliminates.

The combined RTT + interp depth is clamped to maxLagCompTicks so the rewind never exceeds the HitboxHistory ring.

Parameters
rttMsClient's smoothed full round-trip time (ms).
interpDelayMsClient's measured render delay (ms); 0 selects fallback.
interpDelaySnapshotsClient's render delay in snapshots (fallback term).
snapshotEveryNTicksServer's nominal physics-ticks-per-snapshot.
tickRateHzPhysics tick rate.
maxLagCompTicksUpper clamp (= HitboxHistory ring depth).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ msToTicks()

std::uint32_t server::lagcomp::msToTicks ( std::uint32_t ms,
std::uint32_t tickRateHz )
inlineconstexpr

Round a millisecond duration to the nearest whole physics tick.

Integer-only round-to-nearest via (ms * Hz + 500) / 1000.

Note
ms is taken as uint32 so the multiply can't overflow for any uint16 wire value (65535 × 1000 Hz still fits uint32).
Here is the caller graph for this function: