CUGL 2.1
Cornell University Game Library
|
#include <CUScene2Loader.h>
Public Member Functions | |
Scene2Loader () | |
virtual bool | init () override |
virtual bool | init (const std::shared_ptr< ThreadPool > &threads) override |
void | dispose () override |
std::shared_ptr< scene2::SceneNode > | build (const std::string &key, const std::shared_ptr< JsonValue > &json) const |
Public Member Functions inherited from cugl::Loader< scene2::SceneNode > | |
Loader () | |
std::shared_ptr< scene2::SceneNode > | get (const std::string key) const |
std::shared_ptr< scene2::SceneNode > | 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 () | |
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 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) |
bool | contains (const std::string key) const |
bool | complete () const |
float | progress () const |
Static Public Member Functions | |
static std::shared_ptr< Scene2Loader > | alloc () |
static std::shared_ptr< Scene2Loader > | alloc (const std::shared_ptr< ThreadPool > &threads) |
Protected Types | |
enum | Widget { Widget::NODE, Widget::IMAGE, Widget::SOLID, Widget::POLY, Widget::PATH, Widget::WIRE, Widget::ANIMATE, Widget::NINE, Widget::LABEL, Widget::BUTTON, Widget::PROGRESS, Widget::SLIDER, Widget::SCROLL, Widget::TEXTFIELD, Widget::EXTERNAL_IMPORT, Widget::UNKNOWN } |
enum | Form { Form::NONE, Form::ANCHORED, Form::FLOAT, Form::GRID, Form::UNKNOWN } |
Protected Member Functions | |
void | materialize (const std::shared_ptr< scene2::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 | purge (const std::shared_ptr< JsonValue > &json) override |
bool | attach (const std::string &key, const std::shared_ptr< scene2::SceneNode > &node) |
std::shared_ptr< JsonValue > | getWidgetJson (const std::shared_ptr< JsonValue > &json) const |
Protected Member Functions inherited from cugl::Loader< scene2::SceneNode > | |
virtual std::vector< std::string > | keys () override |
bool | purge (const std::string key) override |
bool | verify (const std::string key) const override |
Protected Attributes | |
std::unordered_map< std::string, Widget > | _types |
std::unordered_map< std::string, Form > | _forms |
Protected Attributes inherited from cugl::Loader< scene2::SceneNode > | |
std::unordered_map< std::string, std::shared_ptr< scene2::SceneNode > > | _assets |
std::unordered_set< std::string > | _queue |
Protected Attributes inherited from cugl::BaseLoader | |
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 |
This is an enumeration for identifying layout managers.
Each time you add a new layout, it should be added to this list.
Enumerator | |
---|---|
NONE | The default layout manager, using absolute position |
ANCHORED | A layout manager using anchor points |
FLOAT | A float layout manager |
GRID | A grid layout manager |
UNKNOWN | An unsupported form |
|
strongprotected |
This is an enumeration for identifying scene node types.
Each time you add a new UI widget, it should be added to this list.
|
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<scene2::SceneNode> cugl::Scene2Loader::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. "format": The layout manager to use for this Node. This layout manager will apply to all the children (see below). This JSON object has a layout-specific format. "layout": Node placement using a the layout manager of the parent. This is applied after parsing "data' and will override any settings there. This JSON object has a layout-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.
|
protected |
Translates the JSON of a widget to the JSON of the node that it encodes.
If this scene is built before the JSON of any used widgets have been loaded, this will fail.
json | The JSON object specifying the widget's file and the values for its exposed variables |
|
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 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.
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. "format": The layout manager to use for this Node. This layout manager will apply to all the children (see below). This JSON object has a layout-specific format. "layout": Node placement using a the layout manager of the parent. This is applied after parsing "data' and will override any settings there. This JSON object has a layout-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 layout
|
protected |
The type map for managing constructors