Skip to content

Commit

Permalink
adjust for feedback. last changes tonight.
Browse files Browse the repository at this point in the history
  • Loading branch information
jadebenn committed Apr 4, 2024
1 parent 2c90697 commit 0628fde
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
8 changes: 4 additions & 4 deletions dGame/dComponents/BaseCombatAIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
m_dpEntityEnemy->SetPosition(m_Parent->GetPosition());

//Process enter events
for (const auto en : m_dpEntity->GetNewObjects()) {
m_Parent->OnCollisionPhantom(en);
for (const auto id : m_dpEntity->GetNewObjects()) {
m_Parent->OnCollisionPhantom(id);
}

//Process exit events
for (const auto en : m_dpEntity->GetRemovedObjects()) {
m_Parent->OnCollisionLeavePhantom(en);
for (const auto id : m_dpEntity->GetRemovedObjects()) {
m_Parent->OnCollisionLeavePhantom(id);
}

// Check if we should stop the tether effect
Expand Down
16 changes: 7 additions & 9 deletions dGame/dComponents/PhantomPhysicsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,13 @@ void PhantomPhysicsComponent::Update(float deltaTime) {
if (!m_dpEntity) return;

//Process enter events
for (const auto en : m_dpEntity->GetNewObjects()) {
if (!en) continue;
ApplyCollisionEffect(en, m_EffectType, m_DirectionalMultiplier);
m_Parent->OnCollisionPhantom(en);
for (const auto id : m_dpEntity->GetNewObjects()) {
ApplyCollisionEffect(id, m_EffectType, m_DirectionalMultiplier);
m_Parent->OnCollisionPhantom(id);

//If we are a respawn volume, inform the client:
if (m_IsRespawnVolume) {
auto* const entity = Game::entityManager->GetEntity(en);
auto* const entity = Game::entityManager->GetEntity(id);

if (entity) {
GameMessages::SendPlayerReachedRespawnCheckpoint(entity, m_RespawnPos, m_RespawnRot);
Expand All @@ -341,10 +340,9 @@ void PhantomPhysicsComponent::Update(float deltaTime) {
}

//Process exit events
for (const auto en : m_dpEntity->GetRemovedObjects()) {
if (!en) continue;
ApplyCollisionEffect(en, m_EffectType, 1.0f);
m_Parent->OnCollisionLeavePhantom(en);
for (const auto id : m_dpEntity->GetRemovedObjects()) {
ApplyCollisionEffect(id, m_EffectType, 1.0f);
m_Parent->OnCollisionLeavePhantom(id);
}
}

Expand Down
8 changes: 4 additions & 4 deletions dGame/dComponents/ProximityMonitorComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "EntityManager.h"
#include "SimplePhysicsComponent.h"

const std::vector<LWOOBJID> ProximityMonitorComponent::m_EmptyObjectVec = {};
const std::set<LWOOBJID> ProximityMonitorComponent::m_EmptyObjectSet = {};

ProximityMonitorComponent::ProximityMonitorComponent(Entity* parent, int radiusSmall, int radiusLarge) : Component(parent) {
if (radiusSmall != -1 && radiusLarge != -1) {
Expand Down Expand Up @@ -40,11 +40,11 @@ void ProximityMonitorComponent::SetProximityRadius(dpEntity* entity, const std::
m_ProximitiesData.insert(std::make_pair(name, entity));
}

const std::vector<LWOOBJID>& ProximityMonitorComponent::GetProximityObjects(const std::string& name) {
const std::set<LWOOBJID>& ProximityMonitorComponent::GetProximityObjects(const std::string& name) {
const auto& iter = m_ProximitiesData.find(name);

if (iter == m_ProximitiesData.end()) {
return m_EmptyObjectVec;
return m_EmptyObjectSet;
}

return iter->second->GetCurrentlyCollidingObjects();
Expand All @@ -59,7 +59,7 @@ bool ProximityMonitorComponent::IsInProximity(const std::string& name, LWOOBJID

const auto& collisions = iter->second->GetCurrentlyCollidingObjects();

return std::ranges::find(collisions, objectID) != collisions.cend();
return collisions.contains(objectID);
}

void ProximityMonitorComponent::Update(float deltaTime) {
Expand Down
6 changes: 3 additions & 3 deletions dGame/dComponents/ProximityMonitorComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class ProximityMonitorComponent final : public Component {
/**
* Returns the last of entities that are used to check proximity, given a name
* @param name the proximity name to retrieve physics objects for
* @return a vector of physics entity object IDs for this name
* @return a set of physics entity object IDs for this name
*/
const std::vector<LWOOBJID>& GetProximityObjects(const std::string& name);
const std::set<LWOOBJID>& GetProximityObjects(const std::string& name);

/**
* Checks if the passed object is in proximity of the named proximity sensor
Expand All @@ -70,7 +70,7 @@ class ProximityMonitorComponent final : public Component {
/**
* Default value for the proximity data
*/
static const std::vector<LWOOBJID> m_EmptyObjectVec;
static const std::set<LWOOBJID> m_EmptyObjectSet;
};

#endif // PROXIMITYMONITORCOMPONENT_H
11 changes: 3 additions & 8 deletions dPhysics/dpEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,14 @@ void dpEntity::CheckCollision(dpEntity* other) {
}

const auto objId = other->GetObjectID();
const auto objItr = std::ranges::find(m_CurrentlyCollidingObjects, objId);
const bool wasFound = objItr != m_CurrentlyCollidingObjects.cend();
const bool wasFound = std::ranges::find(m_CurrentlyCollidingObjects, objId) != m_CurrentlyCollidingObjects.cend();
const bool isColliding = m_CollisionShape->IsColliding(other->GetShape());

if (isColliding && !wasFound) {
m_CurrentlyCollidingObjects.emplace_back(objId);
m_CurrentlyCollidingObjects.emplace(objId);
m_NewObjects.push_back(objId);
} else if (!isColliding && wasFound) {
// Erase object ID from currently colliding objects by swapping and popping vector
auto& lastObj = m_CurrentlyCollidingObjects.back();
*objItr = std::move(lastObj);
m_CurrentlyCollidingObjects.pop_back();

m_CurrentlyCollidingObjects.erase(objId);
m_RemovedObjects.push_back(objId);
}
}
Expand Down
9 changes: 5 additions & 4 deletions dPhysics/dpEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "NiQuaternion.h"
#include <vector>
#include <map>
#include <span>

#include "dCommonVars.h"
#include "dpCommon.h"
Expand Down Expand Up @@ -49,9 +50,9 @@ class dpEntity {
bool GetSleeping() const { return m_Sleeping; }
void SetSleeping(bool value) { m_Sleeping = value; }

const std::vector<LWOOBJID>& GetNewObjects() const { return m_NewObjects; }
const std::vector<LWOOBJID>& GetRemovedObjects() const { return m_RemovedObjects; }
const std::vector<LWOOBJID>& GetCurrentlyCollidingObjects() const { return m_CurrentlyCollidingObjects; }
const std::span<const LWOOBJID> GetNewObjects() const { return m_NewObjects; }
const std::span<const LWOOBJID> GetRemovedObjects() const { return m_RemovedObjects; }
const std::set<LWOOBJID>& GetCurrentlyCollidingObjects() const { return m_CurrentlyCollidingObjects; }

void PreUpdate() { m_NewObjects.clear(); m_RemovedObjects.clear(); }

Expand Down Expand Up @@ -82,5 +83,5 @@ class dpEntity {

std::vector<LWOOBJID> m_NewObjects;
std::vector<LWOOBJID> m_RemovedObjects;
std::vector<LWOOBJID> m_CurrentlyCollidingObjects;
std::set<LWOOBJID> m_CurrentlyCollidingObjects;
};

0 comments on commit 0628fde

Please sign in to comment.