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::BaseSceneNode< TSceneNode > Class Template Reference

A CRTP template for all the scene node types present in the project. More...

#include <scene_system.hpp>

Inheritance diagram for ToyMaker::BaseSceneNode< TSceneNode >:
ToyMaker::SceneNodeCore

Protected Member Functions

template<typename... TComponents>
 BaseSceneNode (const Key &key, const Placement &placement, const std::string &name, TComponents...components)
 Constructor for a single node of a subclass.
 
template<typename ... TComponents>
 BaseSceneNode (const Placement &placement, const std::string &name, TComponents...components)
 General constructor for a single node of a subclass.
 
 BaseSceneNode (const nlohmann::json &nodeDescription)
 Constructs a new node of a certain type based on its json description.
 
 BaseSceneNode (const SceneNodeCore &other)
 Constructs a new node of a certain type as a copy of another node.
 
- Protected Member Functions inherited from ToyMaker::SceneNodeCore
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

template<typename ... TComponents>
static std::shared_ptr< TSceneNode > create (const Key &, const Placement &placement, const std::string &name, TComponents...components)
 A (private) method for the creation of a new scene node for a particular type.
 
template<typename ... TComponents>
static std::shared_ptr< TSceneNode > create (const Placement &placement, const std::string &name, TComponents...components)
 A method for creating a scene node of a specific type (TSceneNode)
 
static std::shared_ptr< TSceneNode > create (const nlohmann::json &sceneNodeDescription)
 Creates a scene node of a type based on its description in JSON.
 
static std::shared_ptr< TSceneNode > copy (const std::shared_ptr< const TSceneNode > sceneNode)
 Creates a scene node of a specific type based on another node of that type.
 
- Static Protected Member Functions inherited from ToyMaker::SceneNodeCore
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.
 

Friends

class SceneNodeCore
 

Additional Inherited Members

- Public Member Functions inherited from ToyMaker::SceneNodeCore
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 inherited from ToyMaker::SceneNodeCore
static void SceneNodeCore_del_ (SceneNodeCore *sceneNode)
 Deleter for a managed pointer to a scene node which ensures its onDestroyed virtual function gets called.
 

Detailed Description

template<typename TSceneNode>
class ToyMaker::BaseSceneNode< TSceneNode >

A CRTP template for all the scene node types present in the project.

Template Parameters
TSceneNodeA specialization and subclass of this class.

Constructor & Destructor Documentation

◆ BaseSceneNode() [1/4]

template<typename TSceneNode>
template<typename... TComponents>
ToyMaker::BaseSceneNode< TSceneNode >::BaseSceneNode ( const Key & key,
const Placement & placement,
const std::string & name,
TComponents... components )
inlineprotected

Constructor for a single node of a subclass.

Parameters
keyKey only usable by this class' implementation and other tightly coupled classes and functions (allows certain scene system checks to be skipped).
placementThe initial value of placement for this node.
nameThe name for this node.
componentsInitial values for various components of this node.

◆ BaseSceneNode() [2/4]

template<typename TSceneNode>
template<typename ... TComponents>
ToyMaker::BaseSceneNode< TSceneNode >::BaseSceneNode ( const Placement & placement,
const std::string & name,
TComponents... components )
inlineprotected

General constructor for a single node of a subclass.

Template Parameters
TComponentsA list of component types to be initialized for this node.
Parameters
placementThe initial value for the placement component of this node.
nameThe name for the newly constructed node.
componentsInitial values for various components of this node.

◆ BaseSceneNode() [3/4]

template<typename TSceneNode>
ToyMaker::BaseSceneNode< TSceneNode >::BaseSceneNode ( const nlohmann::json & nodeDescription)
inlineprotected

Constructs a new node of a certain type based on its json description.

Parameters
nodeDescriptionThe description of the node and the types and initial values of its components.

◆ BaseSceneNode() [4/4]

template<typename TSceneNode>
ToyMaker::BaseSceneNode< TSceneNode >::BaseSceneNode ( const SceneNodeCore & other)
inlineprotected

Constructs a new node of a certain type as a copy of another node.

Parameters
otherThe node being used as a template to construct this node.

Member Function Documentation

◆ copy()

template<typename TSceneNode>
std::shared_ptr< TSceneNode > ToyMaker::BaseSceneNode< TSceneNode >::copy ( const std::shared_ptr< const TSceneNode > sceneNode)
staticprotected

Creates a scene node of a specific type based on another node of that type.

Parameters
sceneNodeThe node being copied from.
Returns
std::shared_ptr<TSceneNode> The newly constructed node.
Remarks
An override for this static method is expected for all this class' subclasses.

◆ create() [1/3]

template<typename TSceneNode>
template<typename ... TComponents>
std::shared_ptr< TSceneNode > ToyMaker::BaseSceneNode< TSceneNode >::create ( const Key & key,
const Placement & placement,
const std::string & name,
TComponents... components )
staticprotected

A (private) method for the creation of a new scene node for a particular type.

Template Parameters
TComponentsComponent types of extra componennts to be added to this node.
Parameters
placementThe value of the placement component of this node.
nameThe name of this node.
componentsThe initial values of extra components initialized for this node.
Returns
std::shared_ptr<TSceneNode> A shared pointer to the newly constructed node.
Remarks
An override for this static method is expected for all this class' subclasses.

◆ create() [2/3]

template<typename TSceneNode>
std::shared_ptr< TSceneNode > ToyMaker::BaseSceneNode< TSceneNode >::create ( const nlohmann::json & sceneNodeDescription)
staticprotected

Creates a scene node of a type based on its description in JSON.

Parameters
sceneNodeDescriptionA JSON description of the scene node being constructed.
Returns
std::shared_ptr<TSceneNode> The newly constructed scene node.
Remarks
An override for this static method is expected for all this class' subclasses.

◆ create() [3/3]

template<typename TSceneNode>
template<typename ... TComponents>
std::shared_ptr< TSceneNode > ToyMaker::BaseSceneNode< TSceneNode >::create ( const Placement & placement,
const std::string & name,
TComponents... components )
staticprotected

A method for creating a scene node of a specific type (TSceneNode)

Template Parameters
TComponentsComponent types of extra components to be added to this node.
Parameters
placementThe value of the placement component of this node.
nameThe name of this node.
componentsThe initial values of extra components initialized for this node.
Returns
std::shared_ptr<TSceneNode> A shared pointer to the newly constructed node.
Remarks
An override for this static method is expected for all this class' subclasses.

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