Skip to main content

SpawnRule Class

Combines a condition and amount provider into a complete spawn rule. More...

Declaration

class helios::engine::runtime::spawn::policy::SpawnRule { ... }

Public Constructors Index

SpawnRule (std::unique_ptr< const SpawnCondition > spawnCondition, std::unique_ptr< const amount::SpawnAmountProvider > spawnAmountProvider, const helios::engine::core::data::SpawnRuleId spawnRuleId)

Constructs a SpawnRule with condition, amount provider, and ID. More...

Public Member Functions Index

voidcommit (SpawnRuleState &spawnRuleState, const size_t spawnAmount)

Commits a completed spawn to update rule state. More...

const SpawnCondition &spawnCondition () const noexcept

Returns the spawn condition. More...

helios::engine::runtime::spawn::scheduling::SpawnPlanevaluate (const helios::engine::core::data::GameObjectPoolId gameObjectPoolId, const helios::engine::runtime::pooling::GameObjectPoolSnapshot &poolSnapshot, const SpawnRuleState &spawnRuleState, const helios::engine::runtime::world::UpdateContext &updateContext)

Evaluates the rule and returns a spawn plan. More...

helios::engine::core::data::SpawnRuleIdspawnRuleId () const noexcept

Returns the rule's unique identifier. More...

Private Member Attributes Index

std::unique_ptr< const amount::SpawnAmountProvider >spawnAmountProvider_

Provider that determines spawn quantity. More...

std::unique_ptr< const SpawnCondition >spawnCondition_

Condition that determines if spawning should occur. More...

const helios::engine::core::data::SpawnRuleIdspawnRuleId_

Unique identifier for this rule. More...

Description

Combines a condition and amount provider into a complete spawn rule.

SpawnRule encapsulates the logic for when and how many entities to spawn. It combines:

  • **SpawnCondition:** Determines if spawning should occur
  • **SpawnAmountProvider:** Determines how many to spawn

The SpawnScheduler evaluates rules each frame and creates SpawnPlans for rules whose conditions are satisfied.

Example: ```cpp auto rule = std::make_unique<SpawnRule>( std::make_unique<TimerSpawnCondition>(2.0f), std::make_unique<FixedSpawnAmount>(3), SpawnRuleId{1} ); ```

See Also

SpawnCondition

See Also

SpawnAmountProvider

See Also

SpawnScheduler

Definition at line 47 of file SpawnRule.ixx.

Public Constructors

SpawnRule()

helios::engine::runtime::spawn::policy::SpawnRule::SpawnRule (std::unique_ptr< const SpawnCondition > spawnCondition, std::unique_ptr< const amount::SpawnAmountProvider > spawnAmountProvider, const helios::engine::core::data::SpawnRuleId spawnRuleId)
inline explicit

Constructs a SpawnRule with condition, amount provider, and ID.

Parameters
spawnCondition

Condition determining when to spawn.

spawnAmountProvider

Provider determining how many to spawn.

spawnRuleId

Unique identifier for this rule.

Definition at line 73 of file SpawnRule.ixx.

73 explicit SpawnRule(
74 std::unique_ptr<const SpawnCondition> spawnCondition,
75 std::unique_ptr<const amount::SpawnAmountProvider> spawnAmountProvider,
77 ) :
78 spawnCondition_(std::move(spawnCondition)),
79 spawnAmountProvider_(std::move(spawnAmountProvider)),
80 spawnRuleId_(spawnRuleId) {}

References spawnCondition and spawnRuleId.

Public Member Functions

commit()

void helios::engine::runtime::spawn::policy::SpawnRule::commit (SpawnRuleState & spawnRuleState, const size_t spawnAmount)
inline

Commits a completed spawn to update rule state.

Parameters
spawnRuleState

The state to update.

spawnAmount

The number of entities spawned.

Definition at line 88 of file SpawnRule.ixx.

88 void commit(SpawnRuleState& spawnRuleState, const size_t spawnAmount) {
89 spawnCondition_->onCommit(spawnRuleState, spawnAmount);
90 }

evaluate()

helios::engine::runtime::spawn::scheduling::SpawnPlan helios::engine::runtime::spawn::policy::SpawnRule::evaluate (const helios::engine::core::data::GameObjectPoolId gameObjectPoolId, const helios::engine::runtime::pooling::GameObjectPoolSnapshot & poolSnapshot, const SpawnRuleState & spawnRuleState, const helios::engine::runtime::world::UpdateContext & updateContext)
inline nodiscard

Evaluates the rule and returns a spawn plan.

Parameters
gameObjectPoolId

The pool to spawn from.

poolSnapshot

Current pool state.

spawnRuleState

The rule's runtime state.

updateContext

The current frame's context.

Returns

A SpawnPlan with amount > 0 if condition satisfied, 0 otherwise.

Definition at line 111 of file SpawnRule.ixx.

114 const SpawnRuleState& spawnRuleState,
116 ) {
117 auto amount = spawnAmountProvider_->getAmount(gameObjectPoolId, spawnRuleState, updateContext);
118
119 if (spawnCondition_->isSatisfied(amount, spawnRuleState, poolSnapshot, updateContext)) {
121 }
122
124 }

spawnCondition()

const SpawnCondition & helios::engine::runtime::spawn::policy::SpawnRule::spawnCondition ()
inline nodiscard noexcept

Returns the spawn condition.

Returns

Reference to the spawn condition.

Definition at line 97 of file SpawnRule.ixx.

97 [[nodiscard]] const SpawnCondition& spawnCondition() const noexcept {
98 return *spawnCondition_;
99 }

Referenced by SpawnRule.

spawnRuleId()

helios::engine::core::data::SpawnRuleId helios::engine::runtime::spawn::policy::SpawnRule::spawnRuleId ()
inline nodiscard noexcept

Returns the rule's unique identifier.

Returns

The SpawnRuleId.

Definition at line 131 of file SpawnRule.ixx.

132 return spawnRuleId_;
133 }

Referenced by SpawnRule.

Private Member Attributes

spawnAmountProvider_

std::unique_ptr<const amount::SpawnAmountProvider> helios::engine::runtime::spawn::policy::SpawnRule::spawnAmountProvider_

Provider that determines spawn quantity.

Definition at line 52 of file SpawnRule.ixx.

52 std::unique_ptr<const amount::SpawnAmountProvider> spawnAmountProvider_;

spawnCondition_

std::unique_ptr<const SpawnCondition> helios::engine::runtime::spawn::policy::SpawnRule::spawnCondition_

Condition that determines if spawning should occur.

Definition at line 57 of file SpawnRule.ixx.

57 std::unique_ptr<const SpawnCondition> spawnCondition_;

spawnRuleId_

const helios::engine::core::data::SpawnRuleId helios::engine::runtime::spawn::policy::SpawnRule::spawnRuleId_

Unique identifier for this rule.

Definition at line 62 of file SpawnRule.ixx.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.