RAII handle that restores hitbox capsules on scope exit after a rewindHitboxes call swapped them for historical samples.
More...
#include <LagCompensation.hpp>
|
| RewindHitboxesGuard | rewindHitboxes (Registry ®istry, entt::entity shooter, const glm::vec3 *rayOrigin=nullptr, const glm::vec3 *rayDirection=nullptr, float rayMaxDistance=0.0f) |
| | Rewind every other player's hitbox capsules to where they were on shooter's screen at fire time.
|
RAII handle that restores hitbox capsules on scope exit after a rewindHitboxes call swapped them for historical samples.
Default-constructed instances own nothing and do nothing on destruction — used for shooters with no LagCompTarget, no HitboxHistory neighbours, or zero rewind. Populated instances hold one (entity, capsules) pair per rewound entity; the destructor moves each saved capsule vector back into the entity's live HitboxInstance.
◆ RewindHitboxesGuard() [1/3]
| systems::RewindHitboxesGuard::RewindHitboxesGuard |
( |
| ) |
|
|
default |
◆ ~RewindHitboxesGuard()
| systems::RewindHitboxesGuard::~RewindHitboxesGuard |
( |
| ) |
|
|
inlinenoexcept |
◆ RewindHitboxesGuard() [2/3]
| systems::RewindHitboxesGuard::RewindHitboxesGuard |
( |
const RewindHitboxesGuard & | | ) |
|
|
delete |
◆ RewindHitboxesGuard() [3/3]
| systems::RewindHitboxesGuard::RewindHitboxesGuard |
( |
RewindHitboxesGuard && | other | ) |
|
|
inlinenoexcept |
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ restore()
| void systems::RewindHitboxesGuard::restore |
( |
| ) |
|
|
inlineprivatenoexcept |
◆ rewindHitboxes
| RewindHitboxesGuard rewindHitboxes |
( |
Registry & | registry, |
|
|
entt::entity | shooter, |
|
|
const glm::vec3 * | rayOrigin = nullptr, |
|
|
const glm::vec3 * | rayDirection = nullptr, |
|
|
float | rayMaxDistance = 0.0f ) |
|
friend |
Rewind every other player's hitbox capsules to where they were on shooter's screen at fire time.
Reads LagCompTarget from shooter. If absent or zero, returns a no-op guard immediately (the common case for client-side and for sub-tick-RTT shooters). Otherwise walks every entity with both HitboxInstance and HitboxHistory, finds the most recent history sample whose tick is ≤ targetServerTick, swaps the live capsules for the historical ones, and stashes the originals in the returned guard for restore-on-destruction.
PR-5 (server-perf): two overloads.
- The unfiltered form (kept for compatibility) rewinds every player. O(N) per shot. Pre-PR-5 measurements at 200 bots during fire bursts: this dominated the weapon scope's 6.29 ms p99 — 25 shots × 200 candidate rewinds × ~1–5 µs each ≈ 5–25 ms / sec.
- The ray-filtered form rewindHitboxes(registry, shooter,
origin, direction, maxDistance) adds a broad-phase ray-vs- AABB test BEFORE rewinding each candidate. Players whose bounding box doesn't intersect the shot ray are skipped — no ring scan, no capsule swap. The AABB test costs ~10 ns and prunes >95 % of candidates for typical shot geometry.
shooter itself is not rewound — resolveHitscanHitbox already excludes the shooter from the player-hitbox raycast.
- Parameters
-
| registry | The server ECS registry. |
| shooter | Entity firing the hitscan. Read for LagCompTarget. |
- Returns
- Guard whose destructor restores the original capsules.
◆ registry_
| Registry* systems::RewindHitboxesGuard::registry_ = nullptr |
|
private |
◆ saved_
| std::vector<std::pair<entt::entity, std::vector<WorldCapsule> > > systems::RewindHitboxesGuard::saved_ |
|
private |
The documentation for this class was generated from the following file: