move to unordered_set

This commit is contained in:
David Markowitz 2024-01-13 01:30:47 -08:00
parent d3eb5a56d9
commit d77c0cd409
2 changed files with 8 additions and 30 deletions

View File

@ -1,12 +1,9 @@
#include "GhostComponent.h" #include "GhostComponent.h"
// TODO Move ghosting related code from Player to here
GhostComponent::GhostComponent(Entity* parent) : Component(parent) { GhostComponent::GhostComponent(Entity* parent) : Component(parent) {
m_GhostReferencePoint = NiPoint3::ZERO; m_GhostReferencePoint = NiPoint3::ZERO;
m_GhostOverridePoint = NiPoint3::ZERO; m_GhostOverridePoint = NiPoint3::ZERO;
m_GhostOverride = false; m_GhostOverride = false;
m_ObservedEntities.resize(256);
} }
GhostComponent::~GhostComponent() { GhostComponent::~GhostComponent() {
@ -29,17 +26,11 @@ void GhostComponent::SetGhostOverridePoint(const NiPoint3& value) {
} }
void GhostComponent::AddLimboConstruction(LWOOBJID objectId) { void GhostComponent::AddLimboConstruction(LWOOBJID objectId) {
const auto iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId); m_LimboConstructions.insert(objectId);
if (iter == m_LimboConstructions.end()) {
m_LimboConstructions.push_back(objectId);
}
} }
void GhostComponent::RemoveLimboConstruction(LWOOBJID objectId) { void GhostComponent::RemoveLimboConstruction(LWOOBJID objectId) {
const auto iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId); m_LimboConstructions.erase(objectId);
if (iter != m_LimboConstructions.end()) {
m_LimboConstructions.erase(iter);
}
} }
void GhostComponent::ConstructLimboEntities() { void GhostComponent::ConstructLimboEntities() {
@ -54,27 +45,13 @@ void GhostComponent::ConstructLimboEntities() {
} }
void GhostComponent::ObserveEntity(int32_t id) { void GhostComponent::ObserveEntity(int32_t id) {
for (auto& observedEntity : m_ObservedEntities) { m_ObservedEntities.insert(id);
if (observedEntity == 0 || observedEntity == id) {
observedEntity = id;
return;
}
}
m_ObservedEntities.reserve(m_ObservedEntities.size() + 1);
m_ObservedEntities.push_back(id);
} }
bool GhostComponent::IsObserved(int32_t id) { bool GhostComponent::IsObserved(int32_t id) {
return std::find(m_ObservedEntities.begin(), m_ObservedEntities.end(), id) != m_ObservedEntities.end(); return m_ObservedEntities.contains(id);
} }
void GhostComponent::GhostEntity(int32_t id) { void GhostComponent::GhostEntity(int32_t id) {
for (auto& observedEntity : m_ObservedEntities) { m_ObservedEntities.erase(id);
if (observedEntity == id) {
observedEntity = 0;
}
}
} }

View File

@ -3,6 +3,7 @@
#include "Component.h" #include "Component.h"
#include "eReplicaComponentType.h" #include "eReplicaComponentType.h"
#include <unordered_set>
class NiPoint3; class NiPoint3;
@ -43,9 +44,9 @@ private:
NiPoint3 m_GhostOverridePoint; NiPoint3 m_GhostOverridePoint;
std::vector<int32_t> m_ObservedEntities; std::unordered_set<int32_t> m_ObservedEntities;
std::vector<LWOOBJID> m_LimboConstructions; std::unordered_set<LWOOBJID> m_LimboConstructions;
bool m_GhostOverride; bool m_GhostOverride;
}; };