-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.cpp
More file actions
82 lines (70 loc) · 1.42 KB
/
Entity.cpp
File metadata and controls
82 lines (70 loc) · 1.42 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "Entity.h"
Entity::Entity()
{
}
Entity::Entity(unsigned int ID)
{
entityID = ID;
}
Entity::~Entity()
{
for (std::map<std::type_index, IComponent*>::iterator it = components.begin(); it != components.end(); ++it)
{
delete it->second;
}
}
void Entity::Update()
{
// Loop through entity map
for (std::map<std::type_index, IComponent*>::iterator it = components.begin(); it != components.end(); it++)
{
it->second->Update();
}
}
void Entity::AddComponent(IComponent* component, std::type_index type, bool replace)
{
if (replace || (components.find(type) == components.end()))
{
components[type] = component;
components[type]->entityID = entityID;
}
}
void Entity::RemoveComponent(std::type_index type)
{
components.erase(type);
}
bool Entity::ComponentExists(std::type_index type)
{
if (components.find(type) != components.end())
{
return true;
}
return false;
}
IComponent* Entity::GetComponent(std::type_index type)
{
if (components.find(type) != components.end())
return components[type];
return NULL;
}
void Entity::SetName(std::string name)
{
entityName = name;
}
std::string Entity::getName()
{
return entityName;
}
void Entity::SetID(unsigned int id)
{
entityID = id;
// Loop through components map
for (std::map<std::type_index, IComponent*>::iterator it = components.begin(); it != components.end(); it++)
{
it->second->entityID = id;
}
}
unsigned int Entity::getID()
{
return entityID;
}