-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.cpp
More file actions
250 lines (182 loc) · 6.42 KB
/
Driver.cpp
File metadata and controls
250 lines (182 loc) · 6.42 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
/* Terminal: Driver
Main file for Terminal. Created by Ryan Babij (https://github.com/RyanBabij/Terminal)
TERMINAL CODE SEEMS TO HAVE BEEN PORTED TO WILDCAT FOR MCOM. I NEED TO MANUALLY REVIEW THIS.
License: CC0
*/
#include <string>
#define WILDCAT_USE_OPENGL
//#define WILDCAT_USE_DIRECT3D
// What OS we are compiling for. Currently only Windows and Linux are supported cos I don't got a Mac.
#include <System/Windows.hpp> //#define WILDCAT_WINDOWS
//#define WILDCAT_LINUX
// DYNAMICALLY GENERATED HEADER FILE WITH STRING WHICH COUNTS COMPILATIONS.
#include "CompileCount.hpp"
#include <iostream>
#include "Driver_Settings.cpp"
#include <Container/Vector/Vector.hpp>
#include <cstdlib>
#include <string>
#include <sstream>
/* Tidies up the game and shuts down. */
void shutDown()
{
std::cout<<"Driver::shutDown().\n";
exit(0);
}
//Stolen from https://codereview.stackexchange.com/questions/226/formatter-class
// This allows you to pass multiple datatypes as an std::string.
// Use like this: function( Stream() << "Error Recieved" << 42 << " " << some_code << " '" << some_msg << "'");
class Stream
{
public:
std::stringstream ss_;
// Build a string by chaining << operators.
template<class Field> Stream& operator<<(Field f)
{
ss_ << f;
return *this;
}
// This is a custom typecast to std::string. (C++11)
operator std::string() const { return ss_.str(); }
};
#define GLEW_STATIC
// Need to figure out which of this is better. I think GLEW is more supported.
#include <Graphics/OpenGL/glew.h> // THIS CURRENTLY FIXES LINKER CRAP. Also allows RGBA_COMPRESSED, it would seem.
#define FREEGLUT_STATIC
#include <Graphics/OpenGL/freeglut.h> //
#include <Graphics/Render/Renderer.cpp>
#include <Graphics/Texture/Texture.hpp>
#include <Graphics/Texture/TextureLoader.hpp>
#include <Graphics/Font/Font.hpp>
// This is the global font for now.
Wildcat::Font font8x8;
#include "Driver_LoadTextures.hpp"
#include <Graphics/Png/Png.hpp>
#include <File/FileManager.hpp>
#include <string>
void printHelp()
{
std::cout<<"\nTerminal"<<VERSION<<".\n";
std::cout<<" Warning: This is not a stable release.\n";
std::cout<<" Terminal is a prototype computer terminal emulator for use in games.\n";
std::cout<<" License: Public domain. This program uses a modified version of LodePNG.\n";
std::cout<<" This is a pre-alpha release, and is not fully functional.\n";
std::cout<<"Options:\n";
std::cout<<"None.\n";
std::cout<<"\n";
std::cout<<"Version "<<VERSION<<".\n";
std::cout<<"Compiled: "<<__DATE__<<". "<<__TIME__<<".\n";
std::cout<<"Compile count: "<<COMPILE_COUNT<<".\n";
std::cout<<"\n";
}
void pauseGame()
{
std::cout<<"pauseGame() called.\n";
PAUSE_LOGIC=true;
}
#include <System/Time/Timer.hpp>
/* This object exploits the c++ guarantee that the destructor is always called, in order to deal with unanticipated shutdowns, such as the player clicking the X. However, it seems the destructor guarantee does not apply in some cases, such as ending the process using the task manager, or using ctrl+c from the console. */
class QuitChecker
{
private:
Timer gameTime;
public:
QuitChecker()
{
gameTime.init();
gameTime.start();
// For now we will clear the savedata on startup because it can cause some instability.
std::cout<<"Deleting temporary data folder ("<<SAVE_FOLDER_PATH<<")\n";
if (SAVE_FOLDER_PATH.length() > 0 )
{
FileManager::deleteDirectory(SAVE_FOLDER_PATH,true);
}
}
~QuitChecker()
{
gameTime.update();
if (gameTime.seconds > 10 )
{
std::cout<<"Time played: "<<gameTime.seconds/60<<" minutes.\n";
}
if (CLEAN_SAVES_ON_EXIT)
{
std::cout<<"Deleting temporary data folder ("<<SAVE_FOLDER_PATH<<")\n";
if (SAVE_FOLDER_PATH.length() > 0 )
{
FileManager::deleteDirectory(SAVE_FOLDER_PATH,true);
}
}
}
};
QuitChecker quitChecker;
#include <stdio.h>
#include <Math/Random/GlobalRandom.hpp>
/* No need for a globalRandom object. Just use Random:: */
#include <Device/Mouse/Mouse.hpp>
Mouse globalMouse;
#include <Device/Keyboard/Keyboard.hpp>
Keyboard globalKeyboard;
#include <System/Time/Timer.hpp>
Timer frameRateTimer;
Timer frameRateTimer2; // Using this till I fix fps output
Timer pollRateTimer;
Timer logicRateTimer;
Timer physicsRateTimer;
Timer animationTimer;
Timer playerKeypressTimer;
Timer gameTimer; /* Runs for duration of game without resetting */
/* Use this for checking algo speeds. */
Timer debugTimer;
#include <Math/Geometry/Geometry.hpp>
#include <Device/Display/DisplayInterface.hpp>
#include <Device/Display/DisplayInterfaceManager.hpp>
/* Global display interface manager, to handle all rendering called by driver. */
DisplayInterfaceManager displayInterfaceManager;
#include <Device/Mouse/MouseInterface.hpp>
#include <Device/Mouse/MouseInterfaceManager.hpp>
/* Global mouse interface manager. To handle all objects that recieve mouse events. */
MouseInterfaceManager mouseInterfaceManager;
#include <Device/Keyboard/KeyboardInterface.hpp>
#include <Device/Keyboard/KeyboardInterfaceManager.hpp>
/* Global keyboard interface manager. To handle all objects that recieve keyboard events. */
KeyboardInterfaceManager keyboardInterfaceManager;
#include <Graphics/GUI/GUI_Manager.hpp>
#include <Graphics/GUI/GUI.hpp>
/* GUI manager. Manages all GUI controls. */
GUI_Manager globalGuiManager;
#include <Interface/LogicTick/LogicTickInterface.hpp>
#include <Interface/LogicTick/LogicTickManager.hpp>
LogicTickManager logicTickManager;
#include <Interface/IdleTick/IdleTickInterface.hpp>
#include <Interface/IdleTick/IdleTickManager.hpp>
IdleTickManager idleManager;
// /* Title Menu / Main Menu */
//Also includes Terminal
#include "Menu_Title.hpp"
Menu_Title menuTitle;
/* Initialization goes here. */
#include "Driver_Init.hpp"
/* OpenGL function hooks go here. */
#include "Driver_GLHooks.hpp"
#include <Data/ArgReader.hpp>
int main(int nArgs, char ** arg)
{
ArgReader argReader;
argReader.feed(nArgs,arg);
if (argReader.hasTag("-help") || argReader.hasTag("--help") || argReader.hasTag("-h"))
{
printHelp();
return 0;
}
std::cout<<"\nTerminal "<<VERSION<<". Warning: This is not a stable release.\n";
#ifdef BUILD
std::cout<<"BUILD\n";
#endif
GL_init(nArgs, arg);
/* Initialise game. Load textures, fonts etc. */
init();
/* Reshape is called here. */
glutMainLoop();
return 0;
}