Cornell Cocos
Cornell Extensions to Cocos2d
|
#include <CUFontLoader.h>
Public Member Functions | |
Coordinator () | |
~Coordinator () | |
bool | isLoaded (std::string id) const |
bool | isPending (std::string id) const |
TTFont * | load (std::string source, float size) |
void | loadAsync (std::string source, float size, std::function< void(TTFont *s)> callback) |
TTFont * | allocateSync (TTFont *texture) |
void | allocateAsync (TTFont *texture, FontAtlas *atlas) |
void | release (TTFont *font) |
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.
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.
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.
font | the partially created font object |
atlas | the atlas to associate with the font object |
the font asset
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.
font | the partially created font object |
the font 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 font. 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 font. We only want to load it once.
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.
source | The pathname to the font file |
size | The 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.
source | the pathname to the font file |
callback | callback 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.
font | the font to release. |
the font asset
size_t FontLoader::Coordinator::instances |
The number of active font loader instances