CUGL 2.3
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 | 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< 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 |
virtual size_t | loadCount () const |
virtual size_t | waitCount () const |
bool | complete () const |
float | progress () const |
Protected Member Functions | |
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::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 |
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 |
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 |
|
inlineoverrideprotectedvirtual |
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 |
|
inlineoverrideprotectedvirtual |
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.
|
inlineoverrideprotectedvirtual |
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.
|
inlineoverridevirtual |
Returns the number of textures waiting to load.
This is a rough way to determine how many texture are still pending. A texture is pending if it has been loaded asychronously, and the loading process has not yet finished. This method counts each texture equally regardless of the memory requirements of the format.
Reimplemented from cugl::BaseLoader.
|
protected |
Hash map storing the loaded assets
|
protected |
The assets we are expecting that are not yet loaded