Skip to main content

TimerSpawnCondition Class

A SpawnCondition that triggers spawning at fixed time intervals. More...

Declaration

class helios::engine::runtime::spawn::policy::conditions::TimerSpawnCondition { ... }

Base class

classSpawnCondition

Abstract interface for determining when spawning should occur. More...

Public Constructors Index

TimerSpawnCondition (const float interval)

Constructs a TimerSpawnCondition with the specified interval. More...

Public Member Functions Index

boolisSatisfied (const size_t requestedAmount, const SpawnRuleState &spawnState, const helios::engine::runtime::pooling::GameObjectPoolSnapshot poolSnapshot, const helios::engine::runtime::world::UpdateContext &updateContext) const noexcept override

Checks if the timer interval has elapsed. More...

voidonCommit (SpawnRuleState &spawnRuleState, const size_t spawnAmount) const override

Resets the spawn timer after a successful spawn. More...

Private Member Attributes Index

floatinterval_ = 0.0f

The time interval between spawns in seconds. More...

Description

A SpawnCondition that triggers spawning at fixed time intervals.

TimerSpawnCondition checks if enough time has elapsed since the last spawn to satisfy the interval requirement.

## Behavior

  • **isSatisfied():** Returns true when `sinceLastSpawn >= interval`.
  • **onCommit():** Resets the `sinceLastSpawn` timer to 0

Example: ```cpp // Spawn every 2 seconds auto condition = std::make_unique<TimerSpawnCondition>(2.0f);

auto rule = std::make_unique<SpawnRule>( std::move(condition), std::make_unique<FixedSpawnAmount>(3), SpawnRuleId{1} ); ```

See Also

SpawnCondition

See Also

SpawnRule

See Also

SpawnRuleState

Definition at line 45 of file TimerSpawnCondition.ixx.

Public Constructors

TimerSpawnCondition()

helios::engine::runtime::spawn::policy::conditions::TimerSpawnCondition::TimerSpawnCondition (const float interval)
inline explicit

Constructs a TimerSpawnCondition with the specified interval.

The first spawn will occur after the interval has elapsed, not immediately.

Parameters
interval

The time in seconds between spawn events.

Precondition

interval > 0.0f

Definition at line 66 of file TimerSpawnCondition.ixx.

66 explicit TimerSpawnCondition(const float interval)
67 : interval_(interval) {
68 assert(interval > 0.0f && "Interval must be > 0");
69 }

Public Member Functions

isSatisfied()

bool helios::engine::runtime::spawn::policy::conditions::TimerSpawnCondition::isSatisfied (const size_t requestedAmount, const SpawnRuleState & spawnState, const helios::engine::runtime::pooling::GameObjectPoolSnapshot poolSnapshot, const helios::engine::runtime::world::UpdateContext & updateContext)
inline nodiscard noexcept virtual

Checks if the timer interval has elapsed.

Parameters
requestedAmount

The number of entities requested to spawn.

spawnState

The rule's runtime state containing time since last spawn.

poolSnapshot

Snapshot of the pool's current capacity.

updateContext

The current frame's context.

Returns

true if interval elapsed AND pool has enough inactive entities.

Definition at line 81 of file TimerSpawnCondition.ixx.

81 [[nodiscard]] bool isSatisfied(
82 const size_t requestedAmount,
83 const SpawnRuleState& spawnState,
86 ) const noexcept override {
87 return spawnState.sinceLastSpawn() >= interval_;
88 }

onCommit()

void helios::engine::runtime::spawn::policy::conditions::TimerSpawnCondition::onCommit (SpawnRuleState & spawnRuleState, const size_t spawnAmount)
inline virtual

Resets the spawn timer after a successful spawn.

Parameters
spawnRuleState

The rule's runtime state to update.

spawnAmount

The number of entities that were spawned (unused).

Definition at line 96 of file TimerSpawnCondition.ixx.

96 void onCommit(
97 SpawnRuleState& spawnRuleState,
98 const size_t spawnAmount
99 ) const override {
100 spawnRuleState.setSinceLastSpawn(0.0f);
101 }

Reference helios::engine::runtime::spawn::policy::SpawnRuleState::setSinceLastSpawn.

Private Member Attributes

interval_

float helios::engine::runtime::spawn::policy::conditions::TimerSpawnCondition::interval_ = 0.0f

The time interval between spawns in seconds.

Definition at line 52 of file TimerSpawnCondition.ixx.

52 float interval_ = 0.0f;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.