Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Public Attributes | List of all members
GenericBaseLoader::Coordinator Class Reference

#include <CUGenericLoader.h>

Public Member Functions

 Coordinator ()
 
 ~Coordinator ()
 
bool isLoaded (std::string id) const
 
bool isPending (std::string id) const
 
Assetload (Asset *asset)
 
void loadAsync (Asset *asset, std::function< void(Asset *s)> callback)
 
Assetallocate (Asset *asset)
 
void release (Asset *asset)
 

Public Attributes

size_t instances
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Member Function Documentation

Asset * GenericBaseLoader::Coordinator::allocate ( Asset asset)

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.

Parameters
assetthe partially created asset object

the asset

Returns
the same asset object, loaded from file
bool GenericBaseLoader::Coordinator::isLoaded ( std::string  id) const
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.

Returns
true if a source is allocated and loaded.
bool GenericBaseLoader::Coordinator::isPending ( std::string  id) const
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.

Returns
true if a source is pending allocation.
Asset * GenericBaseLoader::Coordinator::load ( Asset asset)

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.

Parameters
sourceThe pathname to the asset file
sizeThe 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.

Parameters
sourcethe pathname to the asset file
callbackcallback 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.

Parameters
assetthe asset to release.

the asset

Member Data Documentation

size_t GenericBaseLoader::Coordinator::instances

The number of active asset loader instances


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