2#ifndef LIBSBX_SCENES_ASSET_REGISTRY_HPP_
3#define LIBSBX_SCENES_ASSET_REGISTRY_HPP_
5#include <unordered_map>
8#include <libsbx/utility/hashed_string.hpp>
9#include <libsbx/utility/exception.hpp>
11#include <libsbx/math/uuid.hpp>
13#include <libsbx/core/engine.hpp>
15#include <libsbx/assets/assets_module.hpp>
17#include <libsbx/graphics/graphics_module.hpp>
18#include <libsbx/graphics/images/image2d.hpp>
19#include <libsbx/graphics/images/cube_image.hpp>
21namespace sbx::scenes {
24 std::filesystem::path path;
26 std::string type{
"unknown"};
27 std::string source{
"dynamic"};
30template<
typename Handle>
36 return _by_name.contains(name);
40 if (
auto entry = _by_name.find(name); entry != _by_name.end()) {
48 if (_by_name.contains(name)) {
52 _by_name.emplace(name, handle);
53 _metadata.emplace(handle, std::move(metadata));
58 auto metadata(
const Handle& handle)
const ->
const asset_metadata& {
59 return _metadata.at(handle);
62 auto size()
const -> std::size_t {
63 return _by_name.size();
67 return _metadata.begin();
71 return _metadata.end();
76 std::unordered_map<utility::hashed_string, Handle> _by_name;
77 std::unordered_map<Handle, asset_metadata> _metadata;
85 template<
typename... Args>
87 if (_images.has(name)) {
88 return _images.get(name);
91 auto& gfx = core::engine::get_module<graphics::graphics_module>();
93 const auto handle = gfx.add_resource<
graphics::image2d>(path, std::forward<Args>(args)...);
95 _images.insert(name, handle,
asset_metadata{path, name.str(),
"image",
"disk"});
101 return _images.has(name);
105 return _images.get(name);
109 return _images.metadata(handle);
116 template<
typename... Args>
118 if (_cube_images.has(name)) {
119 return _cube_images.get(name);
122 auto& gfx = core::engine::get_module<graphics::graphics_module>();
126 _cube_images.insert(name, handle,
asset_metadata{path, name.str(),
"cube_image",
"disk"});
132 return _cube_images.has(name);
136 return _cube_images.get(name);
140 return _cube_images.metadata(handle);
147 template<
typename Mesh,
typename... Args>
149 if (_meshes.has(name)) {
150 return _meshes.get(name);
153 auto& am = core::engine::get_module<assets::assets_module>();
155 const auto id = am.add_asset<Mesh>(std::forward<Args>(args)...);
157 _meshes.insert(name,
id,
asset_metadata{
"", name.str(),
"mesh",
"generated"});
162 template<
typename Mesh,
typename Path,
typename... Args>
163 requires (std::is_constructible_v<std::filesystem::path, Path>)
165 if (_meshes.has(name)) {
166 return _meshes.get(name);
169 auto& am = core::engine::get_module<assets::assets_module>();
171 const auto id = am.add_asset<Mesh>(path, std::forward<Args>(args)...);
173 _meshes.insert(name,
id,
asset_metadata{path, name.str(),
"mesh",
"disk"});
179 return _meshes.has(name);
183 return _meshes.get(name);
187 return _meshes.metadata(handle);
194 template<
typename Animation,
typename... Args>
196 if (_animations.has(name)) {
197 return _animations.get(name);
200 auto& am = core::engine::get_module<assets::assets_module>();
202 const auto id = am.add_asset<Animation>(std::forward<Args>(args)...);
204 _animations.insert(name,
id,
asset_metadata{
"", name.str(),
"animation",
"generated"});
210 return _animations.has(name);
214 return _animations.get(name);
221 template<
typename Material,
typename... Args>
223 auto& am = core::engine::get_module<assets::assets_module>();
225 if (_materials.has(name)) {
226 return am.get_asset<Material>(_materials.get(name));
229 const auto id = am.add_asset<Material>(std::forward<Args>(args)...);
231 _materials.insert(name,
id,
asset_metadata{
"", name.str(),
"material",
"dynamic"});
233 return am.get_asset<Material>(
id);
237 return _materials.has(name);
241 return _materials.get(name);
245 return _materials.metadata(handle);
Definition: cube_image.hpp:21
Definition: image2d.hpp:52
Definition: resource_storage.hpp:18
Definition: asset_registry.hpp:81
Definition: asset_registry.hpp:31
Definition: hashed_string.hpp:17
Definition: exception.hpp:18