Skip to main content

SpawnCommandHandlerRegistry.ixx File

Registry mapping spawn profile IDs to their command handlers. More...

Included Headers

#include <cassert> #include <unordered_map> #include <vector> #include <helios.engine.core.data.SpawnProfileId> #include <helios.engine.runtime.spawn.SpawnCommandHandler>

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...

Classes Index

classSpawnCommandHandlerRegistry

Registry that maps SpawnProfileIds to their SpawnCommandHandlers. More...

Description

Registry mapping spawn profile IDs to their command handlers.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file SpawnCommandHandlerRegistry.ixx
3 * @brief Registry mapping spawn profile IDs to their command handlers.
4 */
5module;
6
7#include <cassert>
8#include <unordered_map>
9#include <vector>
10
11export module helios.engine.runtime.spawn.SpawnCommandHandlerRegistry;
12
13import helios.engine.runtime.spawn.SpawnCommandHandler;
14import helios.engine.core.data.SpawnProfileId;
15
16
17export namespace helios::engine::runtime::spawn {
18
19
20 /**
21 * @brief Registry that maps SpawnProfileIds to their SpawnCommandHandlers.
22 *
23 * @details SpawnCommandHandlerRegistry provides lookup from spawn profile IDs
24 * to the handlers responsible for processing spawn and despawn commands for
25 * those profiles. This enables the spawn/despawn system to route commands to
26 * the correct manager without direct coupling.
27 *
28 * The registry is owned by the GameWorld and populated during manager
29 * initialization.
30 *
31 * @note Uses amortized O(1) lookup via std::unordered_map.
32 *
33 * @see SpawnCommandHandler
34 * @see SpawnProfileId
35 * @see GameWorld::registerSpawnCommandHandler
36 */
38
39 protected:
40
41 /**
42 * @brief Map from spawn profile IDs to their handlers.
43 *
44 * @details Stores non-owning pointers to handlers. Handlers must outlive
45 * this registry.
46 */
47 std::unordered_map<
50
51
52 public:
53
55
56 /**
57 * @brief Registers a handler for a spawn profile ID.
58 *
59 * @param spawnProfileId The spawn profile ID to register.
60 * @param poolManager The handler to associate with the pool.
61 *
62 * @return True if registration succeeded, false if the ID was already registered.
63 */
64 [[nodiscard]] bool add(
67 ) {
68 if (registry_.contains(spawnProfileId)) {
69 return false;
70 }
71
72 registry_[spawnProfileId] = &poolManager;
73
74 return true;
75 }
76
77 /**
78 * @brief Retrieves the handler for a spawn profile ID.
79 *
80 * @param spawnProfileId The spawn profile ID to look up.
81 *
82 * @return Pointer to the handler if found, nullptr otherwise.
83 */
86 auto it = registry_.find(spawnProfileId);
87
88 if (it == registry_.end()) {
89 return nullptr;
90 }
91
92 return it->second;
93 }
94 };
95
96
97}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.