R-Type  2
Doom but in better
Loading...
Searching...
No Matches
LifetimeSystem.cpp
Go to the documentation of this file.
1#include "LifetimeSystem.hpp"
2#include "IndexedZipper.hpp"
3
4#include "Time.hpp"
5
7{
8 for (auto &&[idx, lif] : IndexedZipper(lifetimes)) {
9 if (!lif) continue;
10 lif->time_left -= Time::deltaTime;
11 if (lif->time_left <= 0.f){
12 r.kill_entity(Entity(idx));
13 r.dispatcher->notify({messageType::P_KILL, idx, {0, 0, 0, "", {0, 0}}});
14 }
15 }
16}
@ P_KILL
Represents a kill event.
void lifetime_system(Registry &r, ComponentContainer< Lifetime > &lifetimes)
Manages the lifetime of entities by decreasing their time left.
Registry * r
Definition Tests.cpp:4
Manages a collection of components associated with entities in an ECS (Entity-Component-System) archi...
Represents an entity in an Entity-Component-System (ECS) architecture.
Definition Entity.hpp:12
void notify(const GameMessage &event)
Notifies the subscribed listener of an event.
Combines multiple containers into a single iterable unit, iterating over corresponding elements from ...
Manages entities and their associated components, enabling the creation, deletion,...
Definition Registry.hpp:23
void kill_entity(const Entity &entity)
Deletes an entity and removes all its components.
Definition Registry.cpp:35
EventDispatcher * dispatcher
Definition Registry.hpp:191
float deltaTime
The time difference between the current frame and the last frame.
Definition Time.cpp:4