-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentityCleanupSystem.cpp
39 lines (32 loc) · 1.49 KB
/
entityCleanupSystem.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
30
31
32
33
34
35
36
37
38
39
#include "entityCleanupSystem.hpp"
#include "collision.hpp"
//////////////////////////////////////////////////////////////////////
/// Custom Constructor
//////////////////////////////////////////////////////////////////////
EntityCleanupSystem::EntityCleanupSystem(ecsWorld& gameWorld)
: m_gameWorld(gameWorld) {
addComponentType(ParticleComponent::Runtime_ID, RequirementsFlag::REQUIRED);
}
//////////////////////////////////////////////////////////////////////
/// updateComponents
//////////////////////////////////////////////////////////////////////
void EntityCleanupSystem::updateComponents(
const double& /*deltaTime*/,
const std::vector<std::vector<ecsBaseComponent*>>& entityComponents) {
std::vector<EntityHandle> entitiesToDelete;
for (const auto& components : entityComponents) {
const auto& particleComponent =
*static_cast<ParticleComponent*>(components[0]);
const auto& position = particleComponent.m_pos;
// Find entities that are out-of-bounds
if (!areColliding_BoxVsBox(
position, vec2(0.5), vec2(256), vec2(256, 256)))
entitiesToDelete.emplace_back(particleComponent.m_entityHandle);
// Find entities that are out-of-health
else if (particleComponent.m_health < 0.0001F)
entitiesToDelete.emplace_back(particleComponent.m_entityHandle);
}
// Remove all out-of-bounds entities
for (const auto& handle : entitiesToDelete)
m_gameWorld.removeEntity(handle);
}