#include <GameObject.h>
Definition at line 28 of file GameObject.h.
◆ GameObject()
| Elevate::GameObject::GameObject |
( |
std::string |
name, |
|
|
std::shared_ptr< Scene > |
scene, |
|
|
std::shared_ptr< GameObject > |
parent = nullptr |
|
) |
| |
Definition at line 22 of file GameObject.cpp.
23 : m_name(name), m_scene(scene.get()), m_parent(parent)
24 {
25 m_goId = s_goIdCount;
26 s_goIdCount++;
27 }
◆ ~GameObject()
| Elevate::GameObject::~GameObject |
( |
| ) |
|
Definition at line 210 of file GameObject.cpp.
211{
213
214
215
216
217
218}
static void UnregisterGameObject(GameObject *obj)
◆ AddChild()
| void Elevate::GameObject::AddChild |
( |
std::shared_ptr< GameObject > |
child | ) |
|
|
protected |
Definition at line 314 of file GameObject.cpp.
315 {
316 if (child)
317 {
318 child->m_parent = shared_from_this();
319 m_childs.emplace(child);
320 m_scene->RemoveFromRoot(child);
321 }
322 }
◆ AddComponent()
template<typename T , typename... Args>
| T & Elevate::GameObject::AddComponent |
( |
Args &&... |
args | ) |
|
Definition at line 24 of file GameObject.inl.
25 {
27
28
29 if (
GetRegistryMap()[m_scene->m_registryId]->all_of<T>(entt::entity(m_entityId)))
30 {
31 EE_ERROR(
"Error: Tried to add an already existing component to the %s GameObject", m_name);
32 return GetRegistryMap()[m_scene->m_registryId]->get<T>(entt::entity(m_entityId));
33 }
34
35 auto& comp =
GetRegistryMap()[m_scene->m_registryId]->emplace<T>(entt::entity(m_entityId), std::forward<Args>(args)...);
36 comp.gameObject = this;
37 comp.Init();
38
39 return comp;
40 }
#define EE_VALIDATE_COMPONENT_TYPE()
std::unordered_map< uint32_t, std::unique_ptr< entt::registry > > & GetRegistryMap()
◆ Create()
| std::shared_ptr< GameObject > Elevate::GameObject::Create |
( |
std::string |
name, |
|
|
std::shared_ptr< Scene > |
scene, |
|
|
std::shared_ptr< GameObject > |
parent = nullptr |
|
) |
| |
|
static |
Definition at line 329 of file GameObject.cpp.
330 {
331 std::shared_ptr<GameObject> obj = std::make_shared<GameObject>(name, scene, parent);
332 obj->Initialize();
333 obj->SetPosition({ 0.0f, 0.0f, 0.0f });
334 return obj;
335 }
◆ Destroy()
| void Elevate::GameObject::Destroy |
( |
| ) |
|
Definition at line 293 of file GameObject.cpp.
294 {
295 if (m_parent) {
296 m_parent->RemoveChild(shared_from_this());
297 }
298 else {
299 m_scene->RemoveFromRoot(shared_from_this());
300 }
301
302 auto childsCopy = m_childs;
303 for (const auto& child : childsCopy)
304 {
305 if (child)
306 {
307 child->Destroy();
308 }
309 }
310 m_childs.clear();
311 m_parent.reset();
312 }
◆ GenGlobalMatrix()
| glm::mat4 Elevate::GameObject::GenGlobalMatrix |
( |
| ) |
const |
Definition at line 338 of file GameObject.cpp.
339 {
340 if (m_parent)
341 {
343 }
344 else
345 {
347 }
348 }
◆ GetChilds()
| std::set< std::shared_ptr< GameObject > > Elevate::GameObject::GetChilds |
( |
| ) |
const |
|
inline |
◆ GetComponent()
template<typename T >
| T * Elevate::GameObject::GetComponent |
( |
bool |
onlyReturnActive = false | ) |
|
Definition at line 43 of file GameObject.inl.
44 {
46
47 T* component =
GetRegistryMap()[m_scene->m_registryId]->try_get<T>(entt::entity(m_entityId));
48
49 if (!component)
50 {
51 return nullptr;
52 }
53
54 if (onlyReturnActive && !component->IsActive())
55 {
56 return nullptr;
57 }
58
59 return component;
60 }
◆ GetComponents()
| std::vector< Component * > Elevate::GameObject::GetComponents |
( |
| ) |
|
Definition at line 220 of file GameObject.cpp.
221 {
222 std::vector<Component*> components;
223 if (!m_scene) return components;
224
226 if (Component* component = entry.getter(weak_from_this())) {
227 components.push_back(component);
228 }
229 }
230
231 return components;
232 }
friend class ComponentRegistry
◆ GetEntityId()
| uint32_t Elevate::GameObject::GetEntityId |
( |
| ) |
|
|
inline |
◆ GetGlobalPosition()
| glm::vec3 Elevate::GameObject::GetGlobalPosition |
( |
| ) |
|
Definition at line 47 of file GameObject.cpp.
48 {
50 return glm::vec3(global[3]);
51 }
glm::mat4 GenGlobalMatrix() const
◆ GetName()
| std::string & Elevate::GameObject::GetName |
( |
| ) |
|
|
inline |
◆ GetObjectId()
| uint32_t Elevate::GameObject::GetObjectId |
( |
| ) |
|
|
inline |
◆ GetScene()
| Scene * Elevate::GameObject::GetScene |
( |
| ) |
|
|
inline |
◆ HasChild()
| const bool Elevate::GameObject::HasChild |
( |
| ) |
const |
|
inline |
Definition at line 59 of file GameObject.h.
59{ return m_childs.size() > 0; }
◆ HasComponent()
template<typename T >
| bool Elevate::GameObject::HasComponent |
( |
| ) |
|
◆ Notify()
| void Elevate::GameObject::Notify |
( |
Event & |
event | ) |
|
|
protected |
Definition at line 87 of file GameObject.cpp.
88 {
90 {
91 if (comp->IsActive())
92 {
93 comp->OnNotify(e);
94 }
95 }
96
97 for (std::shared_ptr<GameObject> child : m_childs)
98 {
99 child->Notify(e);
100 }
101 }
std::vector< Component * > GetComponents()
◆ OnSetPosition()
| void Elevate::GameObject::OnSetPosition |
( |
| ) |
|
|
overrideprotectedvirtual |
Reimplemented from Elevate::ITransformable.
Definition at line 103 of file GameObject.cpp.
104 {
106 {
108 }
109
111 {
112 if (comp->IsActive())
113 {
114 comp->OnSetPosition();
115 }
116 }
117
118 for (std::shared_ptr<GameObject> child : m_childs)
119 {
120 child->OnSetPosition();
121 }
122 }
#define EE_INVALID_ENTITY_ID
static void UpdatePosition(GameObject *obj)
◆ OnSetRotation()
| void Elevate::GameObject::OnSetRotation |
( |
| ) |
|
|
overrideprotectedvirtual |
Reimplemented from Elevate::ITransformable.
Definition at line 124 of file GameObject.cpp.
125 {
127 {
128 if (comp->IsActive())
129 {
130 comp->OnSetRotation();
131 }
132 }
133
134 for (std::shared_ptr<GameObject> child : m_childs)
135 {
136 child->OnSetRotation();
137 }
138 }
◆ OnSetScale()
| void Elevate::GameObject::OnSetScale |
( |
| ) |
|
|
overrideprotectedvirtual |
Reimplemented from Elevate::ITransformable.
Definition at line 140 of file GameObject.cpp.
141 {
143 {
144 if (comp->IsActive())
145 {
146 comp->OnSetScale();
147 }
148 }
149
150 for (std::shared_ptr<GameObject> child : m_childs)
151 {
152 child->OnSetScale();
153 }
154 }
◆ RemoveChild()
| void Elevate::GameObject::RemoveChild |
( |
std::shared_ptr< GameObject > |
child | ) |
|
Definition at line 324 of file GameObject.cpp.
325 {
326 m_childs.erase(child);
327 }
◆ RemoveComponent()
template<typename T >
| void Elevate::GameObject::RemoveComponent |
( |
| ) |
|
Definition at line 71 of file GameObject.inl.
72 {
74
75 if (HasComponent<T>())
76 {
77 GetComponent<T>()->Destroy();
78 GetRegistryMap()[m_scene->m_registryId]->remove<T>(entt::entity(m_entityId));
79 }
80 else EE_ERROR(
"Trying to remove a missing component. You need to add the component before removing it.");
81 }
◆ Render()
| void Elevate::GameObject::Render |
( |
| ) |
|
|
protected |
Definition at line 70 of file GameObject.cpp.
71 {
72
74 {
75 if (comp->IsActive())
76 {
77 comp->Render();
78 }
79 }
80
81 for (std::shared_ptr<GameObject> child : m_childs)
82 {
83 child->Render();
84 }
85 }
◆ RenderInEditor()
| void Elevate::GameObject::RenderInEditor |
( |
| ) |
|
|
protected |
Definition at line 234 of file GameObject.cpp.
235 {
236
238 {
239 if (comp->IsActive())
240 {
241 comp->RenderInEditor();
242 }
243 }
244
245 for (std::shared_ptr<GameObject> child : m_childs)
246 {
247 child->RenderInEditor();
248 }
249 }
◆ RenderWhenSelected()
| void Elevate::GameObject::RenderWhenSelected |
( |
| ) |
|
|
protected |
Definition at line 251 of file GameObject.cpp.
252 {
253
255 {
256 if (comp->IsActive())
257 {
258 comp->RenderWhenSelected();
259 }
260 }
261
262 for (std::shared_ptr<GameObject> child : m_childs)
263 {
264 child->RenderWhenSelected();
265 }
266 }
◆ SetFromGlobalMatrix()
| void Elevate::GameObject::SetFromGlobalMatrix |
( |
const glm::mat4 & |
newWorld | ) |
|
Definition at line 29 of file GameObject.cpp.
30 {
31 glm::mat4 newLocal = m_parent ? glm::inverse(m_parent->GenGlobalMatrix()) * newWorld : newWorld;
32
33 glm::vec3 scale;
34 glm::quat rotationQuat;
35 glm::vec3 position;
36 glm::vec3 skew;
37 glm::vec4 perspective;
38
39 glm::decompose(newLocal, scale, rotationQuat, position, skew, perspective);
40 glm::vec3 rotationEuler = glm::degrees(glm::eulerAngles(rotationQuat));
41
45 }
◆ SetName()
| void Elevate::GameObject::SetName |
( |
std::string |
newName | ) |
|
|
inline |
◆ SetParent()
| void Elevate::GameObject::SetParent |
( |
std::shared_ptr< GameObject > |
newParent | ) |
|
Definition at line 268 of file GameObject.cpp.
269 {
270 if (newParent == m_parent)
271 return;
272
273 if (m_parent)
274 {
275 m_parent->RemoveChild(shared_from_this());
276 }
277
278 this->m_parent = newParent;
279
280 if (newParent)
281 {
282 newParent->AddChild(shared_from_this());
283 if (m_scene)
284 {
285 m_scene->RemoveFromRoot(shared_from_this());
286 }
287 }
288 else {
289 m_scene->AddRootObject(shared_from_this());
290 }
291 }
◆ Update()
| void Elevate::GameObject::Update |
( |
| ) |
|
|
protected |
Definition at line 53 of file GameObject.cpp.
54 {
55
57 {
58 if (comp->IsActive())
59 {
60 comp->Update();
61 }
62 }
63
64 for (std::shared_ptr<GameObject> child : m_childs)
65 {
66 child->Update();
67 }
68 }
◆ ComponentRegistry
◆ Editor::EditorLayer
| friend class Editor::EditorLayer |
|
friend |
◆ Scene
The documentation for this class was generated from the following files: