Skip to main content

SpawnConditionAll.ixx File

Composite condition that requires all child conditions to be satisfied. 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

classSpawnConditionAll

Composite condition requiring all child conditions to pass. More...

Description

Composite condition that requires all child conditions to be satisfied.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file SpawnConditionAll.ixx
3 * @brief Composite condition that requires all child conditions to be satisfied.
4 */
5module;
6
7#include <memory>
8#include <vector>
9
10
11export module helios.engine.runtime.spawn.policy.SpawnConditionAll;
12
13import helios.engine.runtime.spawn.policy.SpawnCondition;
14
15import helios.engine.runtime.spawn.policy.SpawnRuleState;
16import helios.engine.runtime.pooling.GameObjectPoolSnapshot;
17import helios.engine.runtime.world.UpdateContext;
18
19
21
22 /**
23 * @brief Composite condition requiring all child conditions to pass.
24 *
25 * @details SpawnConditionAll implements a logical AND over multiple
26 * SpawnCondition instances. The spawn is permitted only when every
27 * child condition returns `true` from `isSatisfied()`.
28 *
29 * ## Behavior
30 *
31 * - Short-circuits on first failing condition
32 * - Propagates `onCommit()` to all child conditions
33 * - Accepts variadic condition arguments via constructor
34 *
35 * ## Usage
36 *
37 * ```cpp
38 * auto condition = std::make_unique<SpawnConditionAll>(
39 * std::make_unique<TimerCondition>(2.0f),
40 * std::make_unique<RequestedAmountIsAvailableCondition>(),
41 * std::make_unique<MaxActiveCondition>(10)
42 * );
43 *
44 * // Spawns only when: timer elapsed AND pool available AND under max
45 * ```
46 *
47 * @see SpawnCondition
48 * @see TimerCondition
49 * @see RequestedAmountIsAvailableCondition
50 */
52
53 /**
54 * @brief Collection of child conditions to evaluate.
55 */
56 std::vector<std::unique_ptr<helios::engine::runtime::spawn::policy::SpawnCondition>> spawnConditions_;
57
58 public:
59
60 /**
61 * @brief Constructs a composite condition from variadic arguments.
62 *
63 * @tparam Args Types of spawn conditions (must be unique_ptr<SpawnCondition>).
64 *
65 * @param args Spawn conditions to combine. Ownership transferred.
66 */
67 template<typename... Args>
68 explicit SpawnConditionAll(Args&&... args) {
69
70 spawnConditions_.reserve(10);
71
72 (spawnConditions_.push_back(std::forward<Args>(args)), ...);
73
74 }
75
76 /**
77 * @brief Checks if all child conditions are satisfied.
78 *
79 * @details Iterates through all conditions and returns `false` on the
80 * first condition that fails (short-circuit evaluation).
81 *
82 * @param requestedAmount Number of entities requested for spawn.
83 * @param spawnState Current state of the spawn rule.
84 * @param poolSnapshot Snapshot of the entity pool.
85 * @param updateContext Current frame context.
86 *
87 * @return `true` if all conditions pass, `false` otherwise.
88 */
89 [[nodiscard]] bool isSatisfied(
90 const size_t requestedAmount,
91 const SpawnRuleState& spawnState,
94 ) const noexcept override {
95
96
97 for (auto& condition : spawnConditions_) {
98 if (!condition->isSatisfied(requestedAmount, spawnState, poolSnapshot, updateContext)) {
99 return false;
100 }
101 }
102
103 return true;
104
105 };
106
107 /**
108 * @brief Propagates commit to all child conditions.
109 *
110 * @details Calls `onCommit()` on each child condition to allow them
111 * to update their internal state after a successful spawn.
112 *
113 * @param spawnRuleState The rule's runtime state to update.
114 * @param spawnAmount The number of entities that were spawned.
115 */
117 SpawnRuleState& spawnRuleState,
118 const size_t spawnAmount
119 ) const override {
120 for (auto& condition : spawnConditions_) {
121 condition->onCommit(spawnRuleState, spawnAmount);
122 }
123
124 }
125
126
127 };
128
129}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.