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

#include <CUFontLoader.h>

Public Member Functions

 Coordinator ()
 
 ~Coordinator ()
 
bool isLoaded (std::string id) const
 
bool isPending (std::string id) const
 
TTFontload (std::string source, float size)
 
void loadAsync (std::string source, float size, std::function< void(TTFont *s)> callback)
 
TTFontallocateSync (TTFont *texture)
 
void allocateAsync (TTFont *texture, FontAtlas *atlas)
 
void release (TTFont *font)
 

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

FontLoader::Coordinator::Coordinator ( )

Creates a new static coordinator

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

FontLoader::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 FontLoader::Coordinator::allocateAsync ( TTFont font,
FontAtlas *  atlas 
)

Creates a font object and retains a reference to it.

Parameter font is a partially created font object. It has TTConfig information but no associated atlas. This allocates the font object with the given atlas, which was created asynchronously. This method should be used as a callback for the asynchronous loader.

Parameters
fontthe partially created font object
atlasthe atlas to associate with the font object

the font asset

TTFont * FontLoader::Coordinator::allocateSync ( TTFont font)

Creates a font object and retains a reference to it.

Parameter font is a partially created font object. It has TTConfig information but no associated atlas. This allocates the atlas synchronously blocking until it is done. It returns a reference to the same font object, now with atlas information included.

Parameters
fontthe partially created font object

the font asset

Returns
the same font object, complete with atlas
bool FontLoader::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 font. We only want to load it once.

Returns
true if a source is allocated and loaded.
bool FontLoader::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 font. We only want to load it once.

Returns
true if a source is pending allocation.
TTFont * FontLoader::Coordinator::load ( std::string  source,
float  size 
)

Loads the given font into memory

The font 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 font file
sizeThe font size

the font asset upon loading

void FontLoader::Coordinator::loadAsync ( std::string  source,
float  size,
std::function< void(TTFont *s)>  callback 
)

Adds a new font to the loading queue.

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

the font asset upon loading

void FontLoader::Coordinator::release ( TTFont font)

Safely releases the font for one loader

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

Parameters
fontthe font to release.

the font asset

Member Data Documentation

size_t FontLoader::Coordinator::instances

The number of active font loader instances


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