From b8f2e57e9303181a2508324d4ef49687e42aa382 Mon Sep 17 00:00:00 2001 From: Daniel Henry Date: Mon, 8 Sep 2025 23:14:03 -0500 Subject: [PATCH] Entity refactor loose ends Signed-off-by: Daniel Henry --- include/Craft/WWorld.h | 4 +--- src/Craft/WWorld.cpp | 18 +++++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/include/Craft/WWorld.h b/include/Craft/WWorld.h index 1fbf900..6e1e585 100644 --- a/include/Craft/WWorld.h +++ b/include/Craft/WWorld.h @@ -36,9 +36,7 @@ public: private: bool mHasBegun; - Dict> mEntities_; - std::vector> - mEntities; + Dict> mEntities; std::vector> mPendingEntities; ////////// Static diff --git a/src/Craft/WWorld.cpp b/src/Craft/WWorld.cpp index daec91a..09dc5b5 100644 --- a/src/Craft/WWorld.cpp +++ b/src/Craft/WWorld.cpp @@ -11,18 +11,14 @@ void WWorld::Begin() { } void WWorld::Tick(float deltaTime) { - // for (auto &entity : mPendingEntities) { - // entity->Begin(); - // mEntities.push_back(std::move(entity)); - // } for (auto &entity : mPendingEntities) { entity->Begin(); - mEntities_.emplace(entity->Id, std::move(entity)); + mEntities.emplace(entity->Id, std::move(entity)); } mPendingEntities.clear(); for (auto iter = mEntities.begin(); iter != mEntities.end();) { - if ((*iter)->IsDestroyed()) { + if ((*iter).second->IsDestroyed()) { iter = mEntities.erase(iter); } else { ++iter; @@ -30,7 +26,7 @@ void WWorld::Tick(float deltaTime) { } for (auto &entity : mEntities) { - entity->Tick(deltaTime); + entity.second->Tick(deltaTime); } } void WWorld::FixedTick() {} @@ -44,13 +40,13 @@ void WWorld::Reset() { } EEntity &WWorld::GetEntity(entId id) { - return *mEntities_.find(id)->second; + return *mEntities.find(id)->second; } void WWorld::DestroyEntity(entId id) { for (auto &entity : mEntities) { - if (entity->Id == id) { - entity->Destroy(); + if (entity.second->Id == id) { + entity.second->Destroy(); return; } } @@ -58,7 +54,7 @@ void WWorld::DestroyEntity(entId id) { } size_t WWorld::GetTotalEntities() { - return mEntities_.size(); + return mEntities.size(); } } // namespace craft