You.i Engine
CYIAssetLoader Class Reference

Detailed Description

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.

See also
CYIAssetLocator
CYIAssetDecoder
CYIAssetDecoderThread

#include <asset/YiAssetLoader.h>

Inheritance diagram for CYIAssetLoader:

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< CYIAssetDecoderRemoveDecoder (const CYIAssetDecoder *pDecoder)
 
uint32_t GetDecoderCount ()
 
std::shared_ptr< CYIAssetLoad (const CYIRuntimeTypeInfo &assetType, const CYIString &filename, CYIAssetLoadParams *pLoadParams=nullptr)
 
std::shared_ptr< CYIAssetLoadFromPath (const CYIRuntimeTypeInfo &assetType, const CYIString &path, CYIAssetLoadParams *pLoadParams=nullptr)
 
std::shared_ptr< CYIAssetLoadFromPath (const CYIString &path, CYIAssetLoadParams *pLoadParams=nullptr)
 
bool LoadFromPath (const std::shared_ptr< CYIAsset > &pAsset)
 
std::shared_ptr< CYIAssetLoad (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
 
- Public Member Functions inherited from CYISignalHandler
 CYISignalHandler ()
 
 CYISignalHandler (const CYISignalHandler &rSignalHandler)
 
virtual ~CYISignalHandler ()
 
CYISignalHandleroperator= (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 ()
 
- Public Member Functions inherited from CYIThread::Listener
 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 CYIAssetLocatorGetAssetLocator ()
 

Friends

class CYIDecodeJob
 

Constructor & Destructor Documentation

◆ CYIAssetLoader()

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.

Note
The newly-created CYIAssetLoader does not take ownership of pThreadPool.

◆ ~CYIAssetLoader()

virtual CYIAssetLoader::~CYIAssetLoader ( )
virtual

Destroys the asset loader and all the associated decoders.

Member Function Documentation

◆ AbortAsyncLoad()

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.

◆ AddDecoder()

void CYIAssetLoader::AddDecoder ( std::unique_ptr< CYIAssetDecoder pDecoder)

Adds an asset decoder to the asset loader ahead of any existing decoders.

◆ GetAssetLocator()

static const CYIAssetLocator& CYIAssetLoader::GetAssetLocator ( )
static

Returns the default asset root locator.

◆ GetAsyncJobsCount()

size_t CYIAssetLoader::GetAsyncJobsCount ( )

Returns the current number of uncompleted asynchronous decoding jobs

◆ GetDecoderCount()

uint32_t CYIAssetLoader::GetDecoderCount ( )

Returns the number of decoders currently registered.

◆ Load() [1/2]

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.

◆ Load() [2/2]

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.

◆ LoadAsync() [1/2]

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.

◆ LoadAsync() [2/2]

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.

◆ LoadAsyncFromPath() [1/2]

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.

◆ LoadAsyncFromPath() [2/2]

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.

◆ LoadFromPath() [1/3]

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.

◆ LoadFromPath() [2/3]

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.

◆ LoadFromPath() [3/3]

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

◆ ProbeExtension() [1/2]

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.

◆ ProbeExtension() [2/2]

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.

◆ RemoveDecoder()

std::unique_ptr<CYIAssetDecoder> CYIAssetLoader::RemoveDecoder ( const CYIAssetDecoder pDecoder)

Removes an asset decoder from the asset loader.

◆ SetAssetLocator()

static void CYIAssetLoader::SetAssetLocator ( CYIAssetLocator  locator)
static

Sets the asset locator.

Friends And Related Function Documentation

◆ CYIDecodeJob

friend class CYIDecodeJob
friend

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