FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fplbase::AsyncAsset Class Referenceabstract
Inheritance diagram for fplbase::AsyncAsset:
fplbase::Asset fplbase::FileAsset fplbase::Mesh fplbase::Shader fplbase::Texture

Public Types

typedef std::function< void()> AssetFinalizedCallback
 A function pointer to an asset loaded callback function.
 

Public Member Functions

 AsyncAsset ()
 Default constructor for an empty AsyncAsset.
 
 AsyncAsset (const char *filename)
 Construct an AsyncAsset with a given file name. More...
 
virtual ~AsyncAsset ()
 AsyncAsset destructor.
 
virtual void Load ()=0
 Override with the actual loading behavior. More...
 
virtual bool Finalize ()=0
 Override with converting the data into the resource. More...
 
virtual bool IsValid ()=0
 Whether this object loaded and finalized correctly. Call after Finalize has been called (by AssetManager::TryFinalize).
 
bool LoadNow ()
 Performs a synchronous load by calling Load & Finalize. More...
 
void set_filename (const std::string &filename)
 Sets the filename that should be loaded. More...
 
const std::string & filename () const
 The name of the file associated with the resource. More...
 
void AddFinalizeCallback (AssetFinalizedCallback callback)
 Adds a callback to be called when the asset is finalized. More...
 
- Public Member Functions inherited from fplbase::Asset
void IncreaseRefCount ()
 indicate there is an additional owner of this asset. By default, when you call any of the UnLoad*() functions in the AssetManager, that will directly delete the asset since they all start out with a single reference count. Call this function to indicate multiple owners will call Unload*() independently, and only have the asset deleted by the last one.
 

Protected Member Functions

void CallFinalizeCallback ()
 Calls app callbacks when an asset is ready to be used. More...
 

Protected Attributes

std::string filename_
 The resource file name.
 
const uint8_t * data_
 The resource data.
 
std::vector
< AssetFinalizedCallback
finalize_callbacks_
 

Friends

class AsyncLoader
 

Constructor & Destructor Documentation

fplbase::AsyncAsset::AsyncAsset ( const char *  filename)
inlineexplicit

Construct an AsyncAsset with a given file name.

Parameters
[in]filenameA C-string corresponding to the name of the asset file.

Member Function Documentation

void fplbase::AsyncAsset::AddFinalizeCallback ( AssetFinalizedCallback  callback)
inline

Adds a callback to be called when the asset is finalized.

Add a callback so logic can be executed when an asset is done loading.

Parameters
callbackThe function to be called.
void fplbase::AsyncAsset::CallFinalizeCallback ( )
inlineprotected

Calls app callbacks when an asset is ready to be used.

This should be called by descendants as soon as they are finalized.

const std::string& fplbase::AsyncAsset::filename ( ) const
inline

The name of the file associated with the resource.

Returns
Returns the filename.
virtual bool fplbase::AsyncAsset::Finalize ( )
pure virtual

Override with converting the data into the resource.

This should implement the behavior of turning data_ into the actual desired resource. Called on the main thread only. Should check if data_ is null.

Implemented in fplbase::Texture, fplbase::Mesh, and fplbase::Shader.

virtual void fplbase::AsyncAsset::Load ( )
pure virtual

Override with the actual loading behavior.

Load should perform the actual loading of filename_, and store the result in data_, or nullptr upon failure. It is called on the loader thread, so should not access any program state outside of this object. Since there will be only one loader thread, any libraries called by Load need not be MT-safe as long as they're not also called by the main thread.

Implemented in fplbase::Texture, fplbase::Mesh, and fplbase::Shader.

bool fplbase::AsyncAsset::LoadNow ( )
inline

Performs a synchronous load by calling Load & Finalize.

Not used by the loader thread, should be called on the main thread.

Returns
Returns false on failure.
void fplbase::AsyncAsset::set_filename ( const std::string &  filename)
inline

Sets the filename that should be loaded.

Set the the filename in situations where it can't be initialized in the constructor. Must be called before AsyncLoader::QueueJob().

Parameters
filenameThe name of the file to load.

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