chore: use ranges in EntityManager and touch up (#1451)

* EntityManager: ranges and cleanup

Use LWOOBJID for ghosting entities
use ranges::views::values for associative container iteration
remove dead code
comment magic numbers
little bit of optimization (not enough to be game changing or take the time to measure, they are free speedups anyways, we take those)
use cstdint types

* use size_t

* use lwoobjid for ghost candidate
This commit is contained in:
David Markowitz
2024-02-11 12:28:25 -08:00
committed by GitHub
parent ddaac276fe
commit dfb2fd93b4
4 changed files with 66 additions and 97 deletions

View File

@@ -8,7 +8,7 @@ GhostComponent::GhostComponent(Entity* parent) : Component(parent) {
GhostComponent::~GhostComponent() {
for (auto& observedEntity : m_ObservedEntities) {
if (observedEntity == 0) continue;
if (observedEntity == LWOOBJID_EMPTY) continue;
auto* entity = Game::entityManager->GetGhostCandidate(observedEntity);
if (!entity) continue;
@@ -44,14 +44,14 @@ void GhostComponent::ConstructLimboEntities() {
m_LimboConstructions.clear();
}
void GhostComponent::ObserveEntity(int32_t id) {
void GhostComponent::ObserveEntity(LWOOBJID id) {
m_ObservedEntities.insert(id);
}
bool GhostComponent::IsObserved(int32_t id) {
bool GhostComponent::IsObserved(LWOOBJID id) {
return m_ObservedEntities.contains(id);
}
void GhostComponent::GhostEntity(int32_t id) {
void GhostComponent::GhostEntity(LWOOBJID id) {
m_ObservedEntities.erase(id);
}

View File

@@ -33,18 +33,18 @@ public:
void ConstructLimboEntities();
void ObserveEntity(const int32_t id);
void ObserveEntity(const LWOOBJID id);
bool IsObserved(const int32_t id);
bool IsObserved(const LWOOBJID id);
void GhostEntity(const int32_t id);
void GhostEntity(const LWOOBJID id);
private:
NiPoint3 m_GhostReferencePoint;
NiPoint3 m_GhostOverridePoint;
std::unordered_set<int32_t> m_ObservedEntities;
std::unordered_set<LWOOBJID> m_ObservedEntities;
std::unordered_set<LWOOBJID> m_LimboConstructions;