You.i Engine
CYIAssetManager Class Reference

Detailed Description

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< CYIAssetGetAsset (CYIStringView name)
 
std::shared_ptr< CYIAssetGetAssetFromPath (CYIStringView path)
 
std::shared_ptr< CYIRemoteAssetCatalogGetRemoteAssetCatalog (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< CYIAssetCacheStrategyRemoveCacheStrategy (const CYIAssetCacheStrategy *pStrategy)
 
void RestoreHardwareAssets ()
 
bool IsSystemAsset (const std::shared_ptr< const CYIAsset > &pAsset) const
 
std::pair< size_t, size_tGetApproximateAssetsSize (bool includeSystemAssets=true) const
 

Static Public Attributes

static const CYIString YI_NORMALIZED_QUAD_VBO
 
static const CYIString YI_NORMALIZED_QUAD_YFLIP_VBO
 
static const CYIString YI_TEXT_ATLAS_IBO
 
static const CYIString YI_VSHADER_3D
 
static const CYIString YI_FSHADER_3D_BGR
 
static const CYIString YI_PROGRAM_3D_BGR
 
static const CYIString YI_FSHADER_3D_RGB
 
static const CYIString YI_PROGRAM_3D_RGB
 
static const CYIString YI_VSHADER_3D_YUV
 
static const CYIString YI_FSHADER_3D_YUV
 
static const CYIString YI_PROGRAM_3D_YUV
 
static const CYIString YI_VSHADER_3D_YUV_SEPARATE
 
static const CYIString YI_FSHADER_3D_YUV_SEPARATE
 
static const CYIString YI_PROGRAM_3D_YUV_SEPARATE
 
static const CYIString YI_CHECKERBOARD_TEXTURE
 
static const CYIString YI_FSHADER_3D_SOLID
 
static const CYIString YI_PROGRAM_3D_SOLID
 
static const CYIString YI_VSHADER_3D_TEXT
 
static const CYIString YI_FSHADER_3D_TEXT
 
static const CYIString YI_PROGRAM_3D_TEXT
 
static const CYIString YI_VSHADER_3D_TEXT_PROCEDURAL_UV
 
static const CYIString YI_FSHADER_3D_TEXT_PROCEDURAL_UV
 
static const CYIString YI_PROGRAM_3D_TEXT_PROCEDURAL_UV
 
static const CYIString YI_VSHADER_SDF_TEXT
 
static const CYIString YI_FSHADER_SDF_TEXT
 
static const CYIString YI_PROGRAM_SDF_TEXT
 
static const CYIString YI_VSHADER_SDF_APPROX_TEXT
 
static const CYIString YI_FSHADER_SDF_APPROX_TEXT
 
static const CYIString YI_PROGRAM_SDF_APPROX_TEXT
 
static const CYIString YI_VSHADER_VERTEX_COLOR
 
static const CYIString YI_FSHADER_VERTEX_COLOR
 
static const CYIString YI_PROGRAM_VERTEX_COLOR
 
static const CYIString YI_CROSSHAIR_TEXTURE
 
static const CYIString YI_SMALL_CROSSHAIR_TEXTURE
 
static const CYIString YI_VSHADER_3D_EFFECT_BLUR_H
 
static const CYIString YI_FSHADER_3D_EFFECT_BLUR_H
 
static const CYIString YI_PROGRAM_3D_EFFECT_BLUR_H
 
static const CYIString YI_VSHADER_3D_EFFECT_BLUR_V
 
static const CYIString YI_FSHADER_3D_EFFECT_BLUR_V
 
static const CYIString YI_PROGRAM_3D_EFFECT_BLUR_V
 
static const CYIString YI_VSHADER_3D_EFFECT_FLIP_COPY
 
static const CYIString YI_FSHADER_3D_EFFECT_FLIP_COPY
 
static const CYIString YI_PROGRAM_3D_EFFECT_FLIP_COPY
 
static const CYIString YI_VSHADER_3D_EFFECT_TINT
 
static const CYIString YI_FSHADER_3D_EFFECT_TINT
 
static const CYIString YI_PROGRAM_3D_EFFECT_TINT
 
static const CYIString YI_VSHADER_3D_EFFECT_TINT_FLIP_COPY
 
static const CYIString YI_FSHADER_3D_EFFECT_TINT_FLIP_COPY
 
static const CYIString YI_PROGRAM_3D_EFFECT_TINT_FLIP_COPY
 
static const CYIString YI_VSHADER_2D_GEOMETRY_BATCH
 
static const CYIString YI_FSHADER_2D_GEOMETRY_BATCH
 
static const CYIString YI_PROGRAM_2D_GEOMETRY_BATCH
 
static const CYIString YI_VSHADER_2D_NANOVG
 
static const CYIString YI_FSHADER_2D_NANOVG
 
static const CYIString YI_PROGRAM_2D_NANOVG
 
static const CYIString YI_FSHADER_3D_EFFECT_COLOR_REPLACE
 
static const CYIString YI_VSHADER_3D_EFFECT_COLOR_REPLACE
 
static const CYIString YI_PROGRAM_3D_EFFECT_COLOR_REPLACE
 

Protected Member Functions

size_t GetNullAssetsCount () const
 

Friends

class CYIAsset
 
class CYIAssetManagerPriv
 

Constructor & Destructor Documentation

◆ CYIAssetManager()

CYIAssetManager::CYIAssetManager ( CYITextEngine pTextEngine)

◆ ~CYIAssetManager()

virtual CYIAssetManager::~CYIAssetManager ( )
virtual

Member Function Documentation

◆ AddAsset()

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.

◆ AddCacheStrategy()

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.

◆ DumpAssetList()

void CYIAssetManager::DumpAssetList ( ) const

This method prints every asset currently being managed to the log.

◆ ExecuteCacheStrategies()

void CYIAssetManager::ExecuteCacheStrategies ( )

This methods allows clients to control when the cache strategy should be applied.

◆ GetApproximateAssetsSize()

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.

◆ GetAsset()

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.

◆ GetAssetFromPath()

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.

◆ GetAssets()

std::vector<std::shared_ptr<CYIAsset> > CYIAssetManager::GetAssets ( ) const

Returns a list of every asset currently being managed.

◆ GetNullAssetsCount()

size_t CYIAssetManager::GetNullAssetsCount ( ) const
protected

Counts and returns the number of 'null' assets held by this assets manager. This function is used mostly for testing.

◆ GetRemoteAssetCatalog()

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.

Note
A CYIRemoteAssetCatalog is added to the asset manager through AddAsset automically through CYIRemoteAssetCatalog::Create()
See also
GetRemoteAssetCatalogs

◆ GetRemoteAssetCatalogs()

std::vector<std::shared_ptr<CYIRemoteAssetCatalog> > CYIAssetManager::GetRemoteAssetCatalogs ( ) const

Returns the collection of CYIRemoteAssetCatalog that exist in the asset manager.

See also
GetRemoteAssetCatalog

◆ InvalidateHardwareAssets()

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.

◆ IsSystemAsset()

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).

◆ LoadShaders()

void CYIAssetManager::LoadShaders ( )

Load default shaders used by You.i Engine. Will either load a file from disk(consoles) or load the code directly.

◆ RemoveAllAssets()

void CYIAssetManager::RemoveAllAssets ( )

Removes all assets currently being cached by the asset manager.

◆ RemoveAsset()

void CYIAssetManager::RemoveAsset ( const std::shared_ptr< CYIAsset > &  pAsset)

Removes a software asset from the cache.

◆ RemoveAssetsOfType()

void CYIAssetManager::RemoveAssetsOfType ( const CYIRuntimeTypeInfo assetType)

Removes all assets and any associated hardware resources which match the RTTI type provided.

◆ RemoveCacheStrategy()

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.

◆ RemoveNullAssets()

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.

◆ RestoreHardwareAssets()

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.

Friends And Related Function Documentation

◆ CYIAsset

friend class CYIAsset
friend

◆ CYIAssetManagerPriv

friend class CYIAssetManagerPriv
friend

Member Data Documentation

◆ YI_CHECKERBOARD_TEXTURE

const CYIString CYIAssetManager::YI_CHECKERBOARD_TEXTURE
static

Default texture, 2x2 checker board

◆ YI_CROSSHAIR_TEXTURE

const CYIString CYIAssetManager::YI_CROSSHAIR_TEXTURE
static

Default crosshair texture

◆ YI_FSHADER_2D_GEOMETRY_BATCH

const CYIString CYIAssetManager::YI_FSHADER_2D_GEOMETRY_BATCH
static

Geometry Batch 2D shader

◆ YI_FSHADER_2D_NANOVG

const CYIString CYIAssetManager::YI_FSHADER_2D_NANOVG
static

NanoVG 2D shader

◆ YI_FSHADER_3D_BGR

const CYIString CYIAssetManager::YI_FSHADER_3D_BGR
static

RGB -> BGR texture fragment shader

◆ YI_FSHADER_3D_EFFECT_BLUR_H

const CYIString CYIAssetManager::YI_FSHADER_3D_EFFECT_BLUR_H
static

Blurring effect Horizontal

◆ YI_FSHADER_3D_EFFECT_BLUR_V

const CYIString CYIAssetManager::YI_FSHADER_3D_EFFECT_BLUR_V
static

Blurring effect Vertical

◆ YI_FSHADER_3D_EFFECT_COLOR_REPLACE

const CYIString CYIAssetManager::YI_FSHADER_3D_EFFECT_COLOR_REPLACE
static

Color Replace Effect shader

◆ YI_FSHADER_3D_EFFECT_FLIP_COPY

const CYIString CYIAssetManager::YI_FSHADER_3D_EFFECT_FLIP_COPY
static

Effect flip copy shader

◆ YI_FSHADER_3D_EFFECT_TINT

const CYIString CYIAssetManager::YI_FSHADER_3D_EFFECT_TINT
static

Tint Effect shader

◆ YI_FSHADER_3D_EFFECT_TINT_FLIP_COPY

const CYIString CYIAssetManager::YI_FSHADER_3D_EFFECT_TINT_FLIP_COPY
static

Tint Effect with flip copy shader

◆ YI_FSHADER_3D_RGB

const CYIString CYIAssetManager::YI_FSHADER_3D_RGB
static

Texture fragment shader

◆ YI_FSHADER_3D_SOLID

const CYIString CYIAssetManager::YI_FSHADER_3D_SOLID
static

Solid color fragment shader

◆ YI_FSHADER_3D_TEXT

const CYIString CYIAssetManager::YI_FSHADER_3D_TEXT
static

Default text fragment shader

◆ YI_FSHADER_3D_TEXT_PROCEDURAL_UV

const CYIString CYIAssetManager::YI_FSHADER_3D_TEXT_PROCEDURAL_UV
static

Default text fragment shader (with procedural UVs)

◆ YI_FSHADER_3D_YUV

const CYIString CYIAssetManager::YI_FSHADER_3D_YUV
static

Texture fragment shader, YUV colour space

◆ YI_FSHADER_3D_YUV_SEPARATE

const CYIString CYIAssetManager::YI_FSHADER_3D_YUV_SEPARATE
static

Texture fragment shader, YUV colour space with separate UV for chroma

◆ YI_FSHADER_SDF_APPROX_TEXT

const CYIString CYIAssetManager::YI_FSHADER_SDF_APPROX_TEXT
static

SDF text fragment shader

◆ YI_FSHADER_SDF_TEXT

const CYIString CYIAssetManager::YI_FSHADER_SDF_TEXT
static

SDF text fragment shader

◆ YI_FSHADER_VERTEX_COLOR

const CYIString CYIAssetManager::YI_FSHADER_VERTEX_COLOR
static

Solid vertex color fragment shader

◆ YI_NORMALIZED_QUAD_VBO

const CYIString CYIAssetManager::YI_NORMALIZED_QUAD_VBO
static

Normalized [0..1] quad vertices

◆ YI_NORMALIZED_QUAD_YFLIP_VBO

const CYIString CYIAssetManager::YI_NORMALIZED_QUAD_YFLIP_VBO
static

Y-flipped normalized [0..1] quad vertices

◆ YI_PROGRAM_2D_GEOMETRY_BATCH

const CYIString CYIAssetManager::YI_PROGRAM_2D_GEOMETRY_BATCH
static

Geometry Batch 2D shader

◆ YI_PROGRAM_2D_NANOVG

const CYIString CYIAssetManager::YI_PROGRAM_2D_NANOVG
static

NanoVG 2D shader

◆ YI_PROGRAM_3D_BGR

const CYIString CYIAssetManager::YI_PROGRAM_3D_BGR
static

RGB -> BGR texture shader program

◆ YI_PROGRAM_3D_EFFECT_BLUR_H

const CYIString CYIAssetManager::YI_PROGRAM_3D_EFFECT_BLUR_H
static

Blurring effect Horizontal

◆ YI_PROGRAM_3D_EFFECT_BLUR_V

const CYIString CYIAssetManager::YI_PROGRAM_3D_EFFECT_BLUR_V
static

Blurring effect Vertical

◆ YI_PROGRAM_3D_EFFECT_COLOR_REPLACE

const CYIString CYIAssetManager::YI_PROGRAM_3D_EFFECT_COLOR_REPLACE
static

Color Replace Effect shader

◆ YI_PROGRAM_3D_EFFECT_FLIP_COPY

const CYIString CYIAssetManager::YI_PROGRAM_3D_EFFECT_FLIP_COPY
static

Effect flip copy shader

◆ YI_PROGRAM_3D_EFFECT_TINT

const CYIString CYIAssetManager::YI_PROGRAM_3D_EFFECT_TINT
static

Tint Effect shader

◆ YI_PROGRAM_3D_EFFECT_TINT_FLIP_COPY

const CYIString CYIAssetManager::YI_PROGRAM_3D_EFFECT_TINT_FLIP_COPY
static

Tint Effect with flip copy shader

◆ YI_PROGRAM_3D_RGB

const CYIString CYIAssetManager::YI_PROGRAM_3D_RGB
static

Texture shader program

◆ YI_PROGRAM_3D_SOLID

const CYIString CYIAssetManager::YI_PROGRAM_3D_SOLID
static

Solid color shader program

◆ YI_PROGRAM_3D_TEXT

const CYIString CYIAssetManager::YI_PROGRAM_3D_TEXT
static

Default text shader program

◆ YI_PROGRAM_3D_TEXT_PROCEDURAL_UV

const CYIString CYIAssetManager::YI_PROGRAM_3D_TEXT_PROCEDURAL_UV
static

Default text shader program (with procedural UVs)

◆ YI_PROGRAM_3D_YUV

const CYIString CYIAssetManager::YI_PROGRAM_3D_YUV
static

Texture shader program, YUV colour space

◆ YI_PROGRAM_3D_YUV_SEPARATE

const CYIString CYIAssetManager::YI_PROGRAM_3D_YUV_SEPARATE
static

Texture shader program, YUV colour space with separate UV for chroma

◆ YI_PROGRAM_SDF_APPROX_TEXT

const CYIString CYIAssetManager::YI_PROGRAM_SDF_APPROX_TEXT
static

SDF text shader program

◆ YI_PROGRAM_SDF_TEXT

const CYIString CYIAssetManager::YI_PROGRAM_SDF_TEXT
static

SDF text shader program

◆ YI_PROGRAM_VERTEX_COLOR

const CYIString CYIAssetManager::YI_PROGRAM_VERTEX_COLOR
static

Solid vertex color shader program

◆ YI_SMALL_CROSSHAIR_TEXTURE

const CYIString CYIAssetManager::YI_SMALL_CROSSHAIR_TEXTURE
static

Default small crosshair texture

◆ YI_TEXT_ATLAS_IBO

const CYIString CYIAssetManager::YI_TEXT_ATLAS_IBO
static

Text atlas indices

◆ YI_VSHADER_2D_GEOMETRY_BATCH

const CYIString CYIAssetManager::YI_VSHADER_2D_GEOMETRY_BATCH
static

Geometry Batch 2D shader

◆ YI_VSHADER_2D_NANOVG

const CYIString CYIAssetManager::YI_VSHADER_2D_NANOVG
static

NanoVG 2D shader

◆ YI_VSHADER_3D

const CYIString CYIAssetManager::YI_VSHADER_3D
static

Default vertex shader

◆ YI_VSHADER_3D_EFFECT_BLUR_H

const CYIString CYIAssetManager::YI_VSHADER_3D_EFFECT_BLUR_H
static

Blurring effect Horizontal

◆ YI_VSHADER_3D_EFFECT_BLUR_V

const CYIString CYIAssetManager::YI_VSHADER_3D_EFFECT_BLUR_V
static

Blurring effect Vertical

◆ YI_VSHADER_3D_EFFECT_COLOR_REPLACE

const CYIString CYIAssetManager::YI_VSHADER_3D_EFFECT_COLOR_REPLACE
static

Color Replace Effect shader

◆ YI_VSHADER_3D_EFFECT_FLIP_COPY

const CYIString CYIAssetManager::YI_VSHADER_3D_EFFECT_FLIP_COPY
static

Effect flip copy shader

◆ YI_VSHADER_3D_EFFECT_TINT

const CYIString CYIAssetManager::YI_VSHADER_3D_EFFECT_TINT
static

Tint Effect shader

◆ YI_VSHADER_3D_EFFECT_TINT_FLIP_COPY

const CYIString CYIAssetManager::YI_VSHADER_3D_EFFECT_TINT_FLIP_COPY
static

Tint Effect with flip copy shader

◆ YI_VSHADER_3D_TEXT

const CYIString CYIAssetManager::YI_VSHADER_3D_TEXT
static

Default text vertex shader

◆ YI_VSHADER_3D_TEXT_PROCEDURAL_UV

const CYIString CYIAssetManager::YI_VSHADER_3D_TEXT_PROCEDURAL_UV
static

Default text vertex shader (with procedural UVs)

◆ YI_VSHADER_3D_YUV

const CYIString CYIAssetManager::YI_VSHADER_3D_YUV
static

Vertex shader, YUV colour space

◆ YI_VSHADER_3D_YUV_SEPARATE

const CYIString CYIAssetManager::YI_VSHADER_3D_YUV_SEPARATE
static

Vertex shader, YUV colour space with separate UV for chroma

◆ YI_VSHADER_SDF_APPROX_TEXT

const CYIString CYIAssetManager::YI_VSHADER_SDF_APPROX_TEXT
static

SDF text vertex shader

◆ YI_VSHADER_SDF_TEXT

const CYIString CYIAssetManager::YI_VSHADER_SDF_TEXT
static

SDF text vertex shader

◆ YI_VSHADER_VERTEX_COLOR

const CYIString CYIAssetManager::YI_VSHADER_VERTEX_COLOR
static

Solid vertex color shader


The documentation for this class was generated from the following file: