Skip to main content

ResourceRegistry.ixx File

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

Included Headers

Namespaces Index

namespacehelios
namespaceengine
namespaceruntime
namespaceworld

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
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.engine.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.runtime.world.concepts;
25import helios.engine.runtime.messaging.command.concepts;
26import helios.engine.runtime.world.types;
27
29using namespace helios::engine::runtime::messaging::command::concepts;
31using namespace helios::engine::core::memory;
32using namespace helios::engine::runtime::world::concepts;
33using namespace helios::engine::runtime::messaging::command::concepts;
34export namespace helios::engine::runtime::world {
35
36
50
54 ManagerRegistry managerRegistry_;
55
59 CommandBufferRegistry commandBufferRegistry_;
60
61 public:
62
77 template<class T, class... Args>
79 T& emplace(Args&&... args) {
80
81 if constexpr (IsManagerLike<T>) {
82 return managerRegistry_.template add<T>(std::forward<Args>(args)...);
83 }
84
85 if constexpr (IsCommandBufferLike<T>) {
86 return commandBufferRegistry_.template add<T>(std::forward<Args>(args)...);
87 }
88
89 assert(false);
90 }
91
99 template<class T>
101 if constexpr (IsManagerLike<T>) {
102 return managerRegistry_.has<T>();
103 }
104
105 if constexpr (IsCommandBufferLike<T>) {
106 return commandBufferRegistry_.has<T>();
107 }
108
109 return false;
110 }
111
119 template<class T>
121 if constexpr (IsManagerLike<T>) {
122 return managerRegistry_.item<T>();
123 }
124
125 if constexpr (IsCommandBufferLike<T>) {
126 return commandBufferRegistry_.item<T>();
127 }
128
129 return nullptr;
130 }
131
132
144 template<class T>
146 assert(has<T>() && "Resource not found");
147 if constexpr (IsManagerLike<T>) {
148 return *managerRegistry_.item<T>();
149 }
150
151 if constexpr (IsCommandBufferLike<T>) {
152 return *commandBufferRegistry_.item<T>();
153 }
154
155 assert(false);
156 }
157
163 [[nodiscard]] std::span<Manager* const> managers() const noexcept {
164 return managerRegistry_.items();
165 }
166
170 std::span<Manager*> managers() noexcept {
171 return managerRegistry_.items();
172 }
173
179 std::span<CommandBuffer* const> commandBuffers() const noexcept {
180 return commandBufferRegistry_.items();
181 }
182
186 std::span<CommandBuffer*> commandBuffers() noexcept {
187 return commandBufferRegistry_.items();
188 }
189
196 return commandBufferRegistry_;
197 }
198 };
199}
200

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.