Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
AeonGames::Node Class Reference

Scene graph node representing an entity in the game world. More...

#include <aeongames/Node.hpp>

Collaboration diagram for AeonGames::Node:
Collaboration graph

Public Types

enum  FlagBits { EnabledBit = 1 , VisibleBit = 2 , AllBits = 3 }
 Bitmask values for node flags. More...
enum  Flags { Enabled = 0 , Visible , FlagCount }
 Individual flag indices for use with SetFlag/IsFlagEnabled. More...

Public Member Functions

DLL Node (uint32_t aFlags=AllBits)
 Construct a node with the given initial flags.
DLL void SetName (const std::string &aName)
 Set the name of this node.
DLL const std::string & GetName () const
 Get the name of this node.
DLL void Serialize (NodeMsg &aNodeMsg) const
 Serialize this node's state into a protobuf message.
DLL void Deserialize (const NodeMsg &aNodeMsg)
 Deserialize this node's state from a protobuf message.
DLL void SetFlags (uint32_t aFlagBits, bool aEnabled=true)
 Enables or disables a set of node flags.
DLL void SetFlag (enum Flags aFlag, bool aEnabled=true)
 Enables or disables a single node flag.
DLL bool IsFlagEnabled (enum Flags aFlag) const
 Check whether a specific flag is enabled.
DLL NodeAdd (std::unique_ptr< Node > aNode)
 Append a child node.
DLL NodeInsert (size_t aIndex, std::unique_ptr< Node > aNode)
 Insert a child node at a specific index.
DLL std::unique_ptr< NodeRemove (Node *)
 Remove a child node by pointer.
DLL std::unique_ptr< NodeRemoveByIndex (size_t aIndex)
 Remove a child node by index.
DLL Scene * GetScene () const
 Retrieve a pointer to the scene containing the node instance.
DLL void LoopTraverseDFSPreOrder (const std::function< void(Node &) > &aAction)
 Iterative depth first search iteration.
DLL void LoopTraverseDFSPreOrder (const std::function< void(Node &) > &aPreamble, const std::function< void(Node &) > &aPostamble)
 Iterative depth first search iteration.
DLL void LoopTraverseDFSPreOrder (const std::function< void(const Node &) > &aAction) const
 Constant version of LoopTraverseDFSPreOrder.
DLL void LoopTraverseDFSPostOrder (const std::function< void(Node &) > &aAction)
 Iterative depth first search iteration.
DLL void LoopTraverseDFSPostOrder (const std::function< void(const Node &) > &aAction) const
 Constant version of LoopTraverseDFSPostOrder.
DLL void RecursiveTraverseDFSPreOrder (const std::function< void(Node &) > &aAction)
 Recursive depth first search iteration.
DLL void RecursiveTraverseDFSPostOrder (const std::function< void(Node &) > &aAction)
 Recursive depth first search iteration.
DLL void LoopTraverseAncestors (const std::function< void(Node &) > &aAction)
 Traverse ancestors iteratively, calling an action on each.
DLL void LoopTraverseAncestors (const std::function< void(const Node &) > &aAction) const
 Traverse ancestors iteratively (const version).
DLL void RecursiveTraverseAncestors (const std::function< void(Node &) > &aAction)
 Traverse ancestors recursively, calling an action on each.
DLL NodeFind (const std::function< bool(const Node &) > &aUnaryPredicate) const
 Find a descendant node matching a predicate.
DLL const TransformGetLocalTransform () const
 Get the local transform relative to the parent.
DLL const TransformGetGlobalTransform () const
 Get the global (world-space) transform.
DLL const AABBGetAABB () const
 Get the axis-aligned bounding box.
DLL void SetLocalTransform (const Transform &aTransform)
 Set the local transform relative to the parent.
DLL void SetGlobalTransform (const Transform &aTransform)
 Set the global (world-space) transform.
DLL void SetAABB (const AABB &aAABB)
 Set the axis-aligned bounding box.
DLL size_t GetChildrenCount () const
 Get the number of direct child nodes.
DLL NodeGetChild (size_t aIndex) const
 Get a child node by index.
DLL const Nodeoperator[] (const std::size_t index) const
 Access a child node by index (const).
DLL Nodeoperator[] (const std::size_t index)
 Access a child node by index.
DLL NodeParent GetParent () const
 Get this node's parent.
DLL size_t GetIndex () const
 Get this node's index within its parent's child list.
DLL uint32_t GetId () const
 Get the unique identifier of this node.
DLL void Update (const double delta)
 Update this node and its children.
DLL void Render (Renderer &aRenderer, void *aWindowId) const
 Render this node and its children.
DLL void ProcessMessage (uint32_t aMessageType, const void *aMessageData)
 Deliver a message to this node and its components.
Node Data
DLL ComponentAddComponent (std::unique_ptr< Component > aComponent)
 Add a component to this node.
DLL size_t GetComponentCount () const
 Get the number of components attached to this node.
DLL ComponentGetComponentByIndex (size_t aIndex) const
 Get a component by its index.
DLL ComponentGetComponent (uint32_t aId) const
 Get a component by its type identifier.
DLL std::unique_ptr< ComponentRemoveComponent (uint32_t aId)
 Remove a component by its type identifier.

Friends

class Scene

Detailed Description

Scene graph node representing an entity in the game world.

Nodes form a hierarchical tree structure and can hold components, transforms, and bounding volumes.

Definition at line 53 of file Node.hpp.

Member Enumeration Documentation

◆ FlagBits

Bitmask values for node flags.

Definition at line 57 of file Node.hpp.

◆ Flags

Individual flag indices for use with SetFlag/IsFlagEnabled.

Definition at line 64 of file Node.hpp.

Constructor & Destructor Documentation

◆ Node()

AeonGames::Node::Node ( uint32_t aFlags = AllBits)

Construct a node with the given initial flags.

Parameters
aFlagsBitmask of FlagBits to enable. Defaults to AllBits.

Definition at line 45 of file Node.cpp.

Member Function Documentation

◆ Add()

Node * AeonGames::Node::Add ( std::unique_ptr< Node > aNode)

Append a child node.

Parameters
aNodeUnique pointer to the node to add.
Returns
Raw pointer to the added node.

Definition at line 340 of file Node.cpp.

◆ AddComponent()

Component * AeonGames::Node::AddComponent ( std::unique_ptr< Component > aComponent)

Add a component to this node.

Parameters
aComponentUnique pointer to the component.
Returns
Raw pointer to the added component.
Todo
Get Node Data dependencies.

Definition at line 599 of file Node.cpp.

◆ Deserialize()

void AeonGames::Node::Deserialize ( const NodeMsg & aNodeMsg)

Deserialize this node's state from a protobuf message.

Parameters
aNodeMsgThe message to read from.

Definition at line 296 of file Node.cpp.

◆ GetAABB()

const AABB & AeonGames::Node::GetAABB ( ) const

Get the axis-aligned bounding box.

Returns
A const reference to the AABB.
Todo
Decide if transforms should be applied to the AABB and return the result

Definition at line 130 of file Node.cpp.

◆ GetChild()

Node * AeonGames::Node::GetChild ( size_t aIndex) const

Get a child node by index.

Parameters
aIndexIndex of the child.
Returns
Pointer to the child node, or nullptr if out of range.

Definition at line 69 of file Node.cpp.

◆ GetChildrenCount()

size_t AeonGames::Node::GetChildrenCount ( ) const

Get the number of direct child nodes.

Returns
Child count.

Definition at line 56 of file Node.cpp.

◆ GetComponent()

Component * AeonGames::Node::GetComponent ( uint32_t aId) const

Get a component by its type identifier.

Parameters
aIdCRC identifier of the component type.
Returns
Pointer to the component, or nullptr if not found.

Definition at line 616 of file Node.cpp.

◆ GetComponentByIndex()

Component * AeonGames::Node::GetComponentByIndex ( size_t aIndex) const

Get a component by its index.

Parameters
aIndexIndex of the component.
Returns
Pointer to the component, or nullptr if out of range.

Definition at line 594 of file Node.cpp.

◆ GetComponentCount()

size_t AeonGames::Node::GetComponentCount ( ) const

Get the number of components attached to this node.

Returns
Component count.

Definition at line 589 of file Node.cpp.

◆ GetGlobalTransform()

const Transform & AeonGames::Node::GetGlobalTransform ( ) const

Get the global (world-space) transform.

Returns
A const reference to the global transform.

Definition at line 125 of file Node.cpp.

◆ GetId()

uint32_t AeonGames::Node::GetId ( ) const

Get the unique identifier of this node.

Returns
The node id.

Definition at line 210 of file Node.cpp.

◆ GetIndex()

size_t AeonGames::Node::GetIndex ( ) const

Get this node's index within its parent's child list.

Returns
The index position.

Definition at line 77 of file Node.cpp.

◆ GetLocalTransform()

const Transform & AeonGames::Node::GetLocalTransform ( ) const

Get the local transform relative to the parent.

Returns
A const reference to the local transform.

Definition at line 120 of file Node.cpp.

◆ GetName()

const std::string & AeonGames::Node::GetName ( ) const

Get the name of this node.

Returns
A const reference to the node name.

Definition at line 205 of file Node.cpp.

◆ GetParent()

NodeParent AeonGames::Node::GetParent ( ) const

Get this node's parent.

Returns
A NodeParent variant holding either a Node* or Scene*.

Definition at line 73 of file Node.cpp.

◆ GetScene()

Scene * AeonGames::Node::GetScene ( ) const

Retrieve a pointer to the scene containing the node instance.

Returns
A pointer to the scene at the root of the node tree or nullptr if the node is not contained in a scene.

Definition at line 95 of file Node.cpp.

◆ Insert()

Node * AeonGames::Node::Insert ( size_t aIndex,
std::unique_ptr< Node > aNode )

Insert a child node at a specific index.

Parameters
aIndexPosition at which to insert.
aNodeUnique pointer to the node to insert.
Returns
Raw pointer to the inserted node.

Definition at line 317 of file Node.cpp.

◆ IsFlagEnabled()

bool AeonGames::Node::IsFlagEnabled ( enum Flags aFlag) const

Check whether a specific flag is enabled.

Parameters
aFlagThe flag to query.
Returns
true if the flag is enabled.

Definition at line 115 of file Node.cpp.

◆ LoopTraverseAncestors() [1/2]

void AeonGames::Node::LoopTraverseAncestors ( const std::function< void(const Node &) > & aAction) const

Traverse ancestors iteratively (const version).

Definition at line 546 of file Node.cpp.

◆ LoopTraverseAncestors() [2/2]

void AeonGames::Node::LoopTraverseAncestors ( const std::function< void(Node &) > & aAction)

Traverse ancestors iteratively, calling an action on each.

Definition at line 536 of file Node.cpp.

◆ LoopTraverseDFSPostOrder()

DLL void AeonGames::Node::LoopTraverseDFSPostOrder ( const std::function< void(Node &) > & aAction)

Iterative depth first search iteration.

Iterates all descendants without recursion in post-order. This function guarrantees that children are processed before their parent.

Parameters
aActiona function, function pointer or function like object to proccess each child node.
See also
Node::LoopTraverseDFSPreOrder,Node::RecursiveTraverseDFSPreOrder,Node::RecursiveTraverseDFSPostOrder

◆ LoopTraverseDFSPreOrder() [1/2]

DLL void AeonGames::Node::LoopTraverseDFSPreOrder ( const std::function< void(Node &) > & aAction)

Iterative depth first search iteration.

Iterates all descendants without recursion in pre-order. This function guarrantees that parents are processed before their children.

Parameters
aActiona function, function pointer or function like object to proccess each child node.
See also
Node::LoopTraverseDFSPostOrder,Node::RecursiveTraverseDFSPreOrder,Node::RecursiveTraverseDFSPostOrder

◆ LoopTraverseDFSPreOrder() [2/2]

void AeonGames::Node::LoopTraverseDFSPreOrder ( const std::function< void(Node &) > & aPreamble,
const std::function< void(Node &) > & aPostamble )

Iterative depth first search iteration.

Iterates all descendants without recursion in pre-order. This function guarrantees that parents are processed before their children. This function does the same as the single argument version except that it runs two functions, a preamble upon reaching a node and a postamble upon leaving it having run the preambles and postambles of all of the node's children.

Parameters
aPreamblea function, function pointer or function like object to run upon reaching each child node.
aPostamblea function, function pointer or function like object to run upon leaving each child node.
See also
Node::LoopTraverseDFSPostOrder,Node::RecursiveTraverseDFSPreOrder,Node::RecursiveTraverseDFSPostOrder
Todo
(EC++ Item 3) This code is the same as the constant overload, but can't easily be implemented in terms of that because of aAction's node parameter needs to also be const.

Definition at line 393 of file Node.cpp.

◆ operator[]() [1/2]

Node & AeonGames::Node::operator[] ( const std::size_t index)

Access a child node by index.

Parameters
indexIndex of the child.
Returns
Reference to the child node.

Definition at line 65 of file Node.cpp.

◆ operator[]() [2/2]

const Node & AeonGames::Node::operator[] ( const std::size_t index) const

Access a child node by index (const).

Parameters
indexIndex of the child.
Returns
Const reference to the child node.

Definition at line 60 of file Node.cpp.

◆ ProcessMessage()

void AeonGames::Node::ProcessMessage ( uint32_t aMessageType,
const void * aMessageData )

Deliver a message to this node and its components.

Parameters
aMessageTypeType identifier for the message.
aMessageDataPointer to message-specific data.

Definition at line 573 of file Node.cpp.

◆ RecursiveTraverseAncestors()

void AeonGames::Node::RecursiveTraverseAncestors ( const std::function< void(Node &) > & aAction)

Traverse ancestors recursively, calling an action on each.

Definition at line 556 of file Node.cpp.

◆ RecursiveTraverseDFSPostOrder()

DLL void AeonGames::Node::RecursiveTraverseDFSPostOrder ( const std::function< void(Node &) > & aAction)

Recursive depth first search iteration.

Iterates all descendants with recursion in post-order. This function guarrantees that children are processed before their parent.

Parameters
aActiona function, function pointer or function like object to proccess each child node.
See also
Node::LoopTraverseDFSPreOrder,Node::LoopTraverseDFSPostOrder,Node::RecursiveTraverseDFSPreOrder

◆ RecursiveTraverseDFSPreOrder()

void AeonGames::Node::RecursiveTraverseDFSPreOrder ( const std::function< void(Node &) > & aAction)

Recursive depth first search iteration.

Iterates all descendants with recursion in pre-order. This function guarrantees that parents are processed before their children.

Parameters
aActiona function, function pointer or function like object to proccess each child node.
See also
Node::LoopTraverseDFSPreOrder,Node::LoopTraverseDFSPostOrder,Node::RecursiveTraverseDFSPostOrder

Definition at line 527 of file Node.cpp.

◆ Remove()

std::unique_ptr< Node > AeonGames::Node::Remove ( Node * aNode)

Remove a child node by pointer.

Parameters
aNodePointer to the child node to remove.
Returns
Unique pointer to the removed node, or nullptr if not found.

Definition at line 355 of file Node.cpp.

◆ RemoveByIndex()

std::unique_ptr< Node > AeonGames::Node::RemoveByIndex ( size_t aIndex)

Remove a child node by index.

Parameters
aIndexIndex of the child to remove.
Returns
Unique pointer to the removed node.

Definition at line 379 of file Node.cpp.

◆ RemoveComponent()

std::unique_ptr< Component > AeonGames::Node::RemoveComponent ( uint32_t aId)

Remove a component by its type identifier.

Parameters
aIdCRC identifier of the component type.
Returns
Unique pointer to the removed component, or nullptr if not found.

Definition at line 629 of file Node.cpp.

◆ Render()

void AeonGames::Node::Render ( Renderer & aRenderer,
void * aWindowId ) const

Render this node and its children.

Parameters
aRendererThe renderer to draw with.
aWindowIdPlatform-specific window handle.

Definition at line 581 of file Node.cpp.

◆ Serialize()

void AeonGames::Node::Serialize ( NodeMsg & aNodeMsg) const

Serialize this node's state into a protobuf message.

Parameters
aNodeMsgThe message to populate.

Definition at line 218 of file Node.cpp.

◆ SetAABB()

void AeonGames::Node::SetAABB ( const AABB & aAABB)

Set the axis-aligned bounding box.

Parameters
aAABBThe new AABB.

Definition at line 194 of file Node.cpp.

◆ SetFlag()

void AeonGames::Node::SetFlag ( enum Flags aFlag,
bool aEnabled = true )

Enables or disables a single node flag.

Parameters
aFlagFlag to enable/disable.
aEnabledtrue to enable, false to disable.

Definition at line 110 of file Node.cpp.

◆ SetFlags()

void AeonGames::Node::SetFlags ( uint32_t aFlagBits,
bool aEnabled = true )

Enables or disables a set of node flags.

Parameters
aFlagBitsFlag bits to enable/disable.
aEnabledtrue to enable, false to disable.

Definition at line 105 of file Node.cpp.

◆ SetGlobalTransform()

void AeonGames::Node::SetGlobalTransform ( const Transform & aTransform)

Set the global (world-space) transform.

Parameters
aTransformThe new global transform.
Todo
Although this->mLocalTransform has already been computed think about removing the check and let it be recomputed, it may be faster than the branch that needs to run for each node and is false only once.

Definition at line 158 of file Node.cpp.

◆ SetLocalTransform()

void AeonGames::Node::SetLocalTransform ( const Transform & aTransform)

Set the local transform relative to the parent.

Parameters
aTransformThe new local transform.

Definition at line 137 of file Node.cpp.

◆ SetName()

void AeonGames::Node::SetName ( const std::string & aName)

Set the name of this node.

Parameters
aNameThe new name string.

Definition at line 199 of file Node.cpp.

◆ Update()

void AeonGames::Node::Update ( const double delta)

Update this node and its children.

Parameters
deltaElapsed time in seconds since the last update.

Definition at line 565 of file Node.cpp.

◆ Scene

friend class Scene
friend

Definition at line 250 of file Node.hpp.


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