-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntityComponentSystemManager.h
100 lines (75 loc) · 2.2 KB
/
EntityComponentSystemManager.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
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
100
#pragma once
#include "ComponentManager.h"
#include "EntityManager.h"
#include "SystemManager.h"
class EntityComponentSystemManager
{
public:
void Init()
{
// Create pointers to each manager
m_ComponentManager = std::make_unique<ComponentManager>();
m_EntityManager = std::make_unique<EntityManager>();
m_SystemManager = std::make_unique<SystemManager>();
}
// Entity methods
Entity CreateEntity()
{
return m_EntityManager->CreateEntity();
}
void DestroyEntity(Entity entity)
{
m_EntityManager->DestroyEntity(entity);
m_ComponentManager->EntityDestroyed(entity);
m_SystemManager->EntityDestroyed(entity);
}
// Component methods
template<typename T>
void RegisterComponent()
{
m_ComponentManager->RegisterComponent<T>();
}
template<typename T>
void AddComponent(Entity entity, T component)
{
m_ComponentManager->AddComponent<T>(entity, component);
auto signature = m_EntityManager->GetSignature(entity);
signature.set(m_ComponentManager->GetComponentType<T>(), true);
m_EntityManager->SetSignature(entity, signature);
m_SystemManager->EntitySignatureChanged(entity, signature);
}
template<typename T>
void RemoveComponent(Entity entity)
{
m_ComponentManager->RemoveComponent<T>(entity);
auto signature = m_EntityManager->GetSignature(entity);
signature.set(m_ComponentManager->GetComponentType<T>(), false);
m_EntityManager->SetSignature(entity, signature);
m_SystemManager->EntitySignatureChanged(entity, signature);
}
template<typename T>
T& GetComponent(Entity entity)
{
return m_ComponentManager->GetComponent<T>(entity);
}
template<typename T>
ComponentType GetComponentType()
{
return m_ComponentManager->GetComponentType<T>();
}
// System methods
template<typename T>
std::shared_ptr<T> RegisterSystem()
{
return m_SystemManager->RegisterSystem<T>();
}
template<typename T>
void SetSystemSignature(Signature signature)
{
m_SystemManager->SetSignature<T>(signature);
}
private:
std::unique_ptr<ComponentManager> m_ComponentManager;
std::unique_ptr<EntityManager> m_EntityManager;
std::unique_ptr<SystemManager> m_SystemManager;
};