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

#include <CUTextureLoader.h>

Public Member Functions

 Coordinator ()
 
 ~Coordinator ()
 
bool isLoaded (std::string source) const
 
bool isPending (std::string source) const
 
Texture2D * load (std::string source)
 
void loadAsync (std::string source, std::function< void(Texture2D *s)> callback)
 
void allocate (Texture2D *texture, std::string source)
 
void release (Texture2D *texture)
 

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

TextureLoader::Coordinator::Coordinator ( )

Creates a new static coordinator

The static coordinator is ready to go. There is no start method.

TextureLoader::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

void TextureLoader::Coordinator::allocate ( Texture2D *  texture,
std::string  source 
)

Creates a texture object and retains a reference to it.

This method is called when Cocos2D TextureCache is finished loading. It takes the results and packages them in a texture file, which is assigned to _sources.

Parameters
sourceThe texture file information
successWhether the texture was successfully loaded

the texture asset

bool TextureLoader::Coordinator::isLoaded ( std::string  source) 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 texture. We only want to load it once.

Returns
true if a source is allocated and loaded.
bool TextureLoader::Coordinator::isPending ( std::string  source) const
inline

Returns true if a source is pending allocation.

It is possible that there are multiple instances of the loader loading the same texture. We only want to load it once.

Returns
true if a source is pending allocation.
Texture2D * TextureLoader::Coordinator::load ( std::string  source)

Loads the given texture into memory

The texture 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 texture image file

the texture asset upon loading

void TextureLoader::Coordinator::loadAsync ( std::string  source,
std::function< void(Texture2D *s)>  callback 
)

Adds a new texture to the loading queue.

The texture 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 texture file
callbackcallback to invoke when loading is done.

the texture asset upon loading

void TextureLoader::Coordinator::release ( Texture2D *  texture)

Safely releases the texture for one loader

If there are no more references to the texture, it unloads the texture from memory and deletes this object.

Parameters
texturethe texture to release.

the texture asset

Member Data Documentation

size_t TextureLoader::Coordinator::instances

The number of active texture loader instances


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