Cornell Cocos
Cornell Extensions to Cocos2d
|
#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 |
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.
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.
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.
source | The texture file information |
success | Whether the texture was successfully loaded |
the texture 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 texture. 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 texture. We only want to load it once.
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.
source | The 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.
source | the pathname to the texture file |
callback | callback 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.
texture | the texture to release. |
the texture asset
size_t TextureLoader::Coordinator::instances |
The number of active texture loader instances