Skip to main content

GameObjectLifecycleSystem.ixx File

System that processes health depletion events and triggers despawning. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemechanics

High-level gameplay systems and components for game logic. More...

namespacelifecycle

Lifecycle management for entity components and world-level operations. More...

namespacesystems

Systems for processing entity lifecycle transitions. More...

Classes Index

classGameObjectLifecycleSystem

Reacts to HealthDepletedEvents and despawns or deactivates entities. More...

Description

System that processes health depletion events and triggers despawning.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file GameObjectLifecycleSystem.ixx
3 * @brief System that processes health depletion events and triggers despawning.
4 */
5module;
6
7
8#include <vector>
9#include <cassert>
10
11export module helios.engine.mechanics.lifecycle.systems.GameObjectLifecycleSystem;
12
13import helios.engine.state.Bindings;
14import helios.engine.runtime.messaging.command.EngineCommandBuffer;
15
16
17
18import helios.engine.runtime.world.Manager;
19import helios.engine.runtime.world.GameWorld;
20import helios.engine.runtime.world.UpdateContext;
21
22import helios.engine.runtime.spawn;
23
24import helios.engine.mechanics.health.events;
25import helios.engine.mechanics.health.types;
26
27import helios.engine.mechanics.match.components;
28import helios.engine.mechanics.match.events;
29
30import helios.engine.mechanics.health;
31
32import helios.engine.mechanics.spawn.components.SpawnedByProfileComponent;
33
36
43
44import helios.engine.common.tags.SystemRole;
45
47
48 /**
49 * @brief Reacts to HealthDepletedEvents and despawns or deactivates entities.
50 *
51 * Reads HealthDepletedEvents from the phase bus. For each affected entity,
52 * the system inspects the HealthComponent's HealthDepletedBehavior flags:
53 * - If Despawn is set and the entity has a SpawnedByProfileComponent,
54 * a DespawnCommand is enqueued.
55 * - Otherwise the entity is deactivated.
56 */
58
59 public:
60
62
63 /**
64 * @brief Processes health depletion events and enqueues despawn commands.
65 *
66 * @param updateContext Current frame context.
67 */
69
70 auto events = updateContext.readPass<HealthDepletedEvent>();
71
72 for (auto& event : events) {
73 auto go = updateContext.find(event.source());
74
75 if (go) {
76
78 if (hc) {
79 auto healthDepletedBehavior = hc->healthDepletedBehavior();
80 if (hasHealthDepletedFlag(healthDepletedBehavior, HealthDepletedBehavior::Despawn)) {
81 if (auto* sbp = go->get<SpawnedByProfileComponent>()) {
82 assert(sbp->spawnProfileId().value() != 0 && "Entity has no SpawnProfileId.");
83 updateContext.queueCommand<DespawnCommand>(go->entityHandle(), sbp->spawnProfileId());
84 } else {
85 go->setActive(false);
86 /**
87 * @todo remove from gameworld
88 */
89 }
90 }
91 }
92 }
93
94 }
95
96 }
97 };
98
99}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.