-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeleteTimerSystem.cpp
29 lines (24 loc) · 1.06 KB
/
DeleteTimerSystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "DeleteTimerSystem.h"
// the DeleteTimer component has a timestamp for when an entity should be deleted
// this system checks if the current game frame count has reached that timestamp,
// and calls for the entity to be deleted if it has
// this allows for us to have entities with specified lifetime
void DeleteTimerSystem::update()
{
EntityCoordinator& coordinator = EntityCoordinator::getInstance();
std::shared_ptr<EntityQuery> query = coordinator.GetEntityQuery({
coordinator.GetComponentType<DeleteTimer>()
}, {});
ComponentIterator<DeleteTimer> iterator = ComponentIterator<DeleteTimer>(query);
int entCount = query->totalEntitiesFound();
int currGameFrame = GameManager::getInstance().getCurrGameFrame();
for (int i = 0; i < entCount; i++)
{
DeleteTimer* component = iterator.nextComponent();
if (currGameFrame >= component->deletionFrame)
{
EntityID id = iterator.getCurrEnt();
EntityCoordinator::getInstance().scheduleEntityToDelete(id);
}
}
}