CUGL 3.0
Cornell University Game Library
|
#include <CULoader.h>
Public Member Functions | |
Loader () | |
std::shared_ptr< T > | get (const std::string key) const |
std::shared_ptr< T > | 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 |
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< 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 |
Protected Attributes | |
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 |
size_t | _reserved |
std::shared_ptr< ThreadPool > | _loader |
AssetManager * | _manager |
Additional Inherited Members | |
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 | purgeKey (const std::string key) |
virtual bool | purgeJson (const std::shared_ptr< JsonValue > &json) |
virtual bool | verify (const std::string key) const |
This class is a specific template for each loader.
This template works like a generic abstract class in Java. It provides some type correctness. It also provides some base functionality that is common for all loaders. Methods marked as abstract must be overriden in specific loader implementations.
All assets are assigned a key and retrieved via that key. This provides a quick way to reference assets.
IMPORTANT: This class is not even remotely thread-safe. Do not call any of these methods outside of the main CUGL thread.
|
inline |
Creates a degenerate asset loader with no resources
NEVER CALL THIS CONSTRUCTOR. As this is an abstract class, you should call one of the static constructors of the appropriate child class.
|
inline |
Queues up an asset for loading.
This method adds the given key to the queue. It also deducts from the reserve count if that value is non-zero.
key | The asset key to queue. |
|
inline |
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
key | The key associated with the asset |
|
inlineoverridevirtual |
Returns the number of assets that are actively being loaded.
This method is different from waitCount
in that it does not count reserved assets. It only counts those elements which have been queued, but which have not yet been fully loaded.
Reimplemented from cugl::BaseLoader.
|
inlineoverridevirtual |
Returns the set of active keys in this loader.
Reimplemented from cugl::BaseLoader.
|
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.
Reimplemented from cugl::BaseLoader.
|
inline |
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
key | The key associated with the asset |
|
inlineoverridevirtual |
Unloads the asset for the given key
An asset may still be available if it is referenced by a smart pointer. See the description of the specific implementation for how assets are released.
This method is abstract and should be overridden in child classes. You will notice that this method is essentially identical to unload. We separated the methods because overloading and virtual methods do not place nice.
Reimplemented from cugl::BaseLoader.
|
inlineoverridevirtual |
Unloads all assets present in this loader.
An asset may still be available if it is referenced by a smart pointer. See the description of the specific implementation for how assets are released.
Reimplemented from cugl::BaseLoader.
|
inlineoverridevirtual |
Returns true if the key maps to a loaded asset.
This method is useful in case the asset fails to load. You will notice that this method is essentially identical to contains. We separated the methods because overloading and virtual methods do not place nice.
key | The key associated with the asset |
Reimplemented from cugl::BaseLoader.
|
protected |
Hash map storing the loaded assets
|
protected |
The assets we are expecting that are not yet loaded