The Table Engine
GameObject Class Reference

Core class representing an entity in the game world. More...

#include <gameobject.h>

+ Collaboration diagram for GameObject:

Public Member Functions

 GameObject (std::string tag)
 Constructs a new GameObject with the specified tag. More...
 
std::string getId ()
 Gets the unique identifier of the GameObject. More...
 
std::string getTag ()
 Gets the tag identifier of the GameObject. More...
 
template<typename T >
T * getComponent ()
 Gets a component of the specified type. More...
 
template<typename T >
void addComponent (T *component)
 Adds a component to the GameObject. More...
 
template<typename T >
T * getScript ()
 Gets a script of the specified type. More...
 
template<typename T >
void addScript (T *script)
 Adds a script to the GameObject. More...
 
SceneNodegetSceneNode ()
 Gets the SceneNode associated with this GameObject. More...
 
void setSceneNode (SceneNode *sceneNode)
 Sets the SceneNode for this GameObject. More...
 
std::vector< GameObject * > getChildren ()
 Gets all child GameObjects. More...
 
void input ()
 Processes input for this GameObject and its components. More...
 
void update ()
 Updates this GameObject and its components. More...
 
void render ()
 Renders this GameObject and its components. More...
 

Private Member Functions

 ~GameObject ()
 Destructor that cleans up the GameObject and its SceneNode. More...
 

Private Attributes

std::string m_id
 Unique identifier for the GameObject. More...
 
std::string m_tag
 Category identifier (e.g., "Enemy", "Projectile") More...
 
std::vector< Component * > m_components
 List of attached components. More...
 
std::vector< Script * > m_scripts
 List of attached scripts. More...
 
SceneNodem_sceneNode
 Node in the scene graph hierarchy. More...
 

Friends

class SceneNode
 

Detailed Description

Core class representing an entity in the game world.

GameObject serves as the base class for all game entities. It manages components and scripts, handles lifecycle events (input, update, render), and maintains relationships within the scene hierarchy.

Definition at line 20 of file gameobject.h.

Constructor & Destructor Documentation

◆ ~GameObject()

GameObject::~GameObject ( )
private

Destructor that cleans up the GameObject and its SceneNode.

Definition at line 14 of file gameobject.cpp.

◆ GameObject()

GameObject::GameObject ( std::string  tag)

Constructs a new GameObject with the specified tag.

Parameters
tagCategory identifier for the object

Definition at line 7 of file gameobject.cpp.

Member Function Documentation

◆ addComponent()

template<typename T >
void GameObject::addComponent ( T *  component)

Adds a component to the GameObject.

Template Parameters
TThe type of component to add
Parameters
componentPointer to the component instance

Definition at line 133 of file gameobject.h.

◆ addScript()

template<typename T >
void GameObject::addScript ( T *  script)

Adds a script to the GameObject.

Template Parameters
TThe type of script to add
Parameters
scriptPointer to the script instance

Definition at line 150 of file gameobject.h.

◆ getChildren()

std::vector< GameObject * > GameObject::getChildren ( )

Gets all child GameObjects.

Returns
std::vector<GameObject*> List of child GameObjects

Definition at line 44 of file gameobject.cpp.

◆ getComponent()

template<typename T >
T * GameObject::getComponent

Gets a component of the specified type.

Template Parameters
TThe type of component to retrieve
Returns
T* Pointer to the component, or nullptr if not found

Definition at line 123 of file gameobject.h.

◆ getId()

std::string GameObject::getId ( )

Gets the unique identifier of the GameObject.

Returns
std::string The GameObject's ID

Definition at line 28 of file gameobject.cpp.

◆ getSceneNode()

SceneNode * GameObject::getSceneNode ( )

Gets the SceneNode associated with this GameObject.

Returns
SceneNode* Pointer to the SceneNode

Definition at line 36 of file gameobject.cpp.

◆ getScript()

template<typename T >
T * GameObject::getScript

Gets a script of the specified type.

Template Parameters
TThe type of script to retrieve
Returns
T* Pointer to the script, or nullptr if not found

Definition at line 140 of file gameobject.h.

◆ getTag()

std::string GameObject::getTag ( )

Gets the tag identifier of the GameObject.

Returns
std::string The GameObject's tag

Definition at line 32 of file gameobject.cpp.

◆ input()

void GameObject::input ( )

Processes input for this GameObject and its components.

Definition at line 57 of file gameobject.cpp.

◆ render()

void GameObject::render ( )

Renders this GameObject and its components.

Definition at line 75 of file gameobject.cpp.

◆ setSceneNode()

void GameObject::setSceneNode ( SceneNode sceneNode)

Sets the SceneNode for this GameObject.

Parameters
sceneNodePointer to the SceneNode

Definition at line 40 of file gameobject.cpp.

◆ update()

void GameObject::update ( )

Updates this GameObject and its components.

Definition at line 66 of file gameobject.cpp.

Friends And Related Function Documentation

◆ SceneNode

friend class SceneNode
friend

Definition at line 21 of file gameobject.h.

Member Data Documentation

◆ m_components

std::vector<Component*> GameObject::m_components
private

List of attached components.

Definition at line 27 of file gameobject.h.

◆ m_id

std::string GameObject::m_id
private

Unique identifier for the GameObject.

Definition at line 24 of file gameobject.h.

◆ m_sceneNode

SceneNode* GameObject::m_sceneNode
private

Node in the scene graph hierarchy.

Definition at line 30 of file gameobject.h.

◆ m_scripts

std::vector<Script*> GameObject::m_scripts
private

List of attached scripts.

Definition at line 28 of file gameobject.h.

◆ m_tag

std::string GameObject::m_tag
private

Category identifier (e.g., "Enemy", "Projectile")

Definition at line 25 of file gameobject.h.


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