Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
|
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>
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< ECSWorld > | getWorld () 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< ViewportNode > | getLocalViewport () |
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 ViewportNode > | getLocalViewport () 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< 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. | |
std::shared_ptr< SceneNodeCore > | getParentNode () |
Gets the parent node of this node, if one is present. | |
std::shared_ptr< const SceneNodeCore > | getParentNode () const |
Gets (a constant reference to) the parent node of this node, if one is present. | |
std::shared_ptr< SceneNodeCore > | removeNode (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< SceneNodeCore > | copy (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< SceneNodeCore > | clone () 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< SceneNodeCore > | disconnectNode (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< Entity > | mEntity { nullptr } |
The ECSWorld entity which this node is a wrapper over. | |
std::weak_ptr< SceneNodeCore > | mParent {} |
A reference to this node's parent scene node. | |
std::weak_ptr< ViewportNode > | mParentViewport {} |
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< SceneNodeCore > | mPrototype { 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 |
The core of a node in the SceneSystem, a set of components and methods overridable or usable by all types of scene nodes.
|
virtualdefault |
Destroys SceneNodeCore.
Mainly, marks this class and its derivatives' destructors as virtual destructors.
|
protected |
Constructs a scene node object from essential and extra components.
TComponents | A list of component types being added to a node in addition to its placement and transform components. |
placement | The placement component for the newly constructed node. |
name | The name to be given to this node. |
components | A list of component values to initialize this node's components with. |
|
protected |
Constructs a node based on its description of JSON, later verifying that essential components are present.
jsonSceneNode | A description for this node and the initial value of its components. |
|
protected |
Constructs a new node as a copy of another node.
sceneObject | The node being copied. |
|
private |
(Private) Constructs a new node based with essential components and some explicitly specified extra ones.
TComponents | Additional component types being added to this node. |
placement | The placement value for this node. |
name | The name for this node. |
components | The initial values for extra components being added to this node. |
void SceneNodeCore::addComponent | ( | const nlohmann::json & | jsonComponent, |
const bool | bypassSceneActivityCheck = false ) |
Adds a component to the node.
jsonComponent | A description of the node, in JSON, along with its type and initial value. |
bypassSceneActivityCheck | Prevents scene activity check when it is known that this node is not visible to the scene system. |
void ToyMaker::SceneNodeCore::addComponent | ( | const TComponent & | component, |
const bool | bypassSceneActivityCheck = false ) |
Adds a component of type TComponent to the node.
TComponent | The type of component being added. |
component | The value of the component added. |
bypassSceneActivityCheck | Prevents scene activity check when it is known that this node is not visible to the scene system. |
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.
node | The node being added as a descendant of this node. |
where | The path to the node whose immediate child the new node will be. |
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.
component | The description of the component, including its new value and its type. |
bypassSceneActivityCheck | Prevents scene activity check when it is known for certain that the node is not part of the scene system. |
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.
TComponent | The type of component being added or updated. |
component | The components new value, as of the start of the next simulation step. |
bypassSceneActivityCheck | Prevents scene activity check when it is known for certain that the node is not part of the scene system. |
|
privatevirtual |
Virtual method which each type of scene node with special members should implement (in lieu of copy constructors and copy assignment operators.)
Reimplemented in ToyMaker::SimObject, and ToyMaker::ViewportNode.
|
staticprotected |
Creates a new scene tree by copying another scene node and its descendants.
other | The node used as the basis for the construction of a new tree. |
|
private |
Copies component values from another node and replaces the values on node's components with them.
other | The node whose component values are being copied. |
|
private |
Copies descendant nodes belonging to another node, attaches the copies to this node.
other | The node whose descendants are being copied. |
|
staticprivate |
Tests whether there are any cycles in the path up to the node's oldest ancestor.
node | The node whose path to its root is being tested for cycles. |
true | There is a cycle present in the path to this node's root node. |
false | There is no cycle present in the path to this node's root node. |
|
staticprivate |
Disconnects this node from its parent node if it has one.
node | The node whose relationship with its parent is being dissolved. |
TObject ToyMaker::SceneNodeCore::getByPath | ( | const std::string & | where | ) |
Gets a reference to a node or related object by its path.
TObject | The type of object being retrieved, by default a shared pointer to a SceneNode. |
where | The path to the object being retrieved. |
std::vector< std::shared_ptr< SceneNodeCore > > SceneNodeCore::getChildren | ( | ) |
Returns a list of all of this node's immediate children scene nodes.
std::vector< std::shared_ptr< const SceneNodeCore > > SceneNodeCore::getChildren | ( | ) | const |
Returns a list of all of this node's immediate children scene nodes.
TComponent ToyMaker::SceneNodeCore::getComponent | ( | const float | simulationProgress = 1.f | ) | const |
Retrieves a component belonging to this node.
TComponent | The type of component being retrieved. |
simulationProgress | The progress towards the next simulation state after the previous simulation state as a number between 0 and 1. |
std::vector< std::shared_ptr< SceneNodeCore > > SceneNodeCore::getDescendants | ( | ) |
Gets all of the descendant nodes belonging to this scene node.
bool ToyMaker::SceneNodeCore::getEnabled | ( | ) | const |
Returns whether a particular system has been enabled for this node.
TSystem | The system whose influence is being tested. |
true | The system has been enabled, and will influence this node when it is a part of the scene; |
false | The system has been disabled, and won't influence this node even when it is a part of the scene; |
EntityID SceneNodeCore::getEntityID | ( | ) | const |
Returns the entity id associated with these scene node.
|
virtual |
Returns the viewport node which is in the same ECSWorld as and is the closest ancestor of (or the same as) this node.
Reimplemented in ToyMaker::ViewportNode.
|
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.
Reimplemented in ToyMaker::ViewportNode.
std::string SceneNodeCore::getName | ( | ) | const |
Returns the name string for this node.
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.
where | The path to the node being retrieved. |
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.
TSceneNode | The type of node being retrieved, by default a SceneNode. |
entityID | The id belonging to the entity associated with the node being retrieved. |
std::shared_ptr< SceneNodeCore > SceneNodeCore::getParentNode | ( | ) |
Gets the parent node of this node, if one is present.
std::shared_ptr< const SceneNodeCore > SceneNodeCore::getParentNode | ( | ) | const |
Gets (a constant reference to) the parent node of this node, if one is present.
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.
ancestor | A reference to a node which is an ancestor of this node. |
UniversalEntityID SceneNodeCore::getUniversalEntityID | ( | ) | const |
Gets the UniversalEntityID aka the world-entity-id pair associated with this node.
std::string SceneNodeCore::getViewportLocalPath | ( | ) | const |
Gets the path of this node relative to its local viewport node.
std::weak_ptr< ECSWorld > SceneNodeCore::getWorld | ( | ) | const |
WorldID SceneNodeCore::getWorldID | ( | ) | const |
bool ToyMaker::SceneNodeCore::hasComponent | ( | ) | const |
Tests whether this node has a component of a specific type.
TComponent | The type of component whose existence is being tested. |
true | This type of component is present for this node; |
false | This type of component is absent for this node; |
bool SceneNodeCore::hasComponent | ( | const std::string & | type | ) | const |
Tests whether this node has a component of a specific type.
type | The component type string of the component whose existence is being tested. |
true | This type of component is present for this node; |
false | This type of component is absent for this node; |
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.
pathToChild | The path to the descendant node whose existence is being tested. |
true | There is a node present at the path specified; |
false | There is no node present at the path specified; |
bool SceneNodeCore::inScene | ( | ) | const |
Returns whether this node is present as part of the SceneSystem's scene tree.
true | This node is part of the SceneSystem's scene tree. |
false | This node is not part of the SceneSystem's scene tree. |
bool SceneNodeCore::isActive | ( | ) | const |
Returns whether this node is present as part of the SceneSystem's scene tree, AND is active there as well.
true | This node is present and active in the SceneSystem's scene tree. |
false | This node is not present or active in the SceneSystem's scene tree. |
bool SceneNodeCore::isAncestorOf | ( | std::shared_ptr< const SceneNodeCore > | sceneNode | ) | const |
Tests whether a particular scene node is the ancestor of this one.
sceneNode | The scene node being tested as an ancestor. |
true | The argument node is this node's ancestor; |
false | The argument node is not this node's ancestor; |
|
protectedvirtual |
Removes this node's entity from its current ECSWorld and adds it to a new ECSWorld.
world | The new ECSWorld this node's entity should join. |
Reimplemented in ToyMaker::ViewportNode.
|
staticprivate |
Strips the root-most part of the path to a node.
where | The path before removing its prefix. |
|
protectedvirtual |
Scene node lifecycle hook for when a node is made an active part of the SceneSystem.
Reimplemented in ToyMaker::SimObject, and ToyMaker::ViewportNode.
|
protectedvirtual |
Copy assignment operator.
Scene node lifecycle hook for when a node is created.
|
protectedvirtual |
Scene node lifecycle hook for when a node is deactivated on the SceneSystem.
Reimplemented in ToyMaker::SimObject, and ToyMaker::ViewportNode.
|
protectedvirtual |
Scene node lifecycle hook for when a node (and possibly its descendants) are about to be destroyed.
std::vector< std::shared_ptr< SceneNodeCore > > SceneNodeCore::removeChildren | ( | ) |
Disconnects and removes all the child nodes attached to this node.
void ToyMaker::SceneNodeCore::removeComponent | ( | ) |
Removes a component present on this node.
TComponent | The type of component being removed. |
std::shared_ptr< SceneNodeCore > SceneNodeCore::removeNode | ( | const std::string & | where | ) |
Removes a node from the tree present at the path specified.
where | The path to the node being removed. |
|
static |
Deleter for a managed pointer to a scene node which ensures its onDestroyed virtual function gets called.
sceneNode | The pointer to the scene node being deleted. |
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.
TSystem | The system being enabled or disabled for this node. |
state | Whether to enable or disable a system for this node. |
void SceneNodeCore::setName | ( | const std::string & | name | ) |
Sets the name of this node.
name | The new name for this node. |
|
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.
node | The node whose parent viewport is being set. |
newViewport | The node's to-be parent viewport. |
|
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.
prototype | The node that acted as the prototype for this node and its children. |
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).
component | A JSON description of the component's new value along with its type. |
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).
TComponent | The type of component being updated. |
component | The component's new value. |
|
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.
nodeName | The node name whose validity is being asserted. |
|
private |
A mapping of names of this node's child nodes to the indices of the nodes themselves.
|
private |
Flags indicating the state of this scene node in the scene system.
A bitset, each position of which indicates whether a system should influence this node when it is part of the SceneSystem's scene tree.