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

#include <CUSoundLoader.h>

Public Member Functions

 Coordinator ()
 
 ~Coordinator ()
 
bool isLoaded (std::string source) const
 
bool isPending (std::string source) const
 
Soundload (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
 

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

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.

Member Function Documentation

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.

Parameters
sourcethe sound file information
successwhether the sound was successfully loaded
preloadwhether the sound was preloaded at all

the sound asset

bool SoundLoader::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 sound. We only want to load it once.

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

Returns
true if a source is pending allocation.
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.

Parameters
sourceThe 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.

Parameters
sourcethe pathname to the sound file
callbackcallback 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.

Parameters
soundthe sound to release.

the sound asset

Member Data Documentation

size_t SoundLoader::Coordinator::instances

The number of active sound loader instances


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