R-Type 0.1
Loading...
Searching...
No Matches
DeadSystem.hpp
1#pragma once
2
3#include "components/Dead.hpp"
4#include <ISystem.hpp>
5#include <vector>
6
7namespace rtk::systems {
16class DeathSystem final : public rtk::ecs::ISystem {
17public:
18 DeathSystem() = default;
19 ~DeathSystem() override = default;
20
24 void onStart(rtk::ecs::Registry &) override {}
25
30 void update(rtk::ecs::Registry &reg, float) override {
31 auto view = reg.view<component::Dead>();
32
33 std::vector<std::size_t> toDestroy;
34 for (auto entity : view) {
35 toDestroy.push_back(entity);
36 }
37
38 for (auto entity : toDestroy) {
39 reg.remove_entity_from_all_pools(entity);
40 reg.kill_entity(entity);
41 }
42 }
43
47 void onStop(rtk::ecs::Registry &) override {}
48};
49
51} // namespace rtk::systems
Destroys every entity tagged with Dead.
Definition DeadSystem.hpp:16
void update(rtk::ecs::Registry &reg, float) override
Removes the components of dead entities and kills them.
Definition DeadSystem.hpp:30
void onStop(rtk::ecs::Registry &) override
Does nothing.
Definition DeadSystem.hpp:47
void onStart(rtk::ecs::Registry &) override
Does nothing.
Definition DeadSystem.hpp:24
Tag marking an entity for destruction at the end of the frame.
Definition Dead.hpp:17