Skip to main content

ResourceRegistry.ixx File

Type-indexed registry for engine resources with O(1) lookup. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespaceruntime

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

namespaceworld

World state management, resource registry, and per-frame update context. More...

Classes Index

classResourceRegistry

Unified type-indexed registry for all engine resources. More...

Description

Type-indexed registry for engine resources with O(1) lookup.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ResourceRegistry.ixx
3 * @brief Type-indexed registry for engine resources with O(1) lookup.
4 */
5module;
6
7#include <cassert>
8#include <memory>
9#include <span>
10#include <vector>
11
12export module helios.engine.runtime.world.ResourceRegistry;
13
14import helios.engine.runtime.world.Manager;
15
16import helios.core.memory.ErasedUnique;
17
18import helios.engine.runtime.messaging.command.CommandBuffer;
19import helios.engine.runtime.messaging.command.CommandBufferRegistry;
20import helios.engine.runtime.messaging.command.CommandHandlerRegistry;
21
22import helios.engine.runtime.world.ManagerRegistry;
23
24import helios.engine.common.concepts;
25
26import helios.engine.runtime.world.types;
27
30using namespace helios::core::memory;
32
33export namespace helios::engine::runtime::world {
34
35
36 /**
37 * @brief Unified type-indexed registry for all engine resources.
38 *
39 * @details ResourceRegistry acts as the central access point for Managers
40 * and CommandBuffers. It delegates to a ManagerRegistry and a
41 * CommandBufferRegistry internally, routing registration and lookup
42 * based on compile-time concept checks (IsManagerLike / IsCommandBufferLike).
43 *
44 * @see ManagerRegistry
45 * @see CommandBufferRegistry
46 * @see GameWorld
47 */
49
50 /**
51 * @brief Registry for Manager instances.
52 */
53 ManagerRegistry managerRegistry_;
54
55 /**
56 * @brief Registry for CommandBuffer instances.
57 */
58 CommandBufferRegistry commandBufferRegistry_;
59
60 public:
61
62 /**
63 * @brief Registers and constructs a resource of type T.
64 *
65 * @details Routes to ManagerRegistry or CommandBufferRegistry based
66 * on whether T satisfies IsManagerLike or IsCommandBufferLike. The resource
67 * is constructed in-place with forwarded arguments.
68 *
69 * @tparam T The resource type. Must satisfy IsManagerLike or IsCommandBufferLike.
70 * @tparam Args Constructor argument types.
71 *
72 * @param args Arguments forwarded to the T constructor.
73 *
74 * @return Reference to the newly registered resource.
75 */
76 template<class T, class... Args>
77 requires IsManagerLike<T> || IsCommandBufferLike<T>
78 T& emplace(Args&&... args) {
79
80 if constexpr (IsManagerLike<T>) {
81 return managerRegistry_.template add<T>(std::forward<Args>(args)...);
82 }
83
84 if constexpr (IsCommandBufferLike<T>) {
85 return commandBufferRegistry_.template add<T>(std::forward<Args>(args)...);
86 }
87
88 assert(false);
89 }
90
91 /**
92 * @brief Checks if a resource of type T is registered.
93 *
94 * @tparam T The resource type.
95 *
96 * @return True if the resource is registered.
97 */
98 template<class T>
99 bool has() const noexcept {
100 if constexpr (IsManagerLike<T>) {
101 return managerRegistry_.has<T>();
102 }
103
104 if constexpr (IsCommandBufferLike<T>) {
105 return commandBufferRegistry_.has<T>();
106 }
107
108 return false;
109 }
110
111 /**
112 * @brief Retrieves a registered resource by type.
113 *
114 * @tparam T The resource type.
115 *
116 * @return Pointer to the resource, or nullptr if not registered.
117 */
118 template<class T>
119 T* tryGet() const noexcept {
120 if constexpr (IsManagerLike<T>) {
121 return managerRegistry_.item<T>();
122 }
123
124 if constexpr (IsCommandBufferLike<T>) {
125 return commandBufferRegistry_.item<T>();
126 }
127
128 return nullptr;
129 }
130
131
132 /**
133 * @brief Retrieves a registered resource by type (checked).
134 *
135 * @details Asserts that the resource is registered before returning.
136 *
137 * @tparam T The resource type.
138 *
139 * @return Reference to the resource.
140 *
141 * @pre The resource must be registered.
142 */
143 template<class T>
144 T& get() const noexcept {
145 assert(has<T>() && "Resource not found");
146 if constexpr (IsManagerLike<T>) {
147 return *managerRegistry_.item<T>();
148 }
149
150 if constexpr (IsCommandBufferLike<T>) {
151 return *commandBufferRegistry_.item<T>();
152 }
153
154 assert(false);
155 }
156
157 /**
158 * @brief Returns a read-only span of all registered Managers.
159 *
160 * @return Span of Manager pointers in registration order.
161 */
162 [[nodiscard]] std::span<Manager* const> managers() const noexcept {
163 return managerRegistry_.items();
164 }
165
166 /**
167 * @copydoc managers() const
168 */
169 std::span<Manager*> managers() noexcept {
170 return managerRegistry_.items();
171 }
172
173 /**
174 * @brief Returns a read-only span of all registered CommandBuffers.
175 *
176 * @return Span of CommandBuffer pointers in registration order.
177 */
178 std::span<CommandBuffer* const> commandBuffers() const noexcept {
179 return commandBufferRegistry_.items();
180 }
181
182 /**
183 * @copydoc commandBuffers() const
184 */
185 std::span<CommandBuffer*> commandBuffers() noexcept {
186 return commandBufferRegistry_.items();
187 }
188 };
189}
190

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.