CUGL 2.3
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cugl::GenericLoader< T > Class Template Reference

#include <CUGenericLoader.h>

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

Public Member Functions

 GenericLoader ()
 
virtual bool init () override
 
virtual bool init (const std::shared_ptr< ThreadPool > &threads) override
 
bool init (const std::string key, Uint32 priority)
 
bool init (const std::string key, Uint32 priority, const std::shared_ptr< ThreadPool > &threads)
 
void dispose () override
 
- Public Member Functions inherited from cugl::Loader< T >
 Loader ()
 
std::shared_ptr< Tget (const std::string key) const
 
std::shared_ptr< Toperator[] (const std::string key) const
 
size_t loadCount () const override
 
size_t waitCount () const override
 
void unloadAll () override
 
- Public Member Functions inherited from cugl::BaseLoader
 BaseLoader ()
 
 ~BaseLoader ()
 
virtual void dispose ()
 
virtual bool init ()
 
virtual bool init (const std::shared_ptr< ThreadPool > &threads)
 
std::shared_ptr< BaseLoadergetHook ()
 
std::shared_ptr< ThreadPoolgetThreadPool () const
 
void setThreadPool (const std::shared_ptr< ThreadPool > &threads)
 
void setManager (AssetManager *manager)
 
const AssetManagergetManager () const
 
void setJsonKey (const std::string key)
 
const std::string getJsonKey () const
 
void setPriority (Uint32 priority)
 
const Uint32 getPriority () const
 
bool load (const std::string key, const std::string source)
 
bool load (const std::shared_ptr< JsonValue > &json)
 
void loadAsync (const std::string key, const std::string source, LoaderCallback callback)
 
void loadAsync (const std::shared_ptr< JsonValue > &json, LoaderCallback callback)
 
bool unload (const std::string key)
 
bool unload (const std::shared_ptr< JsonValue > &json)
 
virtual void unloadAll ()
 
virtual std::vector< std::string > keys ()
 
bool contains (const std::string key) const
 
virtual size_t loadCount () const
 
virtual size_t waitCount () const
 
bool complete () const
 
float progress () const
 

Static Public Member Functions

static std::shared_ptr< GenericLoader< T > > alloc ()
 
static std::shared_ptr< GenericLoader< T > > alloc (const std::shared_ptr< ThreadPool > &threads)
 
static std::shared_ptr< GenericLoader< T > > alloc (const std::string key, Uint32 priority)
 
static std::shared_ptr< GenericLoader< T > > alloc (const std::string key, Uint32 priority, const std::shared_ptr< ThreadPool > &threads)
 

Protected Member Functions

bool materialize (const std::string key, const std::shared_ptr< T > &asset, LoaderCallback callback)
 
virtual bool read (const std::string key, const std::string source, LoaderCallback callback, bool async) override
 
virtual bool read (const std::shared_ptr< JsonValue > &json, LoaderCallback callback, bool async) override
 
- Protected Member Functions inherited from cugl::Loader< T >
virtual std::vector< std::string > keys () override
 
bool purge (const std::string key) override
 
bool verify (const std::string key) const override
 
- Protected Member Functions inherited from cugl::BaseLoader
virtual bool read (const std::string key, const std::string source, LoaderCallback callback, bool async)
 
virtual bool read (const std::shared_ptr< JsonValue > &json, LoaderCallback callback, bool async)
 
virtual bool purge (const std::string key)
 
virtual bool purge (const std::shared_ptr< JsonValue > &json)
 
virtual bool verify (const std::string key) const
 

Protected Attributes

std::string _jsonKey
 
Uint32 _priority
 
std::shared_ptr< ThreadPool_loader
 
- Protected Attributes inherited from cugl::Loader< T >
std::unordered_map< std::string, std::shared_ptr< T > > _assets
 
std::unordered_set< std::string > _queue
 
- Protected Attributes inherited from cugl::BaseLoader
std::string _jsonKey
 
Uint32 _priority
 
std::shared_ptr< ThreadPool_loader
 
AssetManager_manager
 

Detailed Description

template<class T>
class cugl::GenericLoader< T >

This class is a specialized extension of Loader<T> for type Asset.

This asset loader allows us to allocate generic assets that are subclasses of Asset. The rules for loading the asset are defined in the Asset class. This loader simply converts this interface into the standard one so that it can be used by the AssetManager.

As with all of our loaders, this loader is designed to be attached to an asset manager. Use the method getHook() to get the appropriate pointer for attaching the loader.

Constructor & Destructor Documentation

◆ GenericLoader()

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

Creates a new, uninitialized asset loader

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate a loader on the heap, use one of the static constructors instead.

Member Function Documentation

◆ alloc() [1/4]

template<class T >
static std::shared_ptr< GenericLoader< T > > cugl::GenericLoader< T >::alloc ( )
inlinestatic

Returns a newly allocated generic asset loader.

This loader will not have an associated JSON key. This means that it cannot be used in association with an asset directory. In addition, the loader will have no associated threads. That means any asynchronous loading will fail until a thread is provided via setThreadPool.

Returns
a newly allocated generic asset loader.

◆ alloc() [2/4]

template<class T >
static std::shared_ptr< GenericLoader< T > > cugl::GenericLoader< T >::alloc ( const std::shared_ptr< ThreadPool > &  threads)
inlinestatic

Returns a newly allocated generic asset loader.

This loader will not have an associated JSON key. This means that it cannot be used in association with an asset directory.

Parameters
threadsThe thread pool for asynchronous loading
Returns
a newly allocated generic asset loader.

◆ alloc() [3/4]

template<class T >
static std::shared_ptr< GenericLoader< T > > cugl::GenericLoader< T >::alloc ( const std::string  key,
Uint32  priority 
)
inlinestatic

Returns a newly allocated generic asset loader.

This loader will use the associated JSON key and priority, which means that it supports asset directories. However, the loader will have no associated threads. That means any asynchronous loading will fail until a thread is provided via setThreadPool.

Parameters
keyThe JSON key to use for asset directories
priorityThe loading priority when using an asset directory
Returns
a newly allocated generic asset loader.

◆ alloc() [4/4]

template<class T >
static std::shared_ptr< GenericLoader< T > > cugl::GenericLoader< T >::alloc ( const std::string  key,
Uint32  priority,
const std::shared_ptr< ThreadPool > &  threads 
)
inlinestatic

Returns a newly allocated generic asset loader.

This loader will use the associated JSON key and priority, which means that it supports asset directories. However, the loader will have no associated threads. That means any asynchronous loading will fail until a thread is provided via setThreadPool.

Parameters
keyThe JSON key to use for asset directories
priorityThe loading priority when using an asset directory
threadsThe thread pool for asynchronous loading support
Returns
a newly allocated generic asset loader.

◆ dispose()

template<class T >
void cugl::GenericLoader< T >::dispose ( )
inlineoverridevirtual

Disposes all resources and assets of this loader

Any assets loaded by this object will be immediately released by the loader. However, an asset may still be available if it is referenced by another smart pointer.

Once the loader is disposed, any attempts to load a new asset will fail. You must reinitialize the loader to begin loading assets again.

Reimplemented from cugl::BaseLoader.

◆ init() [1/4]

template<class T >
virtual bool cugl::GenericLoader< T >::init ( )
inlineoverridevirtual

Initializes a new generic asset loader.

This loader will not have an associated JSON key. This means that it cannot be used in association with an asset directory. In addition, the loader will have no associated threads. That means any asynchronous loading will fail until a thread is provided via setThreadPool.

Returns
true if the asset loader was initialized successfully

Reimplemented from cugl::BaseLoader.

◆ init() [2/4]

template<class T >
virtual bool cugl::GenericLoader< T >::init ( const std::shared_ptr< ThreadPool > &  threads)
inlineoverridevirtual

Initializes a new generic asset loader.

This loader will not have an associated JSON key. This means that it cannot be used in association with an asset directory.

Parameters
threadsThe thread pool for asynchronous loading support
Returns
true if the asset loader was initialized successfully

Reimplemented from cugl::BaseLoader.

◆ init() [3/4]

template<class T >
bool cugl::GenericLoader< T >::init ( const std::string  key,
Uint32  priority 
)
inline

Initializes a new generic asset loader.

This loader will use the associated JSON key and priority, which means that it supports asset directories. However, the loader will have no associated threads. That means any asynchronous loading will fail until a thread is provided via setThreadPool.

Parameters
keyThe JSON key to use for asset directories
priorityThe loading priority when using an asset directory
Returns
true if the asset loader was initialized successfully

◆ init() [4/4]

template<class T >
bool cugl::GenericLoader< T >::init ( const std::string  key,
Uint32  priority,
const std::shared_ptr< ThreadPool > &  threads 
)
inline

Initializes a new generic asset loader.

This loader will use the associated JSON key and priority, which means that it supports asset directories. However, the loader will have no associated threads. That means any asynchronous loading will fail until a thread is provided via setThreadPool.

Parameters
keyThe JSON key to use for asset directories
priorityThe loading priority when using an asset directory
threadsThe thread pool for asynchronous loading support
Returns
true if the asset loader was initialized successfully

◆ materialize()

template<class T >
bool cugl::GenericLoader< T >::materialize ( const std::string  key,
const std::shared_ptr< T > &  asset,
LoaderCallback  callback 
)
inlineprotected

Finishes loading the generic asset, finalizing any features in the main thread.

This step effectively calls Asset#materialize(), and passes the result to the optional callback function.

Parameters
keyThe key to access the asset after loading
assetThe generic asset partially loaded
callbackAn optional callback for asynchronous loading

◆ read() [1/2]

template<class T >
virtual bool cugl::GenericLoader< T >::read ( const std::shared_ptr< JsonValue > &  json,
LoaderCallback  callback,
bool  async 
)
inlineoverrideprotectedvirtual

Internal method to support asset loading.

This method supports either synchronous or asynchronous loading, as specified by the given parameter. If the loading is asynchronous, the user may specify an optional callback function.

This method will split the loading across the Asset#preload and the internal materialize method. This ensures that asynchronous loading is safe.

This version of read provides support for JSON directories. The exact format of the directory entry is up to you. However, the directory entry must be loaded manually, as AssetManager does not yet support generic JSON directory entries.

Parameters
jsonThe directory entry for the asset
callbackAn optional callback for asynchronous loading
asyncWhether the asset was loaded asynchronously
Returns
true if the asset was successfully loaded

Reimplemented from cugl::BaseLoader.

◆ read() [2/2]

template<class T >
virtual bool cugl::GenericLoader< T >::read ( const std::string  key,
const std::string  source,
LoaderCallback  callback,
bool  async 
)
inlineoverrideprotectedvirtual

Internal method to support asset loading.

This method supports either synchronous or asynchronous loading, as specified by the given parameter. If the loading is asynchronous, the user may specify an optional callback function.

This method will split the loading across the Asset#preload and the internal materialize method. This ensures that asynchronous loading is safe.

Parameters
keyThe key to access the asset after loading
sourceThe pathname to the asset
callbackAn optional callback for asynchronous loading
asyncWhether the asset was loaded asynchronously
Returns
true if the asset was successfully loaded

Reimplemented from cugl::BaseLoader.

Member Data Documentation

◆ _jsonKey

template<class T >
std::string cugl::BaseLoader::_jsonKey
protected

Access the JSON key in the super class

◆ _loader

template<class T >
std::shared_ptr<ThreadPool> cugl::BaseLoader::_loader
protected

Access the thread pool in the super class

◆ _priority

template<class T >
Uint32 cugl::BaseLoader::_priority
protected

Access the priority in the super class


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