The Table Engine
gameobject.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include "gameobject.h"
4 #include "scenemanager.h"
5 #include "texture.h"
6 
7 GameObject::GameObject(std::string tag) {
8  m_tag = tag;
9  m_id = std::to_string(SceneManager::m_totalObjects++);
10 
12 }
13 
16 
17  for (auto script : m_scripts) {
18  delete script;
19  }
20  for (auto component : m_components) {
21  delete component;
22  }
23 
24  m_components.clear();
25  m_scripts.clear();
26 }
27 
28 std::string GameObject::getId() {
29  return m_id;
30 }
31 
32 std::string GameObject::getTag() {
33  return m_tag;
34 }
35 
37  return m_sceneNode;
38 }
39 
41  m_sceneNode = sceneNode;
42 }
43 
44 std::vector<GameObject*> GameObject::getChildren() {
45  if (m_sceneNode == nullptr) {
46  return std::vector<GameObject*>();
47  }
48 
49  std::vector<GameObject*> children;
50  for (auto childSceneNode : m_sceneNode->getChildren()) {
51  if (childSceneNode->getGameObject() != nullptr)
52  children.push_back(childSceneNode->getGameObject());
53  }
54  return children;
55 }
56 
58  for (auto component : m_components) {
59  component->input();
60  }
61  for (auto script : m_scripts) {
62  script->input();
63  }
64 }
65 
67  for (auto component : m_components) {
68  component->update();
69  }
70  for (auto script : m_scripts) {
71  script->update();
72  }
73 }
74 
76  for (auto component : m_components) {
77  component->render();
78  }
79  for (auto script : m_scripts) {
80  script->render();
81  }
82 }
std::vector< Component * > m_components
List of attached components.
Definition: gameobject.h:27
std::string m_id
Unique identifier for the GameObject.
Definition: gameobject.h:24
std::vector< Script * > m_scripts
List of attached scripts.
Definition: gameobject.h:28
void render()
Renders this GameObject and its components.
Definition: gameobject.cpp:75
SceneNode * getSceneNode()
Gets the SceneNode associated with this GameObject.
Definition: gameobject.cpp:36
std::string getTag()
Gets the tag identifier of the GameObject.
Definition: gameobject.cpp:32
void input()
Processes input for this GameObject and its components.
Definition: gameobject.cpp:57
std::vector< GameObject * > getChildren()
Gets all child GameObjects.
Definition: gameobject.cpp:44
GameObject(std::string tag)
Constructs a new GameObject with the specified tag.
Definition: gameobject.cpp:7
~GameObject()
Destructor that cleans up the GameObject and its SceneNode.
Definition: gameobject.cpp:14
std::string m_tag
Category identifier (e.g., "Enemy", "Projectile")
Definition: gameobject.h:25
void setSceneNode(SceneNode *sceneNode)
Sets the SceneNode for this GameObject.
Definition: gameobject.cpp:40
SceneNode * m_sceneNode
Node in the scene graph hierarchy.
Definition: gameobject.h:30
std::string getId()
Gets the unique identifier of the GameObject.
Definition: gameobject.cpp:28
void update()
Updates this GameObject and its components.
Definition: gameobject.cpp:66
static std::atomic< uint64_t > m_totalObjects
Total number of game objects created.
Definition: scenemanager.h:57
static std::atomic< uint64_t > m_aliveObjects
Current number of active game objects.
Definition: scenemanager.h:58
Represents a node in the scene graph, encapsulating a game object and its hierarchy.
Definition: scene.h:25
const std::vector< SceneNode * > getChildren()
Returns the children of this node.
Definition: scene.cpp:49
Defines the SceneManager class for managing scenes in the game.
Defines the Texture component for managing textures within the Game Engine, encapsulating SDL texture...