Skip to main content

GameObjectPoolRegistry.ixx File

Central registry for managing multiple GameObjectPool instances. More...

Included Headers

#include <memory> #include <unordered_map> #include <ranges> #include <helios.engine.runtime.pooling.types.GameObjectPoolId> #include <helios.engine.runtime.pooling.GameObjectPool>

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespaceruntime

Runtime infrastructure for game execution and lifecycle orchestration. More...

namespacepooling

GameObject pooling for efficient object recycling. More...

Classes Index

classGameObjectPoolRegistry

Central registry for managing multiple named GameObjectPools. More...

Description

Central registry for managing multiple GameObjectPool instances.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file GameObjectPoolRegistry.ixx
3 * @brief Central registry for managing multiple GameObjectPool instances.
4 */
5module;
6
7#include <memory>
8#include <unordered_map>
9#include <ranges>
10
11export module helios.engine.runtime.pooling.GameObjectPoolRegistry;
12
13
14import helios.engine.runtime.pooling.GameObjectPool;
15import helios.engine.runtime.pooling.types.GameObjectPoolId;
16
17
19
20 /**
21 * @brief Central registry for managing multiple named GameObjectPools.
22 *
23 * @details GameObjectPoolRegistry provides a single point of access to all object
24 * pools in the game. Each pool is identified by a strongly-typed GameObjectPoolId,
25 * enabling type-safe lookup without string comparisons.
26 *
27 * The registry owns all pools exclusively via unique_ptr, ensuring proper cleanup
28 * when the registry is destroyed.
29 *
30 * Example usage:
31 * ```cpp
32 * GameObjectPoolRegistry registry;
33 *
34 * constexpr GameObjectPoolId BULLET_POOL{1};
35 * registry.addPool(BULLET_POOL, std::make_unique<GameObjectPool>(100));
36 *
37 * // Later, acquire a bullet from the pool
38 * auto* pool = registry.pool(BULLET_POOL);
39 * helios::util::Guid bulletGuid;
40 * if (pool && pool->acquire(bulletGuid)) {
41 * // Use the bullet
42 * }
43 * ```
44 */
46
47 private:
48
49 /**
50 * @brief Maps pool IDs to their corresponding GameObjectPool instances.
51 */
52 std::unordered_map<helios::engine::runtime::pooling::types::GameObjectPoolId, std::unique_ptr<GameObjectPool>> pools_;
53
54 public:
55
56 /**
57 * @brief Default constructor.
58 */
60
61 /**
62 * @brief Adds a new pool to the registry.
63 *
64 * @details If a pool with the given ID already exists, it will be replaced.
65 * Ownership of the pool is transferred to the registry.
66 *
67 * @param id The unique identifier for this pool.
68 * @param gameObjectPool The pool to add (ownership is transferred).
69 *
70 * @return Raw pointer to the added pool for immediate use.
71 */
74 std::unique_ptr<GameObjectPool> gameObjectPool
75 ) noexcept {
76 pools_[id] = std::move(gameObjectPool);
77 return pools_[id].get();
78 }
79
80 /**
81 * @brief Returns a reference to the internal pool map.
82 *
83 * @details Provides direct access to all pools for iteration or bulk operations.
84 * The returned map should not be modified directly; use `addPool()` instead.
85 *
86 * @return Reference to the pool map.
87 */
88 [[nodiscard]]std::unordered_map<helios::engine::runtime::pooling::types::GameObjectPoolId, std::unique_ptr<GameObjectPool>>& pools() {
89 return pools_;
90 }
91
92
93 /**
94 * @brief Retrieves a pool by its ID.
95 *
96 * @param id The identifier of the pool to retrieve.
97 *
98 * @return Pointer to the pool, or nullptr if not found.
99 */
101
102 const auto& it = pools_.find(id);
103
104 if (it == pools_.end()) {
105 return nullptr;
106 }
107
108 return it->second.get();
109 }
110
111 /**
112 * @brief Checks if a pool with the given ID is registered.
113 *
114 * @param id The identifier of the pool to check.
115 *
116 * @return True if the pool exists, false otherwise.
117 */
118 [[nodiscard]] bool has(const helios::engine::runtime::pooling::types::GameObjectPoolId id) const noexcept {
119 return pools_.contains(id);
120 }
121
122
123 };
124
125}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.