-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
82 lines (62 loc) · 2.06 KB
/
Game.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
//
// Created by Paul on 28.04.2017.
//
#ifndef PAXENGINE3_GAME_H
#define PAXENGINE3_GAME_H
#include <vector>
#include <queue>
#include "system/GameSystem.h"
#include "world/World.h"
#include "world/event/ActiveWorldChangedEvent.h"
#include "world/event/WorldEvent.h"
namespace PAX {
class BehaviourSystem;
class Game : public Updateable
{
private:
bool initialized = false;
EventService eventService;
std::vector<std::unique_ptr<GameSystem>> systems;
std::vector<World*> worlds;
bool worldsLocked = false;
std::queue<World*> worldAddingQueue;
std::queue<World*> worldRemovingQueue;
void handleWorldAddingQueue();
void handleWorldRemovingQueue();
std::vector<std::function<void()>> dispatchedFunctions;
public:
Game();
~Game() override;
EventHandler<WorldEvent&> WorldAdded;
EventHandler<WorldEvent&> WorldRemoved;
virtual void initialize();
virtual void terminate();
bool hasWorld(World *world);
void addWorld(World *world);
bool removeWorld(World *world);
const std::vector<World*>& getWorlds();
void update(UpdateOptions & options) override;
EventService & getEventService();
/**
* Takes ownership of the given system.
* @param system
*/
void addSystem(std::unique_ptr<GameSystem>&& system);
PAX_NODISCARD const std::vector<std::unique_ptr<GameSystem>> & getSystems() const;
/**
* Runs the given function at the end of the next update cycle.
* @param f Function that is dispatched until the end of the next updated cycle.
*/
void dispatch(const std::function<void()>& f);
template<class T>
T * getSystem() const {
for (const std::unique_ptr<GameSystem> & s : systems) {
if (auto t = dynamic_cast<T*>(s.get())) {
return t;
}
}
return nullptr;
}
};
}
#endif //PAXENGINE3_GAME_H