aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager/SystemManager.cpp
blob: f029aa5960931c18ae8ec558450f62a059f765ef (plain)
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
#include "../system/AISystem.h"
#include "../system/AnimatorSystem.h"
#include "../system/AudioSystem.h"
#include "../system/CollisionSystem.h"
#include "../system/EventSystem.h"
#include "../system/InputSystem.h"
#include "../system/ParticleSystem.h"
#include "../system/PhysicsSystem.h"
#include "../system/RenderSystem.h"
#include "../system/ReplaySystem.h"
#include "../system/ScriptSystem.h"

#include "SystemManager.h"

using namespace crepe;
using namespace std;

SystemManager::SystemManager(Mediator & mediator) : Manager(mediator) {
	this->load_system<InputSystem>();
	this->load_system<EventSystem>();
	this->load_system<ScriptSystem>();
	this->load_system<ParticleSystem>();
	this->load_system<AISystem>();
	this->load_system<PhysicsSystem>();
	this->load_system<CollisionSystem>();
	this->load_system<AudioSystem>();
	this->load_system<AnimatorSystem>();
	this->load_system<RenderSystem>();
	this->load_system<ReplaySystem>();

	this->mediator.system_manager = *this;
}

void SystemManager::fixed_update() {
	for (System & system : this->system_order) {
		if (!system.active) continue;
		system.fixed_update();
	}
}

void SystemManager::frame_update() {
	for (System & system : this->system_order) {
		if (!system.active) continue;
		system.frame_update();
	}
}

SystemManager::Snapshot SystemManager::save() {
	Snapshot snapshot;
	for (auto & [type, system] : this->systems) {
		snapshot[type] = system->active;
	}
	return snapshot;
}

void SystemManager::restore(const Snapshot & snapshot) {
	for (auto & [type, active] : snapshot) {
		this->systems[type]->active = active;
	}
}

void SystemManager::disable_all() {
	for (auto & [type, system] : this->systems) {
		system->active = false;
	}
}