This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game.hpp
143 lines (91 loc) · 2.94 KB
/
Game.hpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#pragma once
// TODO: Remove this
#include "../Engine/Input/Input.hpp"
#include "../Engine/Audio/AudioType.h"
#include "../API/Input/EngineInputAPI.hpp"
#include "../Engine/Engine.hpp"
#include "../API/Engine/EngineWindowAPI.hpp"
#include "../API/Audio/EngineAudioAPI.hpp"
#include "../API/XMLParser/MenuParserAPI.hpp"
#include "../API/Input/EngineInputAPI.hpp"
#include "../API/Physics/BodyHandlerAPI.hpp"
#include "./Object/Pool.hpp"
#include "./Components/BulletComponent.hpp"
#include <list>
#include <map>
#include "memory"
#include "CheatMode.hpp"
#include "Components/PlayerSpawnerComponent.hpp"
#include <mutex>
class PhysicsAPI;
class ComponentFactory;
class LevelParserAPI;
class InputAPI;
class RenderingAPI;
class LevelBase;
class PoolLevel;
class Component;
struct LevelData;
class Game {
private:
static Game *_instance;
static std::mutex mutex;
private:
std::unique_ptr<EntityObject> _character;
System<Component> _components; // TODO: Maybe remove this?
std::list<EntityId> _entities;
std::unique_ptr<LevelBase> _levelBase; // TODO: Make a list out of this so we can switch from levels without destroying the other one.
std::unique_ptr<PoolLevel> _poolLevelBase;
std::unique_ptr<ComponentFactory> _componentFactory;
bool _gameLoop = true;
bool _isCheatMode = false;
// API's
std::unique_ptr<InputAPI> _inputAPI;
std::unique_ptr<WindowAPI> _windowAPI;
std::unique_ptr<AudioAPI> _audioAPI;
std::unique_ptr<RenderingAPI> _renderingAPI;
std::unique_ptr<BodyHandlerAPI> _bodyHandlerAPI;
std::unique_ptr<PhysicsAPI> _physicsAPI;
std::unique_ptr<MenuParserAPI> _menuParser;
std::unique_ptr<CheatMode> _cheatMode;
public:
std::string currentSpawnPointName{};
private:
void QuitLevel(std::string command);
void QuitGame(std::string command);
void LoadGame(std::string command);
void NewGame(std::string command);
protected:
Game() = default;
~Game() = default;
public:
Game(Game &other) = delete;
void operator=(const Game &) = delete;
static Game *getInstance();
public:
void initialize();
void gameLoop();
public:
inline PoolLevel* getPoolLevel() {
return _poolLevelBase.get();
}
EntityId createEntity();
void addComponent(EntityId id, Component *comp);
template<typename T>
T *getComponent(EntityId id);
System<Component> getComponents(EntityId id);
template<typename T>
System<T> getComponents(EntityId id);
InputAPI &getInputAPI();
PhysicsAPI &getPhysicsAPI();
RenderingAPI &getRenderingAPI();
AudioAPI &getAudioAPI();
ComponentFactory *getComponentFactory();
void initializeLeveL(const std::string &levelName, const LevelData &data);
void addEventBodyHandler(const std::function<void()> &function);
void unloadLevel();
LevelBase& getLevel();
EntityObject *getCharacter();
void fixedUpdate(float deltaTime);
void renderMenu();
};