forked from Dzejrou/tdt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.hpp
More file actions
234 lines (204 loc) · 5.9 KB
/
Copy pathGame.hpp
File metadata and controls
234 lines (204 loc) · 5.9 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#pragma once
#include <Ogre.h>
#include <OIS.h>
#include <CEGUI/CEGUI.h>
#include <CEGUI/RendererModules/Ogre/Renderer.h>
#include <memory>
#include <vector>
#include "EntitySystem.hpp"
#include "HealthSystem.hpp"
#include "MovementSystem.hpp"
#include "AISystem.hpp"
#include "InputSystem.hpp"
#include "GridSystem.hpp"
#include "TaskSystem.hpp"
#include "lppscript/LppScript.hpp"
#include "SelectionBox.hpp"
#include "EntityPlacer.hpp"
#include "EntityCreator.hpp"
#include "GameSerializer.hpp"
#include "CombatSystem.hpp"
#include "ProductionSystem.hpp"
#include "Enums.hpp"
#include "LuaInterface.hpp"
#include "TimeSystem.hpp"
#include "EventSystem.hpp"
#include "Grid.hpp"
#include "GUI.hpp"
#include "Player.hpp"
#include "LevelGenerators.hpp"
#include "GraphicsSystem.hpp"
#include "TriggerSystem.hpp"
#include "ManaSpellSystem.hpp"
class Game : public Ogre::FrameListener, public OIS::KeyListener,
public OIS::MouseListener, public Ogre::WindowEventListener
{
friend class GameSerializer;
friend class LuaInterface;
friend class GUI;
public:
/**
* Constructor.
*/
Game();
/**
* Destructor.
*/
~Game();
/**
* Brief: Starts the game.
*/
void run();
/**
* Brief: Updates the game in one frame.
* Param: Time since the last frame.
*/
void update(Ogre::Real);
/**
* Brief: Changes the game's state.
* Param: The new state.
*/
void set_state(GAME_STATE);
/**
*
*/
void new_game(std::size_t, std::size_t);
/**
*
*/
void create_empty_level(std::size_t, std::size_t);
/**
* Brief: Resets the main camera's position and orientation to it's original state.
*/
void reset_camera();
protected:
/**
* Inherited methods (callbacks).
* Handle Ogre3D and OIS related stuff.
*/
bool frameRenderingQueued(const Ogre::FrameEvent&) override;
bool keyPressed(const OIS::KeyEvent&) override;
bool keyReleased(const OIS::KeyEvent&) override;
bool mouseMoved(const OIS::MouseEvent&) override;
bool mousePressed(const OIS::MouseEvent&, OIS::MouseButtonID) override;
bool mouseReleased(const OIS::MouseEvent&, OIS::MouseButtonID) override;
void windowResized(Ogre::RenderWindow* rw) override;
void windowClosed(Ogre::RenderWindow* rw) override;
private:
/**
* Init methods.
*/
void ogre_init();
void ois_init();
void cegui_init();
/**
* Brief: Commands the miner with smalles task queue (if any) to mine
* all selected mineable entities.
*/
void command_to_mine();
/**
* Current game state.
*/
GAME_STATE state_;
/**
* Pointers to Ogre3D objects.
*/
std::unique_ptr<Ogre::Root> root_;
Ogre::SceneManager* scene_mgr_;
Ogre::RenderWindow* window_;
Ogre::Camera* main_cam_;
Ogre::Viewport* main_view_;
Ogre::Light* main_light_;
OIS::InputManager* input_;
OIS::Keyboard* keyboard_;
OIS::Mouse* mouse_;
Ogre::Vector3 camera_dir_;
/**
* Unique pointers to systems (sadly all systems require the EntitySystem, which
* requires Ogre::SceneManager, so the all have to be instantiated after the ogre_init method
* call and thus cannot be references).
*/
std::unique_ptr<EntitySystem> entity_system_{nullptr};
std::unique_ptr<HealthSystem> health_system_{nullptr};
std::unique_ptr<MovementSystem> movement_system_{nullptr};
std::unique_ptr<AISystem> ai_system_{nullptr};
std::unique_ptr<InputSystem> input_system_{nullptr};
std::unique_ptr<GridSystem> grid_system_{nullptr};
std::unique_ptr<TaskSystem> task_system_{nullptr};
std::unique_ptr<CombatSystem> combat_system_{nullptr};
std::unique_ptr<ProductionSystem> production_system_{nullptr};
std::unique_ptr<TimeSystem> time_system_{nullptr};
std::unique_ptr<EventSystem> event_system_{nullptr};
std::unique_ptr<GraphicsSystem> graphics_system_{nullptr};
std::unique_ptr<TriggerSystem> trigger_system_{nullptr};
std::unique_ptr<ManaSpellSystem> mana_spell_system_{nullptr};
/**
* Used to save the game.
*/
std::unique_ptr<GameSerializer> game_serializer_{nullptr};
/**
* Vector of all systems used for updating the game's logic.
*/
std::vector<System*> systems_{};
/**
* CEGUI renderer.
*/
CEGUI::OgreRenderer* renderer_;
/**
* Brief: Converts an OIS key code to CEGUI key code.
* Param: OIS key code.
*/
CEGUI::MouseButton ois_to_cegui(OIS::MouseButtonID);
/**
* Allows to spawn entities with the mouse ingame.
*/
std::unique_ptr<EntityPlacer> placer_;
/**
* The game's ground represented by a plane, used for ray intersections.
*/
std::unique_ptr<Ogre::Plane> ground_;
/**
* Entity holding the ground plane. Used for easier plane switching.
*/
Ogre::Entity* ground_entity_;
/**
* Indicates whether the camera is in a free movement mode.
*/
bool camera_free_mode_;
/**
* Backup of the camera position before going to free mode.
*/
Ogre::Vector3 camera_position_backup_;
/**
* Backup of the camera orientation before going to free mode.
*/
Ogre::Quaternion camera_orientation_backup_;
/**
* Brief: Toggles the free camera movement mode.
*/
void toggle_camera_free_mode();
/**
* Brief: Returns a pair consisting of the location of the point where the player
* clicked on the ground plane and a boolean indicating if the click was indeed
* on the ground plane.
*/
std::pair<bool, Ogre::Vector3> get_mouse_click_position(const OIS::MouseEvent&) const;
/**
* Selection box used to select multiple entities at once.
*/
std::unique_ptr<SelectionBox> selection_box_;
/**
* A gui window that allows to place entities selected from a menu.
* (TODO: Allow to create/modify entities.)
*/
std::unique_ptr<EntityCreator> entity_creator_;
/**
* Saved position of the mouse cursor (2D).
*/
Ogre::Vector2 mouse_position_;
/**
* Used to create new levels (that is, to distribute walls and
* gold deposits).
*/
std::unique_ptr<level_generators::LevelGenerator> level_generator_;
};