Skip to main content

HealthManager Class

Manager that processes damage commands and updates entity health. More...

Declaration

class helios::engine::mechanics::health::HealthManager { ... }

Public Member Typedefs Index

usingEngineRoleTag = helios::engine::common::tags::ManagerRole

Public Member Functions Index

voidflush (UpdateContext &updateContext) noexcept

Applies all queued damage and emits health events. More...

boolsubmit (const ApplyDamageCommand applyDamageCommand) noexcept

Enqueues a damage command for deferred processing. More...

voidinit (GameWorld &gameWorld)

Registers this manager as the damage command handler. More...

voidreset ()

Clears all pending damage contexts. More...

Private Member Attributes Index

std::vector< DamageContext >damageContexts_

Pending damage contexts collected via submit(). More...

Private Static Attributes Index

static const helios::util::log::Logger &logger_ = ...

Logger scoped to HealthManager. More...

Description

Manager that processes damage commands and updates entity health.

HealthManager implements the Manager interface for integration into the game loop flush cycle, and provides a registered submit function for ApplyDamageCommand so that incoming damage is queued and applied in batch.

During flush(), each queued DamageContext is resolved: the target's HealthComponent is damaged, a HealthChangedEvent is emitted, and if health reaches zero a HealthDepletedEvent is pushed together with an optional DeadTagComponent.

Event phases:

  • HealthChangedEvent is pushed to the **phase** bus (available to systems in the next phase).
  • HealthDepletedEvent is pushed to the **pass** bus (available to systems after commit within the same pass).
See Also

ApplyDamageCommand

See Also

HealthComponent

See Also

HealthDepletedEvent

See Also

Manager

Definition at line 64 of file HealthManager.ixx.

Public Member Typedefs

EngineRoleTag

using helios::engine::mechanics::health::HealthManager::EngineRoleTag = helios::engine::common::tags::ManagerRole

Public Member Functions

flush()

void helios::engine::mechanics::health::HealthManager::flush (UpdateContext & updateContext)
inline noexcept

Applies all queued damage and emits health events.

For each pending DamageContext the target's HealthComponent is looked up and damaged. A HealthChangedEvent is pushed per hit. When health transitions from alive to dead, the configured HealthDepletedBehavior flags are evaluated and a HealthDepletedEvent is emitted.

HealthChangedEvent is pushed to the phase bus (available next phase); HealthDepletedEvent is pushed to the pass bus (available after commit within the same pass).

Parameters
updateContext

The current frame's update context.

Definition at line 95 of file HealthManager.ixx.

95 void flush(UpdateContext& updateContext) noexcept {
96
97 for (const auto& damageContext : damageContexts_) {
98
99 auto interactionContext = damageContext.interactionContext;
100
101 auto target = updateContext.find(interactionContext.target);
102
103 auto* hc = target->get<HealthComponent>();
104 if (!hc) {
105 continue;
106 }
107
108 bool wasAlive = hc->isAlive();
109 auto damageApplied = damageContext.damage;
110 hc->takeDamage(damageApplied);
111
112 auto* lac = target->get<LastDamageComponent>();
113 if (lac && damageApplied > 0) {
114 lac->setDamageContext(damageContext);
115 }
116
117 auto huc = HealthChangeContext{
118 interactionContext,
119 -damageApplied
120 };
121
122 updateContext.pushPhase<HealthChangedEvent>(huc);
123
124 if (wasAlive && !hc->isAlive()) {
125 auto healthDepletedBehavior = hc->healthDepletedBehavior();
126
127 if (hasHealthDepletedFlag(healthDepletedBehavior, HealthDepletedBehavior::DeadTag)) {
128 target->add<DeadTagComponent>();
129 }
130
131 updateContext.pushPass<HealthDepletedEvent>(target->entityHandle(), damageContext);
132 }
133 }
134
135 damageContexts_.clear();
136 }

References helios::engine::mechanics::health::types::DeadTag, helios::engine::mechanics::health::types::hasHealthDepletedFlag and helios::engine::mechanics::health::components::HealthComponent::isAlive.

init()

void helios::engine::mechanics::health::HealthManager::init (GameWorld & gameWorld)
inline

Registers this manager as the damage command handler.

Parameters
gameWorld

The game world to register with.

Definition at line 157 of file HealthManager.ixx.

157 void init(GameWorld& gameWorld) {
158 gameWorld.template registerCommandHandler<ApplyDamageCommand>(*this);
159 }

reset()

void helios::engine::mechanics::health::HealthManager::reset ()
inline

Clears all pending damage contexts.

Definition at line 164 of file HealthManager.ixx.

164 void reset() {
165 damageContexts_.clear();
166 }

submit()

bool helios::engine::mechanics::health::HealthManager::submit (const ApplyDamageCommand applyDamageCommand)
inline noexcept

Enqueues a damage command for deferred processing.

Parameters
applyDamageCommand

The damage command to enqueue.

Returns

True if the command was accepted.

Definition at line 145 of file HealthManager.ixx.

145 bool submit(
146 const ApplyDamageCommand applyDamageCommand
147 ) noexcept {
148 damageContexts_.push_back(applyDamageCommand.damageContext());
149 return true;
150 };

Private Member Attributes

damageContexts_

std::vector<DamageContext> helios::engine::mechanics::health::HealthManager::damageContexts_

Pending damage contexts collected via submit().

Definition at line 75 of file HealthManager.ixx.

75 std::vector<DamageContext> damageContexts_;

Private Static Attributes

logger_

const helios::util::log::Logger& helios::engine::mechanics::health::HealthManager::logger_
static

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.