CallbackSpawnStrategy Class
A SpawnStrategy that delegates spawning logic to a callback function. More...
Declaration
Base class
| class | SpawnStrategy |
|
Abstract base class defining how GameObjects are spawned. More... | |
Private Member Typedefs Index
| using | SpawnFunction = std::function< bool( const helios::engine::runtime::world::GameWorld &, helios::engine::ecs::GameObject &, const helios::engine::runtime::world::UpdateContext &)> |
|
Function signature for the spawn callback. More... | |
Public Constructors Index
| CallbackSpawnStrategy (SpawnFunction spawnFunction) noexcept | |
|
Constructs a CallbackSpawnStrategy with the given spawn function. More... | |
Public Member Functions Index
| bool | spawn (const helios::engine::runtime::world::GameWorld &gameWorld, helios::engine::ecs::GameObject &gameObject, const helios::engine::runtime::world::UpdateContext &updateContext) noexcept override |
|
Spawns a GameObject by invoking the stored callback function. More... | |
Private Member Attributes Index
| SpawnFunction | spawnFunction_ |
|
The user-provided spawn callback function. More... | |
Description
A SpawnStrategy that delegates spawning logic to a callback function.
CallbackSpawnStrategy provides a lightweight way to define custom spawn behavior without creating a dedicated subclass. The spawn logic is encapsulated in a `std::function` passed at construction time.
Useful for simple or one-off spawn configurations, rapid prototyping, or when the spawn logic is defined dynamically.
Example usage: ```cpp auto strategy = std::make_unique<CallbackSpawnStrategy>( [](const GameWorld*, const Level* level, GameObject* obj, const UpdateContext&) { auto rng = helios::util::Random(1234); float x = rng.randomFloat(-10.0f, 10.0f); float y = rng.randomFloat(-10.0f, 10.0f); obj->get<TransformComponent>()->setTranslation({x, y, 0}); return true; } ); ```
- See Also
- See Also
GameObjectSpawnSystem
Definition at line 49 of file CallbackSpawnStrategy.ixx.
Private Member Typedefs
SpawnFunction
|
Function signature for the spawn callback.
Must not throw
Definition at line 56 of file CallbackSpawnStrategy.ixx.
Public Constructors
CallbackSpawnStrategy()
| inline explicit noexcept |
Constructs a CallbackSpawnStrategy with the given spawn function.
- Parameters
-
spawnFunction The callback function to invoke during spawning. Must be a valid, noexcept callable.
Definition at line 74 of file CallbackSpawnStrategy.ixx.
Public Member Functions
spawn()
| inline nodiscard noexcept virtual |
Spawns a GameObject by invoking the stored callback function.
- Parameters
-
gameWorld Pointer to the current GameWorld. May be nullptr.
level Pointer to the current Level containing bounds and spawn info.
gameObject Pointer to the GameObject being spawned.
updateContext The current frame's update context.
- Returns
The result of the callback function. True if spawning succeeded, false if the object should be returned to the pool.
Definition at line 88 of file CallbackSpawnStrategy.ixx.
Private Member Attributes
spawnFunction_
|
The user-provided spawn callback function.
Definition at line 64 of file CallbackSpawnStrategy.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.