![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUScene3Loader.h>
Public Member Functions | |
Scene3Loader () | |
virtual bool | init () override |
virtual bool | init (const std::shared_ptr< ThreadPool > &threads) override |
void | dispose () override |
std::shared_ptr< scene3::SceneNode > | build (const std::string key, const std::shared_ptr< JsonValue > &json) const |
![]() | |
Loader () | |
std::shared_ptr< SceneNode > | get (const std::string key) const |
std::shared_ptr< SceneNode > | 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< Scene3Loader > | alloc () |
static std::shared_ptr< Scene3Loader > | alloc (const std::shared_ptr< ThreadPool > &threads) |
Protected Types | |
enum class | Widget { NODE , OBJMODEL , BILLBOARD , PARTICLE , UNKNOWN } |
Protected Member Functions | |
bool | materialize (const std::shared_ptr< scene3::SceneNode > &node, 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 | purgeJson (const std::shared_ptr< JsonValue > &json) override |
bool | attach (const std::string key, const std::shared_ptr< scene3::SceneNode > &node) |
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 |
Protected Attributes | |
std::unordered_map< std::string, Widget > | _types |
![]() | |
std::unordered_map< std::string, std::shared_ptr< SceneNode > > | _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<Node>
This asset loader allows us to specify a scene graph subtree, which can be attached to a new or existing scene graph. This is particularly useful for desiging UI elements with a JSON directory structure rather than having to create them programmatically. While not exactly visual wireframing, this makes it easier for UX designers to layout user-interface elements, HUDS and the like.
As UI widgets typically require fonts and images to be loaded already, these should always be the last elements loaded in a loading phase.
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.
|
strongprotected |
|
inline |
Creates a new, uninitialized scene 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 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.
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 |
|
protected |
Attaches all generate nodes to the asset dictionary.
As the asset dictionary must be updated in the main thread, we do not update it until the entire node tree has been materialized. This method assumes that each Node is named with its asset look-up key.
key | The key to access the asset after loading |
node | The scene asset |
std::shared_ptr< scene3::SceneNode > cugl::scene3::Scene3Loader::build | ( | const std::string | key, |
const std::shared_ptr< JsonValue > & | json | ||
) | const |
Recursively builds the scene from the given JSON tree.
This method allows us to maximize the asynchronous creation of scenes. The key is assigned as the name of the root Node of the scene.
The JSON tree should be a tree of widget objects, where each widget object has the following attribute values:
"type": The node type (a Node or any subclass) "data": Data (images, labels) that define the widget. This JSON object has a node-specific format. "children": Any child Nodes of this one. This JSON object has a named attribute for each child.
With the exception of "type", all of these attributes are JSON objects.
key | The key to access the scene after loading |
json | The JSON object defining the scene |
|
inlineoverridevirtual |
Disposes all resources and assets of this loader
Any assets loaded by this object will be immediately released by the loader. However, a texture may still be available if it is referenced by another smart pointer. OpenGL will only release a texture asset once all smart pointer attached to the asset are null.
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.
|
inlineoverridevirtual |
Initializes a new asset loader.
This method bootstraps the loader with any initial resources that it needs to load assets. 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
.
This method is abstract and should be overridden in the specific implementation for each asset.
Reimplemented from cugl::BaseLoader.
|
overridevirtual |
Initializes a new asset loader.
This method bootstraps the loader with any initial resources that it needs to load assets. Attempts to load an asset before this method is called will fail.
This method is abstract and should be overridden in the specific implementation for each asset.
threads | The thread pool for asynchronous loading support |
Reimplemented from cugl::BaseLoader.
|
protected |
Records the given Node with this loader, so that it may be unloaded later.
This method finishes the asset loading started in load
. This step is not safe to be done in a separate thread, as it accesses the main asset table. Therefore, it takes place in the main CUGL thread via Application#schedule
. The scene is stored using the name of the root Node as a key.
This method supports an optional callback function which reports whether the asset was successfully materialized.
node | The scene asset |
callback | An optional callback for asynchronous loading |
|
overrideprotectedvirtual |
Unloads the asset for the given directory entry
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 version of the method not only unloads the given SceneNode
, but also any children attached to it in the JSON specification.
json | The directory entry for the asset |
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 is like the traditional read method except that it assumes the JSON data has already been parsed.
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.
The sources must be a JSON file. It will parse the JSON tree of this file, assigning the given key to the root node. The JSON tree should be a tree of widget objects, where each widget object has the following attribute values:
"type": The node type (a Node or any subclass) "data": Data (images, labels) that define the widget. This JSON object has a node-specific format. "children": Any child Nodes of this one. This JSON object has a named attribute for each child.
With the exception of "type", all of these attributes are JSON objects.
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 |
The type map for managing constructors