SpawnManager Class
Manager for processing spawn and despawn commands. More...
Declaration
Base classes
| class | Manager |
|
Abstract base class for managers that process deferred operations. More... | |
| class | SpawnCommandHandler |
|
Interface for handlers that process spawn and despawn commands. More... | |
Public Constructors Index
| SpawnManager ()=default | |
|
Default constructor. More... | |
Public Member Functions Index
| bool | submit (const helios::engine::runtime::spawn::commands::SpawnCommand &command) noexcept override |
|
Submits a spawn command for deferred processing. More... | |
| bool | submit (const helios::engine::runtime::spawn::commands::DespawnCommand &command) noexcept override |
|
Submits a despawn command for deferred processing. More... | |
| bool | submit (const helios::engine::runtime::spawn::commands::ScheduledSpawnPlanCommand &scheduledSpawnPlanCommand) noexcept override |
|
Submits a scheduled spawn plan command for deferred processing. More... | |
| void | flush (helios::engine::runtime::world::GameWorld &gameWorld, helios::engine::runtime::world::UpdateContext &updateContext) noexcept override |
|
Flushes pending commands, processing despawns then spawns. More... | |
| SpawnManager & | addSpawnProfile (const helios::engine::core::data::SpawnProfileId &spawnProfileId, std::unique_ptr< const helios::engine::runtime::spawn::SpawnProfile > spawnProfile) |
|
Adds a spawn profile for a profile ID. More... | |
| const helios::engine::runtime::spawn::SpawnProfile * | spawnProfile (const helios::engine::core::data::SpawnProfileId &spawnProfileId) const |
|
Returns a spawn profile by ID. More... | |
| void | init (helios::engine::runtime::world::GameWorld &gameWorld) noexcept override |
|
Initializes the manager with the game world. 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< helios::engine::runtime::spawn::commands::ScheduledSpawnPlanCommand > commands, helios::engine::runtime::world::GameWorld &gameWorld, helios::engine::runtime::world::UpdateContext &updateContext) |
|
Processes scheduled spawn plan commands. More... | |
| void | spawnObjects (std::span< helios::engine::runtime::spawn::commands::SpawnCommand > commands, helios::engine::runtime::world::GameWorld &gameWorld, helios::engine::runtime::world::UpdateContext &updateContext) |
|
Processes spawn commands, acquiring and initializing objects. More... | |
| void | despawnObjects (std::span< helios::engine::runtime::spawn::commands::DespawnCommand > commands, helios::engine::runtime::world::GameWorld &gameWorld, helios::engine::runtime::world::UpdateContext &updateContext) |
|
Processes despawn commands, releasing objects back to pools. More... | |
Private Member Attributes Index
| std::vector< helios::engine::runtime::spawn::commands::SpawnCommand > | spawnCommands_ |
|
Queue of pending spawn commands. More... | |
| std::vector< helios::engine::runtime::spawn::commands::DespawnCommand > | despawnCommands_ |
|
Queue of pending despawn commands. More... | |
| std::vector< helios::engine::runtime::spawn::commands::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::core::data::SpawnProfileId, std::unique_ptr< const helios::engine::runtime::spawn::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
SpawnCommand
- See Also
DespawnCommand
- See Also
ScheduledSpawnPlanCommand
- See Also
- See Also
Definition at line 96 of file SpawnManager.ixx.
Public Constructors
SpawnManager()
| default |
Default constructor.
Definition at line 356 of file SpawnManager.ixx.
Referenced by addSpawnProfile.
Public Member Functions
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 438 of file SpawnManager.ixx.
References SpawnManager and spawnProfile.
flush()
| inline noexcept virtual |
Flushes pending commands, processing despawns then spawns.
- Parameters
-
gameWorld The game world.
updateContext The current update context.
Definition at line 403 of file SpawnManager.ixx.
init()
| inline noexcept virtual |
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 475 of file SpawnManager.ixx.
References helios::engine::runtime::world::GameWorld::getManager and helios::engine::runtime::world::GameWorld::registerSpawnCommandHandler.
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 456 of file SpawnManager.ixx.
Referenced by addSpawnProfile.
submit()
| inline noexcept virtual |
Submits a spawn command for deferred processing.
- Parameters
-
command The spawn command to queue.
- Returns
Always returns true.
Definition at line 365 of file SpawnManager.ixx.
submit()
| inline noexcept virtual |
Submits a despawn command for deferred processing.
- Parameters
-
command The despawn command to queue.
- Returns
Always returns true.
Definition at line 377 of file SpawnManager.ixx.
submit()
| inline noexcept virtual |
Submits a scheduled spawn plan command for deferred processing.
- Parameters
-
scheduledSpawnPlanCommand The scheduled plan command to queue.
- Returns
Always returns true.
Definition at line 390 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 332 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 140 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 166 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 260 of file SpawnManager.ixx.
Private Member Attributes
despawnCommands_
|
Queue of pending despawn commands.
Definition at line 107 of file SpawnManager.ixx.
gameObjectPoolManager_
|
Pointer to the pool manager for acquire/release operations.
Definition at line 117 of file SpawnManager.ixx.
scheduledSpawnPlanCommands_
|
Queue of pending scheduled spawn plan commands.
Definition at line 112 of file SpawnManager.ixx.
spawnCommands_
|
Queue of pending spawn commands.
Definition at line 102 of file SpawnManager.ixx.
spawnProfiles_
|
Map from profile IDs to their spawn profiles.
Definition at line 124 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.