Cornell Cocos
Cornell Extensions to Cocos2d
|
#include <CUGenericLoader.h>
Public Member Functions | |
Coordinator () | |
~Coordinator () | |
bool | isLoaded (std::string id) const |
bool | isPending (std::string id) const |
Asset * | load (Asset *asset) |
void | loadAsync (Asset *asset, std::function< void(Asset *s)> callback) |
Asset * | allocate (Asset *asset) |
void | release (Asset *asset) |
Public Attributes | |
size_t | instances |
Class is a static coordinate to garbage collect assets
This coordinate tracks asset usage across all active loaders. When an asset is not used by any loader, it is removed from memory.
GenericBaseLoader::Coordinator::Coordinator | ( | ) |
Creates a new static coordinator
The static coordinator is ready to go. There is no start method.
GenericBaseLoader::Coordinator::~Coordinator | ( | ) |
Destroys the static coordinator, releasing all resources
This will immediately orphan all loader instances and should not be called explicitly.
Creates a asset object and retains a reference to it.
Parameter asset is a partially created asset object. It has the file set, but has not loaded any resources. This method calls the load() method, (in either the main or a separate thread). It returns a reference to the same asset object, now with resources loaded.
asset | the partially created asset object |
the asset
|
inline |
Returns true if a source is allocated and loaded.
It is possible that there are multiple instances of the loader loading the same asset. We only want to load it once.
|
inline |
Returns true if a source is pending allocation.
It is possible that there are multiple instances of the loader loading the same asset. We only want to load it once.
Loads the given asset into memory
Parameter asset is a partially created asset object. It has the file set, but has not loaded any resources. This method calls the load() method, (in either the main or a separate thread). It returns a reference to the same asset object, now with resources loaded.
The asset will be loaded synchronously. It will be available immediately. If it was previously loaded asynchronously, this method will block until it is done.
source | The pathname to the asset file |
size | The size |
the asset upon loading
void GenericBaseLoader::Coordinator::loadAsync | ( | Asset * | asset, |
std::function< void(Asset *s)> | callback | ||
) |
Adds a new asset to the loading queue.
Parameter asset is a partially created asset object. It has the file set, but has not loaded any resources. This method calls the load() method, (in either the main or a separate thread). It returns a reference to the same asset object, now with resources loaded.
The asset will be loaded asynchronously. When it is finished loading, it will be added to this loader, and accessible to ALL loaders. If the file is still pending, the callback will be appended to the callback list.
source | the pathname to the asset file |
callback | callback to invoke when loading is done. |
the asset upon loading
void GenericBaseLoader::Coordinator::release | ( | Asset * | asset | ) |
Safely releases the asset for one loader
If there are no more references to the asset, it unloads the asset from memory and deletes this object.
asset | the asset to release. |
the asset
size_t GenericBaseLoader::Coordinator::instances |
The number of active asset loader instances