Skip to main content

ProjectileSpawnSystem Class

System that spawns projectiles for entities with active ShootComponents. More...

Declaration

class helios::engine::mechanics::combat::systems::ProjectileSpawnSystem { ... }

Public Member Typedefs Index

usingEngineRoleTag = helios::engine::common::tags::SystemRole

Public Constructors Index

ProjectileSpawnSystem (const helios::engine::runtime::spawn::types::SpawnProfileId &spawnProfileId)

Constructs a ProjectileSpawnSystem with the specified spawn profile. More...

Public Member Functions Index

voidupdate (helios::engine::runtime::world::UpdateContext &updateContext) noexcept

Processes all shooting entities and spawns projectiles. More...

Private Member Attributes Index

const helios::engine::runtime::spawn::types::SpawnProfileIdspawnProfileId_

The spawn profile ID used for projectile creation. More...

Description

System that spawns projectiles for entities with active ShootComponents.

ProjectileSpawnSystem iterates all entities that have a ShootComponent, Aim2DComponent, and TranslationStateComponent. When a ShootComponent has non-zero intensity and the aim component has a valid frequency, the system calculates how many projectiles to spawn based on accumulated time and cooldown.

## Fire Rate Mechanics

The system implements an intensity-based fire rate: 1. Accumulates `deltaTime * intensity` into the cooldown timer 2. When timer >= cooldownDelta, spawns `floor(timer / cooldownDelta)` projectiles 3. Reduces timer by spawned amount, preserving fractional remainder

This allows continuous fire with variable intensity affecting the effective rate.

## Spawn Context

Each SpawnCommand includes an EmitterContext containing:

  • **position:** Current translation from TranslationStateComponent
  • **velocity:** sourceVelocity + (aimDirection * projectileSpeed)

Example setup: ```cpp auto projectileSpawnSystem = std::make_unique<ProjectileSpawnSystem>( SpawnProfileId{1} // ID of the projectile spawn profile ); mainPhase.addPass().add(std::move(projectileSpawnSystem)); ```

info

Entities must have ShootComponent, Aim2DComponent, and TranslationStateComponent to be processed.

See Also

ShootComponent

See Also

Aim2DComponent

See Also

SpawnCommand

See Also

EmitterContext

Definition at line 73 of file ProjectileSpawnSystem.ixx.

Public Member Typedefs

EngineRoleTag

using helios::engine::mechanics::combat::systems::ProjectileSpawnSystem::EngineRoleTag = helios::engine::common::tags::SystemRole

Public Constructors

ProjectileSpawnSystem()

helios::engine::mechanics::combat::systems::ProjectileSpawnSystem::ProjectileSpawnSystem (const helios::engine::runtime::spawn::types::SpawnProfileId & spawnProfileId)
inline explicit

Constructs a ProjectileSpawnSystem with the specified spawn profile.

Parameters
spawnProfileId

The ID of the spawn profile to use for projectiles.

Definition at line 93 of file ProjectileSpawnSystem.ixx.

95 ) :
96 spawnProfileId_(spawnProfileId)
97 {}

Public Member Functions

update()

void helios::engine::mechanics::combat::systems::ProjectileSpawnSystem::update (helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept

Processes all shooting entities and spawns projectiles.

For each entity with ShootComponent, Aim2DComponent, and TranslationStateComponent:

1. Skips if aim frequency or intensity are near zero 2. Accumulates `deltaTime * intensity` into the cooldown timer 3. If timer < cooldownDelta, updates timer and continues 4. Calculates projectile count as `floor(timer / cooldownDelta)` 5. Reduces timer by `count * cooldownDelta` 6. Enqueues SpawnCommands with EmitterContext for each projectile

Parameters
updateContext

The current frame's update context.

Definition at line 114 of file ProjectileSpawnSystem.ixx.

115
116 for (auto [entity, tsc, ac, sc, active] : updateContext.view<
121 >().whereEnabled()) {
122
123
124 const float intensity = sc->intensity();
125 const float cooldown = sc->cooldownDelta();
126
127 float timer = sc->cooldownTimer();
128
129 // only process for meaningful values
130 assert(cooldown > helios::math::EPSILON_LENGTH && "Unexpected cooldownDelta");
131 if (ac->frequency() <= helios::math::EPSILON_LENGTH ||
132 intensity <= helios::math::EPSILON_LENGTH) {
133 continue;
134 };
135
136 const float delta = updateContext.deltaTime();
137
138 // update the timer to accumulate frame times * intensity.
139 // will be updated in this frame if projectiles spawned,
140 timer += delta * intensity;
141
142 if (timer < cooldown) {
143 sc->setCooldownTimer(timer);
144 continue;
145 }
146
147 const unsigned int amount = static_cast<unsigned int>(timer / cooldown);
148
149 // reduce timer by the product of projectiles and cooldown,
150 // which leaves a fractional part that did not add a whole projectile
151 // to this frame
152 sc->setCooldownTimer(timer - (amount * cooldown));
153
154 const auto aimDirection = ac->direction().toVec3();
155 assert(aimDirection.isNormalized() && "Unexpected aimDirection.length()");
156
157 for (unsigned int i = 0; i < amount; i++) {
158 updateContext.queueCommand<
160 >(
161 spawnProfileId_,
164 tsc->translation(),
165 sc->sourceVelocity() + (aimDirection * sc->projectileSpeed()),
166 entity.entityHandle()
167 }
168 }
169 );
170 }
171 }
172 }

Reference helios::math::EPSILON_LENGTH.

Private Member Attributes

spawnProfileId_

const helios::engine::runtime::spawn::types::SpawnProfileId helios::engine::mechanics::combat::systems::ProjectileSpawnSystem::spawnProfileId_

The spawn profile ID used for projectile creation.

References a SpawnProfile in the spawn system that defines how projectiles are placed and initialized.

Definition at line 81 of file ProjectileSpawnSystem.ixx.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.