CUGL 2.0
Cornell University Game Library
|
#include <CUGenericLoader.h>
Public Member Functions | |
GenericLoader () | |
void | dispose () override |
Public Member Functions inherited from cugl::Loader< T > | |
Loader () | |
std::shared_ptr< T > | get (const std::string &key) const |
std::shared_ptr< T > | get (const char *key) const |
std::shared_ptr< T > | operator[] (const std::string &key) const |
std::shared_ptr< T > | operator[] (const char *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 bool | init () |
virtual bool | init (const std::shared_ptr< ThreadPool > &threads) |
std::shared_ptr< BaseLoader > | getHook () |
std::shared_ptr< ThreadPool > | getThreadPool () const |
void | setThreadPool (const std::shared_ptr< ThreadPool > &threads) |
void | setManager (AssetManager *manager) |
const AssetManager * | getManager () const |
bool | load (const std::string &key, const std::string &source) |
bool | load (const char *key, const std::string &source) |
bool | load (const std::string &key, const char *source) |
bool | load (const char *key, const char *source) |
bool | load (const std::shared_ptr< JsonValue > &json) |
void | loadAsync (const std::string &key, const std::string &source, LoaderCallback callback) |
void | loadAsync (const char *key, const std::string &source, LoaderCallback callback) |
void | loadAsync (const std::string &key, const char *source, LoaderCallback callback) |
void | loadAsync (const char *key, const char *source, LoaderCallback callback) |
void | loadAsync (const std::shared_ptr< JsonValue > &json, LoaderCallback callback) |
bool | unload (const std::string &key) |
bool | unload (const char *key) |
bool | unload (const std::shared_ptr< JsonValue > &json) |
bool | contains (const std::string &key) const |
bool | contains (const char *key) 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) |
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 > | |
bool | purge (const std::string &key) override |
bool | verify (const std::string &key) const override |
Protected Member Functions inherited from cugl::BaseLoader | |
virtual bool | purge (const std::shared_ptr< JsonValue > &json) |
Protected Attributes | |
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::shared_ptr< ThreadPool > | _loader |
AssetManager * | _manager |
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.
|
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.
|
inlinestatic |
Returns a newly allocated asset loader.
This method bootstraps the loader with any initial resources that it needs to load assets.
This loader will have no associated threads. That means any asynchronous loading will fail until a thread is provided via setThreadPool.
|
inlinestatic |
Returns a newly allocated texture loader.
This method bootstraps the loader with any initial resources that it needs to load assets. In particular, the OpenGL context must be active. Attempts to load an asset before this method is called will fail.
threads | The thread pool for asynchronous loading |
|
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.
|
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.
key | The key to access the asset after loading |
asset | The generic asset partially loaded |
callback | An optional callback for asynchronous loading |
|
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.
json | The directory entry for the asset |
callback | An optional callback for asynchronous loading |
async | Whether the asset was loaded asynchronously |
Reimplemented from cugl::BaseLoader.
|
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.
key | The key to access the asset after loading |
source | The pathname to the asset |
callback | An optional callback for asynchronous loading |
async | Whether the asset was loaded asynchronously |
Reimplemented from cugl::BaseLoader.
|
protected |
Access the thread pool in the super class