group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
LagCompMath.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cstdint>
5
10{
11
17inline constexpr std::uint32_t msToTicks(std::uint32_t ms, std::uint32_t tickRateHz)
18{
19 return (ms * tickRateHz + 500u) / 1000u;
20}
21
49inline std::uint32_t computeRewindTicks(std::uint16_t rttMs,
50 std::uint16_t interpDelayMs,
51 std::uint8_t interpDelaySnapshots,
52 std::uint32_t snapshotEveryNTicks,
53 std::uint32_t tickRateHz,
54 std::uint32_t maxLagCompTicks)
55{
56 // PR-20.7: full-RTT (NOT half-RTT). Our client renders remote players
57 // at `most_recent_snapshot_apply − cl_interp` rather than predicting
58 // them forward to estimated server-now, so the rewind has to absorb
59 // both the inbound and outbound legs of the RTT. See
60 // ServerGame::updateLagCompTargets for the full derivation.
61 const std::uint32_t rttTicks = msToTicks(rttMs, tickRateHz);
62
63 const std::uint32_t interpDelayTicks = (interpDelayMs > 0) ? msToTicks(interpDelayMs, tickRateHz)
64 : static_cast<std::uint32_t>(interpDelaySnapshots) *
65 std::max<std::uint32_t>(1u, snapshotEveryNTicks);
66
67 return std::min<std::uint32_t>(rttTicks + interpDelayTicks, maxLagCompTicks);
68}
69
70} // namespace server::lagcomp
Pure (dependency-free) lag-compensation rewind math.
Definition LagCompMath.hpp:10
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 n...
Definition LagCompMath.hpp:49
constexpr std::uint32_t msToTicks(std::uint32_t ms, std::uint32_t tickRateHz)
Round a millisecond duration to the nearest whole physics tick.
Definition LagCompMath.hpp:17