Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::SceneNodeCore Class Reference

The core of a node in the SceneSystem, a set of components and methods overridable or usable by all types of scene nodes. More...

#include <scene_system.hpp>

Inheritance diagram for ToyMaker::SceneNodeCore:
ToyMaker::BaseSceneNode< SceneNode > ToyMaker::BaseSceneNode< SimObject > ToyMaker::BaseSceneNode< ViewportNode > ToyMaker::BaseSceneNode< TSceneNode > ToyMaker::SceneNode ToyMaker::SimObject ToyMaker::ViewportNode

Classes

struct  getByPath_Helper
 A helper intended to get scene nodes and related objects attached to the scene tree. More...
 
struct  getByPath_Helper< BaseSimObjectAspect & >
 
struct  getByPath_Helper< std::shared_ptr< TObject >, typename std::enable_if_t< std::is_base_of< SceneNodeCore, TObject >::value > >
 
struct  getByPath_Helper< TAspect &, std::enable_if_t< std::is_base_of< BaseSimObjectAspect, TAspect >::value > >
 
struct  Key
 A private struct to limit certain sensitive functions to this class and other closely coupled classes. More...
 

Public Member Functions

virtual ~SceneNodeCore ()=default
 Destroys SceneNodeCore.
 
template<typename TComponent>
void addComponent (const TComponent &component, const bool bypassSceneActivityCheck=false)
 Adds a component of type TComponent to the node.
 
void addComponent (const nlohmann::json &jsonComponent, const bool bypassSceneActivityCheck=false)
 Adds a component to the node.
 
template<typename TComponent>
TComponent getComponent (const float simulationProgress=1.f) const
 Retrieves a component belonging to this node.
 
template<typename TComponent>
bool hasComponent () const
 Tests whether this node has a component of a specific type.
 
bool hasComponent (const std::string &type) const
 Tests whether this node has a component of a specific type.
 
template<typename TComponent>
void updateComponent (const TComponent &component)
 Updates the value of a component of this node (to what it should be at the start of the next simulation step).
 
void updateComponent (const nlohmann::json &component)
 Updates the value of a component of this node (to what it should be at the start of the next simulation step).
 
template<typename TComponent>
void addOrUpdateComponent (const TComponent &component, const bool bypassSceneActivityCheck=false)
 A method for adding a component or updating a component if that component is already present on this node.
 
void addOrUpdateComponent (const nlohmann::json &component, const bool bypassSceneActivityCheck=false)
 A method for adding a component, or updating a component if the same type of component is already present on this node.
 
template<typename TComponent>
void removeComponent ()
 Removes a component present on this node.
 
template<typename TSystem>
void setEnabled (bool state)
 Sets whether or not a given system should be able to influence this scene object.
 
template<typename TSystem>
bool getEnabled () const
 Returns whether a particular system has been enabled for this node.
 
EntityID getEntityID () const
 Returns the entity id associated with these scene node.
 
WorldID getWorldID () const
 Returns the ID of the ECSWorld this node belongs to.
 
UniversalEntityID getUniversalEntityID () const
 Gets the UniversalEntityID aka the world-entity-id pair associated with this node.
 
std::weak_ptr< ECSWorldgetWorld () const
 Gets a reference to the ECSWorld this node belongs to.
 
bool inScene () const
 Returns whether this node is present as part of the SceneSystem's scene tree.
 
bool isActive () const
 Returns whether this node is present as part of the SceneSystem's scene tree, AND is active there as well.
 
bool isAncestorOf (std::shared_ptr< const SceneNodeCore > sceneNode) const
 Tests whether a particular scene node is the ancestor of this one.
 
bool hasNode (const std::string &pathToChild) const
 Tests whether a node specified by some path relative to this node is a real descendant of this node.
 
void addNode (std::shared_ptr< SceneNodeCore > node, const std::string &where)
 Adds a node (or a tree of them) as a child of the node specified by the path in the argument.
 
std::vector< std::shared_ptr< SceneNodeCore > > getChildren ()
 Returns a list of all of this node's immediate children scene nodes.
 
std::vector< std::shared_ptr< const SceneNodeCore > > getChildren () const
 Returns a list of all of this node's immediate children scene nodes.
 
std::vector< std::shared_ptr< SceneNodeCore > > getDescendants ()
 Gets all of the descendant nodes belonging to this scene node.
 
template<typename TObject = std::shared_ptr<SceneNode>>
TObject getByPath (const std::string &where)
 Gets a reference to a node or related object by its path.
 
template<typename TSceneNode = SceneNode>
std::shared_ptr< TSceneNode > getNodeByID (EntityID entityID)
 Gets a pointer to a node by its EntityID, assuming that node and this one belong to the same ECSWorld.
 
std::string getPathFromAncestor (std::shared_ptr< const SceneNodeCore > ancestor) const
 Gets the path from a node (assumed to be an ancestor) to this node.
 
virtual std::shared_ptr< ViewportNodegetLocalViewport ()
 Returns the viewport node which is in the same ECSWorld as and is the closest ancestor of (or the same as) this node.
 
virtual std::shared_ptr< const ViewportNodegetLocalViewport () const
 Returns (a constant reference to) the viewport node which is in the same ECSWorld as and is the closes ancestor of (or the same as) this node.
 
std::shared_ptr< SceneNodeCoregetNode (const std::string &where)
 Gets a reference to a scene node (of any valid type) based on its path relative to this node.
 
std::shared_ptr< SceneNodeCoregetParentNode ()
 Gets the parent node of this node, if one is present.
 
std::shared_ptr< const SceneNodeCoregetParentNode () const
 Gets (a constant reference to) the parent node of this node, if one is present.
 
std::shared_ptr< SceneNodeCoreremoveNode (const std::string &where)
 Removes a node from the tree present at the path specified.
 
std::vector< std::shared_ptr< SceneNodeCore > > removeChildren ()
 Disconnects and removes all the child nodes attached to this node.
 
std::string getName () const
 Returns the name string for this node.
 
void setName (const std::string &name)
 Sets the name of this node.
 
std::string getViewportLocalPath () const
 Gets the path of this node relative to its local viewport node.
 
void setPrototype_ (std::shared_ptr< SceneNodeCore > prototype)
 A reference to the node which was used in order to construct this one.
 
template<>
void setEnabled (bool state)
 
template<>
void removeComponent ()
 
template<>
void removeComponent ()
 
template<>
void removeComponent ()
 
template<>
void setEnabled (bool)
 
template<>
void updateComponent (const AxisAlignedBounds &axisAlignedBoxBounds)
 
template<>
void updateComponent (const ObjectBounds &objectBounds)
 
template<>
void removeComponent ()
 
template<>
void removeComponent ()
 

Static Public Member Functions

static void SceneNodeCore_del_ (SceneNodeCore *sceneNode)
 Deleter for a managed pointer to a scene node which ensures its onDestroyed virtual function gets called.
 

Protected Member Functions

virtual void joinWorld (ECSWorld &world)
 Removes this node's entity from its current ECSWorld and adds it to a new ECSWorld.
 
template<typename ... TComponents>
 SceneNodeCore (const Placement &placement, const std::string &name, TComponents...components)
 Constructs a scene node object from essential and extra components.
 
 SceneNodeCore (const nlohmann::json &jsonSceneNode)
 Constructs a node based on its description of JSON, later verifying that essential components are present.
 
 SceneNodeCore (const SceneNodeCore &sceneObject)
 Constructs a new node as a copy of another node.
 
virtual void onCreated ()
 Copy assignment operator.
 
virtual void onActivated ()
 Scene node lifecycle hook for when a node is made an active part of the SceneSystem.
 
virtual void onDeactivated ()
 Scene node lifecycle hook for when a node is deactivated on the SceneSystem.
 
virtual void onDestroyed ()
 Scene node lifecycle hook for when a node (and possibly its descendants) are about to be destroyed.
 

Static Protected Member Functions

static std::shared_ptr< SceneNodeCorecopy (const std::shared_ptr< const SceneNodeCore > other)
 Creates a new scene tree by copying another scene node and its descendants.
 
static void validateName (const std::string &nodeName)
 Tests whether a given name is actually valid, throwing an error when it is not.
 

Private Types

enum  StateFlags : uint8_t { ENABLED =0x1 , ACTIVE =0x2 }
 Flags that indicate whether this node is enabled and active for the SceneSystem.
 

Private Member Functions

template<typename ... TComponents>
 SceneNodeCore (const Key &, const Placement &placement, const std::string &name, TComponents...components)
 (Private) Constructs a new node based with essential components and some explicitly specified extra ones.
 
virtual std::shared_ptr< SceneNodeCoreclone () const
 Virtual method which each type of scene node with special members should implement (in lieu of copy constructors and copy assignment operators.)
 
void copyDescendants (const SceneNodeCore &other)
 Copies descendant nodes belonging to another node, attaches the copies to this node.
 
void copyAndReplaceAttributes (const SceneNodeCore &other)
 Copies component values from another node and replaces the values on node's components with them.
 
void recomputeChildNameIndexMapping ()
 Utility function for updating SceneHierarchyData components belonging to a single ECSWorld in the SceneSystem.
 

Static Private Member Functions

static void setParentViewport (std::shared_ptr< SceneNodeCore > node, std::shared_ptr< ViewportNode > newViewport)
 Sets a node as the parent viewport of another one.
 
static std::shared_ptr< SceneNodeCoredisconnectNode (std::shared_ptr< SceneNodeCore > node)
 Disconnects this node from its parent node if it has one.
 
static bool detectCycle (std::shared_ptr< SceneNodeCore > node)
 Tests whether there are any cycles in the path up to the node's oldest ancestor.
 
static std::tuple< std::string, std::string > nextInPath (const std::string &where)
 Strips the root-most part of the path to a node.
 

Private Attributes

std::string mName {}
 The name of this scene node.
 
uint8_t mStateFlags { 0x00 | StateFlags::ENABLED }
 Flags indicating the state of this scene node in the scene system.
 
RelativeTo mRelativeTo { RelativeTo::PARENT }
 A marker indicating how this node's transform component should be computed.
 
std::shared_ptr< EntitymEntity { nullptr }
 The ECSWorld entity which this node is a wrapper over.
 
std::weak_ptr< SceneNodeCoremParent {}
 A reference to this node's parent scene node.
 
std::weak_ptr< ViewportNodemParentViewport {}
 A reference to this node's parent viewport (whose meaning changes depending on whether this node is a camera, viewport, or other type of node)
 
std::unordered_map< std::string, std::size_t > mChildNameToNode {}
 A mapping of names of this node's child nodes to the indices of the nodes themselves.
 
std::vector< std::shared_ptr< SceneNodeCore > > mChildren {}
 A list of this node's child nodes.
 
std::shared_ptr< SceneNodeCoremPrototype { nullptr }
 Allows a prototype scene node to be retained as a resource so long as this node is present in memory somewhere.
 
Signature mSystemMask {Signature{}.set()}
 A bitset, each position of which indicates whether a system should influence this node when it is part of the SceneSystem's scene tree.
 

Friends

class SceneSystem
 
template<typename TSceneNode>
class BaseSceneNode
 
class ViewportNode
 

Detailed Description

The core of a node in the SceneSystem, a set of components and methods overridable or usable by all types of scene nodes.

Constructor & Destructor Documentation

◆ ~SceneNodeCore()

virtual ToyMaker::SceneNodeCore::~SceneNodeCore ( )
virtualdefault

Destroys SceneNodeCore.

Mainly, marks this class and its derivatives' destructors as virtual destructors.

◆ SceneNodeCore() [1/4]

template<typename ... TComponents>
ToyMaker::SceneNodeCore::SceneNodeCore ( const Placement & placement,
const std::string & name,
TComponents... components )
protected

Constructs a scene node object from essential and extra components.

Template Parameters
TComponentsA list of component types being added to a node in addition to its placement and transform components.
Parameters
placementThe placement component for the newly constructed node.
nameThe name to be given to this node.
componentsA list of component values to initialize this node's components with.

◆ SceneNodeCore() [2/4]

SceneNodeCore::SceneNodeCore ( const nlohmann::json & jsonSceneNode)
protected

Constructs a node based on its description of JSON, later verifying that essential components are present.

Parameters
jsonSceneNodeA description for this node and the initial value of its components.

◆ SceneNodeCore() [3/4]

SceneNodeCore::SceneNodeCore ( const SceneNodeCore & sceneObject)
protected

Constructs a new node as a copy of another node.

Parameters
sceneObjectThe node being copied.

◆ SceneNodeCore() [4/4]

template<typename ... TComponents>
ToyMaker::SceneNodeCore::SceneNodeCore ( const Key & ,
const Placement & placement,
const std::string & name,
TComponents... components )
private

(Private) Constructs a new node based with essential components and some explicitly specified extra ones.

Template Parameters
TComponentsAdditional component types being added to this node.
Parameters
placementThe placement value for this node.
nameThe name for this node.
componentsThe initial values for extra components being added to this node.

Member Function Documentation

◆ addComponent() [1/2]

void SceneNodeCore::addComponent ( const nlohmann::json & jsonComponent,
const bool bypassSceneActivityCheck = false )

Adds a component to the node.

Parameters
jsonComponentA description of the node, in JSON, along with its type and initial value.
bypassSceneActivityCheckPrevents scene activity check when it is known that this node is not visible to the scene system.

◆ addComponent() [2/2]

template<typename TComponent>
void ToyMaker::SceneNodeCore::addComponent ( const TComponent & component,
const bool bypassSceneActivityCheck = false )

Adds a component of type TComponent to the node.

Template Parameters
TComponentThe type of component being added.
Parameters
componentThe value of the component added.
bypassSceneActivityCheckPrevents scene activity check when it is known that this node is not visible to the scene system.

◆ addNode()

void SceneNodeCore::addNode ( std::shared_ptr< SceneNodeCore > node,
const std::string & where )

Adds a node (or a tree of them) as a child of the node specified by the path in the argument.

Parameters
nodeThe node being added as a descendant of this node.
whereThe path to the node whose immediate child the new node will be.

◆ addOrUpdateComponent() [1/2]

void SceneNodeCore::addOrUpdateComponent ( const nlohmann::json & component,
const bool bypassSceneActivityCheck = false )

A method for adding a component, or updating a component if the same type of component is already present on this node.

Parameters
componentThe description of the component, including its new value and its type.
bypassSceneActivityCheckPrevents scene activity check when it is known for certain that the node is not part of the scene system.

◆ addOrUpdateComponent() [2/2]

template<typename TComponent>
void ToyMaker::SceneNodeCore::addOrUpdateComponent ( const TComponent & component,
const bool bypassSceneActivityCheck = false )

A method for adding a component or updating a component if that component is already present on this node.

Template Parameters
TComponentThe type of component being added or updated.
Parameters
componentThe components new value, as of the start of the next simulation step.
bypassSceneActivityCheckPrevents scene activity check when it is known for certain that the node is not part of the scene system.

◆ clone()

std::shared_ptr< SceneNodeCore > SceneNodeCore::clone ( ) const
privatevirtual

Virtual method which each type of scene node with special members should implement (in lieu of copy constructors and copy assignment operators.)

Returns
std::shared_ptr<SceneNodeCore> A new node constructed based on this node.

Reimplemented in ToyMaker::SimObject, and ToyMaker::ViewportNode.

◆ copy()

std::shared_ptr< SceneNodeCore > SceneNodeCore::copy ( const std::shared_ptr< const SceneNodeCore > other)
staticprotected

Creates a new scene tree by copying another scene node and its descendants.

Parameters
otherThe node used as the basis for the construction of a new tree.
Returns
std::shared_ptr<SceneNodeCore> The root node of the newly constructed scene tree.

◆ copyAndReplaceAttributes()

void SceneNodeCore::copyAndReplaceAttributes ( const SceneNodeCore & other)
private

Copies component values from another node and replaces the values on node's components with them.

Parameters
otherThe node whose component values are being copied.

◆ copyDescendants()

void SceneNodeCore::copyDescendants ( const SceneNodeCore & other)
private

Copies descendant nodes belonging to another node, attaches the copies to this node.

Parameters
otherThe node whose descendants are being copied.

◆ detectCycle()

bool SceneNodeCore::detectCycle ( std::shared_ptr< SceneNodeCore > node)
staticprivate

Tests whether there are any cycles in the path up to the node's oldest ancestor.

Parameters
nodeThe node whose path to its root is being tested for cycles.
Return values
trueThere is a cycle present in the path to this node's root node.
falseThere is no cycle present in the path to this node's root node.

◆ disconnectNode()

std::shared_ptr< SceneNodeCore > SceneNodeCore::disconnectNode ( std::shared_ptr< SceneNodeCore > node)
staticprivate

Disconnects this node from its parent node if it has one.

Parameters
nodeThe node whose relationship with its parent is being dissolved.
Returns
std::shared_ptr<SceneNodeCore> A reference to the disconnected node, the same one passed as an argument.

◆ getByPath()

template<typename TObject>
TObject ToyMaker::SceneNodeCore::getByPath ( const std::string & where)

Gets a reference to a node or related object by its path.

Template Parameters
TObjectThe type of object being retrieved, by default a shared pointer to a SceneNode.
Parameters
whereThe path to the object being retrieved.
Returns
TObject The object retrieved.

◆ getChildren() [1/2]

std::vector< std::shared_ptr< SceneNodeCore > > SceneNodeCore::getChildren ( )

Returns a list of all of this node's immediate children scene nodes.

Returns
std::vector<std::shared_ptr<SceneNodeCore>> A list of this node's immediate children scene nodes.

◆ getChildren() [2/2]

std::vector< std::shared_ptr< const SceneNodeCore > > SceneNodeCore::getChildren ( ) const

Returns a list of all of this node's immediate children scene nodes.

Returns
std::vector<std::shared_ptr<const SceneNodeCore>> A list of (immutable) references to this node's immediate children scene nodes.

◆ getComponent()

template<typename TComponent>
TComponent ToyMaker::SceneNodeCore::getComponent ( const float simulationProgress = 1.f) const

Retrieves a component belonging to this node.

Template Parameters
TComponentThe type of component being retrieved.
Parameters
simulationProgressThe progress towards the next simulation state after the previous simulation state as a number between 0 and 1.
Returns
TComponent The retrieved component value.

◆ getDescendants()

std::vector< std::shared_ptr< SceneNodeCore > > SceneNodeCore::getDescendants ( )

Gets all of the descendant nodes belonging to this scene node.

Returns
std::vector<std::shared_ptr<SceneNodeCore>> A list of descendant nodes belonging to this scene node.

◆ getEnabled()

template<typename TSystem>
bool ToyMaker::SceneNodeCore::getEnabled ( ) const

Returns whether a particular system has been enabled for this node.

Template Parameters
TSystemThe system whose influence is being tested.
Return values
trueThe system has been enabled, and will influence this node when it is a part of the scene;
falseThe system has been disabled, and won't influence this node even when it is a part of the scene;

◆ getEntityID()

EntityID SceneNodeCore::getEntityID ( ) const

Returns the entity id associated with these scene node.

Returns
EntityID The ID of the entity associated with this node.

◆ getLocalViewport() [1/2]

std::shared_ptr< ViewportNode > SceneNodeCore::getLocalViewport ( )
virtual

Returns the viewport node which is in the same ECSWorld as and is the closest ancestor of (or the same as) this node.

Returns
std::shared_ptr<ViewportNode> The local viewport node.

Reimplemented in ToyMaker::ViewportNode.

◆ getLocalViewport() [2/2]

std::shared_ptr< const ViewportNode > SceneNodeCore::getLocalViewport ( ) const
virtual

Returns (a constant reference to) the viewport node which is in the same ECSWorld as and is the closes ancestor of (or the same as) this node.

Returns
std::shared_ptr<const ViewportNode> The local viewport node.

Reimplemented in ToyMaker::ViewportNode.

◆ getName()

std::string SceneNodeCore::getName ( ) const

Returns the name string for this node.

Returns
std::string The name of this node.

◆ getNode()

std::shared_ptr< SceneNodeCore > SceneNodeCore::getNode ( const std::string & where)

Gets a reference to a scene node (of any valid type) based on its path relative to this node.

Parameters
whereThe path to the node being retrieved.
Returns
std::shared_ptr<SceneNodeCore> The retrieved node.

◆ getNodeByID()

template<typename TSceneNode>
std::shared_ptr< TSceneNode > ToyMaker::SceneNodeCore::getNodeByID ( EntityID entityID)

Gets a pointer to a node by its EntityID, assuming that node and this one belong to the same ECSWorld.

Template Parameters
TSceneNodeThe type of node being retrieved, by default a SceneNode.
Parameters
entityIDThe id belonging to the entity associated with the node being retrieved.
Returns
std::shared_ptr<TSceneNode> A shared pointer to the node retrieved.

◆ getParentNode() [1/2]

std::shared_ptr< SceneNodeCore > SceneNodeCore::getParentNode ( )

Gets the parent node of this node, if one is present.

Returns
std::shared_ptr<SceneNodeCore> This node's parent node.

◆ getParentNode() [2/2]

std::shared_ptr< const SceneNodeCore > SceneNodeCore::getParentNode ( ) const

Gets (a constant reference to) the parent node of this node, if one is present.

Returns
std::shared_ptr<const SceneNodeCore> This node's parent node.

◆ getPathFromAncestor()

std::string SceneNodeCore::getPathFromAncestor ( std::shared_ptr< const SceneNodeCore > ancestor) const

Gets the path from a node (assumed to be an ancestor) to this node.

Parameters
ancestorA reference to a node which is an ancestor of this node.
Returns
std::string The path from the ancestor to this node.

◆ getUniversalEntityID()

UniversalEntityID SceneNodeCore::getUniversalEntityID ( ) const

Gets the UniversalEntityID aka the world-entity-id pair associated with this node.

Returns
UniversalEntityID The world-entity-id pair associated with this node.

◆ getViewportLocalPath()

std::string SceneNodeCore::getViewportLocalPath ( ) const

Gets the path of this node relative to its local viewport node.

Returns
std::string The path to this node from its local viewport node.
See also
getLocalViewport()

◆ getWorld()

std::weak_ptr< ECSWorld > SceneNodeCore::getWorld ( ) const

Gets a reference to the ECSWorld this node belongs to.

Returns
std::weak_ptr<ECSWorld> The ECSWorld this node belongs to.

◆ getWorldID()

WorldID SceneNodeCore::getWorldID ( ) const

Returns the ID of the ECSWorld this node belongs to.

Returns
WorldID The ID of the ECSWorld this node belongs to.

◆ hasComponent() [1/2]

template<typename TComponent>
bool ToyMaker::SceneNodeCore::hasComponent ( ) const

Tests whether this node has a component of a specific type.

Template Parameters
TComponentThe type of component whose existence is being tested.
Return values
trueThis type of component is present for this node;
falseThis type of component is absent for this node;

◆ hasComponent() [2/2]

bool SceneNodeCore::hasComponent ( const std::string & type) const

Tests whether this node has a component of a specific type.

Parameters
typeThe component type string of the component whose existence is being tested.
Return values
trueThis type of component is present for this node;
falseThis type of component is absent for this node;

◆ hasNode()

bool SceneNodeCore::hasNode ( const std::string & pathToChild) const

Tests whether a node specified by some path relative to this node is a real descendant of this node.

Parameters
pathToChildThe path to the descendant node whose existence is being tested.
Return values
trueThere is a node present at the path specified;
falseThere is no node present at the path specified;

◆ inScene()

bool SceneNodeCore::inScene ( ) const

Returns whether this node is present as part of the SceneSystem's scene tree.

Return values
trueThis node is part of the SceneSystem's scene tree.
falseThis node is not part of the SceneSystem's scene tree.
Todo
We can't be certain the value returned by this method and the one in the SceneSystem are in sync. Remove this redundancy somehow.

◆ isActive()

bool SceneNodeCore::isActive ( ) const

Returns whether this node is present as part of the SceneSystem's scene tree, AND is active there as well.

Return values
trueThis node is present and active in the SceneSystem's scene tree.
falseThis node is not present or active in the SceneSystem's scene tree.
Todo
We can't be certain the value returned by this method and the one in the SceneSystem are in sync. Remove this redundancy somehow.

◆ isAncestorOf()

bool SceneNodeCore::isAncestorOf ( std::shared_ptr< const SceneNodeCore > sceneNode) const

Tests whether a particular scene node is the ancestor of this one.

Parameters
sceneNodeThe scene node being tested as an ancestor.
Return values
trueThe argument node is this node's ancestor;
falseThe argument node is not this node's ancestor;

◆ joinWorld()

void SceneNodeCore::joinWorld ( ECSWorld & world)
protectedvirtual

Removes this node's entity from its current ECSWorld and adds it to a new ECSWorld.

Parameters
worldThe new ECSWorld this node's entity should join.

Reimplemented in ToyMaker::ViewportNode.

◆ nextInPath()

std::tuple< std::string, std::string > SceneNodeCore::nextInPath ( const std::string & where)
staticprivate

Strips the root-most part of the path to a node.

Parameters
whereThe path before removing its prefix.
Returns
std::tuple<std::string, std::string> - .first - The name of the node (presumably a child of the caller object) relative to which the stripped path is valid; - .second - The path with its prefix removed;

◆ onActivated()

void SceneNodeCore::onActivated ( )
protectedvirtual

Scene node lifecycle hook for when a node is made an active part of the SceneSystem.

Reimplemented in ToyMaker::SimObject, and ToyMaker::ViewportNode.

◆ onCreated()

void SceneNodeCore::onCreated ( )
protectedvirtual

Copy assignment operator.

Todo
Sit down and figure out whether this operator will ever actually need to be used.

Scene node lifecycle hook for when a node is created.

◆ onDeactivated()

void SceneNodeCore::onDeactivated ( )
protectedvirtual

Scene node lifecycle hook for when a node is deactivated on the SceneSystem.

Reimplemented in ToyMaker::SimObject, and ToyMaker::ViewportNode.

◆ onDestroyed()

void SceneNodeCore::onDestroyed ( )
protectedvirtual

Scene node lifecycle hook for when a node (and possibly its descendants) are about to be destroyed.

Todo
Figure out whether this is actually necessary, and why it was we couldn't just use the virtual destructor.

◆ removeChildren()

std::vector< std::shared_ptr< SceneNodeCore > > SceneNodeCore::removeChildren ( )

Disconnects and removes all the child nodes attached to this node.

Returns
std::vector<std::shared_ptr<SceneNodeCore>> A list of child nodes removed.

◆ removeComponent()

template<typename TComponent>
void ToyMaker::SceneNodeCore::removeComponent ( )

Removes a component present on this node.

Template Parameters
TComponentThe type of component being removed.

◆ removeNode()

std::shared_ptr< SceneNodeCore > SceneNodeCore::removeNode ( const std::string & where)

Removes a node from the tree present at the path specified.

Parameters
whereThe path to the node being removed.
Returns
std::shared_ptr<SceneNodeCore> A reference to the removed node.

◆ SceneNodeCore_del_()

void SceneNodeCore::SceneNodeCore_del_ ( SceneNodeCore * sceneNode)
static

Deleter for a managed pointer to a scene node which ensures its onDestroyed virtual function gets called.

Parameters
sceneNodeThe pointer to the scene node being deleted.
Todo
See whether onDestroyed actually gets called, and whether this function is even necessary given that virtual destructors already exist.

◆ setEnabled()

template<typename TSystem>
void ToyMaker::SceneNodeCore::setEnabled ( bool state)

Sets whether or not a given system should be able to influence this scene object.

If the node hasn't already been made part of the scene, the activation will occur after it has been added to it. Otherwise, the activation occurs right away.

Template Parameters
TSystemThe system being enabled or disabled for this node.
Parameters
stateWhether to enable or disable a system for this node.

◆ setName()

void SceneNodeCore::setName ( const std::string & name)

Sets the name of this node.

Parameters
nameThe new name for this node.

◆ setParentViewport()

void SceneNodeCore::setParentViewport ( std::shared_ptr< SceneNodeCore > node,
std::shared_ptr< ViewportNode > newViewport )
staticprivate

Sets a node as the parent viewport of another one.

For regular nodes, the side effect would be to move this node's entity and component's into the ECSWorld of its new parent viewport.

Parameters
nodeThe node whose parent viewport is being set.
newViewportThe node's to-be parent viewport.

◆ setPrototype_()

void ToyMaker::SceneNodeCore::setPrototype_ ( std::shared_ptr< SceneNodeCore > prototype)
inline

A reference to the node which was used in order to construct this one.

May be useful in the future when there is more formal support for the notion of assets.

Parameters
prototypeThe node that acted as the prototype for this node and its children.
Todo
Think of a safer way to accomplish this.

◆ updateComponent() [1/2]

void SceneNodeCore::updateComponent ( const nlohmann::json & component)

Updates the value of a component of this node (to what it should be at the start of the next simulation step).

Parameters
componentA JSON description of the component's new value along with its type.

◆ updateComponent() [2/2]

template<typename TComponent>
void ToyMaker::SceneNodeCore::updateComponent ( const TComponent & component)

Updates the value of a component of this node (to what it should be at the start of the next simulation step).

Template Parameters
TComponentThe type of component being updated.
Parameters
componentThe component's new value.

◆ validateName()

void SceneNodeCore::validateName ( const std::string & nodeName)
staticprotected

Tests whether a given name is actually valid, throwing an error when it is not.

A node should contain letters, numbers, underscores, and should not match kSceneRootName.

Parameters
nodeNameThe node name whose validity is being asserted.

Member Data Documentation

◆ mChildNameToNode

std::unordered_map<std::string, std::size_t> ToyMaker::SceneNodeCore::mChildNameToNode {}
private

A mapping of names of this node's child nodes to the indices of the nodes themselves.

See also
mChildren

◆ mStateFlags

uint8_t ToyMaker::SceneNodeCore::mStateFlags { 0x00 | StateFlags::ENABLED }
private

Flags indicating the state of this scene node in the scene system.

See also
StateFlags

◆ mSystemMask

Signature ToyMaker::SceneNodeCore::mSystemMask {Signature{}.set()}
private

A bitset, each position of which indicates whether a system should influence this node when it is part of the SceneSystem's scene tree.

See also
SystemManager

The documentation for this class was generated from the following files: