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>
Public Types | |
enum | PathType { PathType::Absolute = 0, PathType::Relative } |
Public Member Functions | |
virtual | ~CYIAsset () |
const CYIString & | GetPath () const |
CYIAssetLoadParams * | GetLoadParameters () const |
virtual std::pair< size_t, size_t > | GetApproximateSize () const |
bool | SetName (const CYIString &name) |
const CYIString & | GetName () 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 |
|
strong |
|
virtual |
|
protected |
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.
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.
Reimplemented in CYIAssetBufferObjectData, CYIRemoteAssetCatalog, CYIAssetTextureRaw, CYIAssetFramebuffer, CYIAssetTexture, CYIAssetSound, CYIAssetVideo, CYIAssetJSON, and CYIAssetTextureFramebuffer.
|
protected |
Returns a unique identifier id, representing the asset; this ID should not be exposed through the public interface.
CYIAssetLoadParams* CYIAsset::GetLoadParameters | ( | ) | const |
This is used by the asset's corresponding asset decoder.
const CYIString& CYIAsset::GetName | ( | ) | const |
Returns the optional name for this asset, if it has been set; an empty string will be returned otherwise.
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.
bool CYIAsset::IsLoaded | ( | ) | const |
Returns true if the asset is currently loaded; false otherwise.
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.
|
protectedvirtual |
Reimplemented in CYIAssetHardware.
|
protectedvirtual |
|
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.
|
protected |
|
protected |
|
protected |
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.
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.
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.
|
friend |
|
friend |
|
friend |
|
staticprotected |