Skip to main content

CallbackSpawnStrategy Class

A SpawnStrategy that delegates spawning logic to a callback function. More...

Declaration

class helios::engine::mechanics::spawn::logic::CallbackSpawnStrategy { ... }

Base class

classSpawnStrategy

Abstract base class defining how GameObjects are spawned. More...

Private Member Typedefs Index

usingSpawnFunction = 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

boolspawn (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

SpawnFunctionspawnFunction_

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

SpawnStrategy

See Also

GameObjectSpawnSystem

Definition at line 49 of file CallbackSpawnStrategy.ixx.

Private Member Typedefs

SpawnFunction

using helios::engine::mechanics::spawn::logic::CallbackSpawnStrategy::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.

Must not throw

Definition at line 56 of file CallbackSpawnStrategy.ixx.

56 using SpawnFunction = std::function<bool(

Public Constructors

CallbackSpawnStrategy()

helios::engine::mechanics::spawn::logic::CallbackSpawnStrategy::CallbackSpawnStrategy (SpawnFunction spawnFunction)
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.

74 explicit CallbackSpawnStrategy(SpawnFunction spawnFunction) noexcept :
75 spawnFunction_(std::move(spawnFunction)) {}

Public Member Functions

spawn()

bool helios::engine::mechanics::spawn::logic::CallbackSpawnStrategy::spawn (const helios::engine::runtime::world::GameWorld & gameWorld, helios::engine::ecs::GameObject & gameObject, const helios::engine::runtime::world::UpdateContext & updateContext)
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.

88 [[nodiscard]] bool spawn(
92 ) noexcept override {
93 return spawnFunction_(gameWorld, gameObject, updateContext);
94 }

Private Member Attributes

spawnFunction_

SpawnFunction helios::engine::mechanics::spawn::logic::CallbackSpawnStrategy::spawnFunction_

The user-provided spawn callback function.

Definition at line 64 of file CallbackSpawnStrategy.ixx.

64 SpawnFunction spawnFunction_;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.