Skip to main content

RequestedAmountIsAvailableCondition.ixx File

Spawn condition checking pool availability for requested amount. 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...

namespaceconditions

Spawn conditions for controlling spawn timing. More...

Classes Index

classRequestedAmountIsAvailableCondition

Condition verifying the pool has enough inactive entities. More...

Description

Spawn condition checking pool availability for requested amount.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file RequestedAmountIsAvailableCondition.ixx
3 * @brief Spawn condition checking pool availability for requested amount.
4 */
5module;
6
7#include <cassert>
8
9export module helios.engine.runtime.spawn.policy.conditions.RequestedAmountIsAvailableCondition;
10
11import helios.engine.runtime.spawn.policy.SpawnCondition;
12import helios.engine.runtime.spawn.policy.SpawnRuleState;
13import helios.engine.runtime.pooling.GameObjectPoolSnapshot;
14import helios.engine.runtime.world.UpdateContext;
15
17
18 /**
19 * @brief Condition verifying the pool has enough inactive entities.
20 *
21 * @details RequestedAmountIsAvailableCondition checks whether the entity
22 * pool contains at least as many inactive (recyclable) entities as the
23 * spawn request requires. This prevents spawn failures due to pool
24 * exhaustion.
25 *
26 * ## Behavior
27 *
28 * - Returns `true` if `requestedAmount <= poolSnapshot.inactiveCount`
29 * - Resets the spawn timer on commit (via `setSinceLastSpawn(0)`)
30 *
31 * ## Usage
32 *
33 * ```cpp
34 * auto condition = std::make_unique<RequestedAmountIsAvailableCondition>();
35 *
36 * // Often combined with other conditions
37 * auto combined = std::make_unique<SpawnConditionAll>(
38 * std::make_unique<TimerCondition>(2.0f),
39 * std::make_unique<RequestedAmountIsAvailableCondition>()
40 * );
41 * ```
42 *
43 * @see SpawnCondition
44 * @see SpawnConditionAll
45 * @see GameObjectPoolSnapshot
46 */
48
49 public:
50
51 /**
52 * @brief Checks if the pool has enough inactive entities.
53 *
54 * @param requestedAmount Number of entities requested for spawn.
55 * @param spawnState Current state of the spawn rule (unused).
56 * @param poolSnapshot Snapshot containing pool availability info.
57 * @param updateContext Current frame context (unused).
58 *
59 * @return `true` if inactive count >= requested amount.
60 */
61 [[nodiscard]] bool isSatisfied(
62 const size_t requestedAmount,
63 const SpawnRuleState& spawnState,
66 ) const noexcept override {
67 return requestedAmount <= poolSnapshot.inactiveCount;
68 }
69
70 /**
71 * @brief Resets the spawn timer after a successful spawn.
72 *
73 * @details Sets `sinceLastSpawn` to zero, restarting the timer for
74 * conditions that depend on spawn intervals.
75 *
76 * @param spawnRuleState The rule's runtime state to update.
77 * @param spawnAmount The number of entities that were spawned (unused).
78 */
79 void onCommit(
80 SpawnRuleState& spawnRuleState,
81 const size_t spawnAmount
82 ) const override {
83 spawnRuleState.setSinceLastSpawn(0.0f);
84 }
85
86 /**
87 * @brief Resets the spawn timer.
88 *
89 * @param spawnRuleState The rule's runtime state to reset.
90 */
91 void onReset(
92 SpawnRuleState& spawnRuleState
93 ) const noexcept override {
94 spawnRuleState.setSinceLastSpawn(0.0f);
95 }
96
97 };
98
99}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.