You.i Engine
CYIAsset Class Reference

Detailed Description

Base class for any asset. An asset provides functions for dynamically loading and unloading itself and is used by other classes to help manage device resource consumption. A loaded asset can be created by loading an asset file or by programmatically constructing one at run time. Once loaded, an asset occupies memory and should be unloaded whenever possible based on the resource strategy used by your application. Unloading an asset frees the memory associated with the underlying object, such as a CYIBitmap which is associated with an CYIAssetTexture, but does not remove the asset from the CYIAssetManager if it is being managed.

Every asset must have an associated RTTI type as this type is used internally by various You.i Engine classes for managing specific kinds of assets.

An asset should also be estimatable in size as this can be used by caching classes which are bounded by hard memory limits.

#include <asset/YiAsset.h>

Inheritance diagram for CYIAsset:

Public Types

enum  PathType {
  PathType::Absolute = 0,
  PathType::Relative
}
 

Public Member Functions

virtual ~CYIAsset ()
 
const CYIStringGetPath () const
 
CYIAssetLoadParamsGetLoadParameters () const
 
virtual std::pair< size_t, size_tGetApproximateSize () const
 
bool SetName (const CYIString &name)
 
const CYIStringGetName () const
 
bool Load ()
 
void Unload ()
 
bool IsLoaded () const
 
bool Equals (const std::shared_ptr< CYIAsset > &pAsset)
 
virtual bool Prepare ()
 

Protected Member Functions

 CYIAsset ()
 
ssize_t GetID () const
 
void SetPath (const CYIString &path, PathType pathType)
 
void SetApproximateSize (size_t size)
 
void SetLoaded (bool assetLoaded)
 
void SetLoadParameters (std::unique_ptr< CYIAssetLoadParams > pParams)
 
virtual void OnLoad ()
 
virtual void OnUnload ()
 

Static Protected Attributes

static ssize_t INVALID_ID
 

Friends

class CYIAssetManager
 
class CYIAssetLoader
 
class CYIDecodeTask
 

Member Enumeration Documentation

◆ PathType

enum CYIAsset::PathType
strong

Used by SetPath to determined if the path provided is absolute or relative.

Enumerator
Absolute 
Relative 

Constructor & Destructor Documentation

◆ ~CYIAsset()

virtual CYIAsset::~CYIAsset ( )
virtual

◆ CYIAsset()

CYIAsset::CYIAsset ( )
protected

Member Function Documentation

◆ Equals()

bool CYIAsset::Equals ( const std::shared_ptr< CYIAsset > &  pAsset)

Returns true if the pAsset object is equivalent to this asset. Equivalency is determined by comparing the paths of each asset object; virtual assets cannot be used with this function and will always return false.

◆ GetApproximateSize()

virtual std::pair<size_t, size_t> CYIAsset::GetApproximateSize ( ) const
virtual

Calculates and returns the approximate number of bytes currently used by this asset. The first item of the returned pair object represents the memory currently taken in the CPU main memory, and the second item of the returned pair object represents the memory currently taken in the GPU memory.

Note
This function only returns an approximate memory consumption as the exact memory consumption changes depending on the used C++ libraries and on the specific GPU infrastructure and drivers used by the system.

Reimplemented in CYIAssetBufferObjectData, CYIRemoteAssetCatalog, CYIAssetTextureRaw, CYIAssetFramebuffer, CYIAssetTexture, CYIAssetSound, CYIAssetVideo, CYIAssetJSON, and CYIAssetTextureFramebuffer.

◆ GetID()

ssize_t CYIAsset::GetID ( ) const
protected

Returns a unique identifier id, representing the asset; this ID should not be exposed through the public interface.

◆ GetLoadParameters()

CYIAssetLoadParams* CYIAsset::GetLoadParameters ( ) const

This is used by the asset's corresponding asset decoder.

See also
CYIAssetDecoder

◆ GetName()

const CYIString& CYIAsset::GetName ( ) const

Returns the optional name for this asset, if it has been set; an empty string will be returned otherwise.

See also
SetName

◆ GetPath()

const CYIString& CYIAsset::GetPath ( ) const

This is used by the asset's corresponding asset decoder. If the path returned is null or empty, the asset is automatically declared a virtual asset.

See also
CYIAssetDecoder

◆ IsLoaded()

bool CYIAsset::IsLoaded ( ) const

Returns true if the asset is currently loaded; false otherwise.

◆ Load()

bool CYIAsset::Load ( )

If the asset has not been programmatically created, load the asset and return true if the load operation was successful; false otherwise.

◆ OnLoad()

virtual void CYIAsset::OnLoad ( )
protectedvirtual

Reimplemented in CYIAssetHardware.

◆ OnUnload()

◆ Prepare()

virtual bool CYIAsset::Prepare ( )
virtual

Do any preparation necessary when the asset is added to the asset manager and/or loaded.

This function must be called by the user if this asset is not added to the asset manager, or if the asset is not loaded from disk.

Reimplemented in CYIAssetHardware.

◆ SetApproximateSize()

void CYIAsset::SetApproximateSize ( size_t  size)
protected

◆ SetLoaded()

void CYIAsset::SetLoaded ( bool  assetLoaded)
protected

◆ SetLoadParameters()

void CYIAsset::SetLoadParameters ( std::unique_ptr< CYIAssetLoadParams pParams)
protected

◆ SetName()

bool CYIAsset::SetName ( const CYIString name)

Sets an optional name for the asset, so that it can be retrieved later or shared with other objects. For managed assets, it is recommended that a reference to the asset be retained for the lifetime of the consuming object. Returns false if the name could not be set. The name may not be set if the asset has already been added to the asset manager and another asset in the asset manager has the same name. Assets in the asset manager must be uniquely named.

See also
CYIAssetManager::GetAsset

◆ SetPath()

void CYIAsset::SetPath ( const CYIString path,
PathType  pathType 
)
protected

Sets the path to the asset.

If the path provided was marked to be PathType::Relative, it will be turned into an absolute path using the CYIAssetLocator. If the path provided is an empty string, the asset will be considered 'virtual', which means that the asset was generated at run-time and does not exist on disk.

◆ Unload()

void CYIAsset::Unload ( )

Frees up most of the underlying memory used by this asset; if the asset has been programmatically created, this function has no effect.

Friends And Related Function Documentation

◆ CYIAssetLoader

friend class CYIAssetLoader
friend

◆ CYIAssetManager

friend class CYIAssetManager
friend

◆ CYIDecodeTask

friend class CYIDecodeTask
friend

Member Data Documentation

◆ INVALID_ID

ssize_t CYIAsset::INVALID_ID
staticprotected

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