-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity_space.hh
59 lines (42 loc) · 1.15 KB
/
entity_space.hh
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
#include <vector>
#include <memory>
#include "util/util.hh"
#include "entity.hh"
#ifndef _SCRATCH_ENTITY_SPACE
#define _SCRATCH_ENTITY_SPACE
#ifdef _DEBUG
using namespace util::io; // when not debugging, shouldn't have print stmts
#endif
/**
* An environment which manages the specified components.
*
*/
template <class... Components>
struct EntitySpace
{
using Index = util::TypeVector<Components...>;
using EntityType = Entity<Components...>;
using Entities = std::vector<EntityType>;
using Iterator = typename Entities::iterator;
using BitMask = typename EntityType::BitMask;
static const size_t max_components = sizeof...(Components);
// members
Entities m_entities;
EntityID insert(EntityType&& entity)
{
EntityID id = 0;
auto it = m_entities.begin();
while (it != m_entities.end() &&
!it->is_empty())
++it, ++id;
m_entities.insert(it, std::move(entity));
return id;
}
EntityType& operator[](EntityID id)
{ return m_entities[id]; }
Iterator begin() { return m_entities.begin(); }
Iterator end() { return m_entities.end(); }
};
#ifdef _BUILD_TEST
#endif
#endif