-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.cpp
More file actions
56 lines (45 loc) · 1.32 KB
/
Entity.cpp
File metadata and controls
56 lines (45 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Entity.h"
#include "Editor.h"
namespace Engine
{
Entity* Entity::addChild()
{
Entity* t = new Entity(this);
m_childs.push_back(t);
return t;
}
void Entity::addChild(Entity* entity)
{
m_childs.push_back(entity);
}
//Returns true if there is recursion
bool Entity::check_recursion(Entity* entity)
{
if (!m_parent)//no parent
return false;
if (entity == m_parent)
return true;
return m_parent->check_recursion(entity);
}
void Entity::drawEditorGUI_Properties()
{
Editor::Instance()->renderEntityEditorPropertiesGui(this);
}
void Entity::setParent(Entity* parent) {
if (parent->check_recursion(this))
return;
//separate from actual parent
if (m_parent) {
auto iter = std::find(m_parent->m_childs.begin(), m_parent->m_childs.end(), this);//search this entity
m_parent->m_childs.erase(iter);//delete from childs
}
m_parent = parent;
transform.parent = &m_parent->transform;
parent->m_childs.push_back(this);
}
bool Entity::isChild(Entity* entity)
{
auto iter = std::find(m_childs.begin(), m_childs.end(), entity);
return iter != m_childs.end();
}
}