group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
systems::RewindHitboxesGuard Class Reference

RAII handle that restores hitbox capsules on scope exit after a rewindHitboxes call swapped them for historical samples. More...

#include <LagCompensation.hpp>

Public Member Functions

 RewindHitboxesGuard ()=default
 ~RewindHitboxesGuard () noexcept
 RewindHitboxesGuard (const RewindHitboxesGuard &)=delete
RewindHitboxesGuardoperator= (const RewindHitboxesGuard &)=delete
 RewindHitboxesGuard (RewindHitboxesGuard &&other) noexcept
RewindHitboxesGuardoperator= (RewindHitboxesGuard &&other) noexcept

Private Member Functions

void restore () noexcept
 Walk saved_ and move each stored capsules vector back into its entity's HitboxInstance.

Private Attributes

Registryregistry_ = nullptr
std::vector< std::pair< entt::entity, std::vector< WorldCapsule > > > saved_

Friends

RewindHitboxesGuard rewindHitboxes (Registry &registry, 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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ RewindHitboxesGuard() [1/3]

systems::RewindHitboxesGuard::RewindHitboxesGuard ( )
default
Here is the caller graph for this function:

◆ ~RewindHitboxesGuard()

systems::RewindHitboxesGuard::~RewindHitboxesGuard ( )
inlinenoexcept
Here is the call graph for this function:

◆ RewindHitboxesGuard() [2/3]

systems::RewindHitboxesGuard::RewindHitboxesGuard ( const RewindHitboxesGuard & )
delete
Here is the call graph for this function:

◆ RewindHitboxesGuard() [3/3]

systems::RewindHitboxesGuard::RewindHitboxesGuard ( RewindHitboxesGuard && other)
inlinenoexcept
Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/2]

RewindHitboxesGuard & systems::RewindHitboxesGuard::operator= ( const RewindHitboxesGuard & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

RewindHitboxesGuard & systems::RewindHitboxesGuard::operator= ( RewindHitboxesGuard && other)
inlinenoexcept
Here is the call graph for this function:

◆ restore()

void systems::RewindHitboxesGuard::restore ( )
inlineprivatenoexcept

Walk saved_ and move each stored capsules vector back into its entity's HitboxInstance.

No-op when registry_ is null or saved_ is empty.

Here is the caller graph for this function:

◆ 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
registryThe server ECS registry.
shooterEntity firing the hitscan. Read for LagCompTarget.
Returns
Guard whose destructor restores the original capsules.

Member Data Documentation

◆ 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: