Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
SceneManager Class Reference

#include <CUSceneManager.h>

Inheritance diagram for SceneManager:

Public Member Functions

void start ()
 
void stop ()
 
bool isActive () const
 
template<typename T >
bool attach (Loader< T > *loader)
 
template<typename T >
bool isAttached ()
 
template<typename T >
bool detach ()
 
void detachAll ()
 
template<typename T >
Loader< T > * access ()
 
size_t loadCount () const
 
size_t waitCount () const
 
bool isComplete () const
 
float progress () const
 
template<typename T >
T * get (std::string key) const
 
template<typename T >
T * load (std::string key, std::string source)
 
template<typename T >
void loadAsync (std::string key, std::string source)
 
template<typename T >
void unload (std::string key)
 
void unloadAll ()
 
 detachAll ()
 

Static Public Member Functions

static SceneManagercreate ()
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: SceneManager() : _active(false) {} ~SceneManager() { if (_active) { stop()
 

Protected Attributes

bool _active
 
std::unordered_map< size_t, BaseLoader * > _handlers
 

Detailed Description

Class is an asset manager for a single scene.

This asset manager is uses to manage a collection of loaders. Loaders must be "attached" to the asset manager. The asset manager does not come with a collection of asset managers pre-installed. You will need to do this yourself in the start-up code for each scene.

Once a loader is attached to this asset manager, the manager obtains ownership of the loader. It will be responsible for garbage collection when it is done.

Member Function Documentation

template<typename T >
Loader<T>* SceneManager::access ( )
inline

Returns the loader the given asset Type

The type of the asset is specified by the template parameter T.

Returns
the loader the given asset Type
template<typename T >
bool SceneManager::attach ( Loader< T > *  loader)
inline

Attaches the given loader to an asset manager

The type of the asset is specified by the template parameter T. Once attached, all assets of type T will use this loader for this scene. In addition, this asset manager will obtain ownership of the loader and be responsible for its garbage collection.

Parameters
loaderThe loader for asset T

a reference to this loader

Returns
false if there is already a loader for this asset
NS_CC_BEGIN SceneManager * SceneManager::create ( )
static

Creates a new SceneManager.

This constructor does not start the scene manager or attach any loaders. It simply creates an object that is ready to accept loader objects. Call start() when you are ready to start using it.

Returns
an autoreleased SceneManager object
template<typename T >
bool SceneManager::detach ( )
inline

Detaches a loader for an asset type

The type of the asset is specified by the template parameter T. The loader will be released and deleted if there are no further references to it.

the reference to the loader

Returns
true if there was a loader of that Type.
void SceneManager::detachAll ( )
inline

Detaches all loaders from this asset manager

The loaders will be released and deleted if there are no further references to them.

the reference to all loaders

template<typename T >
T* SceneManager::get ( std::string  key) const
inline

Returns the asset for the given key.

The type of the asset is specified by the template parameter T.

Parameters
keyThe key to identify the given asset
Returns
the asset for the given key.
bool SceneManager::isActive ( ) const
inline

Returns true if this asset manager is active.

An active manager is one that can load assets (e.g. method start() has been called). If it is not active, none of its attached loaders are active either.

Returns
true if this asset manager is active.
template<typename T >
bool SceneManager::isAttached ( )
inline

Returns True if there is a loader for the given asset Type

The type of the asset is specified by the template parameter T.

Returns
True if there is a loader for the given asset Type
bool SceneManager::isComplete ( ) const
inline

Returns true if the loader has finished loading all assets.

It is not safe to use asynchronously loaded assets until all loading is complete. This method allows us to determine when asset loading is complete.

Returns
true if the loader has finished loading
template<typename T >
T* SceneManager::load ( std::string  key,
std::string  source 
)
inline

Loads an asset and assigns it to the given key.

The type of the asset is specified by the template parameter T. The asset will be loaded synchronously. It will be available immediately. This method should be limited to those times in which an asset is really necessary immediately, such as for a loading screen.

Parameters
keyThe key to access the asset after loading
sourceThe pathname to the asset source
Returns
the loaded asset
template<typename T >
void SceneManager::loadAsync ( std::string  key,
std::string  source 
)
inline

Adds a new asset to the loading queue.

The type of the asset is specified by the template parameter T. The asset will be loaded asynchronously. When it is finished loading, it will be added to this loader, and accessible under the given key. This method will mark the loading process as not complete, even if it was completed previously. It is not safe to access the loaded asset until it is complete again.

Parameters
keyThe key to access the asset after loading
sourceThe pathname to the asset source
size_t SceneManager::loadCount ( ) const

Returns the number of assets currently loaded.

This is a rough way to determine how many assets have been loaded so far. This method counts each asset equally regardless of the memory requirements of each asset.

This method is abstract and should be overridden in the specific implementation for each asset.

Returns
the number of assets currently loaded.
float SceneManager::progress ( ) const
inline

Returns the loader progress as a percentage.

This method returns a value between 0 and 1. A value of 0 means no assets have been loaded. A value of 1 means that all assets have been loaded.

Anything in-between indicates that there are assets which have been loaded asynchronously and have not completed loading. It is not safe to use asynchronously loaded assets until all loading is complete.

Returns
the loader progress as a percentage.
void SceneManager::start ( )

Starts this asset manager.

This method bootstraps the manager with any initial resources that it needs to load assets. Attempts to use any loader attached to this manager, before this method is called, will fail.

By separating this call from the constructor, this allows us to construct loaders and attach them to this manager before we are ready to load assets.

void SceneManager::stop ( )

Stops this manager, removing all assets.

All of the loaders attached to this resource manager will immediately release their assets. However, an asset may still be available if it is attached to another loader or scene manager. This depends on the loaders involved.

Once the manager is stopped, any attempts to load a new asset will fail. You must call start() to begin loading assets again.

template<typename T >
void SceneManager::unload ( std::string  key)
inline

Unloads the asset for the given key.

The type of the asset is specified by the template parameter T. This method simply unloads the asset for the scene associated with this loader. Depending upon the loader, it may not be removed from memory if there are other loaders referencing the same asset.

Parameters
keythe key referencing the asset
void SceneManager::unloadAll ( )
inline

Unloads all assets present in this loader.

This method unloads all assets for the scene associated with this loader. Depending upon the loaders, the assets may not be removed from memory if there are other loaders referencing the same assets.

size_t SceneManager::waitCount ( ) const

Returns the number of assets waiting to load.

This is a rough way to determine how many assets are still pending. An asset is pending if it has been loaded asychronously, and the loading process has not yet finished. This method counts each asset equally regardless of the memory requirements of each asset.

This method is abstract and should be overridden in the specific implementation for each asset.

Returns
the number of assets waiting to load.

Member Data Documentation

bool SceneManager::_active
protected

Whether or not this scene manager is active

std::unordered_map<size_t,BaseLoader*> SceneManager::_handlers
protected

The individual loaders for each type


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