Explorar el Código

Console, Game, Menu, OpenRaider and Window are global services.

Thomas Buck hace 10 años
padre
commit
ed67843df6
Se han modificado 10 ficheros con 356 adiciones y 322 borrados
  1. 0
    4
      include/OpenRaider.h
  2. 9
    6
      include/main.h
  3. 4
    4
      src/Camera.cpp
  4. 11
    13
      src/Console.cpp
  5. 71
    71
      src/Game.cpp
  6. 22
    24
      src/Menu.cpp
  7. 102
    136
      src/OpenRaider.cpp
  8. 52
    52
      src/Render.cpp
  9. 5
    5
      src/WindowSDL.cpp
  10. 80
    7
      src/main.cpp

+ 0
- 4
include/OpenRaider.h Ver fichero

@@ -57,11 +57,7 @@ public:
57 57
 
58 58
     //! \fixme should be private
59 59
 
60
-    Window *mWindow;
61 60
     Sound *mSound;
62
-    Menu *mMenu;
63
-    Console *mConsole;
64
-    Game *mGame;
65 61
 
66 62
     bool mMapListFilled;
67 63
     std::vector<char *> mMapList;

+ 9
- 6
include/main.h Ver fichero

@@ -7,14 +7,17 @@
7 7
 #ifndef _MAIN_H_
8 8
 #define _MAIN_H_
9 9
 
10
+#include "Console.h"
11
+#include "Game.h"
12
+#include "Menu.h"
10 13
 #include "OpenRaider.h"
14
+#include "Window.h"
11 15
 
12
-extern OpenRaider *gOpenRaider; //!< Main Game Singleton
13
-
14
-/*!
15
- * \brief atexit() handler
16
- */
17
-void cleanupHandler(void);
16
+Console    &getConsole();
17
+Game       &getGame();
18
+Menu       &getMenu();
19
+OpenRaider &getOpenRaider();
20
+Window     &getWindow();
18 21
 
19 22
 /*!
20 23
  * \brief Program entry point

+ 4
- 4
src/Camera.cpp Ver fichero

@@ -171,22 +171,22 @@ void Camera::command(enum camera_command cmd) {
171 171
             break;
172 172
         case CAMERA_ROTATE_UP:
173 173
             if (mTheta2 < (M_PI / 2)) {
174
-                mTheta2 += gOpenRaider->mCameraRotationDeltaY;
174
+                mTheta2 += getOpenRaider().mCameraRotationDeltaY;
175 175
                 rotate(mTheta2, 1.0f, 0.0f, 0.0f);
176 176
             }
177 177
             break;
178 178
         case CAMERA_ROTATE_DOWN:
179 179
             if (mTheta2 > -(M_PI / 2)) {
180
-                mTheta2 -= gOpenRaider->mCameraRotationDeltaY;
180
+                mTheta2 -= getOpenRaider().mCameraRotationDeltaY;
181 181
                 rotate(mTheta2, 1.0f, 0.0f, 0.0f);
182 182
             }
183 183
             break;
184 184
         case CAMERA_ROTATE_RIGHT:
185
-            mTheta += gOpenRaider->mCameraRotationDeltaX;
185
+            mTheta += getOpenRaider().mCameraRotationDeltaX;
186 186
             rotate(mTheta, 0.0f, 1.0f, 0.0f);
187 187
             break;
188 188
         case CAMERA_ROTATE_LEFT:
189
-            mTheta -= gOpenRaider->mCameraRotationDeltaX;
189
+            mTheta -= getOpenRaider().mCameraRotationDeltaX;
190 190
             rotate(mTheta, 0.0f, 1.0f, 0.0f);
191 191
             break;
192 192
         case CAMERA_MOVE_UP:

+ 11
- 13
src/Console.cpp Ver fichero

@@ -58,7 +58,7 @@ Console::~Console() {
58 58
 
59 59
 void Console::setVisible(bool visible) {
60 60
     mVisible = visible;
61
-    gOpenRaider->mWindow->setTextInput(mVisible);
61
+    getWindow().setTextInput(mVisible);
62 62
 }
63 63
 
64 64
 bool Console::isVisible() {
@@ -78,8 +78,8 @@ void Console::print(const char *s, ...) {
78 78
 }
79 79
 
80 80
 #define LINE_GEOMETRY(window) unsigned int firstLine = 35; \
81
-        unsigned int lastLine = (window->mHeight / 2) - 55; \
82
-        unsigned int inputLine = (window->mHeight / 2) - 30; \
81
+        unsigned int lastLine = (window.mHeight / 2) - 55; \
82
+        unsigned int inputLine = (window.mHeight / 2) - 30; \
83 83
         unsigned int lineSteps = 20; \
84 84
         unsigned int lineCount = (lastLine - firstLine + lineSteps) / lineSteps; \
85 85
         while (((lineCount * lineSteps) + firstLine) < inputLine) { \
@@ -88,17 +88,15 @@ void Console::print(const char *s, ...) {
88 88
         }
89 89
 
90 90
 void Console::display() {
91
-    Window *window = gOpenRaider->mWindow;
92
-
93 91
     if (mVisible) {
94 92
         // Calculate line drawing geometry
95 93
         // Depends on window height, so recalculate every time
96
-        LINE_GEOMETRY(window);
94
+        LINE_GEOMETRY(getWindow());
97 95
 
98 96
         // Draw half-transparent *overlay*
99 97
         glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
100 98
         glDisable(GL_TEXTURE_2D);
101
-        glRecti(0, 0, window->mWidth, window->mHeight / 2);
99
+        glRecti(0, 0, getWindow().mWidth, getWindow().mHeight / 2);
102 100
         glEnable(GL_TEXTURE_2D);
103 101
 
104 102
         int scrollIndicator;
@@ -108,7 +106,7 @@ void Console::display() {
108 106
             scrollIndicator = 100;
109 107
         }
110 108
 
111
-        gOpenRaider->mWindow->drawText(10, 10, 0.70f, OR_BLUE,
109
+        getWindow().drawText(10, 10, 0.70f, OR_BLUE,
112 110
                 "%s uptime %lus scroll %d%%", VERSION, systemTimerGet() / 1000, scrollIndicator);
113 111
 
114 112
         // Draw output log
@@ -122,15 +120,15 @@ void Console::display() {
122 120
             historyOffset = mHistory.size() - lineCount;
123 121
         }
124 122
         for (int i = 0; i < end; i++) {
125
-            gOpenRaider->mWindow->drawText(10, ((i + drawOffset) * lineSteps) + firstLine,
123
+            getWindow().drawText(10, ((i + drawOffset) * lineSteps) + firstLine,
126 124
                     0.75f, OR_BLUE, "%s", mHistory[i + historyOffset - mLineOffset]);
127 125
         }
128 126
 
129 127
         // Draw current input
130 128
         if ((mInputBufferPointer > 0) && (mInputBuffer[0] != '\0')) {
131
-            gOpenRaider->mWindow->drawText(10, inputLine, 0.75f, OR_BLUE, "> %s", mInputBuffer);
129
+            getWindow().drawText(10, inputLine, 0.75f, OR_BLUE, "> %s", mInputBuffer);
132 130
         } else {
133
-            gOpenRaider->mWindow->drawText(10, inputLine, 0.75f, OR_BLUE, ">");
131
+            getWindow().drawText(10, inputLine, 0.75f, OR_BLUE, ">");
134 132
         }
135 133
 
136 134
         //! \todo display the current mPartialInput. The UTF-8 segfaults SDL-TTF, somehow?
@@ -143,7 +141,7 @@ void Console::handleKeyboard(KeyboardButton key, bool pressed) {
143 141
         if ((mInputBufferPointer > 0) && (mInputBuffer[0] != '\0')) {
144 142
             mHistory.push_back(bufferString("> %s", mInputBuffer));
145 143
             mCommandHistory.push_back(bufferString("%s", mInputBuffer));
146
-            int error = gOpenRaider->command(mInputBuffer);
144
+            int error = getOpenRaider().command(mInputBuffer);
147 145
             if (error != 0) {
148 146
                 print("Error Code: %d", error);
149 147
             }
@@ -246,7 +244,7 @@ void Console::handleText(char *text, bool notFinished) {
246 244
 }
247 245
 
248 246
 void Console::handleMouseScroll(int xrel, int yrel) {
249
-    LINE_GEOMETRY(gOpenRaider->mWindow);
247
+    LINE_GEOMETRY(getWindow());
250 248
 
251 249
     if (mHistory.size() > lineCount) {
252 250
         if (yrel > 0) {

+ 71
- 71
src/Game.cpp Ver fichero

@@ -64,7 +64,7 @@ int Game::initialize() {
64 64
 
65 65
     // Set up Renderer
66 66
     mRender = new Render();
67
-    mRender->initTextures(gOpenRaider->mDataDir, &mTextureStart, &mTextureLevelOffset);
67
+    mRender->initTextures(getOpenRaider().mDataDir, &mTextureStart, &mTextureLevelOffset);
68 68
 
69 69
     // Enable Renderer
70 70
     mRender->setMode(Render::modeLoadScreen);
@@ -84,7 +84,7 @@ void Game::destroy() {
84 84
 
85 85
     mWorld.destroy();
86 86
     mRender->ClearWorld();
87
-    gOpenRaider->mSound->clear(); // Remove all previously loaded sounds
87
+    getOpenRaider().mSound->clear(); // Remove all previously loaded sounds
88 88
 }
89 89
 
90 90
 int Game::loadLevel(const char *level) {
@@ -94,7 +94,7 @@ int Game::loadLevel(const char *level) {
94 94
     mName = bufferString("%s", level);
95 95
 
96 96
     // Load the level pak into TombRaider
97
-    gOpenRaider->mConsole->print("Loading %s", mName);
97
+    getConsole().print("Loading %s", mName);
98 98
     int error = mTombRaider.Load(mName);
99 99
     if (error != 0) {
100 100
         return error;
@@ -115,7 +115,7 @@ int Game::loadLevel(const char *level) {
115 115
         tmp[dir + 8] = '\0';
116 116
         error = mTombRaider.loadSFX(tmp);
117 117
         if (error != 0) {
118
-            gOpenRaider->mConsole->print("Could not load %s", tmp);
118
+            getConsole().print("Could not load %s", tmp);
119 119
         }
120 120
         delete [] tmp;
121 121
     }
@@ -133,7 +133,7 @@ int Game::loadLevel(const char *level) {
133 133
 
134 134
     // Check if the level contains Lara
135 135
     if (mLara == NULL) {
136
-        gOpenRaider->mConsole->print("Can't find Lara entity in level pak!");
136
+        getConsole().print("Can't find Lara entity in level pak!");
137 137
         return -1;
138 138
     }
139 139
 
@@ -187,7 +187,7 @@ void Game::display() {
187 187
 
188 188
 int Game::command(std::vector<char *> *args) {
189 189
     if (args->size() < 1) {
190
-        gOpenRaider->mConsole->print("Invalid use of game-command!");
190
+        getConsole().print("Invalid use of game-command!");
191 191
         return -1;
192 192
     }
193 193
 
@@ -198,44 +198,44 @@ int Game::command(std::vector<char *> *args) {
198 198
             if (strcmp(mode, "wireframe") == 0) {
199 199
                 if (mLoaded) {
200 200
                     mRender->setMode(Render::modeWireframe);
201
-                    gOpenRaider->mConsole->print("Wireframe mode");
201
+                    getConsole().print("Wireframe mode");
202 202
                 } else {
203
-                    gOpenRaider->mConsole->print("Load a level to set this mode!");
203
+                    getConsole().print("Load a level to set this mode!");
204 204
                     return -2;
205 205
                 }
206 206
             } else if (strcmp(mode, "solid") == 0) {
207 207
                 if (mLoaded) {
208 208
                     mRender->setMode(Render::modeSolid);
209
-                    gOpenRaider->mConsole->print("Solid mode");
209
+                    getConsole().print("Solid mode");
210 210
                 } else {
211
-                    gOpenRaider->mConsole->print("Load a level to set this mode!");
211
+                    getConsole().print("Load a level to set this mode!");
212 212
                     return -3;
213 213
                 }
214 214
             } else if (strcmp(mode, "texture") == 0) {
215 215
                 if (mLoaded) {
216 216
                     mRender->setMode(Render::modeTexture);
217
-                    gOpenRaider->mConsole->print("Texture mode");
217
+                    getConsole().print("Texture mode");
218 218
                 } else {
219
-                    gOpenRaider->mConsole->print("Load a level to set this mode!");
219
+                    getConsole().print("Load a level to set this mode!");
220 220
                     return -4;
221 221
                 }
222 222
             } else if (strcmp(mode, "vertexlight") == 0) {
223 223
                 if (mLoaded) {
224 224
                     mRender->setMode(Render::modeVertexLight);
225
-                    gOpenRaider->mConsole->print("Vertexlight mode");
225
+                    getConsole().print("Vertexlight mode");
226 226
                 } else {
227
-                    gOpenRaider->mConsole->print("Load a level to set this mode!");
227
+                    getConsole().print("Load a level to set this mode!");
228 228
                     return -5;
229 229
                 }
230 230
             } else if (strcmp(mode, "titlescreen") == 0) {
231 231
                 mRender->setMode(Render::modeLoadScreen);
232
-                gOpenRaider->mConsole->print("Titlescreen mode");
232
+                getConsole().print("Titlescreen mode");
233 233
             } else {
234
-                gOpenRaider->mConsole->print("Invalid use of mode command (%s)!", mode);
234
+                getConsole().print("Invalid use of mode command (%s)!", mode);
235 235
                 return -6;
236 236
             }
237 237
         } else {
238
-            gOpenRaider->mConsole->print("Invalid use of mode command!");
238
+            getConsole().print("Invalid use of mode command!");
239 239
             return -7;
240 240
         }
241 241
     } else if (strcmp(cmd, "move") == 0) {
@@ -244,30 +244,30 @@ int Game::command(std::vector<char *> *args) {
244 244
                 char *move = args->at(1);
245 245
                 if (strcmp(move, "walk") == 0) {
246 246
                     mLara->moveType = worldMoveType_walk;
247
-                    gOpenRaider->mConsole->print("Lara is walking...");
247
+                    getConsole().print("Lara is walking...");
248 248
                 } else if (strcmp(move, "fly") == 0) {
249 249
                     mLara->moveType = worldMoveType_fly;
250
-                    gOpenRaider->mConsole->print("Lara is flying...");
250
+                    getConsole().print("Lara is flying...");
251 251
                 } else if (strcmp(move, "noclip") == 0) {
252 252
                     mLara->moveType = worldMoveType_noClipping;
253
-                    gOpenRaider->mConsole->print("Lara is noclipping...");
253
+                    getConsole().print("Lara is noclipping...");
254 254
                 } else {
255
-                    gOpenRaider->mConsole->print("Invalid use of move command (%s)!", move);
255
+                    getConsole().print("Invalid use of move command (%s)!", move);
256 256
                     return -8;
257 257
                 }
258 258
             } else {
259
-                gOpenRaider->mConsole->print("Load a level to change the movement type!");
259
+                getConsole().print("Load a level to change the movement type!");
260 260
                 return -9;
261 261
             }
262 262
         } else {
263
-            gOpenRaider->mConsole->print("Invalid use of move command!");
263
+            getConsole().print("Invalid use of move command!");
264 264
             return -10;
265 265
         }
266 266
     } else if (strcmp(cmd, "sound") == 0) {
267 267
         if (args->size() > 1) {
268
-            gOpenRaider->mSound->play(atoi(args->at(1)));
268
+            getOpenRaider().mSound->play(atoi(args->at(1)));
269 269
         } else {
270
-            gOpenRaider->mConsole->print("Invalid use of sound command!");
270
+            getConsole().print("Invalid use of sound command!");
271 271
             return -11;
272 272
         }
273 273
     } else if (strcmp(cmd, "animate") == 0) {
@@ -285,7 +285,7 @@ int Game::command(std::vector<char *> *args) {
285 285
                                 m->setAnimation(0);
286 286
                     }
287 287
                 } else {
288
-                    gOpenRaider->mConsole->print("Animations need to be enabled!");
288
+                    getConsole().print("Animations need to be enabled!");
289 289
                 }
290 290
             } else if (c == 'p') {
291 291
                 // Step all skeletal models to their previous animation
@@ -299,67 +299,67 @@ int Game::command(std::vector<char *> *args) {
299 299
                                 m->setAnimation(m->model->animation.size() - 1);
300 300
                     }
301 301
                 } else {
302
-                    gOpenRaider->mConsole->print("Animations need to be enabled!");
302
+                    getConsole().print("Animations need to be enabled!");
303 303
                 }
304 304
             } else {
305 305
                 // Enable or disable animating all skeletal models
306 306
                 bool b;
307 307
                 if (readBool(args->at(1), &b) < 0) {
308
-                    gOpenRaider->mConsole->print("Pass BOOL to animate command!");
308
+                    getConsole().print("Pass BOOL to animate command!");
309 309
                     return -12;
310 310
                 }
311 311
                 if (b)
312 312
                     mRender->setFlags(Render::fAnimateAllModels);
313 313
                 else
314 314
                     mRender->clearFlags(Render::fAnimateAllModels);
315
-                gOpenRaider->mConsole->print(b ? "Animating all models" : "No longer animating all models");
315
+                getConsole().print(b ? "Animating all models" : "No longer animating all models");
316 316
             }
317 317
         } else {
318
-            gOpenRaider->mConsole->print("Invalid use of animate command!");
318
+            getConsole().print("Invalid use of animate command!");
319 319
             return -13;
320 320
         }
321 321
     } else if (strcmp(cmd, "help") == 0) {
322 322
         if (args->size() < 2) {
323
-            gOpenRaider->mConsole->print("game-command Usage:");
324
-            gOpenRaider->mConsole->print("  game COMMAND");
325
-            gOpenRaider->mConsole->print("Available commands:");
326
-            gOpenRaider->mConsole->print("  move [walk|fly|noclip]");
327
-            gOpenRaider->mConsole->print("  sound INT");
328
-            gOpenRaider->mConsole->print("  mode MODE");
329
-            gOpenRaider->mConsole->print("  animate [BOOL|n|p]");
323
+            getConsole().print("game-command Usage:");
324
+            getConsole().print("  game COMMAND");
325
+            getConsole().print("Available commands:");
326
+            getConsole().print("  move [walk|fly|noclip]");
327
+            getConsole().print("  sound INT");
328
+            getConsole().print("  mode MODE");
329
+            getConsole().print("  animate [BOOL|n|p]");
330 330
         } else if (strcmp(args->at(1), "sound") == 0) {
331
-            gOpenRaider->mConsole->print("game-sound-command Usage:");
332
-            gOpenRaider->mConsole->print("  game sound INT");
333
-            gOpenRaider->mConsole->print("Where INT is a valid sound ID integer");
331
+            getConsole().print("game-sound-command Usage:");
332
+            getConsole().print("  game sound INT");
333
+            getConsole().print("Where INT is a valid sound ID integer");
334 334
         } else if (strcmp(args->at(1), "move") == 0) {
335
-            gOpenRaider->mConsole->print("game-move-command Usage:");
336
-            gOpenRaider->mConsole->print("  game move COMMAND");
337
-            gOpenRaider->mConsole->print("Where COMMAND is one of the following:");
338
-            gOpenRaider->mConsole->print("  walk");
339
-            gOpenRaider->mConsole->print("  fly");
340
-            gOpenRaider->mConsole->print("  noclip");
335
+            getConsole().print("game-move-command Usage:");
336
+            getConsole().print("  game move COMMAND");
337
+            getConsole().print("Where COMMAND is one of the following:");
338
+            getConsole().print("  walk");
339
+            getConsole().print("  fly");
340
+            getConsole().print("  noclip");
341 341
         } else if (strcmp(args->at(1), "mode") == 0) {
342
-            gOpenRaider->mConsole->print("game-mode-command Usage:");
343
-            gOpenRaider->mConsole->print("  game mode MODE");
344
-            gOpenRaider->mConsole->print("Where MODE is one of the following:");
345
-            gOpenRaider->mConsole->print("  wireframe");
346
-            gOpenRaider->mConsole->print("  solid");
347
-            gOpenRaider->mConsole->print("  texture");
348
-            gOpenRaider->mConsole->print("  vertexlight");
349
-            gOpenRaider->mConsole->print("  titlescreen");
342
+            getConsole().print("game-mode-command Usage:");
343
+            getConsole().print("  game mode MODE");
344
+            getConsole().print("Where MODE is one of the following:");
345
+            getConsole().print("  wireframe");
346
+            getConsole().print("  solid");
347
+            getConsole().print("  texture");
348
+            getConsole().print("  vertexlight");
349
+            getConsole().print("  titlescreen");
350 350
         } else if (strcmp(args->at(1), "animate") == 0) {
351
-            gOpenRaider->mConsole->print("game-animate-command Usage:");
352
-            gOpenRaider->mConsole->print("  game animate [n|p|BOOL]");
353
-            gOpenRaider->mConsole->print("Where the commands have the following meaning:");
354
-            gOpenRaider->mConsole->print("  BOOL to (de)activate animating all models");
355
-            gOpenRaider->mConsole->print("  n to step all models to their next animation");
356
-            gOpenRaider->mConsole->print("  p to step all models to their previous animation");
351
+            getConsole().print("game-animate-command Usage:");
352
+            getConsole().print("  game animate [n|p|BOOL]");
353
+            getConsole().print("Where the commands have the following meaning:");
354
+            getConsole().print("  BOOL to (de)activate animating all models");
355
+            getConsole().print("  n to step all models to their next animation");
356
+            getConsole().print("  p to step all models to their previous animation");
357 357
         } else {
358
-            gOpenRaider->mConsole->print("No help available for game %s.", args->at(1));
358
+            getConsole().print("No help available for game %s.", args->at(1));
359 359
             return -14;
360 360
         }
361 361
     } else {
362
-        gOpenRaider->mConsole->print("Invalid use of game-command (%s)!", cmd);
362
+        getConsole().print("Invalid use of game-command (%s)!", cmd);
363 363
         return -15;
364 364
     }
365 365
 
@@ -390,7 +390,7 @@ void Game::processPakSounds()
390 390
     {
391 391
         mTombRaider.getSoundSample(i, &riffSz, &riff);
392 392
 
393
-        gOpenRaider->mSound->addWave(riff, riffSz, &id, gOpenRaider->mSound->SoundFlagsNone);
393
+        getOpenRaider().mSound->addWave(riff, riffSz, &id, getOpenRaider().mSound->SoundFlagsNone);
394 394
 
395 395
         //if (((i + 1) == TR_SOUND_F_PISTOL) && (id > 0))
396 396
         //{
@@ -404,7 +404,7 @@ void Game::processPakSounds()
404 404
         //pos[0] = sound[i].x;
405 405
         //pos[1] = sound[i].y;
406 406
         //pos[2] = sound[i].z;
407
-        //gOpenRaider->mSound->SourceAt(id, pos);
407
+        //getOpenRaider().mSound->SourceAt(id, pos);
408 408
 
409 409
         //printf(".");
410 410
         //fflush(stdout);
@@ -868,7 +868,7 @@ void Game::processMoveable(int index, int i, int *ent,
868 868
                     }
869 869
 
870 870
                     mRender->setFlags(Render::fRenderPonytail);
871
-                    gOpenRaider->mConsole->print("Found known ponytail");
871
+                    getConsole().print("Found known ponytail");
872 872
                 }
873 873
                 break; // ?
874 874
             case TR_VERSION_1:
@@ -890,7 +890,7 @@ void Game::processMoveable(int index, int i, int *ent,
890 890
                     r_model->ponyOff2 = 0;
891 891
 
892 892
                     mRender->setFlags(Render::fRenderPonytail);
893
-                    gOpenRaider->mConsole->print("Found ponytail?");
893
+                    getConsole().print("Found ponytail?");
894 894
                 }
895 895
                 break;
896 896
         }
@@ -1009,11 +1009,11 @@ void Game::processMoveable(int index, int i, int *ent,
1009 1009
             //   if (frame_offset + 8 > _tombraider.NumFrames())
1010 1010
             if (frame_offset > mTombRaider.NumFrames())
1011 1011
             {
1012
-                gOpenRaider->mConsole->print("WARNING: Bad animation frame %i > %i",
1012
+                getConsole().print("WARNING: Bad animation frame %i > %i",
1013 1013
                         frame_offset, mTombRaider.NumFrames());
1014 1014
 
1015 1015
                 // Mongoose 2002.08.15, Attempt to skip more likely bad animation data
1016
-                gOpenRaider->mConsole->print("WARNING: Handling bad animation data...");
1016
+                getConsole().print("WARNING: Handling bad animation data...");
1017 1017
                 return; //continue;
1018 1018
             }
1019 1019
 
@@ -1366,7 +1366,7 @@ void Game::processRooms()
1366 1366
 
1367 1367
         if (!mTombRaider.isRoomValid(index))
1368 1368
         {
1369
-            gOpenRaider->mConsole->print("WARNING: Handling invalid vertex array in room");
1369
+            getConsole().print("WARNING: Handling invalid vertex array in room");
1370 1370
             mWorld.addRoom(0x0);
1371 1371
             mRender->addRoom(0x0);
1372 1372
 
@@ -1585,7 +1585,7 @@ void Game::processRooms()
1585 1585
 
1586 1586
             if (texture > (int)TextureLimit)
1587 1587
             {
1588
-                gOpenRaider->mConsole->print("Handling bad room[%i].tris[%i].texture = %i",
1588
+                getConsole().print("Handling bad room[%i].tris[%i].texture = %i",
1589 1589
                         index, t, texture);
1590 1590
                 texture = TextureLimit - 1;
1591 1591
             }
@@ -1619,7 +1619,7 @@ void Game::processRooms()
1619 1619
 
1620 1620
             if (texture > (int)TextureLimit)
1621 1621
             {
1622
-                gOpenRaider->mConsole->print("Handling bad room[%i].quad[%i].texture = %i",
1622
+                getConsole().print("Handling bad room[%i].quad[%i].texture = %i",
1623 1623
                         index, r, texture);
1624 1624
                 texture = TextureLimit - 1;
1625 1625
             }

+ 22
- 24
src/Menu.cpp Ver fichero

@@ -47,7 +47,7 @@ bool Menu::isVisible() {
47 47
 
48 48
 void Menu::displayMapList() {
49 49
     // Estimate displayable number of items
50
-    int items = (gOpenRaider->mWindow->mHeight - 110) / 25;
50
+    int items = (getWindow().mHeight - 110) / 25;
51 51
 
52 52
     // Select which part of the list to show
53 53
     int min, max;
@@ -56,15 +56,15 @@ void Menu::displayMapList() {
56 56
     else
57 57
         min = 0;
58 58
 
59
-    if ((mCursor + (items / 2)) < gOpenRaider->mMapList.size())
59
+    if ((mCursor + (items / 2)) < getOpenRaider().mMapList.size())
60 60
         max = mCursor + (items / 2);
61 61
     else
62
-        max = gOpenRaider->mMapList.size();
62
+        max = getOpenRaider().mMapList.size();
63 63
 
64 64
     while ((max - min) < items) {
65 65
         if (min > 0)
66 66
             min--;
67
-        else if (max < ((int)gOpenRaider->mMapList.size()))
67
+        else if (max < ((int)getOpenRaider().mMapList.size()))
68 68
             max++;
69 69
         else
70 70
             break;
@@ -73,40 +73,38 @@ void Menu::displayMapList() {
73 73
     mMin = min;
74 74
 
75 75
     for (int i = 0; i < (max - min); i++) {
76
-        char *map = gOpenRaider->mMapList[i + min];
76
+        char *map = getOpenRaider().mMapList[i + min];
77 77
         if ((i + min) == (int)mCursor)
78
-            gOpenRaider->mWindow->drawText(25, 100 + (25 * i), 0.75f, RED, "%s", map);
78
+            getWindow().drawText(25, 100 + (25 * i), 0.75f, RED, "%s", map);
79 79
         else
80
-            gOpenRaider->mWindow->drawText(25, 100 + (25 * i), 0.75f, OR_BLUE, "%s", map);
80
+            getWindow().drawText(25, 100 + (25 * i), 0.75f, OR_BLUE, "%s", map);
81 81
     }
82 82
 }
83 83
 
84 84
 void Menu::display() {
85
-    Window *window = gOpenRaider->mWindow;
86
-
87 85
     if (mVisible) {
88 86
         // Draw half-transparent *overlay*
89 87
         glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
90 88
         glDisable(GL_TEXTURE_2D);
91
-        glRecti(0, 0, window->mWidth, window->mHeight);
89
+        glRecti(0, 0, getWindow().mWidth, getWindow().mHeight);
92 90
         glEnable(GL_TEXTURE_2D);
93 91
 
94 92
         // Draw heading text
95
-        mainText.x = (window->mWidth / 2) - (mainText.w / 2);
96
-        window->writeString(&mainText);
93
+        mainText.x = (getWindow().mWidth / 2) - (mainText.w / 2);
94
+        getWindow().writeString(&mainText);
97 95
 
98
-        if (!gOpenRaider->mMapListFilled) {
99
-            gOpenRaider->mWindow->drawText(25, (window->mHeight / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");
96
+        if (!getOpenRaider().mMapListFilled) {
97
+            getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");
100 98
         } else {
101
-            if (gOpenRaider->mMapList.size() == 0) {
102
-                gOpenRaider->mWindow->drawText(25, (window->mHeight / 2) - 20, 0.75f, RED, "No maps found! See README.md");
99
+            if (getOpenRaider().mMapList.size() == 0) {
100
+                getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, RED, "No maps found! See README.md");
103 101
             } else {
104 102
                 // draw *play button* above list
105 103
                 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
106 104
                 glDisable(GL_TEXTURE_2D);
107 105
                 glRecti(25, 25, 100, 75);
108 106
                 glEnable(GL_TEXTURE_2D);
109
-                gOpenRaider->mWindow->drawText(40, 35, 0.75f, BLACK, "Play");
107
+                getWindow().drawText(40, 35, 0.75f, BLACK, "Play");
110 108
 
111 109
                 displayMapList();
112 110
             }
@@ -122,16 +120,16 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
122 120
         if (mCursor > 0)
123 121
             mCursor--;
124 122
         else
125
-            mCursor = gOpenRaider->mMapList.size() - 1;
123
+            mCursor = getOpenRaider().mMapList.size() - 1;
126 124
     } else if (key == down) {
127
-        if (mCursor < (gOpenRaider->mMapList.size() - 1))
125
+        if (mCursor < (getOpenRaider().mMapList.size() - 1))
128 126
             mCursor++;
129 127
         else
130 128
             mCursor = 0;
131 129
     } else if (key == right) {
132 130
         int i = 10;
133
-        if (mCursor > (gOpenRaider->mMapList.size() - 11))
134
-            i = gOpenRaider->mMapList.size() - 1 - mCursor;
131
+        if (mCursor > (getOpenRaider().mMapList.size() - 11))
132
+            i = getOpenRaider().mMapList.size() - 1 - mCursor;
135 133
         while (i-- > 0)
136 134
             handleKeyboard(down, true);
137 135
     } else if (key == left) {
@@ -141,15 +139,15 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
141 139
         while (i-- > 0)
142 140
             handleKeyboard(up, true);
143 141
     } else if (key == enter) {
144
-        char *tmp = bufferString("load %s", gOpenRaider->mMapList[mCursor]);
145
-        if (gOpenRaider->command(tmp) == 0)
142
+        char *tmp = bufferString("load %s", getOpenRaider().mMapList[mCursor]);
143
+        if (getOpenRaider().command(tmp) == 0)
146 144
             setVisible(false);
147 145
         delete [] tmp;
148 146
     }
149 147
 }
150 148
 
151 149
 void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
152
-    int items = (gOpenRaider->mWindow->mHeight - 110) / 25;
150
+    int items = (getWindow().mHeight - 110) / 25;
153 151
 
154 152
     if ((!released) || (button != leftmouse))
155 153
         return;

+ 102
- 136
src/OpenRaider.cpp Ver fichero

@@ -15,11 +15,11 @@
15 15
 #include "config.h"
16 16
 #include "Console.h"
17 17
 #include "Game.h"
18
+#include "main.h"
18 19
 #include "math/math.h"
19 20
 #include "Menu.h"
20 21
 #include "Sound.h"
21 22
 #include "TombRaider.h"
22
-#include "Window.h"
23 23
 #include "utils/strings.h"
24 24
 #include "utils/time.h"
25 25
 #include "OpenRaider.h"
@@ -34,11 +34,7 @@ OpenRaider::OpenRaider() {
34 34
     mDataDir = NULL;
35 35
     mMapListFilled = false;
36 36
 
37
-    mMenu = new Menu();
38
-    mConsole = new Console();
39 37
     mSound = new Sound();
40
-    mWindow = new WindowSDL();
41
-    mGame = new Game();
42 38
 
43 39
     for (int i = 0; i < ActionEventCount; i++)
44 40
         keyBindings[i] = unknown;
@@ -48,21 +44,9 @@ OpenRaider::OpenRaider() {
48 44
 }
49 45
 
50 46
 OpenRaider::~OpenRaider() {
51
-    if (mGame)
52
-        delete mGame;
53
-
54
-    if (mMenu)
55
-        delete mMenu;
56
-
57
-    if (mConsole)
58
-        delete mConsole;
59
-
60 47
     if (mSound)
61 48
         delete mSound;
62 49
 
63
-    if (mWindow)
64
-        delete mWindow;
65
-
66 50
     if (mBaseDir)
67 51
         delete mBaseDir;
68 52
 
@@ -86,11 +70,11 @@ int OpenRaider::loadConfig(const char *config) {
86 70
     assert(config[0] != '\0');
87 71
 
88 72
     char *configFile = fullPath(config, 0);
89
-    mConsole->print("Loading config from \"%s\"...", configFile);
73
+    getConsole().print("Loading config from \"%s\"...", configFile);
90 74
 
91 75
     FILE *f = fopen(configFile, "r");
92 76
     if (f == NULL) {
93
-        mConsole->print("Could not open file!");
77
+        getConsole().print("Could not open file!");
94 78
         return -1;
95 79
     }
96 80
 
@@ -98,7 +82,7 @@ int OpenRaider::loadConfig(const char *config) {
98 82
     while (fgets(buffer, 256, f) != NULL) {
99 83
         int error = command(buffer);
100 84
         if (error != 0) {
101
-            mConsole->print("Error Code: %d", error);
85
+            getConsole().print("Error Code: %d", error);
102 86
         }
103 87
     }
104 88
 
@@ -148,14 +132,14 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
148 132
 
149 133
     if (strcmp(command, "set") == 0) {
150 134
         if (args->size() != 2) {
151
-            mConsole->print("Invalid use of set-command");
135
+            getConsole().print("Invalid use of set-command");
152 136
             return -2;
153 137
         } else {
154 138
             return set(args->at(0), args->at(1));
155 139
         }
156 140
     } else if (strcmp(command, "bind") == 0) {
157 141
         if (args->size() != 2) {
158
-            mConsole->print("Invalid use of bind-command");
142
+            getConsole().print("Invalid use of bind-command");
159 143
             return -3;
160 144
         } else {
161 145
             return bind(args->at(0), args->at(1));
@@ -164,29 +148,29 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
164 148
         exit(0);
165 149
     } else if (strcmp(command, "help") == 0) {
166 150
         if (args->size() == 0) {
167
-            mConsole->print("Available commands:");
168
-            mConsole->print("  load - load a level");
169
-            mConsole->print("  set  - set a parameter");
170
-            mConsole->print("  bind - bind a keyboard/mouse action");
171
-            mConsole->print("  game - send a command to the game engine");
172
-            mConsole->print("  help - print command help");
173
-            mConsole->print("  quit - exit OpenRaider");
174
-            mConsole->print("Use help COMMAND to get additional info");
151
+            getConsole().print("Available commands:");
152
+            getConsole().print("  load - load a level");
153
+            getConsole().print("  set  - set a parameter");
154
+            getConsole().print("  bind - bind a keyboard/mouse action");
155
+            getConsole().print("  game - send a command to the game engine");
156
+            getConsole().print("  help - print command help");
157
+            getConsole().print("  quit - exit OpenRaider");
158
+            getConsole().print("Use help COMMAND to get additional info");
175 159
         } else if (args->size() == 1) {
176 160
             return help(args->at(0));
177 161
         } else {
178
-            mConsole->print("Invalid use of help-command");
162
+            getConsole().print("Invalid use of help-command");
179 163
             return -4;
180 164
         }
181 165
     } else if (strcmp(command, "load") == 0) {
182 166
         char *tmp = bufferString("%s/%s", mPakDir, args->at(0));
183
-        int error = mGame->loadLevel(tmp);
167
+        int error = getGame().loadLevel(tmp);
184 168
         delete [] tmp;
185 169
         return error;
186 170
     } else if (strcmp(command, "game") == 0) {
187
-        return mGame->command(args);
171
+        return getGame().command(args);
188 172
     } else {
189
-        mConsole->print("Unknown command: %s ", command);
173
+        getConsole().print("Unknown command: %s ", command);
190 174
         return -1;
191 175
     }
192 176
 
@@ -198,48 +182,48 @@ int OpenRaider::help(const char *cmd) {
198 182
     assert(cmd[0] != '\0');
199 183
 
200 184
     if (strcmp(cmd, "set") == 0) {
201
-        mConsole->print("set-Command Usage:");
202
-        mConsole->print("  set VAR VAL");
203
-        mConsole->print("Available Variables:");
204
-        mConsole->print("  basedir     STRING");
205
-        mConsole->print("  pakdir      STRING");
206
-        mConsole->print("  audiodir    STRING");
207
-        mConsole->print("  datadir     STRING");
208
-        mConsole->print("  font        STRING");
209
-        mConsole->print("  gldriver    STRING");
210
-        mConsole->print("  size        \"INTxINT\"");
211
-        mConsole->print("  fullscreen  BOOL");
212
-        mConsole->print("  audio       BOOL");
213
-        mConsole->print("  volume      BOOL");
214
-        mConsole->print("  mouse_x     FLOAT");
215
-        mConsole->print("  mouse_y     FLOAT");
216
-        mConsole->print("  fps         BOOL");
217
-        mConsole->print("Enclose STRINGs with \"\"!");
218
-        mConsole->print("size expects a STRING in the specified format");
185
+        getConsole().print("set-Command Usage:");
186
+        getConsole().print("  set VAR VAL");
187
+        getConsole().print("Available Variables:");
188
+        getConsole().print("  basedir     STRING");
189
+        getConsole().print("  pakdir      STRING");
190
+        getConsole().print("  audiodir    STRING");
191
+        getConsole().print("  datadir     STRING");
192
+        getConsole().print("  font        STRING");
193
+        getConsole().print("  gldriver    STRING");
194
+        getConsole().print("  size        \"INTxINT\"");
195
+        getConsole().print("  fullscreen  BOOL");
196
+        getConsole().print("  audio       BOOL");
197
+        getConsole().print("  volume      BOOL");
198
+        getConsole().print("  mouse_x     FLOAT");
199
+        getConsole().print("  mouse_y     FLOAT");
200
+        getConsole().print("  fps         BOOL");
201
+        getConsole().print("Enclose STRINGs with \"\"!");
202
+        getConsole().print("size expects a STRING in the specified format");
219 203
     } else if (strcmp(cmd, "bind") == 0) {
220
-        mConsole->print("bind-Command Usage:");
221
-        mConsole->print("  bind ACTION KEY");
222
-        mConsole->print("Available Actions:");
223
-        mConsole->print("  menu");
224
-        mConsole->print("  console");
225
-        mConsole->print("  forward");
226
-        mConsole->print("  backward");
227
-        mConsole->print("  left");
228
-        mConsole->print("  right");
229
-        mConsole->print("  jump");
230
-        mConsole->print("  crouch");
231
-        mConsole->print("  use");
232
-        mConsole->print("  holster");
233
-        mConsole->print("Key-Format:");
234
-        mConsole->print("  'a' or '1'    for character/number keys");
235
-        mConsole->print("  \"leftctrl\"  for symbols and special keys");
204
+        getConsole().print("bind-Command Usage:");
205
+        getConsole().print("  bind ACTION KEY");
206
+        getConsole().print("Available Actions:");
207
+        getConsole().print("  menu");
208
+        getConsole().print("  console");
209
+        getConsole().print("  forward");
210
+        getConsole().print("  backward");
211
+        getConsole().print("  left");
212
+        getConsole().print("  right");
213
+        getConsole().print("  jump");
214
+        getConsole().print("  crouch");
215
+        getConsole().print("  use");
216
+        getConsole().print("  holster");
217
+        getConsole().print("Key-Format:");
218
+        getConsole().print("  'a' or '1'    for character/number keys");
219
+        getConsole().print("  \"leftctrl\"  for symbols and special keys");
236 220
     } else if (strcmp(cmd, "load") == 0) {
237
-        mConsole->print("load-Command Usage:");
238
-        mConsole->print("  load levelfile.name");
221
+        getConsole().print("load-Command Usage:");
222
+        getConsole().print("  load levelfile.name");
239 223
     } else if (strcmp(cmd, "game") == 0) {
240
-        mConsole->print("Use \"game help\" for more info");
224
+        getConsole().print("Use \"game help\" for more info");
241 225
     } else {
242
-        mConsole->print("No help available for %s", cmd);
226
+        getConsole().print("No help available for %s", cmd);
243 227
         return -1;
244 228
     }
245 229
 
@@ -304,51 +288,51 @@ int OpenRaider::set(const char *var, const char *value) {
304 288
         // value has format like "\"1024x768\""
305 289
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
306 290
         if (sscanf(value, "\"%dx%d\"", &w, &h) != 2) {
307
-            mConsole->print("set-size-Error: Invalid value (%s)", value);
291
+            getConsole().print("set-size-Error: Invalid value (%s)", value);
308 292
             return -2;
309 293
         }
310
-        mWindow->setSize(w, h);
294
+        getWindow().setSize(w, h);
311 295
     } else if (strcmp(var, "fullscreen") == 0) {
312 296
         bool fullscreen = false;
313 297
         if (readBool(value, &fullscreen) != 0) {
314
-            mConsole->print("set-fullscreen-Error: Invalid value (%s)", value);
298
+            getConsole().print("set-fullscreen-Error: Invalid value (%s)", value);
315 299
             return -3;
316 300
         }
317
-        mWindow->setFullscreen(fullscreen);
301
+        getWindow().setFullscreen(fullscreen);
318 302
     } else if (strcmp(var, "gldriver") == 0) {
319
-        mWindow->setDriver(value);
303
+        getWindow().setDriver(value);
320 304
     } else if (strcmp(var, "audio") == 0) {
321 305
         bool audio = false;
322 306
         if (readBool(value, &audio) != 0) {
323
-            mConsole->print("set-audio-Error: Invalid value (%s)", value);
307
+            getConsole().print("set-audio-Error: Invalid value (%s)", value);
324 308
             return -4;
325 309
         }
326 310
         mSound->setEnabled(audio);
327 311
     } else if (strcmp(var, "volume") == 0) {
328 312
         float vol = 1.0f;
329 313
         if (sscanf(value, "%f", &vol) != 1) {
330
-            mConsole->print("set-volume-Error: Invalid value (%s)", value);
314
+            getConsole().print("set-volume-Error: Invalid value (%s)", value);
331 315
             return -5;
332 316
         }
333 317
         mSound->setVolume(vol);
334 318
     } else if (strcmp(var, "mouse_x") == 0) {
335 319
         float sense = 1.0f;
336 320
         if (sscanf(value, "%f", &sense) != 1) {
337
-            mConsole->print("set-mouse_x-Error: Invalid value (%s)", value);
321
+            getConsole().print("set-mouse_x-Error: Invalid value (%s)", value);
338 322
             return -6;
339 323
         }
340 324
         mCameraRotationDeltaX = OR_DEG_TO_RAD(sense);
341 325
     } else if (strcmp(var, "mouse_y") == 0) {
342 326
         float sense = 1.0f;
343 327
         if (sscanf(value, "%f", &sense) != 1) {
344
-            mConsole->print("set-mouse_y-Error: Invalid value (%s)", value);
328
+            getConsole().print("set-mouse_y-Error: Invalid value (%s)", value);
345 329
             return -7;
346 330
         }
347 331
         mCameraRotationDeltaY = OR_DEG_TO_RAD(sense);
348 332
     } else if (strcmp(var, "fps") == 0) {
349 333
         bool fps = false;
350 334
         if (readBool(value, &fps) != 0) {
351
-            mConsole->print("set-fps-Error: Invalid value (%s)", value);
335
+            getConsole().print("set-fps-Error: Invalid value (%s)", value);
352 336
             return -8;
353 337
         }
354 338
         mFPS = fps;
@@ -364,14 +348,14 @@ int OpenRaider::set(const char *var, const char *value) {
364 348
         char *quotes = stringReplace(value, "\"", "");
365 349
         char *tmp = expandDirectoryNames(quotes);
366 350
         if (tmp == NULL) {
367
-            mWindow->setFont(quotes);
351
+            getWindow().setFont(quotes);
368 352
         } else {
369
-            mWindow->setFont(tmp);
353
+            getWindow().setFont(tmp);
370 354
             delete [] tmp;
371 355
         }
372 356
         delete [] quotes;
373 357
     } else {
374
-        mConsole->print("set-Error: Unknown variable (%s = %s)", var, value);
358
+        getConsole().print("set-Error: Unknown variable (%s = %s)", var, value);
375 359
         return -1;
376 360
     }
377 361
 
@@ -409,7 +393,7 @@ int OpenRaider::bind(const char *action, const char *key) {
409 393
     } else if (strcmp(tmp, "holster") == 0) {
410 394
         return bind(holsterAction, key);
411 395
     } else {
412
-        mConsole->print("bind-Error: Unknown action (%s --> %s)", key, action);
396
+        getConsole().print("bind-Error: Unknown action (%s --> %s)", key, action);
413 397
         return -1;
414 398
     }
415 399
 }
@@ -427,7 +411,7 @@ int OpenRaider::bind(ActionEvents action, const char *key) {
427 411
             || ((c >= 'a') && (c <= 'z'))) {
428 412
             keyBindings[action] = (KeyboardButton)c;
429 413
         } else {
430
-            mConsole->print("bind-\'\'-Error: Unknown key (%s)", key);
414
+            getConsole().print("bind-\'\'-Error: Unknown key (%s)", key);
431 415
             return -1;
432 416
         }
433 417
     } else if ((key[0] == '\"') && (key[length - 1] == '\"')) {
@@ -540,13 +524,13 @@ int OpenRaider::bind(ActionEvents action, const char *key) {
540 524
         } else if (strcmp(tmp, "rightmouse") == 0) {
541 525
             keyBindings[action] = rightmouse;
542 526
         } else {
543
-            mConsole->print("bind-\"\"-Error: Unknown key (%s)", key);
527
+            getConsole().print("bind-\"\"-Error: Unknown key (%s)", key);
544 528
             delete [] tmp;
545 529
             return -2;
546 530
         }
547 531
         delete [] tmp;
548 532
     } else {
549
-        mConsole->print("bind-Error: Unknown key (%s)", key);
533
+        getConsole().print("bind-Error: Unknown key (%s)", key);
550 534
         return -3;
551 535
     }
552 536
     return 0;
@@ -589,7 +573,7 @@ void OpenRaider::loadPakFolderRecursive(const char *dir) {
589 573
                         // Just load relative filename
590 574
                         mMapList.push_back(bufferString("%s", (fullPathMap + strlen(mPakDir) + 1)));
591 575
                     } else {
592
-                        mConsole->print("Error: pak file '%s' %s",
576
+                        getConsole().print("Error: pak file '%s' %s",
593 577
                                 fullPathMap, (error == -1) ? "not found" : "invalid");
594 578
                     }
595 579
                 }
@@ -600,7 +584,7 @@ void OpenRaider::loadPakFolderRecursive(const char *dir) {
600 584
         }
601 585
         closedir(pakDir);
602 586
     } else {
603
-        mConsole->print("Could not open PAK dir %s!", dir);
587
+        getConsole().print("Could not open PAK dir %s!", dir);
604 588
     }
605 589
 }
606 590
 
@@ -618,27 +602,9 @@ int OpenRaider::initialize() {
618 602
     assert(mInit == false);
619 603
     assert(mRunning == false);
620 604
 
621
-    // Initialize Windowing
622
-    if (mWindow->initialize() != 0)
623
-        return -1;
624
-
625
-    // Initialize OpenGL
626
-    if (mWindow->initializeGL() != 0)
627
-        return -2;
628
-
629
-    // Initialize window font
630
-    if (mWindow->initializeFont() != 0)
631
-        return -3;
632
-
633 605
     // Initialize sound
634 606
     if (mSound->initialize() != 0)
635
-        return -4;
636
-
637
-    // Initialize game engine
638
-    if (mGame->initialize() != 0)
639
-        return -5;
640
-
641
-    mMenu->setVisible(true);
607
+        return -1;
642 608
 
643 609
     mInit = true;
644 610
 
@@ -657,29 +623,29 @@ void OpenRaider::run() {
657 623
         clock_t startTime = systemTimerGet();
658 624
 
659 625
         // Get keyboard and mouse input
660
-        mWindow->eventHandling();
626
+        getWindow().eventHandling();
661 627
 
662 628
         // Clear screen
663 629
         glClearColor(0.00f, 0.00f, 0.00f, 1.0f);
664 630
         glClear(GL_COLOR_BUFFER_BIT);
665 631
 
666 632
         // Draw game scene
667
-        mGame->display();
633
+        getGame().display();
668 634
 
669 635
         // Draw 2D overlays (console and menu)
670
-        mWindow->glEnter2D();
636
+        getWindow().glEnter2D();
671 637
 
672
-        mConsole->display();
673
-        mMenu->display();
638
+        getConsole().display();
639
+        getMenu().display();
674 640
 
675 641
         // Draw FPS counter
676 642
         if (mFPS)
677
-            mWindow->drawText(10, mWindow->mHeight - 20, 0.5f, OR_BLUE, "%dFPS", fps);
643
+            getWindow().drawText(10, getWindow().mHeight - 20, 0.5f, OR_BLUE, "%dFPS", fps);
678 644
 
679
-        mWindow->glExit2D();
645
+        getWindow().glExit2D();
680 646
 
681 647
         // Put new frame on screen
682
-        mWindow->swapBuffersGL();
648
+        getWindow().swapBuffersGL();
683 649
 
684 650
         // Fill map list after first render pass,
685 651
         // so menu *loading screen* is visible
@@ -703,24 +669,24 @@ void OpenRaider::handleKeyboard(KeyboardButton key, bool pressed) {
703 669
     assert(mRunning == true);
704 670
 
705 671
     if ((keyBindings[menuAction] == key) && pressed) {
706
-        mMenu->setVisible(!mMenu->isVisible());
707
-    } else if (!mMenu->isVisible()) {
672
+        getMenu().setVisible(!getMenu().isVisible());
673
+    } else if (!getMenu().isVisible()) {
708 674
         if ((keyBindings[consoleAction] == key) && pressed) {
709
-            mConsole->setVisible(!mConsole->isVisible());
710
-        } else if (!mConsole->isVisible()) {
675
+            getConsole().setVisible(!getConsole().isVisible());
676
+        } else if (!getConsole().isVisible()) {
711 677
             for (int i = forwardAction; i < ActionEventCount; i++) {
712 678
                 if (keyBindings[i] == key) {
713
-                    mGame->handleAction((ActionEvents)i, pressed);
679
+                    getGame().handleAction((ActionEvents)i, pressed);
714 680
                 }
715 681
             }
716 682
         } else {
717
-            mConsole->handleKeyboard(key, pressed);
683
+            getConsole().handleKeyboard(key, pressed);
718 684
         }
719 685
     } else {
720
-        mMenu->handleKeyboard(key, pressed);
686
+        getMenu().handleKeyboard(key, pressed);
721 687
     }
722 688
 
723
-    mWindow->setMousegrab(!(mMenu->isVisible() || mConsole->isVisible()));
689
+    getWindow().setMousegrab(!(getMenu().isVisible() || getConsole().isVisible()));
724 690
 }
725 691
 
726 692
 void OpenRaider::handleText(char *text, bool notFinished) {
@@ -729,8 +695,8 @@ void OpenRaider::handleText(char *text, bool notFinished) {
729 695
     assert(mInit == true);
730 696
     assert(mRunning == true);
731 697
 
732
-    if ((mConsole->isVisible()) && (!mMenu->isVisible())) {
733
-        mConsole->handleText(text, notFinished);
698
+    if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
699
+        getConsole().handleText(text, notFinished);
734 700
     }
735 701
 }
736 702
 
@@ -739,12 +705,12 @@ void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton
739 705
     assert(mInit == true);
740 706
     assert(mRunning == true);
741 707
 
742
-    if (mMenu->isVisible()) {
743
-        mMenu->handleMouseClick(x, y, button, released);
744
-    } else if (!mConsole->isVisible()) {
708
+    if (getMenu().isVisible()) {
709
+        getMenu().handleMouseClick(x, y, button, released);
710
+    } else if (!getConsole().isVisible()) {
745 711
         for (int i = forwardAction; i < ActionEventCount; i++) {
746 712
             if (keyBindings[i] == button) {
747
-                mGame->handleAction((ActionEvents)i, !released);
713
+                getGame().handleAction((ActionEvents)i, !released);
748 714
             }
749 715
         }
750 716
     }
@@ -755,8 +721,8 @@ void OpenRaider::handleMouseMotion(int xrel, int yrel) {
755 721
     assert(mInit == true);
756 722
     assert(mRunning == true);
757 723
 
758
-    if ((!mConsole->isVisible()) && (!mMenu->isVisible())) {
759
-        mGame->handleMouseMotion(xrel, yrel);
724
+    if ((!getConsole().isVisible()) && (!getMenu().isVisible())) {
725
+        getGame().handleMouseMotion(xrel, yrel);
760 726
     }
761 727
 }
762 728
 
@@ -765,8 +731,8 @@ void OpenRaider::handleMouseScroll(int xrel, int yrel) {
765 731
     assert(mInit == true);
766 732
     assert(mRunning == true);
767 733
 
768
-    if ((mConsole->isVisible()) && (!mMenu->isVisible())) {
769
-        mConsole->handleMouseScroll(xrel, yrel);
734
+    if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
735
+        getConsole().handleMouseScroll(xrel, yrel);
770 736
     }
771 737
 }
772 738
 

+ 52
- 52
src/Render.cpp Ver fichero

@@ -36,11 +36,11 @@ bool compareEntites(const void *voidA, const void *voidB)
36 36
     if (!a || !b)
37 37
         return false; // error really
38 38
 
39
-    distA = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(a->pos[0],
39
+    distA = getGame().mRender->mViewVolume.getDistToSphereFromNear(a->pos[0],
40 40
             a->pos[1],
41 41
             a->pos[2],
42 42
             1.0f);
43
-    distB = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
43
+    distB = getGame().mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
44 44
             b->pos[1],
45 45
             b->pos[2],
46 46
             1.0f);
@@ -57,11 +57,11 @@ bool compareStaticModels(const void *voidA, const void *voidB)
57 57
     if (!a || !b)
58 58
         return false; // error really
59 59
 
60
-    distA = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(a->pos[0],
60
+    distA = getGame().mRender->mViewVolume.getDistToSphereFromNear(a->pos[0],
61 61
             a->pos[1],
62 62
             a->pos[2],
63 63
             128.0f);
64
-    distB = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
64
+    distB = getGame().mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
65 65
             b->pos[1],
66 66
             b->pos[2],
67 67
             128.0f);
@@ -117,7 +117,7 @@ Render::~Render()
117 117
 
118 118
 void Render::screenShot(char *filenameBase)
119 119
 {
120
-    mTexture.glScreenShot(filenameBase, gOpenRaider->mWindow->mWidth, gOpenRaider->mWindow->mHeight);
120
+    mTexture.glScreenShot(filenameBase, getWindow().mWidth, getWindow().mHeight);
121 121
 }
122 122
 
123 123
 unsigned int Render::getFlags() {
@@ -234,7 +234,7 @@ void Render::initEmitter(const char *name, unsigned int size,
234 234
 
235 235
 void Render::ClearWorld()
236 236
 {
237
-    gOpenRaider->mGame->mLara = NULL;
237
+    getGame().mLara = NULL;
238 238
 
239 239
     mRoomRenderList.clear();
240 240
 
@@ -509,14 +509,14 @@ void Render::Display()
509 509
 
510 510
     index = -1;
511 511
 
512
-    if (gOpenRaider->mGame->mLara)
512
+    if (getGame().mLara)
513 513
     {
514 514
         float yaw;
515 515
         int sector;
516 516
         float camOffsetH = 0.0f;
517 517
 
518 518
 
519
-        switch (gOpenRaider->mGame->mLara->moveType)
519
+        switch (getGame().mLara->moveType)
520 520
         {
521 521
             case worldMoveType_fly:
522 522
             case worldMoveType_noClipping:
@@ -529,12 +529,12 @@ void Render::Display()
529 529
                 break;
530 530
         }
531 531
 
532
-        curPos[0] = gOpenRaider->mGame->mLara->pos[0];
533
-        curPos[1] = gOpenRaider->mGame->mLara->pos[1];
534
-        curPos[2] = gOpenRaider->mGame->mLara->pos[2];
535
-        yaw = gOpenRaider->mGame->mLara->angles[1];
532
+        curPos[0] = getGame().mLara->pos[0];
533
+        curPos[1] = getGame().mLara->pos[1];
534
+        curPos[2] = getGame().mLara->pos[2];
535
+        yaw = getGame().mLara->angles[1];
536 536
 
537
-        index = gOpenRaider->mGame->mLara->room;
537
+        index = getGame().mLara->room;
538 538
 
539 539
         // Mongoose 2002.08.24, New 3rd person camera hack
540 540
         camPos[0] = curPos[0];
@@ -544,26 +544,26 @@ void Render::Display()
544 544
         camPos[0] -= (1024.0f * sinf(yaw));
545 545
         camPos[2] -= (1024.0f * cosf(yaw));
546 546
 
547
-        sector = gOpenRaider->mGame->mWorld.getSector(index, camPos[0], camPos[2]);
547
+        sector = getGame().mWorld.getSector(index, camPos[0], camPos[2]);
548 548
 
549 549
         // Handle camera out of world
550
-        if (sector < 0 || gOpenRaider->mGame->mWorld.isWall(index, sector))
550
+        if (sector < 0 || getGame().mWorld.isWall(index, sector))
551 551
         {
552 552
             camPos[0] = curPos[0] + (64.0f * sinf(yaw));
553 553
             camPos[1] -= 64.0f;
554 554
             camPos[2] = curPos[2] + (64.0f * cosf(yaw));
555 555
         }
556 556
 
557
-        gOpenRaider->mGame->mCamera->setPosition(camPos);
557
+        getGame().mCamera->setPosition(camPos);
558 558
     }
559 559
 
560 560
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
561 561
     glLoadIdentity();
562 562
 
563 563
     // Setup view in OpenGL with camera
564
-    gOpenRaider->mGame->mCamera->update();
565
-    gOpenRaider->mGame->mCamera->getPosition(camPos);
566
-    gOpenRaider->mGame->mCamera->getTarget(atPos);
564
+    getGame().mCamera->update();
565
+    getGame().mCamera->getPosition(camPos);
566
+    getGame().mCamera->getTarget(atPos);
567 567
     // Mongoose 2002.08.13, Quick fix to render OpenRaider upside down
568 568
 
569 569
     gluLookAt(camPos[0], camPos[1], camPos[2], atPos[0], atPos[1], atPos[2], 0.0f, -1.0f, 0.0f);
@@ -572,33 +572,33 @@ void Render::Display()
572 572
     updateViewVolume();
573 573
 
574 574
     // Let's see the LoS -- should be event controled
575
-    if (gOpenRaider->mGame->mLara)
575
+    if (getGame().mLara)
576 576
     {
577
-        //      SkeletalModel *mdl = (SkeletalModel *)gOpenRaider->mGame->mLara->tmpHook;
577
+        //      SkeletalModel *mdl = (SkeletalModel *)getGame().mLara->tmpHook;
578 578
 
579 579
         // Draw in solid colors
580 580
         glDisable(GL_TEXTURE_2D);
581 581
         glDisable(GL_CULL_FACE);
582 582
 
583
-        if (gOpenRaider->mGame->mLara->state == 64) // eWeaponFire
583
+        if (getGame().mLara->state == 64) // eWeaponFire
584 584
         {
585 585
             vec3_t u, v; //, s, t;
586 586
 
587
-            // Center of gOpenRaider->mGame->mLara
587
+            // Center of getGame().mLara
588 588
             u[0] = curPos[0];
589 589
             u[1] = curPos[1] - 512.0f;
590 590
             u[2] = curPos[2];
591 591
 
592
-            // Location gOpenRaider->mGame->mLara is aiming at?  ( Not finished yet )
593
-            v[0] = u[0] + (9000.0f * sinf(gOpenRaider->mGame->mLara->angles[1]));
594
-            v[1] = u[1] + (9000.0f * sinf(gOpenRaider->mGame->mLara->angles[2]));
595
-            v[2] = u[2] + (9000.0f * cosf(gOpenRaider->mGame->mLara->angles[1]));
592
+            // Location getGame().mLara is aiming at?  ( Not finished yet )
593
+            v[0] = u[0] + (9000.0f * sinf(getGame().mLara->angles[1]));
594
+            v[1] = u[1] + (9000.0f * sinf(getGame().mLara->angles[2]));
595
+            v[2] = u[2] + (9000.0f * cosf(getGame().mLara->angles[1]));
596 596
 
597 597
             // Test tracing of aim
598 598
             renderTrace(0, u, v); // v = target
599 599
         }
600 600
 
601
-        entity_t *route = gOpenRaider->mGame->mLara->master;
601
+        entity_t *route = getGame().mLara->master;
602 602
 
603 603
         while (route)
604 604
         {
@@ -642,14 +642,14 @@ void Render::Display()
642 642
     {
643 643
         entity_t *e;
644 644
         std::vector<entity_t *> entityRenderList;
645
-        std::vector<entity_t *> *entities = gOpenRaider->mGame->mWorld.getEntities();
645
+        std::vector<entity_t *> *entities = getGame().mWorld.getEntities();
646 646
 
647 647
         for (unsigned int i = 0; i < entities->size(); i++)
648 648
         {
649 649
             e = entities->at(i);
650 650
 
651 651
             // Mongoose 2002.03.26, Don't show lara to it's own player
652
-            if (!e || e == gOpenRaider->mGame->mLara)
652
+            if (!e || e == getGame().mLara)
653 653
             {
654 654
                 continue;
655 655
             }
@@ -759,10 +759,10 @@ void Render::drawLoadScreen()
759 759
     float x = 0.0f, y = 0.0f, z = -160.0f;
760 760
     float w, h;
761 761
 
762
-    if (gOpenRaider->mWindow->mWidth < gOpenRaider->mWindow->mHeight)
763
-        w = h = (float)gOpenRaider->mWindow->mWidth;
762
+    if (getWindow().mWidth < getWindow().mHeight)
763
+        w = h = (float)getWindow().mWidth;
764 764
     else
765
-        w = h = (float)gOpenRaider->mWindow->mHeight;
765
+        w = h = (float)getWindow().mHeight;
766 766
 
767 767
 
768 768
     if (mTexture.getTextureCount() <= 0)
@@ -956,7 +956,7 @@ void Render::buildRoomRenderList(RenderRoom *rRoom)
956 956
 
957 957
 void Render::drawSkyMesh(float scale)
958 958
 {
959
-    skeletal_model_t *model = gOpenRaider->mGame->mWorld.getModel(mSkyMesh);
959
+    skeletal_model_t *model = getGame().mWorld.getModel(mSkyMesh);
960 960
 
961 961
 
962 962
     if (!model)
@@ -973,7 +973,7 @@ void Render::drawSkyMesh(float scale)
973 973
     glTranslated(0.0, 1000.0, 0.0);
974 974
     glScaled(scale, scale, scale);
975 975
     //drawModel(model);
976
-    //drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mSkyMesh), );
976
+    //drawModelMesh(getGame().mWorld.getMesh(mSkyMesh), );
977 977
     glPopMatrix();
978 978
     glEnable(GL_DEPTH_TEST);
979 979
 }
@@ -989,15 +989,15 @@ void Render::drawObjects()
989 989
 
990 990
 
991 991
     // Draw lara or other player model ( move to entity rendering method )
992
-    if (mFlags & Render::fViewModel && gOpenRaider->mGame->mLara && gOpenRaider->mGame->mLara->tmpHook)
992
+    if (mFlags & Render::fViewModel && getGame().mLara && getGame().mLara->tmpHook)
993 993
     {
994
-        SkeletalModel *mdl = static_cast<SkeletalModel *>(gOpenRaider->mGame->mLara->tmpHook);
994
+        SkeletalModel *mdl = static_cast<SkeletalModel *>(getGame().mLara->tmpHook);
995 995
 
996 996
         if (mdl)
997 997
         {
998 998
 
999 999
             // Mongoose 2002.03.22, Test 'idle' aniamtions
1000
-            if (!gOpenRaider->mGame->mLara->moving)
1000
+            if (!getGame().mLara->moving)
1001 1001
             {
1002 1002
                 frame = mdl->getIdleAnimation();
1003 1003
 
@@ -1023,16 +1023,16 @@ void Render::drawObjects()
1023 1023
         glPushMatrix();
1024 1024
 
1025 1025
 #ifdef USING_FPS_CAMERA
1026
-        gOpenRaider->mGame->mCamera->getPosition(curPos);
1026
+        getGame().mCamera->getPosition(curPos);
1027 1027
         glTranslated(curPos[0], curPos[1], curPos[2]);
1028
-        glRotated(gOpenRaider->mGame->mCamera->getYaw(), 0, 1, 0);
1028
+        glRotated(getGame().mCamera->getYaw(), 0, 1, 0);
1029 1029
         glTranslated(0, 500, 1200);
1030 1030
 #else
1031
-        glTranslated(gOpenRaider->mGame->mLara->pos[0], gOpenRaider->mGame->mLara->pos[1], gOpenRaider->mGame->mLara->pos[2]);
1032
-        glRotated(gOpenRaider->mGame->mCamera->getYaw(), 0, 1, 0);
1031
+        glTranslated(getGame().mLara->pos[0], getGame().mLara->pos[1], getGame().mLara->pos[2]);
1032
+        glRotated(getGame().mCamera->getYaw(), 0, 1, 0);
1033 1033
 #endif
1034 1034
 
1035
-        drawModel(static_cast<SkeletalModel *>(gOpenRaider->mGame->mLara->tmpHook));
1035
+        drawModel(static_cast<SkeletalModel *>(getGame().mLara->tmpHook));
1036 1036
         glPopMatrix();
1037 1037
     }
1038 1038
 
@@ -1041,7 +1041,7 @@ void Render::drawObjects()
1041 1041
     {
1042 1042
         std::vector<sprite_seq_t *> *sprites;
1043 1043
 
1044
-        sprites = gOpenRaider->mGame->mWorld.getSprites();
1044
+        sprites = getGame().mWorld.getSprites();
1045 1045
 
1046 1046
         for (unsigned int i = 0; i < sprites->size(); i++)
1047 1047
         {
@@ -1161,7 +1161,7 @@ void Render::drawModel(SkeletalModel *model)
1161 1161
 
1162 1162
                 if (tag2)
1163 1163
                 {
1164
-                    drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(tag2->mesh), Render::skeletalMesh);
1164
+                    drawModelMesh(getGame().mWorld.getMesh(tag2->mesh), Render::skeletalMesh);
1165 1165
                 }
1166 1166
             }
1167 1167
         }
@@ -1204,19 +1204,19 @@ void Render::drawModel(SkeletalModel *model)
1204 1204
                     {
1205 1205
                         glPushMatrix();
1206 1206
                         glTranslatef(mdl->ponyOff2, 0.0, 0.0);
1207
-                        drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mdl->ponytailMeshId + i),
1207
+                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1208 1208
                                 Render::skeletalMesh);
1209 1209
                         glPopMatrix();
1210 1210
 
1211 1211
                         glPushMatrix();
1212 1212
                         glTranslatef(-mdl->ponyOff2, 0.0, 0.0);
1213
-                        drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mdl->ponytailMeshId + i),
1213
+                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1214 1214
                                 Render::skeletalMesh);
1215 1215
                         glPopMatrix();
1216 1216
                     }
1217 1217
                     else
1218 1218
                     {
1219
-                        drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mdl->ponytailMeshId + i),
1219
+                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1220 1220
                                 Render::skeletalMesh);
1221 1221
                     }
1222 1222
                 }
@@ -1230,7 +1230,7 @@ void Render::drawModel(SkeletalModel *model)
1230 1230
             }
1231 1231
         }
1232 1232
 
1233
-        drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(tag->mesh), Render::skeletalMesh);
1233
+        drawModelMesh(getGame().mWorld.getMesh(tag->mesh), Render::skeletalMesh);
1234 1234
     }
1235 1235
 
1236 1236
     // Cycle frames ( cheap hack from old ent state based system )
@@ -1554,7 +1554,7 @@ void Render::drawSprite(sprite_t *sprite)
1554 1554
     glTranslated(sprite->pos[0], sprite->pos[1], sprite->pos[2]);
1555 1555
 
1556 1556
     // Sprites must always face camera, because they have no depth  =)
1557
-    glRotated(gOpenRaider->mGame->mCamera->getYaw(), 0, 1, 0);
1557
+    glRotated(getGame().mCamera->getYaw(), 0, 1, 0);
1558 1558
 
1559 1559
     switch (mMode)
1560 1560
     {
@@ -1612,7 +1612,7 @@ void Render::drawRoomModel(static_model_t *mesh)
1612 1612
     if (!mesh)
1613 1613
         return;
1614 1614
 
1615
-    r_mesh = gOpenRaider->mGame->mWorld.getMesh(mesh->index);
1615
+    r_mesh = getGame().mWorld.getMesh(mesh->index);
1616 1616
 
1617 1617
     if (!r_mesh)
1618 1618
         return;
@@ -1862,7 +1862,7 @@ void Render::ViewModel(entity_t *ent, int index)
1862 1862
         return;
1863 1863
     }
1864 1864
 
1865
-    model = gOpenRaider->mGame->mWorld.getModel(index);
1865
+    model = getGame().mWorld.getModel(index);
1866 1866
 
1867 1867
     if (model)
1868 1868
     {

+ 5
- 5
src/WindowSDL.cpp Ver fichero

@@ -182,7 +182,7 @@ void WindowSDL::eventHandling() {
182 182
     while(SDL_PollEvent(&event)) {
183 183
         switch (event.type) {
184 184
             case SDL_MOUSEMOTION:
185
-                gOpenRaider->handleMouseMotion(event.motion.xrel, event.motion.yrel);
185
+                getOpenRaider().handleMouseMotion(event.motion.xrel, event.motion.yrel);
186 186
                 break;
187 187
 
188 188
             case SDL_MOUSEBUTTONDOWN:
@@ -194,16 +194,16 @@ void WindowSDL::eventHandling() {
194 194
                     button = rightmouse;
195 195
                 else
196 196
                     button = middlemouse;
197
-                gOpenRaider->handleMouseClick(event.button.x, event.button.y, button, (event.type == SDL_MOUSEBUTTONUP));
197
+                getOpenRaider().handleMouseClick(event.button.x, event.button.y, button, (event.type == SDL_MOUSEBUTTONUP));
198 198
                 break;
199 199
 
200 200
             case SDL_MOUSEWHEEL:
201
-                gOpenRaider->handleMouseScroll(event.wheel.x, event.wheel.y);
201
+                getOpenRaider().handleMouseScroll(event.wheel.x, event.wheel.y);
202 202
                 break;
203 203
 
204 204
             case SDL_TEXTINPUT:
205 205
             case SDL_TEXTEDITING:
206
-                gOpenRaider->handleText(event.text.text, (event.type == SDL_TEXTEDITING));
206
+                getOpenRaider().handleText(event.text.text, (event.type == SDL_TEXTEDITING));
207 207
                 break;
208 208
 
209 209
             case SDL_KEYDOWN:
@@ -474,7 +474,7 @@ void WindowSDL::eventHandling() {
474 474
                         break;
475 475
 
476 476
                 }
477
-                gOpenRaider->handleKeyboard(key, (event.type == SDL_KEYDOWN));
477
+                getOpenRaider().handleKeyboard(key, (event.type == SDL_KEYDOWN));
478 478
                 break;
479 479
 
480 480
             case SDL_WINDOWEVENT:

+ 80
- 7
src/main.cpp Ver fichero

@@ -12,13 +12,50 @@
12 12
 #include "config.h"
13 13
 #include "main.h"
14 14
 #include "utils/time.h"
15
+#include "WindowSDL.h"
15 16
 
17
+Console *gConsole = NULL;
18
+Game *gGame = NULL;
19
+Menu *gMenu = NULL;
16 20
 OpenRaider *gOpenRaider = NULL;
21
+Window *gWindow = NULL;
22
+
23
+Console &getConsole() {
24
+    return *gConsole;
25
+}
26
+
27
+Game &getGame() {
28
+    return *gGame;
29
+}
30
+
31
+Menu &getMenu() {
32
+    return *gMenu;
33
+}
34
+
35
+OpenRaider &getOpenRaider() {
36
+    return *gOpenRaider;
37
+}
38
+
39
+Window &getWindow() {
40
+    return *gWindow;
41
+}
42
+
43
+void cleanupHandler(void) {
44
+    if (gConsole)
45
+        delete gConsole;
46
+
47
+    if (gGame)
48
+        delete gGame;
49
+
50
+    if (gMenu)
51
+        delete gMenu;
17 52
 
18
-void cleanupHandler() {
19 53
     if (gOpenRaider)
20 54
         delete gOpenRaider;
21 55
 
56
+    if (gWindow)
57
+        delete gWindow;
58
+
22 59
     printf("\nThanks for testing %s\n", VERSION);
23 60
     printf("Build date: %s @ %s\n", __DATE__, __TIME__);
24 61
     printf("Build host: %s\n", BUILD_HOST);
@@ -29,8 +66,6 @@ void cleanupHandler() {
29 66
 int main(int argc, char *argv[]) {
30 67
     const char *config = NULL;
31 68
 
32
-    systemTimerReset();
33
-
34 69
     // Handle arguments
35 70
     if (argc == 1) {
36 71
         // Use default rc file path
@@ -62,9 +97,13 @@ int main(int argc, char *argv[]) {
62 97
     }
63 98
 
64 99
     // Create globals
65
-    atexit(cleanupHandler);
66 100
     printf("Initializing %s\n", VERSION);
101
+    atexit(cleanupHandler);
67 102
     gOpenRaider = new OpenRaider();
103
+    gWindow = new WindowSDL();
104
+    gConsole = new Console();
105
+    gMenu = new Menu();
106
+    gGame = new Game();
68 107
 
69 108
     // Try to load a configuration
70 109
     if (gOpenRaider->loadConfig(config) != 0) {
@@ -76,11 +115,45 @@ int main(int argc, char *argv[]) {
76 115
         }
77 116
     }
78 117
 
79
-    // Initialize the "subsystems"
80
-    gOpenRaider->initialize();
118
+    // Initialize Windowing
119
+    int error = gWindow->initialize();
120
+    if (error != 0) {
121
+        printf("Could not initialize Window (%d)!\n", error);
122
+        return 3;
123
+    }
124
+
125
+    // Initialize OpenGL
126
+    error = gWindow->initializeGL();
127
+    if (error != 0) {
128
+        printf("Could not initialize OpenGL (%d)!\n", error);
129
+        return 4;
130
+    }
131
+
132
+    error = gWindow->initializeFont();
133
+    if (error != 0) {
134
+        printf("Could not initialize SDL-TTF (%d)!\n", error);
135
+        return 5;
136
+    }
137
+
138
+    error = gOpenRaider->initialize();
139
+    if (error != 0) {
140
+        printf("Could not initialize OpenRaider (%d)!\n", error);
141
+        return 6;
142
+    }
143
+
144
+    // Initialize game engine
145
+    error = gGame->initialize();
146
+    if (error != 0) {
147
+        printf("Could not initialize Game Engine (%d)!\n", error);
148
+        return 7;
149
+    }
150
+
151
+    gMenu->setVisible(true);
152
+
153
+    systemTimerReset();
81 154
 
82 155
     // Enter Main loop
83
-    gOpenRaider->mConsole->print("Starting %s", VERSION);
156
+    gConsole->print("Starting %s", VERSION);
84 157
     gOpenRaider->run();
85 158
 
86 159
     return 0;

Loading…
Cancelar
Guardar