49#include <glm/common.hpp>
50#include <glm/vec3.hpp>
79 other.registry_ =
nullptr;
87 saved_ = std::move(other.saved_);
88 other.registry_ =
nullptr;
101 for (
auto& [entity, capsules] :
saved_) {
105 inst->capsules = std::move(capsules);
112 std::vector<std::pair<entt::entity, std::vector<WorldCapsule>>>
saved_;
148 entt::entity shooter,
149 const glm::vec3* rayOrigin =
nullptr,
150 const glm::vec3* rayDirection =
nullptr,
151 float rayMaxDistance = 0.0f)
155 const auto* target = registry.try_get<
LagCompTarget>(shooter);
156 if (target ==
nullptr || target->targetServerTick == 0)
159 const uint32_t targetTick = target->targetServerTick;
160 const bool haveFilter = rayOrigin !=
nullptr && rayDirection !=
nullptr && rayMaxDistance > 0.0f;
180 const float lagWindowSec =
static_cast<float>(target->lagTicks) / 128.0f;
184 if (entity == shooter)
191 const auto* pos = registry.try_get<
Position>(entity);
193 if (pos !=
nullptr && shape !=
nullptr) {
194 glm::vec3 expand = shape->halfExtents;
195 if (
const auto* vel = registry.try_get<
Velocity>(entity)) {
196 expand += glm::abs(vel->value) * lagWindowSec;
199 .min = pos->value - expand,
200 .max = pos->value + expand,
202 float aabbDist = rayMaxDistance;
203 glm::vec3 aabbNormal{0.0f};
204 if (!
physics::raycastAABB(*rayOrigin, *rayDirection, bounds, rayMaxDistance, aabbDist, aabbNormal)) {
214 for (std::size_t i = 0; i < hist.
count; ++i) {
215 const auto& sample = hist.
ring[i];
216 if (sample.tick == 0)
218 if (sample.tick > targetTick)
220 if (best ==
nullptr || sample.tick > best->
tick)
234 if (!guard.
saved_.empty())
AABB collision shape component for physics entities.
Server-side ring buffer of recent hitbox capsule snapshots per entity.
Skeleton-driven hitbox types: body regions, capsule definitions, damage profiles, and per-entity runt...
Per-shooter rewind target for lag-compensated hitscan.
World-space position component for ECS entities.
Shared hitscan raycasting against world geometry and player hitboxes.
Shared ECS registry type alias for the game engine.
entt::registry Registry
Shared ECS registry type alias.
Definition Registry.hpp:11
Linear velocity component for ECS entities.
RewindHitboxesGuard & operator=(RewindHitboxesGuard &&other) noexcept
Definition LagCompensation.hpp:82
friend RewindHitboxesGuard rewindHitboxes(Registry &, entt::entity, const glm::vec3 *, const glm::vec3 *, float)
Rewind every other player's hitbox capsules to where they were on shooter's screen at fire time.
Definition LagCompensation.hpp:147
RewindHitboxesGuard(RewindHitboxesGuard &&other) noexcept
Definition LagCompensation.hpp:76
RewindHitboxesGuard()=default
~RewindHitboxesGuard() noexcept
Definition LagCompensation.hpp:71
void restore() noexcept
Walk saved_ and move each stored capsules vector back into its entity's HitboxInstance.
Definition LagCompensation.hpp:97
std::vector< std::pair< entt::entity, std::vector< WorldCapsule > > > saved_
Definition LagCompensation.hpp:112
RewindHitboxesGuard(const RewindHitboxesGuard &)=delete
Registry * registry_
Definition LagCompensation.hpp:111
RewindHitboxesGuard & operator=(const RewindHitboxesGuard &)=delete
bool raycastAABB(glm::vec3 origin, glm::vec3 direction, const WorldAABB &box, float maxDistance, float &outDistance, glm::vec3 &outNormal)
Ray vs axis-aligned box intersection (slab method).
Definition Raycast.hpp:44
Client-only input sampling system — split into two halves so mouse look can run every iterate() (smoo...
Definition DebugUI.hpp:15
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.
Definition LagCompensation.hpp:147
Axis-aligned bounding box defined by half-extents from the entity's Position.
Definition CollisionShape.hpp:16
Per-tick capsule snapshot stored in the history ring.
Definition HitboxHistory.hpp:41
uint32_t tick
Server tick when the sample was recorded. 0 = unset.
Definition HitboxHistory.hpp:42
std::vector< WorldCapsule > capsules
Definition HitboxHistory.hpp:43
Ring buffer of recent hitbox snapshots for one entity.
Definition HitboxHistory.hpp:66
std::size_t count
Number of samples written so far, capped at k_capacity.
Definition HitboxHistory.hpp:82
std::array< HitboxHistorySample, k_capacity > ring
Definition HitboxHistory.hpp:74
ECS components.
Definition Hitbox.hpp:108
std::vector< WorldCapsule > capsules
~12 capsules per character.
Definition Hitbox.hpp:109
Server tick to which to rewind other entities' hitboxes when resolving this entity's hitscan.
Definition LagCompTarget.hpp:23
World-space position of an entity, in game units.
Definition Position.hpp:10
Linear velocity of an entity, in game units per second.
Definition Velocity.hpp:10
An axis-aligned box in world space, used as static collision geometry.
Definition SweptCollision.hpp:32