SpawnManager Class
Manager for processing spawn and despawn commands. More...
Declaration
Public Member Typedefs Index
| using | EngineRoleTag = helios::engine::common::tags::ManagerRole |
Public Constructors Index
| SpawnManager ()=default | |
|
Default constructor. More... | |
Public Member Functions Index
| bool | submit (const SpawnCommand command) noexcept |
|
Submits a spawn command for deferred processing. More... | |
| void | addScheduler (std::unique_ptr< helios::engine::runtime::spawn::scheduling::SpawnScheduler > scheduler) |
|
Adds a spawn scheduler to this manager. More... | |
| bool | submit (const DespawnCommand command) noexcept |
|
Submits a despawn command for deferred processing. More... | |
| bool | submit (const ScheduledSpawnPlanCommand scheduledSpawnPlanCommand) noexcept |
|
Submits a scheduled spawn plan command for deferred processing. More... | |
| void | flush (helios::engine::runtime::world::UpdateContext &updateContext) noexcept |
|
Flushes pending commands, processing despawns then spawns. More... | |
| SpawnManager & | addSpawnProfile (const SpawnProfileId &spawnProfileId, std::unique_ptr< const SpawnProfile > spawnProfile) |
|
Adds a spawn profile for a profile ID. More... | |
| const SpawnProfile * | spawnProfile (const SpawnProfileId &spawnProfileId) const |
|
Returns a spawn profile by ID. More... | |
| void | init (helios::engine::runtime::world::GameWorld &gameWorld) noexcept |
|
Initializes the manager with the game world. More... | |
| void | reset () |
|
Resets all schedulers, profiles, and pending commands. More... | |
| std::span< std::unique_ptr< helios::engine::runtime::spawn::scheduling::SpawnScheduler > > | spawnSchedulers () |
|
Returns a span of all registered spawn schedulers. More... | |
Private Member Functions Index
| void | ensureBounds (helios::engine::ecs::GameObject go, helios::math::aabbf &bounds) |
|
Ensures that the bounds are properly computed.. More... | |
| void | executeScheduledSpawnPlanCommands (std::span< ScheduledSpawnPlanCommand > commands, helios::engine::runtime::world::UpdateContext &updateContext) |
|
Processes scheduled spawn plan commands. More... | |
| void | spawnObjects (std::span< SpawnCommand > commands, helios::engine::runtime::world::UpdateContext &updateContext) |
|
Processes spawn commands, acquiring and initializing objects. More... | |
| void | despawnObjects (std::span< DespawnCommand > commands, helios::engine::runtime::world::UpdateContext &updateContext) |
|
Processes despawn commands, releasing objects back to pools. More... | |
Private Member Attributes Index
| std::vector< std::unique_ptr< helios::engine::runtime::spawn::scheduling::SpawnScheduler > > | spawnSchedulers_ |
|
Collection of schedulers that manage spawn rules and conditions. More... | |
| std::vector< SpawnCommand > | spawnCommands_ |
|
Queue of pending spawn commands. More... | |
| std::vector< DespawnCommand > | despawnCommands_ |
|
Queue of pending despawn commands. More... | |
| std::vector< ScheduledSpawnPlanCommand > | scheduledSpawnPlanCommands_ |
|
Queue of pending scheduled spawn plan commands. More... | |
| helios::engine::runtime::pooling::GameObjectPoolManager * | gameObjectPoolManager_ = nullptr |
|
Pointer to the pool manager for acquire/release operations. More... | |
| std::unordered_map< helios::engine::runtime::spawn::types::SpawnProfileId, std::unique_ptr< const SpawnProfile > > | spawnProfiles_ |
|
Map from profile IDs to their spawn profiles. More... | |
Description
Manager for processing spawn and despawn commands.
SpawnManager is a Manager that handles the lifecycle of pooled GameObjects. It receives commands via SpawnCommandHandler::submit() and queues them for deferred processing during the manager flush phase.
## Command Processing Order
During flush(), commands are processed in this order: 1. **Despawn commands** - Entities are returned to their pools 2. **Spawn commands** - Single entities are acquired and initialized 3. **Scheduled spawn plan commands** - Batch spawns from scheduler
## Spawn Profiles
Each spawn profile defines:
- Which pool to acquire entities from
- How to position spawned entities (SpawnPlacer)
- How to initialize spawned entities (SpawnInitializer)
## Integration
SpawnManager registers itself with the GameWorld for each profile ID, allowing commands to route to the correct handler.
Example: ```cpp auto spawnManager = std::make_unique<SpawnManager>();
spawnManager->addSpawnProfile(bulletProfileId, std::make_unique<SpawnProfile>( SpawnProfile{ .gameObjectPoolId = bulletPoolId, .spawnPlacer = std::make_unique<EmitterSpawnPlacer>(), .spawnInitializer = std::make_unique<EmitterInitializer>() } ));
gameWorld.addManager(std::move(spawnManager)); ```
- See Also
- See Also
- See Also
- See Also
- See Also
SpawnCommandHandler
Definition at line 105 of file SpawnManager.ixx.
Public Member Typedefs
EngineRoleTag
|
Definition at line 368 of file SpawnManager.ixx.
Public Constructors
SpawnManager()
| default |
Default constructor.
Definition at line 373 of file SpawnManager.ixx.
Referenced by addSpawnProfile.
Public Member Functions
addScheduler()
| inline |
Adds a spawn scheduler to this manager.
Schedulers evaluate spawn rules and produce spawn plans based on game conditions. Multiple schedulers can be added for different spawn categories.
- Parameters
-
scheduler The scheduler to add. Ownership is transferred.
Definition at line 396 of file SpawnManager.ixx.
addSpawnProfile()
| inline |
Adds a spawn profile for a profile ID.
Registers a spawn profile that defines how entities should be spawned for this profile. The profile contains the pool ID, placer, and initializer.
- Parameters
-
spawnProfileId The unique ID for this profile.
spawnProfile The profile configuration. Ownership transferred.
- Returns
Reference to this manager for chaining.
- Precondition
No profile is already registered for this ID.
Definition at line 467 of file SpawnManager.ixx.
References SpawnManager and spawnProfile.
flush()
| inline noexcept |
Flushes pending commands, processing despawns then spawns.
- Parameters
-
gameWorld The game world.
updateContext The current update context.
Definition at line 433 of file SpawnManager.ixx.
init()
| inline noexcept |
Initializes the manager with the game world.
Acquires a reference to the GameObjectPoolManager and registers this manager as the SpawnCommandHandler for all configured spawn profiles.
- Parameters
-
gameWorld The game world to initialize with.
Definition at line 504 of file SpawnManager.ixx.
reset()
| inline |
Resets all schedulers, profiles, and pending commands.
Called during level transitions or game restarts to clear all spawn state. Resets each scheduler, calls `onReset()` on all placers and initializers, and clears all pending command queues.
Definition at line 519 of file SpawnManager.ixx.
spawnProfile()
| inline nodiscard |
Returns a spawn profile by ID.
- Parameters
-
spawnProfileId The profile ID to look up.
- Returns
Pointer to the profile, or nullptr if not found.
Definition at line 485 of file SpawnManager.ixx.
Referenced by addSpawnProfile.
spawnSchedulers()
| inline |
Returns a span of all registered spawn schedulers.
- Returns
Span of spawn scheduler unique pointers.
Definition at line 541 of file SpawnManager.ixx.
submit()
| inline noexcept |
Submits a spawn command for deferred processing.
- Parameters
-
command The spawn command to queue.
- Returns
Always returns true.
Definition at line 382 of file SpawnManager.ixx.
submit()
| inline noexcept |
Submits a despawn command for deferred processing.
- Parameters
-
command The despawn command to queue.
- Returns
Always returns true.
Definition at line 407 of file SpawnManager.ixx.
submit()
| inline noexcept |
Submits a scheduled spawn plan command for deferred processing.
- Parameters
-
scheduledSpawnPlanCommand The scheduled plan command to queue.
- Returns
Always returns true.
Definition at line 420 of file SpawnManager.ixx.
Private Member Functions
despawnObjects()
| inline |
Processes despawn commands, releasing objects back to pools.
- Parameters
-
commands Span of despawn commands to process.
gameWorld The game world.
updateContext The current update context.
Definition at line 349 of file SpawnManager.ixx.
ensureBounds()
| inline |
Ensures that the bounds are properly computed..
Checks if the bounding box was initialized (i.e. has valid min/max values: min <= max). If the bounds are inverted (min > max), it recomputes the world AABB using the GameObject's components (ModelAabb, ScaleState, RotationState, SceneNode, TranslationState).
- Parameters
-
go The GameObject to compute bounds for.
bounds The bounding box to check and potentially update.
Definition at line 159 of file SpawnManager.ixx.
executeScheduledSpawnPlanCommands()
| inline |
Processes scheduled spawn plan commands.
Iterates through each plan, acquires entities from the pool, positions them using the profile's placer, initializes them using the profile's initializer, and pushes a frame event for confirmation.
- Parameters
-
commands Span of scheduled spawn plan commands to process.
gameWorld The game world.
updateContext The current update context.
Definition at line 185 of file SpawnManager.ixx.
spawnObjects()
| inline |
Processes spawn commands, acquiring and initializing objects.
- Parameters
-
commands Span of spawn commands to process.
gameWorld The game world.
updateContext The current update context.
Definition at line 278 of file SpawnManager.ixx.
Private Member Attributes
despawnCommands_
|
Queue of pending despawn commands.
Definition at line 126 of file SpawnManager.ixx.
gameObjectPoolManager_
|
Pointer to the pool manager for acquire/release operations.
Definition at line 136 of file SpawnManager.ixx.
scheduledSpawnPlanCommands_
|
Queue of pending scheduled spawn plan commands.
Definition at line 131 of file SpawnManager.ixx.
spawnCommands_
|
Queue of pending spawn commands.
Definition at line 121 of file SpawnManager.ixx.
spawnProfiles_
|
Map from profile IDs to their spawn profiles.
Definition at line 143 of file SpawnManager.ixx.
spawnSchedulers_
|
Collection of schedulers that manage spawn rules and conditions.
Each scheduler owns and evaluates its registered spawn rules independently. When conditions are met, the scheduler produces ScheduledSpawnPlan instances for execution. Multiple schedulers allow grouping spawn rules by category (e.g., enemies, powerups, projectiles).
Definition at line 116 of file SpawnManager.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.