Files
DarkflameServer/dPhysics/dpEntity.h
Aaron Kimbrell 9907d7deb8 fix: filter physics volumes like the client's collision groups
Volumes on the server touched far more than in the client:

- An enemy's body in the physics world was a sphere the size of its aggro
  radius, so trigger and damage volumes caught enemies from far away
  (Cavalry Hill enemies taking damage on spawn). It is now the enemy's
  own radius and collision group from its physics component.
- Trigger volumes ignored their collision group and caught everything.
  dpEntity now filters with the client's collision filter
  (PeCollisionFilter, 1.10.64 0x00fb6940, group table from 0x00fcf9a0):
  POI walls ignore enemies, threat clearing walls ignore players, and
  so on. The aggro sensor keeps seeing only players.
- Rotated boxes were tested as the axis aligned box around them, which
  for a turned wall covers a big square (the AG survival boundary).
  Sphere and point tests now use the box's own axes.

Proximity monitors take an optional collision group like live's
SetProximityRadius; the AM shield generators use live's (10 finds
enemies, 1 finds players).

Fixes #1127
Refs #1971

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 09:33:11 -05:00

89 lines
2.7 KiB
C++

#pragma once
#include "NiPoint3.h"
#include "NiQuaternion.h"
#include <vector>
#include <unordered_set>
#include <span>
#include "dCommonVars.h"
#include "dpCommon.h"
#include "dpShapeBase.h"
#include "dpCollisionFilter.h"
#include "dpGrid.h"
class dpEntity {
friend class dpGrid; //using friend here for now so grid can access everything
public:
dpEntity(const LWOOBJID& objectID, dpShapeType shapeType, bool isStatic = true);
dpEntity(const LWOOBJID& objectID, NiPoint3 boxDimensions, bool isStatic = true);
dpEntity(const LWOOBJID& objectID, float width, float height, float depth, bool isStatic = true);
dpEntity(const LWOOBJID& objectID, float radius, bool isStatic = true);
~dpEntity();
void Update(float deltaTime);
void CheckCollision(dpEntity* other);
const NiPoint3& GetPosition() const { return m_Position; }
const NiQuaternion& GetRotation() const { return m_Rotation; }
const float GetScale() const { return m_Scale; }
const NiPoint3& GetVelocity() const { return m_Velocity; }
const NiPoint3& GetAngularVelocity() const { return m_AngularVelocity; }
void SetPosition(const NiPoint3& newPos);
void SetRotation(const NiQuaternion& newRot);
void SetScale(float newScale);
void SetVelocity(const NiPoint3& newVelocity);
void SetAngularVelocity(const NiPoint3& newAngularVelocity);
dpShapeBase* GetShape() { return m_CollisionShape; }
bool GetIsStatic() const { return m_IsStatic; }
// The collision filter value (see dpCollisionFilter): the client's collision group, 0 touches everything
uint32_t GetCollisionGroup() const { return m_CollisionGroup; }
void SetCollisionGroup(uint32_t value) { m_CollisionGroup = value; }
bool GetSleeping() const { return m_Sleeping; }
void SetSleeping(bool value) { m_Sleeping = value; }
std::span<const LWOOBJID> GetNewObjects() const { return m_NewObjects; }
std::span<const LWOOBJID> GetRemovedObjects() const { return m_RemovedObjects; }
const std::unordered_set<LWOOBJID>& GetCurrentlyCollidingObjects() const { return m_CurrentlyCollidingObjects; }
void PreUpdate() { m_NewObjects.clear(); m_RemovedObjects.clear(); }
const LWOOBJID& GetObjectID() const { return m_ObjectID; }
void SetGrid(dpGrid* grid);
bool GetIsGargantuan() const { return m_IsGargantuan; }
private:
LWOOBJID m_ObjectID;
dpShapeBase* m_CollisionShape;
bool m_IsStatic;
NiPoint3 m_Position;
NiQuaternion m_Rotation = QuatUtils::IDENTITY;
float m_Scale;
NiPoint3 m_Velocity;
NiPoint3 m_AngularVelocity;
dpGrid* m_Grid = nullptr;
uint32_t m_CollisionGroup;
bool m_Sleeping = false;
bool m_IsGargantuan = false;
std::vector<LWOOBJID> m_NewObjects;
std::vector<LWOOBJID> m_RemovedObjects;
std::unordered_set<LWOOBJID> m_CurrentlyCollidingObjects;
};