Entity refactor loose ends

Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
2025-09-08 23:14:03 -05:00
parent 82c366b165
commit b8f2e57e93
2 changed files with 8 additions and 14 deletions

View File

@@ -36,9 +36,7 @@ public:
private:
bool mHasBegun;
Dict<entId, unique<EEntity>> mEntities_;
std::vector<unique<EEntity>>
mEntities;
Dict<entId, unique<EEntity>> mEntities;
std::vector<unique<EEntity>> mPendingEntities;
////////// Static

View File

@@ -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