16#ifndef AEONGAMES_NODE_H
17#define AEONGAMES_NODE_H
24#include <unordered_map>
29#include "aeongames/CRC.hpp"
30#include "aeongames/Component.hpp"
31#include "aeongames/DependencyMap.hpp"
43 return std::holds_alternative<Node*> ( aNodeParent ) ? std::get<Node*> ( aNodeParent ) :
nullptr;
48 return std::holds_alternative<Scene*> ( aNodeParent ) ? std::get<Scene*> ( aNodeParent ) :
nullptr;
72 DLL
Node ( uint32_t aFlags = AllBits );
75 DLL
void SetName (
const std::string& aName );
78 DLL
const std::string&
GetName()
const;
81 DLL
void Serialize ( NodeMsg& aNodeMsg )
const;
89 DLL
void SetFlags ( uint32_t aFlagBits,
bool aEnabled =
true );
94 DLL
void SetFlag (
enum Flags aFlag,
bool aEnabled =
true );
102 DLL
Node*
Add ( std::unique_ptr<Node> aNode );
107 DLL
Node*
Insert (
size_t aIndex, std::unique_ptr<Node> aNode );
139 const std::function<
void (
Node& ) >& aPreamble,
140 const std::function<
void (
Node& ) >& aPostamble );
173 DLL
Node*
Find (
const std::function<
bool (
const Node& ) >& aUnaryPredicate )
const;
215 DLL uint32_t
GetId()
const;
240 DLL
void Update (
const double delta );
248 DLL
void ProcessMessage ( uint32_t aMessageType,
const void* aMessageData );
253 Transform mLocalTransform{};
254 Transform mGlobalTransform{};
256 std::vector<std::unique_ptr<Node >> mNodes{};
257 DependencyMap<uint32_t> mComponentDependencyMap{};
261 std::vector<std::unique_ptr<Component >> mComponents{};
264 mutable std::vector<Node*>::size_type mIterator{ 0 };
266 std::bitset<8> mFlags{};
Header for the axis aligned bounding box class.
#define LoopTraverseDFSPreOrder(...)
Macro generating LoopTraverseDFSPreOrder implementations for const and non-const variants.
Axis Aligned Bounding Box class.
Abstract base class for node components.
Scene graph node representing an entity in the game world.
DLL void SetLocalTransform(const Transform &aTransform)
Set the local transform relative to the parent.
DLL Component * GetComponent(uint32_t aId) const
Get a component by its type identifier.
DLL const Node & operator[](const std::size_t index) const
Access a child node by index (const).
DLL Component * GetComponentByIndex(size_t aIndex) const
Get a component by its index.
DLL std::unique_ptr< Node > Remove(Node *)
Remove a child node by pointer.
DLL Scene * GetScene() const
Retrieve a pointer to the scene containing the node instance.
DLL const Transform & GetLocalTransform() const
Get the local transform relative to the parent.
DLL const AABB & GetAABB() const
Get the axis-aligned bounding box.
DLL uint32_t GetId() const
Get the unique identifier of this node.
DLL void SetAABB(const AABB &aAABB)
Set the axis-aligned bounding box.
DLL size_t GetIndex() const
Get this node's index within its parent's child list.
DLL Node * GetChild(size_t aIndex) const
Get a child node by index.
DLL Node * Find(const std::function< bool(const Node &) > &aUnaryPredicate) const
Find a descendant node matching a predicate.
DLL Node(uint32_t aFlags=AllBits)
Construct a node with the given initial flags.
Flags
Individual flag indices for use with SetFlag/IsFlagEnabled.
DLL void Serialize(NodeMsg &aNodeMsg) const
Serialize this node's state into a protobuf message.
DLL void RecursiveTraverseDFSPostOrder(const std::function< void(Node &) > &aAction)
Recursive depth first search iteration.
DLL void SetName(const std::string &aName)
Set the name of this node.
DLL void RecursiveTraverseDFSPreOrder(const std::function< void(Node &) > &aAction)
Recursive depth first search iteration.
FlagBits
Bitmask values for node flags.
DLL const std::string & GetName() const
Get the name of this node.
DLL void SetGlobalTransform(const Transform &aTransform)
Set the global (world-space) transform.
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.
DLL const Transform & GetGlobalTransform() const
Get the global (world-space) transform.
DLL std::unique_ptr< Component > RemoveComponent(uint32_t aId)
Remove a component by its type identifier.
DLL Node * Add(std::unique_ptr< Node > aNode)
Append a child node.
DLL NodeParent GetParent() const
Get this node's parent.
DLL void RecursiveTraverseAncestors(const std::function< void(Node &) > &aAction)
Traverse ancestors recursively, calling an action on each.
DLL void LoopTraverseAncestors(const std::function< void(Node &) > &aAction)
Traverse ancestors iteratively, calling an action on each.
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 Update(const double delta)
Update this node and its children.
DLL void Deserialize(const NodeMsg &aNodeMsg)
Deserialize this node's state from a protobuf message.
DLL void LoopTraverseDFSPreOrder(const std::function< void(Node &) > &aAction)
Iterative depth first search iteration.
DLL Node * Insert(size_t aIndex, std::unique_ptr< Node > aNode)
Insert a child node at a specific index.
DLL size_t GetComponentCount() const
Get the number of components attached to this node.
DLL bool IsFlagEnabled(enum Flags aFlag) const
Check whether a specific flag is enabled.
DLL Component * AddComponent(std::unique_ptr< Component > aComponent)
Add a component to this node.
DLL void SetFlag(enum Flags aFlag, bool aEnabled=true)
Enables or disables a single node flag.
DLL std::unique_ptr< Node > RemoveByIndex(size_t aIndex)
Remove a child node by index.
DLL void LoopTraverseDFSPostOrder(const std::function< void(const Node &) > &aAction) const
Constant version of LoopTraverseDFSPostOrder.
DLL void SetFlags(uint32_t aFlagBits, bool aEnabled=true)
Enables or disables a set of node flags.
DLL size_t GetChildrenCount() const
Get the number of direct child nodes.
Abstract base class for rendering backends.
Scene class. Scene is the container for all elements in a game level, takes care of collision,...
<- This is here just for the literals
Scene * GetScenePtr(const NodeParent &aNodeParent)
Extract the Scene pointer from a NodeParent variant.
Node * GetNodePtr(const NodeParent &aNodeParent)
Extract the Node pointer from a NodeParent variant.
std::variant< Node *, Scene * > NodeParent
Variant type representing a node's parent (either a Node or a Scene).