forked from matachi/Artemis-Cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
World.cpp
executable file
·99 lines (77 loc) · 1.89 KB
/
World.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "World.h"
#include "Entity.h"
#include "SystemManager.h"
#include "EntityManager.h"
#include "SystemBitManager.h"
#include "ComponentType.h"
namespace artemis {
World::World() {
//TODO add more managers
this->systemManager = new SystemManager(*this);
this->entityManager = new EntityManager(*this);
this->groupManager = new GroupManager();
this->tagManager = new TagManager();
delta = 0;
}
void World::deleteEntity(Entity& e) {
if(!deleted.contains(&e))
deleted.add(&e);
}
float World::getDelta() {
return this->delta;
}
SystemManager* World::getSystemManager() {
return systemManager;
}
EntityManager* World::getEntityManager() {
return entityManager;
}
GroupManager* World::getGroupManager(){
return groupManager;
}
TagManager* World::getTagManager(){
return tagManager;
}
void World::loopStart() {
if(!refreshed.isEmpty()) {
for(int i=0; i<refreshed.getCount(); i++) {
//TODO ADD MANAGERs
entityManager->refresh(*refreshed.get(i));
}
refreshed.clear();
}
if(!deleted.isEmpty()) {
for(int i=0; i<deleted.getCount(); i++) {
Entity & e = *deleted.get(i);
groupManager->remove(e);
tagManager->remove(e);
entityManager->remove(e);
}
deleted.clear();
}
}
Entity& World::createEntity() {
return entityManager->create();
}
Entity& World::getEntity(int entityId) {
return entityManager->getEntity(entityId);
}
void World::refreshEntity(Entity& e) {
refreshed.add(&e);
}
void World::setDelta(float delta) {
this->delta = delta;
}
World::~World() {
//Entity manager should be deleted first.
refreshed.clear();
deleted.clear();
delete entityManager;
delete systemManager;
delete groupManager;
delete tagManager;
ComponentTypeManager::deleteComponentTypes();
SystemBitManager::removeBitSets();
ComponentType::reset();
}
};