-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityManager.cpp
More file actions
50 lines (45 loc) · 1.21 KB
/
EntityManager.cpp
File metadata and controls
50 lines (45 loc) · 1.21 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
#include "EntityManager.h"
int EntityManager::createEntity(Entity::EntityType entityType)
{
std::shared_ptr<Entity> newEntity;
switch (entityType)
{
case Entity::PLAYER:
try {
newEntity = std::move(std::make_shared<PlayerEntity>());
}
catch (const std::bad_alloc& e)
{
std::cout << "Failed to allocate memory: " << e.what() << std::endl;
}
break;
case Entity::ENEMY:
break;
default:
break;
}
// For reference:
// std::map<int, std::map<Component::ComponentType, std::shared_ptr<Component>>> entityAtlas;
std::map < Component::ComponentType, std::shared_ptr<Component>> innerMap;
this->entityAtlas.insert(std::make_pair(++nextEntityId, innerMap));
return nextEntityId;
}
void EntityManager::addComponent(int entityId, Component::ComponentType componentType)
{
auto& entRef = entityAtlas.at(entityId);
switch (componentType)
{
case Component::ComponentType::POSITION:
entRef.emplace(componentType, std::make_unique<PositionComponent>());
break;
case Component::ComponentType::VELOCITY:
entRef.emplace(componentType, std::make_unique<VelocityComponent>());
break;
case Component::ComponentType::GRAPHICS:
break;
case Component::ComponentType::PHYSICS:
break;
default:
break;
}
}