Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
GenericLoader< T > Class Template Reference

#include <CUGenericLoader.h>

Inheritance diagram for GenericLoader< T >:
Loader< T > BaseLoader

Public Member Functions

void start () override
 
void stop () override
 
size_t waitCount () const override
 
size_t loadCount () const override
 
bool contains (std::string key) const override
 
T * get (std::string key) const override
 
T * load (std::string key, std::string source) override
 
void loadAsync (std::string key, std::string source) override
 
void unload (std::string key) override
 
void unloadAll () override
 
 GenericLoader ()
 
virtual ~GenericLoader ()
 
- Public Member Functions inherited from Loader< T >
T * operator[] (std::string key) const
 
- Public Member Functions inherited from BaseLoader
bool isActive () const
 
bool isComplete () const
 
float progress () const
 
CC_CONSTRUCTOR_ACCESS _active (false)
 
virtual ~BaseLoader ()
 

Static Public Member Functions

static GenericLoader< T > * create ()
 

Protected Attributes

GenericBaseLoader_internal
 
- Protected Attributes inherited from Loader< T >
std::unordered_map< std::string, T * > _assets
 
- Protected Attributes inherited from BaseLoader
bool _active
 

Additional Inherited Members

- Public Attributes inherited from BaseLoader
CC_CONSTRUCTOR_ACCESS __pad0__: BaseLoader() : Ref()
 

Detailed Description

template<class T>
class GenericLoader< T >

Class is a implementation of Loader<T> where T is a subclass of Asset.

This asset loader allows us to allocate generic from the associated source files. Instances of this loader wrap GenericBaseLoader, giving us access to the static coordinator for assets. It decides When an asset is truly ready to be unloaded. We assume that all instances are run only in the Director thread.

Constructor & Destructor Documentation

template<class T>
GenericLoader< T >::GenericLoader ( )
inline

Creates a new, uninitialized asset loader

template<class T>
virtual GenericLoader< T >::~GenericLoader ( )
inlinevirtual

Disposes of the asset loader.

This destructor will stop the asset loader if not done so already.

Member Function Documentation

template<class T>
bool GenericLoader< T >::contains ( std::string  key) const
inlineoverridevirtual

Returns true if the key maps to a loaded asset.

This method is useful in case the asset fails to load.

Parameters
keythe key associated with the asset
Returns
True if the key maps to a loaded asset.

Reimplemented from Loader< T >.

template<class T>
static GenericLoader<T>* GenericLoader< T >::create ( )
inlinestatic

Creates a new GenericLoader.

This constructor does not start the generic loader. It simply creates an object for the generic loader so that it can be attached to the asset manager. Call start() when you are ready to start using it.

Returns
an autoreleased GenericLoader object
template<class T>
T* GenericLoader< T >::get ( std::string  key) const
inlineoverridevirtual

Returns the asset for the given key.

If the key is valid, the asset is guaranteed not to be null. Otherwise, this method returns nullptr

Parameters
keythe key associated with the asset
Returns
the asset pointer for the given key

Reimplemented from Loader< T >.

template<class T>
T* GenericLoader< T >::load ( std::string  key,
std::string  source 
)
inlineoverridevirtual

Loads a asset and assigns it to the given key.

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 file

the loaded asset

Returns
the loaded asset

Reimplemented from Loader< T >.

template<class T>
void GenericLoader< T >::loadAsync ( std::string  key,
std::string  source 
)
inlineoverridevirtual

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.

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

the asset upon loading

Reimplemented from BaseLoader.

template<class T>
size_t GenericLoader< T >::loadCount ( ) const
inlineoverridevirtual

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.

Returns
the number of assets currently loaded.

Reimplemented from Loader< T >.

template<class T>
void GenericLoader< T >::start ( )
inlineoverridevirtual

Starts this GenericLoader.

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. The asset manager is backed by a central coordinator that allows the sharing of assets.

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

Reimplemented from BaseLoader.

template<class T>
void GenericLoader< T >::stop ( )
inlineoverridevirtual

Stops this GenericLoader, 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. Once the loader is stopped, any attempts to load a new asset will fail. You must call start() to begin loading assets again.

Reimplemented from BaseLoader.

template<class T>
void GenericLoader< T >::unload ( std::string  key)
inlineoverridevirtual

Unloads the asset for the given key.

This method simply unloads the asset for the scene associated with this loader. The asset will not be deleted or removed from memory until it is removed from all instances of GenericLoader.

Parameters
keythe key referencing the asset

the asset for the given key

Reimplemented from BaseLoader.

template<class T>
void GenericLoader< T >::unloadAll ( )
inlineoverridevirtual

Unloads all assets present in this loader.

This method simply unloads the assets for the scene associated with this loader. The assets will not be deleted or removed from memory until they are removed from all instances of GenericLoader.

all loaded assets

Reimplemented from BaseLoader.

template<class T>
size_t GenericLoader< T >::waitCount ( ) const
inlineoverridevirtual

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 the format.

Returns
the number of assets waiting to load.

Reimplemented from BaseLoader.

Member Data Documentation

template<class T>
GenericBaseLoader* GenericLoader< T >::_internal
protected

Wrapped reference to the base loader


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