13 { a.GetRuntimeID() } -> std::same_as<uint32_t>;
14 { a.m_Name } -> std::convertible_to<std::string>;
15 { a == b } -> std::convertible_to<bool>;
16 typename T::AssetType;
23 template<
typename Descriptor>
25 { Descriptor::AssetType::Create(d) } -> std::same_as<std::shared_ptr<typename Descriptor::AssetType>>;
31 template<
typename Asset>
47 std::unordered_map<std::type_index, std::any> m_Caches;
48 std::mutex m_CacheMutex;
49 std::unordered_map<std::type_index, std::any> m_Placeholders;
59 template <Internal::CanBeLoaded Descriptor>
60 static std::shared_ptr<typename Descriptor::AssetType>
Get(
const Descriptor& descriptor) {
62 std::lock_guard lock(s_Cache->m_CacheMutex);
64 auto& cache = GetCache<typename Descriptor::AssetType>();
65 if (
const auto it = cache.find(descriptor.GetRuntimeID()); it != cache.end()) {
71 std::shared_ptr<typename Descriptor::AssetType> newAsset = Descriptor::AssetType::Create(descriptor);
72 cache[descriptor.GetRuntimeID()] = newAsset;
83 template <Internal::CanBeLoaded Descriptor>
84 static void Preload(
const std::initializer_list<Descriptor> descriptors) {
87 for (
const auto& descriptor : descriptors) {
99 template <Internal::IsDescriptor Descriptor>
100 static void Unload(
const std::initializer_list<Descriptor>& descriptors) {
101 std::lock_guard lock(s_Cache->m_CacheMutex);
104 for (
const auto& descriptor : descriptors) {
105 auto& cache = GetCache<typename Descriptor::AssetType>();
107 if (!cache.contains(descriptor.GetRuntimeID())) {
112 auto ptr = cache.at(descriptor.GetRuntimeID());
113 if (ptr.use_count() > 1) {
117 cache.erase(descriptor.GetRuntimeID());
129 template<Internal::IsAsset AssetType>
132 if (!s_Cache->m_Placeholders.contains(std::type_index(
typeid(AssetType)))) {
133 s_Cache->m_Placeholders[std::type_index(
typeid(AssetType))] = placeholderInstance;
146 template<Internal::IsAsset AssetType>
148 if (s_Cache->m_Placeholders.contains(std::type_index(
typeid(AssetType)))) {
149 return std::any_cast<std::shared_ptr<AssetType>>(s_Cache->m_Placeholders[std::type_index(
typeid(AssetType))]);
161 template<Internal::IsAsset AssetType>
163 return s_Cache->m_Placeholders.contains(std::type_index(
typeid(AssetType)));
171 template <
typename AssetType>
173 std::lock_guard lock(s_Cache->m_CacheMutex);
175 if (s_Cache->m_Caches.contains(std::type_index(
typeid(AssetType)))) {
176 GetCache<AssetType>().clear();
183 static void Shutdown();
184 static void RegisterPlaceholders();
186 template <
typename AssetType>
187 static std::unordered_map<uint32_t, std::shared_ptr<AssetType>>& GetCache() {
188 const auto typeIndex = std::type_index(
typeid(AssetType));
189 if (!s_Cache->m_Caches.contains(typeIndex)) {
190 s_Cache->m_Caches[typeIndex] = std::unordered_map<uint32_t, std::shared_ptr<AssetType>>();
192 return std::any_cast<std::unordered_map<uint32_t, std::shared_ptr<AssetType>>&>(s_Cache->m_Caches.at(typeIndex));
195 static Cache* s_Cache;
#define CORI_CLEAN_TYPE_NAME(tn)
#define CORI_CORE_DEBUG_TAGGED(...)
#define CORI_CORE_ERROR_TAGGED(...)
#define CORI_CORE_WARN_TAGGED(...)
#define CORI_CORE_INFO_TAGGED(...)
#define CORI_PROFILE_FUNCTION()
Used when you want to manually control the asset lifetime, loading, preloading, unloading.
static void Unload(const std::initializer_list< Descriptor > &descriptors)
Unloads a group (or one) of assets from the cache.
static std::shared_ptr< typename Descriptor::AssetType > Get(const Descriptor &descriptor)
Gets the asset from the asset manager cache, it works with any asset that has a Descriptor defined.
static void Preload(const std::initializer_list< Descriptor > descriptors)
Preloads a group (or one) of assets into the cache.
static void ClearCache()
Clears cache for o specified asset type.
static std::shared_ptr< AssetType > GetPlaceholder()
Retrieves the instance of placeholder for a specified asset type.
static bool HasPlaceholder()
Checks if an asset type have placeholder registered.
static void RegisterPlaceholder(const std::shared_ptr< AssetType > &placeholderInstance)
This allows you to register a placeholder for a specific asset that you can later retrieve.
Main Application object, there can only be one Application object. Basically a root of the program.
Checks if AssetType of Descriptor can be loaded by the AssetManager.
Checks if Asset is an asset type that AssetManager can work with.
Checks T can be considered a descriptor.
Core systems of the engine are here.