Skip to main content

SpawnRule.ixx File

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

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespaceruntime

Runtime infrastructure for game execution and lifecycle orchestration. More...

namespacespawn

Entity spawning infrastructure for the helios engine. More...

namespacepolicy

Spawn rules, conditions, and amount providers. More...

Classes Index

classSpawnRule

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

Description

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

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file SpawnRule.ixx
3 * @brief Combines a condition and amount provider into a complete spawn rule.
4 */
5module;
6
7#include <memory>
8
9export module helios.engine.runtime.spawn.policy.SpawnRule;
10
11import helios.engine.runtime.spawn.policy.SpawnCondition;
12import helios.engine.runtime.spawn.policy.amount.SpawnAmountProvider;
13import helios.engine.runtime.spawn.policy.SpawnRuleState;
14import helios.engine.runtime.spawn.scheduling.SpawnPlan;
15import helios.engine.runtime.pooling.GameObjectPoolSnapshot;
16import helios.engine.runtime.world;
17import helios.engine.runtime.pooling.types.GameObjectPoolId;
18import helios.engine.runtime.spawn.types.SpawnRuleId;
19
21
22 /**
23 * @brief Combines a condition and amount provider into a complete spawn rule.
24 *
25 * @details SpawnRule encapsulates the logic for when and how many entities
26 * to spawn. It combines:
27 *
28 * - **SpawnCondition:** Determines if spawning should occur
29 * - **SpawnAmountProvider:** Determines how many to spawn
30 *
31 * The SpawnScheduler evaluates rules each frame and creates SpawnPlans
32 * for rules whose conditions are satisfied.
33 *
34 * Example:
35 * ```cpp
36 * auto rule = std::make_unique<SpawnRule>(
37 * std::make_unique<TimerSpawnCondition>(2.0f),
38 * std::make_unique<FixedSpawnAmount>(3),
39 * SpawnRuleId{1}
40 * );
41 * ```
42 *
43 * @see SpawnCondition
44 * @see SpawnAmountProvider
45 * @see SpawnScheduler
46 */
47 class SpawnRule {
48
49 /**
50 * @brief Provider that determines spawn quantity.
51 */
52 std::unique_ptr<const amount::SpawnAmountProvider> spawnAmountProvider_;
53
54 /**
55 * @brief Condition that determines if spawning should occur.
56 */
57 std::unique_ptr<const SpawnCondition> spawnCondition_;
58
59 /**
60 * @brief Unique identifier for this rule.
61 */
63
64 public:
65
66 /**
67 * @brief Constructs a SpawnRule with condition, amount provider, and ID.
68 *
69 * @param spawnCondition Condition determining when to spawn.
70 * @param spawnAmountProvider Provider determining how many to spawn.
71 * @param spawnRuleId Unique identifier for this rule.
72 */
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) {}
81
82 /**
83 * @brief Commits a completed spawn to update rule state.
84 *
85 * @param spawnRuleState The state to update.
86 * @param spawnAmount The number of entities spawned.
87 */
88 void commit(SpawnRuleState& spawnRuleState, const size_t spawnAmount) const {
89 spawnCondition_->onCommit(spawnRuleState, spawnAmount);
90 }
91
92 /**
93 * @brief Resets the rule's condition state.
94 *
95 * @param spawnRuleState The state to reset.
96 */
97 void reset(SpawnRuleState& spawnRuleState) const{
98 spawnCondition_->onReset(spawnRuleState);
99 }
100
101 /**
102 * @brief Returns the spawn condition.
103 *
104 * @return Reference to the spawn condition.
105 */
106 [[nodiscard]] const SpawnCondition& spawnCondition() const noexcept {
107 return *spawnCondition_;
108 }
109
110 /**
111 * @brief Evaluates the rule and returns a spawn plan.
112 *
113 * @param gameObjectPoolId The pool to spawn from.
114 * @param poolSnapshot Current pool state.
115 * @param spawnRuleState The rule's runtime state.
116 * @param gameWorld The game world where the spawn plan is executed.
117 * @param updateContext The current frame's context.
118 *
119 * @return A SpawnPlan with amount > 0 if condition satisfied, 0 otherwise.
120 */
124 const SpawnRuleState& spawnRuleState,
127 ) {
128 auto amount = spawnAmountProvider_->getAmount(gameObjectPoolId, spawnRuleState, gameWorld, updateContext);
129
130 if (spawnCondition_->isSatisfied(amount, spawnRuleState, poolSnapshot, updateContext)) {
132 }
133
135 }
136
137 /**
138 * @brief Returns the rule's unique identifier.
139 *
140 * @return The SpawnRuleId.
141 */
143 return spawnRuleId_;
144 }
145
146 };
147
148}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.