-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathEntitySystem.h
executable file
·71 lines (63 loc) · 1.71 KB
/
EntitySystem.h
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
#ifndef ENTITY_SYSTEM_H
#define ENTITY_SYSTEM_H
#include <bitset>
#include "BitSize.h"
#include "Component.h"
#include <iostream>
#include <assert.h>
#include <typeinfo>
#include <bitset>
#include "ImmutableBag.h"
//#include "Entity.h"
#include "ComponentTypeManager.h"
namespace artemis {
class Entity;
class World;
/**
* The most raw entity system. It should not typically be used, but you can create your own
* entity system handling by extending this. It is recommended that you use the other provided
* entity system implementations.
*/
class EntitySystem {
public:
void printTypeFlag() {
std::cout << typeFlags;
}
std::bitset<BITSIZE> getSystemBit() {
return systemBit;
}
void setSystemBit(std::bitset<BITSIZE> bit);
virtual ~EntitySystem();
/*override these functions*/
virtual void initialize() {};
void setWorld(World *world);
void change(Entity &e);
void process();
int getEntityCount();
protected:
EntitySystem() { this->world = NULL; };
World * world;
/**
* Call this in the constructor of the derived system
*/
template<typename component_type>
void addComponentType() {
//Add Bits to typeflags
typeFlags |= ComponentTypeManager::getBit<component_type>();
}
/*override these functions*/
virtual void begin() {};
virtual void end() {};
virtual void removed(Entity &e) {};
virtual void added(Entity &e) {};
//Abstracts
virtual void processEntities(ImmutableBag<Entity*> & bag) = 0;
virtual bool checkProcessing() = 0;
private:
std::bitset<BITSIZE> systemBit;
std::bitset<BITSIZE> typeFlags;
Bag<Entity*> actives;
void remove(Entity &e);
};
};
#endif