Cornell Cocos
Cornell Extensions to Cocos2d
|
#include <CUSoundLoader.h>
Public Member Functions | |
Coordinator () | |
~Coordinator () | |
bool | isLoaded (std::string source) const |
bool | isPending (std::string source) const |
Sound * | load (std::string source) |
void | loadAsync (std::string source, std::function< void(Sound *s)> callback) |
void | allocate (std::string source, bool success, bool preload=true) |
void | release (Sound *sound) |
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.
SoundLoader::Coordinator::Coordinator | ( | ) |
Creates a new static coordinator
The static coordinator is ready to go. There is no start method.
SoundLoader::Coordinator::~Coordinator | ( | ) |
Destroys new static coordinator, releasing all resources
This will immediately orphan all loader instances and should not be called explicitly.
void SoundLoader::Coordinator::allocate | ( | std::string | source, |
bool | success, | ||
bool | preload = true |
||
) |
Creates a Sound object and retains a reference to it.
This method is called when experimental::AudioEngine is done loading. It takes the results and packages them in a sound file, which is assigned to _sources.
source | the sound file information |
success | whether the sound was successfully loaded |
preload | whether the sound was preloaded at all |
the sound 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 sound. 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 sound. We only want to load it once.
Sound * SoundLoader::Coordinator::load | ( | std::string | source | ) |
Loads the given sound into memory
The sound 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 sound file |
the sound asset upon loading
void SoundLoader::Coordinator::loadAsync | ( | std::string | source, |
std::function< void(Sound *s)> | callback | ||
) |
Adds a new sound to the loading queue.
The sound 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 sound file |
callback | callback to invoke when loading is done. |
the sound asset upon loading
void SoundLoader::Coordinator::release | ( | Sound * | sound | ) |
Safely releases the sound for one loader
If there are no more references to the sound, it unloads the sound from memory and deletes this object.
sound | the sound to release. |
the sound asset
size_t SoundLoader::Coordinator::instances |
The number of active sound loader instances