Cornell Cocos
Cornell Extensions to Cocos2d
|
#include <CUSceneManager.h>
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 SceneManager * | create () |
Public Attributes | |
CC_CONSTRUCTOR_ACCESS | __pad0__: SceneManager() : _active(false) {} ~SceneManager() { if (_active) { stop() |
Protected Attributes | |
bool | _active |
std::unordered_map< size_t, BaseLoader * > | _handlers |
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.
|
inline |
Returns the loader the given asset Type
The type of the asset is specified by the template parameter T.
|
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.
loader | The loader for asset T |
a reference to this loader
|
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.
|
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
|
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
|
inline |
Returns the asset for the given key.
The type of the asset is specified by the template parameter T.
key | The key to identify the given asset |
|
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.
|
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.
|
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.
|
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.
key | The key to access the asset after loading |
source | The pathname to the asset 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.
key | The key to access the asset after loading |
source | The 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.
|
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.
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.
|
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.
key | the key referencing the asset |
|
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.
|
protected |
Whether or not this scene manager is active
|
protected |
The individual loaders for each type