-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathBaseEngine.h
More file actions
252 lines (215 loc) · 6.97 KB
/
Copy pathBaseEngine.h
File metadata and controls
252 lines (215 loc) · 6.97 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#pragma once
#include <future>
#include "World.h"
#include "JobManager.h"
#include <bx/commandline.h>
#include <engine/GameClock.h>
#include <engine/GameSession.h>
#include <engine/World.h>
#include <logic/Console.h>
#include <logic/SavegameManager.h>
#include <memory/StaticReferencedAllocator.h>
#include <media/Video.h>
#include <ui/View.h>
#include <vdfs/fileIndex.h>
#include <media/Video.h>
namespace UI
{
class Hud;
class zFont;
class zFontCache;
}
namespace Audio
{
class AudioEngine;
}
namespace Engine
{
class GameSession;
const int MAX_NUM_WORLDS = 4;
class BaseEngine
{
public:
struct EngineArgs
{
EngineArgs()
: cmdline(0, NULL)
{
}
std::string gameBaseDirectory;
std::string startupZEN;
std::string playerScriptname;
bool startNewGame;
std::string testVisual;
std::string modfile;
bool noTextureFiltering;
bx::CommandLine cmdline;
};
BaseEngine();
virtual ~BaseEngine();
/**
* @brief Initializes the Engine
*/
virtual void initEngine(int argc, char** argv);
/**
* @return Basic gametype this is. Needed for sky configuration, for example
*/
Daedalus::GameType getBasicGameType() { return m_BasicGameType; };
/**
* @return Basic gametype this is. Needed for sky configuration, for example
*/
void setBasicGameType(Daedalus::GameType type) { m_BasicGameType = type; }
/**
* @brief Frame update // TODO: Remove width and height
*/
void frameUpdate(double dt, uint16_t width, uint16_t m_height);
/**
* @return Main VDF-Archive
*/
VDFS::FileIndex& getVDFSIndex() { return m_FileIndex; }
/**
* Returns the world-instance of the given handle.
* Note: Do not save this pointer somewhere! It may change!
* @param h Handle to look up
* @return Data of the world-instance
*/
World::WorldInstance& getWorldInstance(Handle::WorldHandle& h);
/**
* @return Gameclock
*/
GameClock& getGameClock();
/**
* information stored in a session is cleared when loading a savegame or starting a new game
* @return GameSession
*/
GameSession& getSession() { return *m_Session; }
/**
* drop all information bound to the current session
*/
void resetSession();
/**
* Access for executing/queueing tasks that should be done synchronously or asynchronously
*/
JobManager& getJobManager();
/**
* @return Console
*/
Logic::Console& getConsole() { return m_Console; }
/**
* @return Arguments passed to the engine
*/
EngineArgs getEngineArgs();
/**
* @return Base-level UI-View. Parent of all other views.
*/
UI::View& getRootUIView() { return m_RootUIView; }
Media::VideoPlayer& getVideoPlayer() { return *m_VideoPlayer; }
/**
* // TODO: Move to GameEngine, or pass GameEngine to world!
* @return HUD
*/
UI::Hud& getHud() { return *m_pHUD; }
UI::zFontCache& getFontCache() { return *m_pFontCache; }
Audio::AudioEngine& getAudioEngine() { return *m_AudioEngine; }
/**
* Sets the path the engine is looking for files
* @param path New path
*/
void setContentBasePath(const std::string& path) { m_ContentBasePath = path; }
/*+
* @return The path where the engine is looking for content files
*/
const std::string& getContentBasePath() { return m_ContentBasePath; }
/**
* @return Allocator for always present textures
*/
Textures::TextureAllocator& getEngineTextureAlloc() { return m_EngineTextureAlloc; }
/**
* @return data-access to the main world
*/
Handle::WorldHandle getMainWorld();
/**
* Saves the given world to a file, as savegame
* @param world World to save
* @param file File to save to
* @return Whether the operation was successful
*/
bool saveWorld(Handle::WorldHandle world, const std::string& file);
/**
* Pauses or continues the game.
* @param paused
*/
void setPaused(bool paused);
/**
* Pauses or continues the game. Depending on the current state
*/
void togglePaused() { setPaused(!m_Paused); }
/**
* Called when a world was added
* TODO onWorld... should be protected, but currently need to call this function from GameSession
*/
virtual void onWorldCreated(Handle::WorldHandle world);
virtual void onWorldRemoved(Handle::WorldHandle world){};
/**
* amount of time for the next frame that should not be considered as elapsed
*/
Utils::TimeSpan m_ExcludedFrameTime;
protected:
/**
* Handles delegation of function calls to main thread and starting of asynchronous operations
* contains ID of the main thread (bgfx thread), MUST BE initialized first
*/
JobManager m_JobManager;
/**
* Update-method for subclasses
*/
virtual void onFrameUpdate(double dt, uint16_t width, uint16_t height) = 0;
/**
* @brief Called to load archives into the main VDFS-Index
* Overwrite to load your own default archives
*/
virtual void loadArchives();
/**
* Enum with values for Gothic I and Gothic II
*/
Daedalus::GameType m_BasicGameType;
/**
* Main VDFS-Index
*/
VDFS::FileIndex m_FileIndex;
/**
* Game session, stores information that should be reset on starting a new game/loading
* unique_ptr is used, because we can't overwrite the session itself,
* because it has a member variable reference
*/
std::unique_ptr<GameSession> m_Session;
/**
* ingame console
*/
Logic::Console m_Console;
/**
* Arguments
*/
EngineArgs m_Args;
Audio::AudioEngine* m_AudioEngine = nullptr;
Media::VideoPlayer* m_VideoPlayer = nullptr;
/**
* Base UI-View
*/
UI::View m_RootUIView;
UI::Hud* m_pHUD;
UI::zFontCache* m_pFontCache;
/**
* Allocator for always present textures
*/
Textures::TextureAllocator m_EngineTextureAlloc;
/**
* Folder where the content is
*/
std::string m_ContentBasePath;
/**
* if the engine is paused. When it is paused the world doesn't receive the delta time updates
*/
bool m_Paused;
};
}