mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
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>
148 lines
4.0 KiB
C++
148 lines
4.0 KiB
C++
#include "dpEntity.h"
|
|
#include "dpShapeSphere.h"
|
|
#include "dpShapeBox.h"
|
|
#include "dpGrid.h"
|
|
|
|
dpEntity::dpEntity(const LWOOBJID& objectID, dpShapeType shapeType, bool isStatic) {
|
|
m_ObjectID = objectID;
|
|
m_IsStatic = isStatic;
|
|
m_CollisionShape = nullptr;
|
|
m_Scale = 1.0f;
|
|
m_CollisionGroup = 0;
|
|
|
|
switch (shapeType) {
|
|
case dpShapeType::Sphere:
|
|
m_CollisionShape = new dpShapeSphere(this, 1.0f);
|
|
break;
|
|
|
|
case dpShapeType::Box:
|
|
m_CollisionShape = new dpShapeBox(this, 1.0f, 1.0f, 1.0f);
|
|
break;
|
|
|
|
default:
|
|
LOG("No shape for shapeType: %d", static_cast<int32_t>(shapeType));
|
|
}
|
|
}
|
|
|
|
dpEntity::dpEntity(const LWOOBJID& objectID, NiPoint3 boxDimensions, bool isStatic) {
|
|
m_ObjectID = objectID;
|
|
m_IsStatic = isStatic;
|
|
m_CollisionShape = nullptr;
|
|
m_Scale = 1.0f;
|
|
m_CollisionGroup = 0;
|
|
|
|
m_CollisionShape = new dpShapeBox(this, boxDimensions.x, boxDimensions.y, boxDimensions.z);
|
|
}
|
|
|
|
dpEntity::dpEntity(const LWOOBJID& objectID, float width, float height, float depth, bool isStatic) {
|
|
m_ObjectID = objectID;
|
|
m_IsStatic = isStatic;
|
|
m_CollisionShape = nullptr;
|
|
m_Scale = 1.0f;
|
|
m_CollisionGroup = 0;
|
|
|
|
m_CollisionShape = new dpShapeBox(this, width, height, depth);
|
|
}
|
|
|
|
dpEntity::dpEntity(const LWOOBJID& objectID, float radius, bool isStatic) {
|
|
m_ObjectID = objectID;
|
|
m_IsStatic = isStatic;
|
|
m_CollisionShape = nullptr;
|
|
m_Scale = 1.0f;
|
|
m_CollisionGroup = 0;
|
|
|
|
m_CollisionShape = new dpShapeSphere(this, radius);
|
|
}
|
|
|
|
dpEntity::~dpEntity() {
|
|
delete m_CollisionShape;
|
|
m_CollisionShape = nullptr;
|
|
}
|
|
|
|
void dpEntity::Update(float deltaTime) {
|
|
m_NewObjects.clear();
|
|
m_RemovedObjects.clear();
|
|
|
|
if (m_IsStatic) return;
|
|
//m_Position = m_Position + (m_Velocity * deltaTime);
|
|
}
|
|
|
|
void dpEntity::CheckCollision(dpEntity* other) {
|
|
if (!m_CollisionShape) return;
|
|
|
|
if (!dpCollisionFilter::ShouldCollide(m_CollisionGroup, other->m_CollisionGroup)) return;
|
|
|
|
const auto objId = other->GetObjectID();
|
|
const auto objItr = m_CurrentlyCollidingObjects.find(objId);
|
|
const bool wasFound = objItr != m_CurrentlyCollidingObjects.cend();
|
|
const bool isColliding = m_CollisionShape->IsColliding(other->GetShape());
|
|
|
|
if (isColliding && !wasFound) {
|
|
m_CurrentlyCollidingObjects.emplace(objId);
|
|
m_NewObjects.push_back(objId);
|
|
} else if (!isColliding && wasFound) {
|
|
m_CurrentlyCollidingObjects.erase(objItr);
|
|
m_RemovedObjects.push_back(objId);
|
|
}
|
|
}
|
|
|
|
void dpEntity::SetPosition(const NiPoint3& newPos) {
|
|
if (!m_CollisionShape) return;
|
|
|
|
//Update the grid if needed:
|
|
if (m_Grid) m_Grid->Move(this, newPos.x, newPos.z);
|
|
|
|
//If we're a box, we need to first undo the previous position, otherwise things get screwy:
|
|
if (m_CollisionShape->GetShapeType() == dpShapeType::Box) {
|
|
auto box = static_cast<dpShapeBox*>(m_CollisionShape);
|
|
|
|
if (m_Position != NiPoint3()) {
|
|
box->SetPosition(NiPoint3(-m_Position.x, -m_Position.y, -m_Position.z));
|
|
}
|
|
|
|
box->SetPosition(newPos);
|
|
}
|
|
|
|
m_Position = newPos;
|
|
}
|
|
|
|
void dpEntity::SetRotation(const NiQuaternion& newRot) {
|
|
if (!m_CollisionShape) return;
|
|
m_Rotation = newRot;
|
|
|
|
if (m_CollisionShape->GetShapeType() == dpShapeType::Box) {
|
|
auto box = static_cast<dpShapeBox*>(m_CollisionShape);
|
|
box->SetRotation(newRot);
|
|
}
|
|
}
|
|
|
|
void dpEntity::SetScale(float newScale) {
|
|
if (!m_CollisionShape) return;
|
|
m_Scale = newScale;
|
|
|
|
if (m_CollisionShape->GetShapeType() == dpShapeType::Box) {
|
|
auto box = static_cast<dpShapeBox*>(m_CollisionShape);
|
|
box->SetScale(newScale);
|
|
}
|
|
}
|
|
|
|
void dpEntity::SetVelocity(const NiPoint3& newVelocity) {
|
|
m_Velocity = newVelocity;
|
|
}
|
|
|
|
void dpEntity::SetAngularVelocity(const NiPoint3& newAngularVelocity) {
|
|
m_AngularVelocity = newAngularVelocity;
|
|
}
|
|
|
|
void dpEntity::SetGrid(dpGrid* grid) {
|
|
m_Grid = grid;
|
|
|
|
if (m_CollisionShape->GetShapeType() == dpShapeType::Sphere && static_cast<dpShapeSphere*>(m_CollisionShape)->GetRadius() * 2.0f > static_cast<float>(m_Grid->CELL_SIZE)) {
|
|
m_IsGargantuan = true;
|
|
} else if (m_CollisionShape->GetShapeType() == dpShapeType::Box && static_cast<dpShapeBox*>(m_CollisionShape)->GetWidth() > static_cast<float>(m_Grid->CELL_SIZE)) {
|
|
m_IsGargantuan = true;
|
|
}
|
|
|
|
m_Grid->Add(this);
|
|
}
|