R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
HealthSystem.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** RTYPE
4** File description:
5** HealthSystem
6*/
7
8#include "HealthSystem.hpp"
9#include "../../Components/IComponent.hpp"
10#include "../../Components/PendingDestroy.hpp"
11
12namespace ecs {
16 void HealthSystem::update(Registry &registry, float deltaTime) {
17 auto entities = registry.getEntitiesWithMask(this->getComponentMask());
18 std::vector<std::uint32_t> toDestroy;
19
20 for (auto entityId : entities) {
21 auto &health = registry.getComponent<Health>(entityId);
22
23 if (health.isInvincible()) {
24 float timer = health.getInvincibilityTimer() - deltaTime;
25 health.setInvincibilityTimer(timer);
26
27 if (timer <= 0.0f) {
28 health.setInvincible(false);
29 health.setInvincibilityTimer(0.0f);
30 }
31 }
32
33 if (health.getCurrentHealth() <= 0) {
34 toDestroy.push_back(entityId);
35 }
36 }
37
38 for (auto entityId : toDestroy) {
39 // Mark for destruction with proper client notification
40 if (!registry.hasComponent<PendingDestroy>(entityId)) {
42 }
43 }
44 }
45
47 return (1ULL << getComponentType<Health>());
48 }
49} // namespace ecs
void update(Registry &registry, float deltaTime) override
Updates health-related logic for all entities.
ComponentMask getComponentMask() const override
Gets the component mask for this system.
Component representing entity health and invincibility.
Definition Health.hpp:20
float getInvincibilityTimer() const
Get remaining invincibility time.
Definition Health.hpp:62
Marker component indicating entity should be destroyed.
Manages entities, their signatures and component type registrations.
Definition Registry.hpp:68
std::vector< Address > getEntitiesWithMask(Signature requiredMask)
Get all entities matching a specific component mask.
Definition Registry.cpp:79
T & getComponent(Address address)
Get a component from an entity.
bool hasComponent(Address address)
Check if an entity has a specific component.
void setComponent(Address address, const T &component)
Set/add a component to an entity with its data.
Maximum number of distinct component types supported by the Registry.
Definition GameLogic.hpp:26
std::uint64_t ComponentMask
Type alias for component bitmask.
Definition ISystem.hpp:24
@ Killed
Entity was killed (health <= 0)