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

#include <CULoader.h>

Inheritance diagram for BaseLoader:
Loader< T > Loader< Asset > Loader< Sound > Loader< Texture2D > Loader< TTFont > GenericLoader< T > GenericBaseLoader SoundLoader TextureLoader FontLoader

Public Member Functions

virtual void start ()
 
virtual void stop ()
 
bool isActive () const
 
virtual void loadAsync (std::string key, std::string source)
 
virtual void unload (std::string key)
 
virtual void unloadAll ()
 
virtual size_t loadCount () const
 
virtual size_t waitCount () const
 
bool isComplete () const
 
float progress () const
 
CC_CONSTRUCTOR_ACCESS _active (false)
 
virtual ~BaseLoader ()
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: BaseLoader() : Ref()
 

Protected Attributes

bool _active
 

Detailed Description

Class provides a polymorphic base to the loader system.

This is effectively a Java-style interface. It identifies the methods that all loaders must have, and provides a type for the AssetManager to use in its underlying storage container.

Constructor & Destructor Documentation

virtual BaseLoader::~BaseLoader ( )
inlinevirtual

Diposes the base loader, releasing all resources

This destructor is protected, as loaders will use Cocos2d's reference counting system for garbage collection.

Member Function Documentation

bool BaseLoader::isActive ( ) const
inline

Returns true if this resource loader is active.

An active resource loader is one that can load assets (e.g. method start() has been called).

Returns
true if this resource loader is active.
bool BaseLoader::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
virtual void BaseLoader::loadAsync ( std::string  key,
std::string  source 
)
inlinevirtual

Adds a new asset to the loading queue.

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.

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

Parameters
keyThe key to access the asset after loading
sourceThe pathname to the asset

Reimplemented in GenericLoader< T >, FontLoader, TextureLoader, GenericBaseLoader, and SoundLoader.

virtual size_t BaseLoader::loadCount ( ) const
inlinevirtual

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.

Reimplemented in GenericLoader< T >, Loader< T >, Loader< Asset >, Loader< Sound >, Loader< Texture2D >, and Loader< TTFont >.

float BaseLoader::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.
virtual void BaseLoader::start ( )
inlinevirtual

Starts this resource loader.

This method bootstraps the loader with any initial resources that it needs to load assets. Attempts to load an asset before this method is called will fail.

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

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

Reimplemented in GenericLoader< T >, FontLoader, TextureLoader, GenericBaseLoader, and SoundLoader.

virtual void BaseLoader::stop ( )
inlinevirtual

Stops this resource loader removing all assets.

Any assets loaded by this loader will be immediately released by the loader. However, an asset may still be available if it is attached to another loader. See the description of the specific implementation for how assets are released.

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

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

Reimplemented in GenericLoader< T >, FontLoader, TextureLoader, GenericBaseLoader, and SoundLoader.

virtual void BaseLoader::unload ( std::string  key)
inlinevirtual

Unloads the asset for the given key.

An asset may still be available if it is attached to another loader. See the description of the specific implementation for how assets are released.

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

Parameters
keythe key referencing the asset

Reimplemented in GenericLoader< T >, FontLoader, TextureLoader, GenericBaseLoader, and SoundLoader.

virtual void BaseLoader::unloadAll ( )
inlinevirtual

Unloads all assets present in this loader.

An asset may still be available if it is attached to another loader. See the description of the specific implementation for how assets are released. This method is similar to stop(), except that new assets can be loaded.

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

Reimplemented in GenericLoader< T >, FontLoader, TextureLoader, GenericBaseLoader, and SoundLoader.

virtual size_t BaseLoader::waitCount ( ) const
inlinevirtual

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.

Reimplemented in GenericLoader< T >, FontLoader, TextureLoader, GenericBaseLoader, and SoundLoader.

Member Data Documentation

bool BaseLoader::_active
protected

Whether or not this resource loader is active


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