![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUGradientLoader.h>
Public Member Functions | |
GradientLoader () | |
void | dispose () override |
![]() | |
Loader () | |
std::shared_ptr< Gradient > | get (const std::string key) const |
std::shared_ptr< Gradient > | operator[] (const std::string key) const |
size_t | loadCount () const override |
size_t | inFlight () const override |
void | enqueue (const std::string key) |
void | unloadAll () override |
virtual std::vector< std::string > | keys () override |
bool | purgeKey (const std::string key) override |
bool | verify (const std::string key) const override |
![]() | |
BaseLoader () | |
~BaseLoader () | |
virtual void | dispose () |
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 |
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 |
void | reserve (size_t amount) |
virtual size_t | loadCount () const |
size_t | waitCount () const |
virtual size_t | inFlight () const |
bool | complete () const |
float | progress () const |
Static Public Member Functions | |
static std::shared_ptr< GradientLoader > | alloc () |
static std::shared_ptr< GradientLoader > | alloc (const std::shared_ptr< ThreadPool > &threads) |
Protected Member Functions | |
std::shared_ptr< Gradient > | preload (const std::string key, const std::string source) |
std::shared_ptr< Gradient > | preload (const std::shared_ptr< JsonValue > &json) |
bool | materialize (const std::string key, const std::shared_ptr< Gradient > &gradient, 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 |
![]() | |
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 | purgeKey (const std::string key) |
virtual bool | purgeJson (const std::shared_ptr< JsonValue > &json) |
virtual bool | verify (const std::string key) const |
Additional Inherited Members | |
![]() | |
std::unordered_map< std::string, std::shared_ptr< Gradient > > | _assets |
std::unordered_set< std::string > | _queue |
![]() | |
std::string | _jsonKey |
Uint32 | _priority |
size_t | _reserved |
std::shared_ptr< ThreadPool > | _loader |
AssetManager * | _manager |
This class is a specific implementation of Loader<Gradient>
This asset loader allows us to allocate color gradients from a JSON specification. The format of this json data is the same as that required by Gradient#allocWithData
.
Technically, this loader uses the two phase loading system that all other loaders do. However, gradients can be full materialized off the main thread, so this is not a major issue.
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 gradient 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 gradient 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.
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 gradient 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
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.
|
protected |
Assigns the gradient to the given key.
This method finishes the asset loading started in preload
. As the gradient is fully materialized, all it does is assign the key to the asset. We do this to make sure the key access is thread safe.
This method supports an optional callback function which reports whether the asset was successfully materialized.
key | The key to access the asset after loading |
gradient | The gradient to assign the key |
callback | An optional callback for asynchronous loading |
|
protected |
Loads the portion of this asset that is safe to load outside the main thread.
In the case of the gradient, this is the entire asset. The only thing that materialize does is assign the key, ensuring that key access is safe on the main thread.
json | The JSON entry specifying the asset |
|
protected |
Loads the portion of this asset that is safe to load outside the main thread.
In the case of the gradient, this is the entire asset. The only thing that materialize does is assign the key, ensuring that key access is safe on the main thread.
key | The key to access the asset after loading |
source | The pathname to the asset |
|
overrideprotectedvirtual |
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 preload
and materialize
methods. This ensures that asynchronous loading is safe.
This version of read provides support for JSON directories. A gradient entry is a JSON object (or the name of a file containing a JSON object), satisfying the specification of Gradient#allocWithData
.
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.
|
overrideprotectedvirtual |
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 preload
and materialize
methods. This ensures that asynchronous loading is safe.
A gradient is a JSON file, whose contents satisfy the specification of Gradient#allocWithData
.
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.