The Table Engine
SceneTree Class Reference

Manages a tree structure of SceneNodes, facilitating scene graph operations. More...

#include <scene.h>

+ Collaboration diagram for SceneTree:

Public Member Functions

 SceneTree ()
 Constructor for creating a root node of the scene tree. More...
 
 ~SceneTree ()
 Destructor, cleans up the tree resources. More...
 
void addChild (GameObject *child, bool isBackground=false)
 Adds a child GameObject to the scene tree. More...
 
void traverseTree (std::function< void(SceneNode *)> callback)
 Traverses the entire tree, executing a callback on each node. More...
 
void traverseTree (SceneNode *node, std::function< void(SceneNode *)> callback)
 Traverses the tree from a specific node, executing a callback on each node. More...
 
GameObjectfindGameObjectById (std::string id)
 Finds a GameObject by its ID. More...
 
std::vector< GameObject * > findGameObjectsByTag (std::string tag)
 Finds GameObjects by a tag. More...
 
std::vector< GameObject * > & findCachedGameObjectsInFrame (std::string tag)
 Retrieves the game objects cached by tag. More...
 
void resetCachedGameObjectsInFrame ()
 Resets the cached game objects for a new frame, clearing the current frame's cache. More...
 
int gameStatus ()
 Retrieves the current game status. More...
 

Private Attributes

SceneNodem_root
 Root node of the scene tree. More...
 
std::unordered_map< std::string, GameObject * > m_cachedGameObjects
 Cache for faster lookup of GameObjects by ID. More...
 
std::unordered_map< std::string, std::vector< GameObject * > > m_cachedGameObjectsInFrame
 Cache for faster lookup of GameObjects by tag within a frame. More...
 

Detailed Description

Manages a tree structure of SceneNodes, facilitating scene graph operations.

SceneTree provides mechanisms to add children, traverse the tree, and perform lookups for game objects based on IDs and tags.

Definition at line 108 of file scene.h.

Constructor & Destructor Documentation

◆ SceneTree()

SceneTree::SceneTree ( )

Constructor for creating a root node of the scene tree.

Definition at line 79 of file scene.cpp.

◆ ~SceneTree()

SceneTree::~SceneTree ( )

Destructor, cleans up the tree resources.

Definition at line 83 of file scene.cpp.

Member Function Documentation

◆ addChild()

void SceneTree::addChild ( GameObject child,
bool  isBackground = false 
)

Adds a child GameObject to the scene tree.

Parameters
childPointer to the GameObject to add.
isBackgroundFlag indicating if the child is part of the background.

Definition at line 87 of file scene.cpp.

◆ findCachedGameObjectsInFrame()

std::vector< GameObject * > & SceneTree::findCachedGameObjectsInFrame ( std::string  tag)

Retrieves the game objects cached by tag.

Parameters
tagThe tag string to search for.
Returns
Vector of GameObjects with the specified tag.

Definition at line 139 of file scene.cpp.

◆ findGameObjectById()

GameObject * SceneTree::findGameObjectById ( std::string  id)

Finds a GameObject by its ID.

Parameters
idThe ID string of the GameObject to find.
Returns
Pointer to the GameObject if found, nullptr otherwise.

Definition at line 104 of file scene.cpp.

◆ findGameObjectsByTag()

std::vector< GameObject * > SceneTree::findGameObjectsByTag ( std::string  tag)

Finds GameObjects by a tag.

Parameters
tagThe tag string to search for.
Returns
Vector of GameObjects with the specified tag.

Definition at line 114 of file scene.cpp.

◆ gameStatus()

int SceneTree::gameStatus ( )

Retrieves the current game status.

Returns
Integer representing the current game status.

Definition at line 147 of file scene.cpp.

◆ resetCachedGameObjectsInFrame()

void SceneTree::resetCachedGameObjectsInFrame ( )

Resets the cached game objects for a new frame, clearing the current frame's cache.

Definition at line 143 of file scene.cpp.

◆ traverseTree() [1/2]

void SceneTree::traverseTree ( SceneNode node,
std::function< void(SceneNode *)>  callback 
)

Traverses the tree from a specific node, executing a callback on each node.

Parameters
nodeStarting node for traversal.
callbackFunction to execute for each node.

Definition at line 95 of file scene.cpp.

◆ traverseTree() [2/2]

void SceneTree::traverseTree ( std::function< void(SceneNode *)>  callback)

Traverses the entire tree, executing a callback on each node.

Parameters
callbackFunction to execute for each node.

Definition at line 91 of file scene.cpp.

Member Data Documentation

◆ m_cachedGameObjects

std::unordered_map<std::string, GameObject*> SceneTree::m_cachedGameObjects
private

Cache for faster lookup of GameObjects by ID.

Definition at line 176 of file scene.h.

◆ m_cachedGameObjectsInFrame

std::unordered_map<std::string, std::vector<GameObject*> > SceneTree::m_cachedGameObjectsInFrame
private

Cache for faster lookup of GameObjects by tag within a frame.

Definition at line 177 of file scene.h.

◆ m_root

SceneNode* SceneTree::m_root
private

Root node of the scene tree.

Definition at line 174 of file scene.h.


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