6#include <entt/core/hashed_string.hpp>
7#include <entt/resource/cache.hpp>
29 return std::make_shared<ResourceType>(std::forward<Args>(args)...);
52 template <typename... Args> entt::resource<ResourceType>
Add(const entt::hashed_string &
id, Args &&...args)
54 auto ret =
cache.load(
id, std::forward<Args>(args)...);
58 Log::Warning(fmt::format(
"Resource with id {} already exists. Overwriting.", id.data()));
59 ret = cache.force_load(id, std::forward<Args>(args)...);
62 return ret.first->second;
73 [[nodiscard]] ResourceType &
Get(
const entt::hashed_string &
id)
75 auto resource =
cache[id];
91 [[nodiscard]]
const ResourceType &
Get(
const entt::hashed_string &
id)
const
93 const auto &resource =
cache[id];
97 fmt::format(
"Resource with id {} not found.", std::string_view(
id.data(),
id.size())));
115 [[nodiscard]]
bool Contains(
const entt::hashed_string &
id)
const {
return cache.contains(
id); }
171 [[nodiscard]] ResourceType &
GetOrDefault(
const entt::hashed_string &
id)
173 auto resource =
cache[id];
180 fmt::format(
"Resource with id {} not found and no default resource is set.",
id.data()));
193 [[nodiscard]]
const ResourceType &
GetOrDefault(
const entt::hashed_string &
id)
const
195 const auto &resource =
cache[id];
202 fmt::format(
"Resource with id {} not found and no default resource is set.",
id.data()));
215 entt::resource_cache<ResourceType, ResourceLoader>
cache{};
Definition ResourceManagerError.hpp:26
const ResourceType & GetDefault() const
Get the default resource.
Definition ResourceManager.hpp:155
void Remove(const entt::hashed_string &id)
Delete an resource from the manager.
Definition ResourceManager.hpp:107
ResourceManager & operator=(const ResourceManager &)=delete
entt::resource< BindGroup > Add(const entt::hashed_string &id, Args &&...args)
Definition ResourceManager.hpp:52
ResourceManager(ResourceManager &&) noexcept=default
const ResourceType & Get(const entt::hashed_string &id) const
Get the reference to a stored resource.
Definition ResourceManager.hpp:91
void SetDefault(Args &&...args)
Definition ResourceManager.hpp:128
~ResourceManager()=default
std::optional< BindGroup > defaultResource
Definition ResourceManager.hpp:216
const ResourceType & GetOrDefault(const entt::hashed_string &id) const
Get the reference to a stored resource, or the default resource if it doesn't exist.
Definition ResourceManager.hpp:193
ResourceType & GetOrDefault(const entt::hashed_string &id)
Get the reference to a stored resource, or the default resource if it doesn't exist.
Definition ResourceManager.hpp:171
ResourceManager(const ResourceManager &)=delete
ResourceType & Get(const entt::hashed_string &id)
Get the reference to a stored resource.
Definition ResourceManager.hpp:73
ResourceManager()=default
void SetDefault(ResourceType &&resource)
Set the default resource that will be used as fallback.
Definition ResourceManager.hpp:126
ResourceType & GetDefault()
Get the default resource.
Definition ResourceManager.hpp:140
bool HasDefault() const
Check if a default resource has been set.
Definition ResourceManager.hpp:212
entt::resource_cache< BindGroup, ResourceLoader > cache
Definition ResourceManager.hpp:215
bool Contains(const entt::hashed_string &id) const
Check whenever the resource with given id exists in the manager.
Definition ResourceManager.hpp:115
Definition ResourceManager.hpp:11
ResourceLoader structure is used to load a resource from another resource or from arguments.
Definition ResourceManager.hpp:24
result_type operator()(Args &&...args) const
Definition ResourceManager.hpp:27
std::shared_ptr< ResourceType > result_type
Definition ResourceManager.hpp:25