The asset loader provides an interface for loading asset objects, which in turn wrap resource objects like bitmaps, shaders, etc.
Asset objects are produced by decoding specific files though the CYIAssetDecoder interface. The asset loader can have multiple decoders registered, depending on the number of file format types your application needs to support.
Assets can be loaded synchronously or asynchronously depending on the needs of the application.
In order to help manage the large variety of asset types needed by some applications, the asset loader should be supplied with an asset location via an CYIAssetLocator object. The asset locator will provide the asset loader with a a base directory and specialized paths for specific asset types.
#include <asset/YiAssetLoader.h>
Classes | |
class | DecodeListener |
Listener interface for asynchronously decoded asset objects. More... | |
Public Member Functions | |
CYIAssetLoader (CYIAssetManager *pAssetManager, CYIThreadPool *pThreadPool=nullptr) | |
virtual | ~CYIAssetLoader () |
void | AddDecoder (std::unique_ptr< CYIAssetDecoder > pDecoder) |
std::unique_ptr< CYIAssetDecoder > | RemoveDecoder (const CYIAssetDecoder *pDecoder) |
uint32_t | GetDecoderCount () |
std::shared_ptr< CYIAsset > | Load (const CYIRuntimeTypeInfo &assetType, const CYIString &filename, CYIAssetLoadParams *pLoadParams=nullptr) |
std::shared_ptr< CYIAsset > | LoadFromPath (const CYIRuntimeTypeInfo &assetType, const CYIString &path, CYIAssetLoadParams *pLoadParams=nullptr) |
std::shared_ptr< CYIAsset > | LoadFromPath (const CYIString &path, CYIAssetLoadParams *pLoadParams=nullptr) |
bool | LoadFromPath (const std::shared_ptr< CYIAsset > &pAsset) |
std::shared_ptr< CYIAsset > | Load (const CYIRuntimeTypeInfo &assetType, const uint8_t *pData, size_t dataSize, CYIAssetLoadParams *pLoadParams=nullptr) |
int32_t | LoadAsync (const CYIRuntimeTypeInfo &assetType, const CYIString &filename, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate) |
int32_t | LoadAsyncFromPath (const CYIRuntimeTypeInfo &assetType, const CYIString &path, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate) |
int32_t | LoadAsyncFromPath (const CYIString &path, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate) |
int32_t | LoadAsync (const CYIRuntimeTypeInfo &assetType, const uint8_t *pData, size_t dataSize, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate) |
void | AbortAsyncLoad (int32_t decodeTaskID, bool notifyListener=false) |
size_t | GetAsyncJobsCount () |
CYIString | ProbeExtension (const CYIRuntimeTypeInfo &assetType, const uint8_t *pData, uint32_t dataSize) const |
CYIString | ProbeExtension (const uint8_t *pData, uint32_t dataSize) const |
![]() | |
CYISignalHandler () | |
CYISignalHandler (const CYISignalHandler &rSignalHandler) | |
virtual | ~CYISignalHandler () |
CYISignalHandler & | operator= (const CYISignalHandler &rSignalHandler) |
void | MoveToThread (CYIThread *pThread) |
This function allows the user to override the default thread affinity to any CYIThread that may or may not be running. More... | |
CYIThreadHandle | GetThreadAffinity () const |
void | SetThreadAffinity (const CYIThreadHandle &rThreadAffinity) |
virtual bool | IsConnected () const |
virtual bool | IsConnected (const CYISignalBase &rSignal) const |
void | Disconnect (CYISignalBase &rSignal) |
void | DisconnectFromAllSignals () |
![]() | |
Listener () | |
virtual | ~Listener () |
virtual void | OnThreadStarted (CYIThread *) |
virtual void | OnThreadTerminated (CYIThread *) |
virtual void | OnThreadFinished (CYIThread *) |
Static Public Member Functions | |
static void | SetAssetLocator (CYIAssetLocator locator) |
static const CYIAssetLocator & | GetAssetLocator () |
Friends | |
class | CYIDecodeJob |
CYIAssetLoader::CYIAssetLoader | ( | CYIAssetManager * | pAssetManager, |
CYIThreadPool * | pThreadPool = nullptr |
||
) |
Creates an asset loader with no associated decoders. If no thread pool is provided, a thread pool will be created internally.
|
virtual |
Destroys the asset loader and all the associated decoders.
void CYIAssetLoader::AbortAsyncLoad | ( | int32_t | decodeTaskID, |
bool | notifyListener = false |
||
) |
Aborts the specified asynchronous asset decoding task. By default, this method will try to synchronously abort the decoding task and guarantees that the listener won't be called for this decoding task. Set notifyListener to true to be notified when the decode task completes.
void CYIAssetLoader::AddDecoder | ( | std::unique_ptr< CYIAssetDecoder > | pDecoder | ) |
Adds an asset decoder to the asset loader ahead of any existing decoders.
|
static |
Returns the default asset root locator.
size_t CYIAssetLoader::GetAsyncJobsCount | ( | ) |
Returns the current number of uncompleted asynchronous decoding jobs
uint32_t CYIAssetLoader::GetDecoderCount | ( | ) |
Returns the number of decoders currently registered.
std::shared_ptr<CYIAsset> CYIAssetLoader::Load | ( | const CYIRuntimeTypeInfo & | assetType, |
const CYIString & | filename, | ||
CYIAssetLoadParams * | pLoadParams = nullptr |
||
) |
Loads an asset of the specified assetType which is named by filename. Any additional parameters required by the asset decoded should be supplied through the specialized CYIAssetLoadParams type.
filename will be located using the system root locator.
std::shared_ptr<CYIAsset> CYIAssetLoader::Load | ( | const CYIRuntimeTypeInfo & | assetType, |
const uint8_t * | pData, | ||
size_t | dataSize, | ||
CYIAssetLoadParams * | pLoadParams = nullptr |
||
) |
Loads an asset of the specified assetType, the contents of which are contains in pData. Any additional parameters required by the asset decoded should be supplied through the specialized CYIAssetLoadParams type.
int32_t CYIAssetLoader::LoadAsync | ( | const CYIRuntimeTypeInfo & | assetType, |
const CYIString & | filename, | ||
CYIAssetLoadParams * | pLoadParams, | ||
DecodeListener * | pListener, | ||
void * | pListenerPrivate | ||
) |
Asynchronously loads an asset of the specified assetType which named by filename. Any additional parameters required by the asset decoded should be supplied through the specialized CYIAssetLoadParams type. Once the asset has been loaded, the pListener object will be called back. Any private data needing to be passed back to the application through the DecodeListener interface should supply it through the pListenerPrivate pointer.
filename will be located using the system root locator.
The function will return a unique job identifier which can be used to cancel the loading task.
int32_t CYIAssetLoader::LoadAsync | ( | const CYIRuntimeTypeInfo & | assetType, |
const uint8_t * | pData, | ||
size_t | dataSize, | ||
CYIAssetLoadParams * | pLoadParams, | ||
DecodeListener * | pListener, | ||
void * | pListenerPrivate | ||
) |
Asynchronously loads an asset of the specified assetType, the contents of which are contains in pData. Any additional parameters required by the asset decoded should be supplied through the specialized CYIAssetLoadParams type. Once the asset has been loaded, the pListener object will be called back. Any private data needing to be passed back to the application through the DecodeListener interface should supply it through the pListenerPrivate pointer.
The function will return a unique job identifier which can be used to cancel the loading task.
int32_t CYIAssetLoader::LoadAsyncFromPath | ( | const CYIRuntimeTypeInfo & | assetType, |
const CYIString & | path, | ||
CYIAssetLoadParams * | pLoadParams, | ||
DecodeListener * | pListener, | ||
void * | pListenerPrivate | ||
) |
Asynchronously loads an asset of the specified assetType which is pointed to by path. Any additional parameters required by the asset decoded should be supplied through the specialized CYIAssetLoadParams type. Once the asset has been loaded, the pListener object will be called back. Any private data needing to be passed back to the application through the DecodeListener interface should supply it through the pListenerPrivate pointer.
The function will return a unique job identifier which can be used to cancel the loading task.
int32_t CYIAssetLoader::LoadAsyncFromPath | ( | const CYIString & | path, |
CYIAssetLoadParams * | pLoadParams, | ||
DecodeListener * | pListener, | ||
void * | pListenerPrivate | ||
) |
Asynchronously loads an asset which is pointed to by path. Any additional parameters required by the asset decoded should be supplied through the specialized CYIAssetLoadParams type. Once the asset has been loaded, the pListener object will be called back. Any private data needing to be passed back to the application through the DecodeListener interface should supply it through the pListenerPrivate pointer.
The function will return a unique job identifier which can be used to cancel the loading task.
std::shared_ptr<CYIAsset> CYIAssetLoader::LoadFromPath | ( | const CYIRuntimeTypeInfo & | assetType, |
const CYIString & | path, | ||
CYIAssetLoadParams * | pLoadParams = nullptr |
||
) |
Loads an asset of the specified assetType which is pointed to by path. Any additional parameters required by the asset decoded should be supplied through the specialized CYIAssetLoadParams type.
std::shared_ptr<CYIAsset> CYIAssetLoader::LoadFromPath | ( | const CYIString & | path, |
CYIAssetLoadParams * | pLoadParams = nullptr |
||
) |
Loads an asset which is pointed to by path. Any additional parameters required by the asset decoder should be supplied through the specialized CYIAssetLoadParams type.
bool CYIAssetLoader::LoadFromPath | ( | const std::shared_ptr< CYIAsset > & | pAsset | ) |
Loads and populates an existing asset which has a path set and optionally a load parameter required by the asset decoder. This function is called automaticaly when calling CYIAsset::Load
CYIString CYIAssetLoader::ProbeExtension | ( | const CYIRuntimeTypeInfo & | assetType, |
const uint8_t * | pData, | ||
uint32_t | dataSize | ||
) | const |
Examine the data, look for a compatible decoder then return the associate extension, or an empty string if one cannot be found.
CYIString CYIAssetLoader::ProbeExtension | ( | const uint8_t * | pData, |
uint32_t | dataSize | ||
) | const |
Examine the data, look for a compatible decoder then return the associate extension, or an empty string if one cannot be found.
std::unique_ptr<CYIAssetDecoder> CYIAssetLoader::RemoveDecoder | ( | const CYIAssetDecoder * | pDecoder | ) |
Removes an asset decoder from the asset loader.
|
static |
Sets the asset locator.
|
friend |