From d77c0cd40930511bda9c2f282615e8411d5180ea Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Sat, 13 Jan 2024 01:30:47 -0800 Subject: [PATCH] move to unordered_set --- dGame/dComponents/GhostComponent.cpp | 33 +++++----------------------- dGame/dComponents/GhostComponent.h | 5 +++-- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/dGame/dComponents/GhostComponent.cpp b/dGame/dComponents/GhostComponent.cpp index b1f4220c..2978c912 100644 --- a/dGame/dComponents/GhostComponent.cpp +++ b/dGame/dComponents/GhostComponent.cpp @@ -1,12 +1,9 @@ #include "GhostComponent.h" -// TODO Move ghosting related code from Player to here GhostComponent::GhostComponent(Entity* parent) : Component(parent) { m_GhostReferencePoint = NiPoint3::ZERO; m_GhostOverridePoint = NiPoint3::ZERO; m_GhostOverride = false; - - m_ObservedEntities.resize(256); } GhostComponent::~GhostComponent() { @@ -29,17 +26,11 @@ void GhostComponent::SetGhostOverridePoint(const NiPoint3& value) { } void GhostComponent::AddLimboConstruction(LWOOBJID objectId) { - const auto iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId); - if (iter == m_LimboConstructions.end()) { - m_LimboConstructions.push_back(objectId); - } + m_LimboConstructions.insert(objectId); } void GhostComponent::RemoveLimboConstruction(LWOOBJID objectId) { - const auto iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId); - if (iter != m_LimboConstructions.end()) { - m_LimboConstructions.erase(iter); - } + m_LimboConstructions.erase(objectId); } void GhostComponent::ConstructLimboEntities() { @@ -54,27 +45,13 @@ void GhostComponent::ConstructLimboEntities() { } void GhostComponent::ObserveEntity(int32_t id) { - for (auto& observedEntity : m_ObservedEntities) { - if (observedEntity == 0 || observedEntity == id) { - observedEntity = id; - - return; - } - } - - m_ObservedEntities.reserve(m_ObservedEntities.size() + 1); - - m_ObservedEntities.push_back(id); + m_ObservedEntities.insert(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) { - for (auto& observedEntity : m_ObservedEntities) { - if (observedEntity == id) { - observedEntity = 0; - } - } + m_ObservedEntities.erase(id); } diff --git a/dGame/dComponents/GhostComponent.h b/dGame/dComponents/GhostComponent.h index 379a3864..5ae308a4 100644 --- a/dGame/dComponents/GhostComponent.h +++ b/dGame/dComponents/GhostComponent.h @@ -3,6 +3,7 @@ #include "Component.h" #include "eReplicaComponentType.h" +#include class NiPoint3; @@ -43,9 +44,9 @@ private: NiPoint3 m_GhostOverridePoint; - std::vector m_ObservedEntities; + std::unordered_set m_ObservedEntities; - std::vector m_LimboConstructions; + std::unordered_set m_LimboConstructions; bool m_GhostOverride; };