This class provides a cache that users can use to store various types of assets.
When an asset is retreived, smart pointers are used to handle memory usage. The asset will only be deleted if all references to it are removed - including the one held by this class.
Assets with the same file path are considered duplicates. Adding an asset with duplicate path will fail.
For some assets, like CYIAssetTexture for example, a hardware asset (or GPU object) may also be available and can be used with specific classes in You.i Engine.
#include <asset/YiAssetManager.h>
Public Member Functions | |
CYIAssetManager (CYITextEngine *pTextEngine) | |
virtual | ~CYIAssetManager () |
void | AddCacheStrategy (std::unique_ptr< CYIAssetCacheStrategy > pStrategy) |
bool | AddAsset (const std::shared_ptr< CYIAsset > &pAsset) |
void | ExecuteCacheStrategies () |
void | DumpAssetList () const |
std::vector< std::shared_ptr< CYIAsset > > | GetAssets () const |
std::shared_ptr< CYIAsset > | GetAsset (CYIStringView name) |
std::shared_ptr< CYIAsset > | GetAssetFromPath (CYIStringView path) |
std::shared_ptr< CYIRemoteAssetCatalog > | GetRemoteAssetCatalog (uint64_t catalogID) const |
std::vector< std::shared_ptr< CYIRemoteAssetCatalog > > | GetRemoteAssetCatalogs () const |
void | InvalidateHardwareAssets () |
void | LoadShaders () |
void | RemoveNullAssets () |
void | RemoveAllAssets () |
void | RemoveAsset (const std::shared_ptr< CYIAsset > &pAsset) |
void | RemoveAssetsOfType (const CYIRuntimeTypeInfo &assetType) |
std::unique_ptr< CYIAssetCacheStrategy > | RemoveCacheStrategy (const CYIAssetCacheStrategy *pStrategy) |
void | RestoreHardwareAssets () |
bool | IsSystemAsset (const std::shared_ptr< const CYIAsset > &pAsset) const |
std::pair< size_t, size_t > | GetApproximateAssetsSize (bool includeSystemAssets=true) const |
Protected Member Functions | |
size_t | GetNullAssetsCount () const |
Friends | |
class | CYIAsset |
class | CYIAssetManagerPriv |
CYIAssetManager::CYIAssetManager | ( | CYITextEngine * | pTextEngine | ) |
|
virtual |
bool CYIAssetManager::AddAsset | ( | const std::shared_ptr< CYIAsset > & | pAsset | ) |
Adds a shared asset pAsset to the asset manager and returns true if the asset was successfully added or the asset already exists in the asset manager (determined by ID or path).
Returns false if the asset is nullptr, cannot be prepared, or an asset with the same name (with different ID or path) already exists in the asset manager.
The asset provided will be populated with a unique ID.
void CYIAssetManager::AddCacheStrategy | ( | std::unique_ptr< CYIAssetCacheStrategy > | pStrategy | ) |
Adds an asset cache strategy pStrategy for use by the asset manager. The caching strategy cannot be nullptr.
void CYIAssetManager::DumpAssetList | ( | ) | const |
This method prints every asset currently being managed to the log.
void CYIAssetManager::ExecuteCacheStrategies | ( | ) |
This methods allows clients to control when the cache strategy should be applied.
std::pair<size_t, size_t> CYIAssetManager::GetApproximateAssetsSize | ( | bool | includeSystemAssets = true | ) | const |
Returns a pair object containing the total estimated size of all assets in this assets manager. The first item of the pair is the estimated used CPU memory, and the second item of the pair is the estimated used GPU memory.
includeSystemAssets can be set to false to exclude system assets from the returned estimate.
std::shared_ptr<CYIAsset> CYIAssetManager::GetAsset | ( | CYIStringView | name | ) |
Returns a shared asset after supplying a unique name, which was supplied when the asset was built. It will return a null pointer if the name cannot be found, or if the asset has been released.
std::shared_ptr<CYIAsset> CYIAssetManager::GetAssetFromPath | ( | CYIStringView | path | ) |
Returns the CYIAsset that is associated with a unique, fully-qualified path. Returns a null pointer if the asset path is not found.
std::vector<std::shared_ptr<CYIAsset> > CYIAssetManager::GetAssets | ( | ) | const |
Returns a list of every asset currently being managed.
|
protected |
Counts and returns the number of 'null' assets held by this assets manager. This function is used mostly for testing.
std::shared_ptr<CYIRemoteAssetCatalog> CYIAssetManager::GetRemoteAssetCatalog | ( | uint64_t | catalogID | ) | const |
Returns the CYIRemoteAssetCatalog that is associated with the given ID. Returns a null pointer if the CYIRemoteAssetCatalog is not found.
std::vector<std::shared_ptr<CYIRemoteAssetCatalog> > CYIAssetManager::GetRemoteAssetCatalogs | ( | ) | const |
Returns the collection of CYIRemoteAssetCatalog that exist in the asset manager.
void CYIAssetManager::InvalidateHardwareAssets | ( | ) |
In the event that the hardware context is lost, this method can be called to invalidate the hardware resources, which will remove all registered hardware resources.
bool CYIAssetManager::IsSystemAsset | ( | const std::shared_ptr< const CYIAsset > & | pAsset | ) | const |
Returns true if the provided asset is a system asset. A system asset is an asset instantiated and tracked by You.i Engine (rather than by the user's application).
void CYIAssetManager::LoadShaders | ( | ) |
Load default shaders used by You.i Engine. Will either load a file from disk(consoles) or load the code directly.
void CYIAssetManager::RemoveAllAssets | ( | ) |
Removes all assets currently being cached by the asset manager.
void CYIAssetManager::RemoveAsset | ( | const std::shared_ptr< CYIAsset > & | pAsset | ) |
Removes a software asset from the cache.
void CYIAssetManager::RemoveAssetsOfType | ( | const CYIRuntimeTypeInfo & | assetType | ) |
Removes all assets and any associated hardware resources which match the RTTI type provided.
std::unique_ptr<CYIAssetCacheStrategy> CYIAssetManager::RemoveCacheStrategy | ( | const CYIAssetCacheStrategy * | pStrategy | ) |
Removes the asset cache strategy pStrategy in use by the asset manager. The caching strategy pStrategy cannot be nullptr.
void CYIAssetManager::RemoveNullAssets | ( | ) |
Removes all null assets being cached by the assets manager.
When assets are no longer used, they are automatically deleted. However the assets manager retains (null) pointers to those assets. Calling this function frees that memory.
void CYIAssetManager::RestoreHardwareAssets | ( | ) |
In the event that the hardware context is restored, this method can be called to restore the hardware resources after they were invalidated using InvalidateHardwareAssets.
|
friend |
|
friend |
|
static |
Default texture, 2x2 checker board
|
static |
Default crosshair texture
|
static |
Geometry Batch 2D shader
|
static |
NanoVG 2D shader
|
static |
RGB -> BGR texture fragment shader
|
static |
Blurring effect Horizontal
|
static |
Blurring effect Vertical
|
static |
Color Replace Effect shader
|
static |
Effect flip copy shader
|
static |
Tint Effect shader
|
static |
Tint Effect with flip copy shader
|
static |
Texture fragment shader
|
static |
Solid color fragment shader
|
static |
Default text fragment shader
|
static |
Default text fragment shader (with procedural UVs)
|
static |
Texture fragment shader, YUV colour space
|
static |
Texture fragment shader, YUV colour space with separate UV for chroma
|
static |
SDF text fragment shader
|
static |
SDF text fragment shader
|
static |
Solid vertex color fragment shader
|
static |
Normalized [0..1] quad vertices
|
static |
Y-flipped normalized [0..1] quad vertices
|
static |
Geometry Batch 2D shader
|
static |
NanoVG 2D shader
|
static |
RGB -> BGR texture shader program
|
static |
Blurring effect Horizontal
|
static |
Blurring effect Vertical
|
static |
Color Replace Effect shader
|
static |
Effect flip copy shader
|
static |
Tint Effect shader
|
static |
Tint Effect with flip copy shader
|
static |
Texture shader program
|
static |
Solid color shader program
|
static |
Default text shader program
|
static |
Default text shader program (with procedural UVs)
|
static |
Texture shader program, YUV colour space
|
static |
Texture shader program, YUV colour space with separate UV for chroma
|
static |
SDF text shader program
|
static |
SDF text shader program
|
static |
Solid vertex color shader program
|
static |
Default small crosshair texture
|
static |
Text atlas indices
|
static |
Geometry Batch 2D shader
|
static |
NanoVG 2D shader
|
static |
Default vertex shader
|
static |
Blurring effect Horizontal
|
static |
Blurring effect Vertical
|
static |
Color Replace Effect shader
|
static |
Effect flip copy shader
|
static |
Tint Effect shader
|
static |
Tint Effect with flip copy shader
|
static |
Default text vertex shader
|
static |
Default text vertex shader (with procedural UVs)
|
static |
Vertex shader, YUV colour space
|
static |
Vertex shader, YUV colour space with separate UV for chroma
|
static |
SDF text vertex shader
|
static |
SDF text vertex shader
|
static |
Solid vertex color shader