|
group2 0.1.0
CSE 125 Group 2
|
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. | |
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.
|
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.
| rttMs | Client's smoothed full round-trip time (ms). |
| interpDelayMs | Client's measured render delay (ms); 0 selects fallback. |
| interpDelaySnapshots | Client's render delay in snapshots (fallback term). |
| snapshotEveryNTicks | Server's nominal physics-ticks-per-snapshot. |
| tickRateHz | Physics tick rate. |
| maxLagCompTicks | Upper clamp (= HitboxHistory ring depth). |
|
inlineconstexpr |
Round a millisecond duration to the nearest whole physics tick.
Integer-only round-to-nearest via (ms * Hz + 500) / 1000.