Skip to main content

SpawnAmountByCallback.ixx File

Amount provider that delegates to a user-provided callback. 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...

namespaceamount

Spawn amount providers for determining spawn quantities. More...

Classes Index

classSpawnAmountByCallback

Amount provider that delegates to a user-provided callback. More...

Description

Amount provider that delegates to a user-provided callback.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file SpawnAmountByCallback.ixx
3 * @brief Amount provider that delegates to a user-provided callback.
4 */
5module;
6
7#include <functional>
8
9export module helios.engine.runtime.spawn.policy.amount.SpawnAmountByCallback;
10
11import helios.engine.core.data.GameObjectPoolId;
12import helios.engine.runtime.spawn.policy.amount.SpawnAmountProvider;
13import helios.engine.runtime.spawn.policy.SpawnRuleState;
14import helios.engine.runtime.world.UpdateContext;
15
17
18 /**
19 * @brief Amount provider that delegates to a user-provided callback.
20 *
21 * @details SpawnAmountByCallback allows dynamic spawn quantity calculation
22 * by delegating to a std::function. This enables complex logic based on
23 * game state, difficulty, pool availability, or other runtime factors.
24 *
25 * Example:
26 * ```cpp
27 * auto dynamicAmount = std::make_unique<SpawnAmountByCallback>(
28 * [&DIFFICULTY_LEVEL](const GameObjectPoolId& poolId, const SpawnRuleState& state,
29 * const UpdateContext& ctx) -> size_t {
30 * // Scale spawn count with difficulty
31 * return 2 * DIFFICULTY_LEVEL;
32 * }
33 * );
34 * ```
35 *
36 * @see SpawnAmountProvider
37 * @see FixedSpawnAmount
38 */
40
41 /**
42 * @brief Function signature for amount evaluation.
43 */
44 using AmountEvaluator = std::function<size_t(
46 const SpawnRuleState&,
48 )>;
49
50 /**
51 * @brief The callback function for calculating spawn amount.
52 */
53 AmountEvaluator evaluator_;
54
55 public:
56
57 /**
58 * @brief Constructs a SpawnAmountByCallback with the given evaluator.
59 *
60 * @param evaluator The callback function to calculate spawn amount.
61 */
62 explicit SpawnAmountByCallback(AmountEvaluator evaluator)
63 : evaluator_(std::move(evaluator)) {}
64
65 /**
66 * @brief Returns the spawn amount by invoking the callback.
67 *
68 * @param gameObjectPoolId The pool to spawn from.
69 * @param spawnRuleState The rule's runtime state.
70 * @param updateContext The current frame's context.
71 *
72 * @return The calculated spawn amount.
73 */
74 [[nodiscard]] size_t getAmount(
76 const SpawnRuleState& spawnRuleState,
78 ) const override {
79 return evaluator_(gameObjectPoolId, spawnRuleState, updateContext);
80 }
81
82 };
83
84
85}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.