-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystemManager.cpp
86 lines (71 loc) · 2.09 KB
/
SystemManager.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
#include "SystemManager.h"
namespace PMgene::Core
{
SystemManager::SystemManager(
const std::shared_ptr<CommunicationManager>& communicationManagerInput) :
ISender(communicationManagerInput, "SystemManager")
{
messageCodesToSubscribe.emplace_back(MC_ENTITY_DESTROYED);
SendMessage(std::make_shared<Message>(MG_INFO, MC_MANAGER_INITIALIZED, senderName));
}
template <typename T>
std::shared_ptr<T> SystemManager::RegisterSystem()
{
const char* typeName = typeid(T).name();
//assert(mSystems.find(typeName) == mSystems.end() && "Registering system more than once.");
auto system = std::make_shared<T>();
systems.insert({typeName, system});
return system;
}
template <typename T>
void SystemManager::SetSignature(EntitySignature signature)
{
const char* typeName = typeid(T).name();
//assert(mSystems.find(typeName) != mSystems.end() && "System used before registered.");
signatures.insert({typeName, signature});
}
void SystemManager::EntityDestroyed(Entity entity)
{
for (const auto& pair : systems)
{
const auto& system = pair.second;
system->entities.erase(entity);
}
}
void SystemManager::EntitySignatureChanged(Entity entity, EntitySignature entitySignature)
{
for (const auto& pair : systems)
{
const auto& type = pair.first;
const auto& system = pair.second;
const auto& systemSignature = signatures[type];
if ((entitySignature & systemSignature) == systemSignature)
{
system->entities.insert(entity);
}
else
{
system->entities.erase(entity);
}
}
}
void SystemManager::ProcessLastMessage()
{
const auto messageToProcess = GetNewestMessage();
switch (messageToProcess->GetCode())
{
case MC_ENTITY_DESTROYED:
{
//EntityDestroyed(reinterpret_cast<Entity>(messageToProcess->GetFirstArgument()));
break;
}
case MC_ENTITY_SIGNATURE_CHANGED:
{
//const auto entity = reinterpret_cast<Entity>(messageToProcess->GetFirstArgument());
//const auto signature = static_cast<EntitySignature*>(messageToProcess->GetSecondArgument());
//EntitySignatureChanged(entity, *signature);
}
default:;
}
}
}