Saga
Saga Game Engine
Loading...
Searching...
No Matches
systemManager.h
Go to the documentation of this file.
1#pragma once
2
3#include "system.h"
4#include <atomic>
5#include <functional>
6#include <memory>
7#include <unordered_map>
8#include "../Datastructures/eventmap.h"
9#include "../Entity/entity.h"
10
11namespace Saga {
12
18public:
26 enum class Stage {
27 Awake,
28 Start,
30 Update,
34 Draw,
36 };
37
41 enum Id : uint64_t {};
42
43public:
45 virtual ~SystemManager();
46
55 template <typename ...DataType>
56 EventMap::Id addStagedSystem(std::shared_ptr<System<DataType...>> system, Stage stage = Stage::Update);
57
66
78 template <typename Event, typename ...DataType>
79 EventMap::Id addEventSystem(Event event, std::shared_ptr<System<DataType...>> system);
80
88 template <typename Event>
89 void removeEventSystem(Event event, EventMap::Id id);
90
102 template <typename Event, typename ...DataType>
103 EventMap::Id addEventSystem(Event event, Saga::Entity entity, std::shared_ptr<System<Saga::Entity, DataType...>> system);
104
113 template <typename Event>
114 void removeEventSystem(Event event, Saga::Entity entity, EventMap::Id id);
115
124
131 void removeKeyboardEventSystem(int key, EventMap::Id id);
132
141
148 void removeMouseEventSystem(int key, EventMap::Id id);
149
158
167
175
182
183protected:
188 enum class OtherInput {
189 MOUSE_POS,
190 SCROLL,
192 };
193 static auto id_value()
194 -> uint64_t & {
195 static uint64_t the_id;
196 return the_id;
197 }
198
203
207 std::unordered_map<int, EventMap> eventSystemsMap;
208
209 // input maps
212 EventMap otherInputMap; //< scroll and mouse pos falls into this category
213};
214} // namespace Saga
215
216#include "systemManager.inl"
A mapping between events (which are ints under the hood) and callbacks.
Definition: eventmap.h:45
Id
Definition: eventmap.h:47
Manages Systems in the ECS model. Allows for System to be added, but not invoked.
Definition: systemManager.h:17
void removeStagedSystem(EventMap::Id id, Stage stage=Stage::Update)
Remove a staged System.
Definition: systemManager.cpp:8
Id
Used for id of Systems.
Definition: systemManager.h:41
void removeWindowResizeSystem(EventMap::Id id)
Remove a resize System.
Definition: systemManager.cpp:33
virtual ~SystemManager()
Definition: systemManager.cpp:6
EventMap mouseInputMap
Definition: systemManager.h:211
static auto id_value() -> uint64_t &
Definition: systemManager.h:193
EventMap::Id addStagedSystem(std::shared_ptr< System< DataType... > > system, Stage stage=Stage::Update)
Add a staged System to the list of systems.
Definition: systemManager.inl:8
SystemManager()
Definition: systemManager.cpp:5
std::unordered_map< int, EventMap > eventSystemsMap
Maps entity to an EventMap that maps Event to System.
Definition: systemManager.h:207
EventMap::Id addWindowResizeSystem(System< int, int > system)
Add a System to receive when the window resize.
Definition: systemManager.cpp:31
EventMap stagedSystemsMap
Map between Stage and Systems.
Definition: systemManager.h:202
EventMap::Id addEventSystem(Event event, std::shared_ptr< System< DataType... > > system)
Add an event System. Event systems are Systems triggerable by events broadcasted by the program,...
Definition: systemManager.inl:12
EventMap keyboardInputMap
Definition: systemManager.h:210
EventMap::Id addMousePosSystem(System< double, double > system)
Add a System to receive mouse position.
Definition: systemManager.cpp:21
void removeMouseEventSystem(int key, EventMap::Id id)
Remove a System from responding to mouse button inputs.
Definition: systemManager.cpp:18
void removeEventSystem(Event event, EventMap::Id id)
Remove the System from being called when an event is broadcasted.
Definition: systemManager.inl:17
EventMap::Id addMouseEventSystem(int key, System< int > system)
Add a System to respond to a mouse button inputs.
Definition: systemManager.cpp:16
EventMap::Id addKeyboardEventSystem(int key, System< int > system)
Add a System to respond to a keyboard input.
Definition: systemManager.cpp:11
EventMap otherInputMap
Definition: systemManager.h:212
Stage
Stages in the Saga engine where systems can be set to run in. Awake is a stage that happens at the ve...
Definition: systemManager.h:26
void removeMousePosSystem(EventMap::Id id)
Definition: systemManager.cpp:23
void removeKeyboardEventSystem(int key, EventMap::Id id)
Remove a keyboard System.
Definition: systemManager.cpp:13
void removeScrollSystem(EventMap::Id id)
Definition: systemManager.cpp:28
EventMap::Id addScrollSystem(System< double > system)
Add a System to receive scroll input.
Definition: systemManager.cpp:26
OtherInput
Types of input events, with button events excluded.
Definition: systemManager.h:188
Definition: app.cpp:8
std::function< void(std::shared_ptr< GameWorld >, DataType...)> System
System is a function that accepts a shared_ptr to a GameWorld, as well as extra variables.
Definition: system.h:14