Used when you want to manually control the asset lifetime, loading, preloading, unloading.
More...
#include <AssetManager.hpp>
|
| template<Internal::CanBeLoaded Descriptor> |
| 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.
|
| template<Internal::CanBeLoaded Descriptor> |
| static void | Preload (const std::initializer_list< Descriptor > descriptors) |
| | Preloads a group (or one) of assets into the cache.
|
| template<Internal::IsDescriptor Descriptor> |
| static void | Unload (const std::initializer_list< Descriptor > &descriptors) |
| | Unloads a group (or one) of assets from the cache.
|
| template<Internal::IsAsset AssetType> |
| 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.
|
| template<Internal::IsAsset AssetType> |
| static std::shared_ptr< AssetType > | GetPlaceholder () |
| | Retrieves the instance of placeholder for a specified asset type.
|
| template<Internal::IsAsset AssetType> |
| static bool | HasPlaceholder () |
| | Checks if an asset type have placeholder registered.
|
| template<typename AssetType> |
| static void | ClearCache () |
| | Clears cache for o specified asset type.
|
Used when you want to manually control the asset lifetime, loading, preloading, unloading.
Mainly used for assets that are not bound to any particular object, but you want to keep them alive.
For example: Fonts, AnimationPacks, Sounds, etc. Because all asset lifetimes in Cori are managed by a shared pointers, if not for the AssetManager these asset would be unloaded as soon as some object is done with them and refcount dropped to 0, AssetManger is a convenient place to keep these objects loaded and alive.
For loading and later reviving the asset AssetManger uses descriptors that describe how to load a particular asset.
Definition at line 45 of file AssetManager.hpp.
◆ ClearCache()
template<typename AssetType>
| void Cori::AssetManager::ClearCache |
( |
| ) |
|
|
inlinestatic |
Clears cache for o specified asset type.
- Template Parameters
-
| AssetType | The type os asset that we want to clear cache for. |
- Note
- If an asset is still used somewhere (ref count > 1) it will be removed from cache, but freed only when the ref count drops to 0.
Definition at line 172 of file AssetManager.hpp.
◆ Get()
template<Internal::CanBeLoaded Descriptor>
| std::shared_ptr< typename Descriptor::AssetType > Cori::AssetManager::Get |
( |
const Descriptor & | descriptor | ) |
|
|
inlinestatic |
Gets the asset from the asset manager cache, it works with any asset that has a Descriptor defined.
- Template Parameters
-
| Descriptor | Will be deduced, no need to specify. |
- Parameters
-
| descriptor | Instance of the asset descriptor. |
- Returns
- A shared pointer to the loaded asset.
Definition at line 60 of file AssetManager.hpp.
◆ GetPlaceholder()
template<Internal::IsAsset AssetType>
| std::shared_ptr< AssetType > Cori::AssetManager::GetPlaceholder |
( |
| ) |
|
|
inlinestatic |
Retrieves the instance of placeholder for a specified asset type.
- Template Parameters
-
| AssetType | Asset type to retrieve a placeholder for. |
- Returns
- Asset placeholder instnace of success, nullptr if placeholder for this asset wasn't registered.
Definition at line 147 of file AssetManager.hpp.
◆ HasPlaceholder()
template<Internal::IsAsset AssetType>
| bool Cori::AssetManager::HasPlaceholder |
( |
| ) |
|
|
inlinestatic |
Checks if an asset type have placeholder registered.
- Template Parameters
-
| AssetType | Asset type to check the existence of placeholder for. |
- Returns
- True if there is a placeholder registered, false otherwise.
Definition at line 162 of file AssetManager.hpp.
◆ Preload()
template<Internal::CanBeLoaded Descriptor>
| void Cori::AssetManager::Preload |
( |
const std::initializer_list< Descriptor > | descriptors | ) |
|
|
inlinestatic |
Preloads a group (or one) of assets into the cache.
- Template Parameters
-
| Descriptor | Will be deduced, no need to specify. |
- Parameters
-
| descriptors | An list of asset descriptors to preload, all should have the same type, can't mix different asset descriptor types in one call. |
It is needed to avoid the stutter that will be caused when the asset is requested but not yet loaded.
Definition at line 84 of file AssetManager.hpp.
◆ RegisterPlaceholder()
template<Internal::IsAsset AssetType>
| void Cori::AssetManager::RegisterPlaceholder |
( |
const std::shared_ptr< AssetType > & | placeholderInstance | ) |
|
|
inlinestatic |
This allows you to register a placeholder for a specific asset that you can later retrieve.
- Template Parameters
-
| AssetType | Type of asset to register placeholder for. |
- Parameters
-
| placeholderInstance | Asset instance that we will consider a placeholder. |
Definition at line 130 of file AssetManager.hpp.
◆ Unload()
template<Internal::IsDescriptor Descriptor>
| void Cori::AssetManager::Unload |
( |
const std::initializer_list< Descriptor > & | descriptors | ) |
|
|
inlinestatic |
Unloads a group (or one) of assets from the cache.
- Template Parameters
-
| Descriptor | Will be deduced, no need to specify. |
- Parameters
-
| descriptors | An list of asset descriptors to unloaded, all should have the same type, can't mix different asset descriptor types in one call. |
- Note
- If an asset is still used somewhere (ref count > 1) it will be removed from cache, but freed only when the ref count drops to 0.
Definition at line 100 of file AssetManager.hpp.
The documentation for this class was generated from the following files: