Procházet zdrojové kódy

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

Thomas Buck před 10 roky
rodič
revize
ed67843df6
10 změnil soubory, kde provedl 356 přidání a 322 odebrání
  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 Zobrazit soubor

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

+ 9
- 6
include/main.h Zobrazit soubor

7
 #ifndef _MAIN_H_
7
 #ifndef _MAIN_H_
8
 #define _MAIN_H_
8
 #define _MAIN_H_
9
 
9
 
10
+#include "Console.h"
11
+#include "Game.h"
12
+#include "Menu.h"
10
 #include "OpenRaider.h"
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
  * \brief Program entry point
23
  * \brief Program entry point

+ 4
- 4
src/Camera.cpp Zobrazit soubor

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

+ 11
- 13
src/Console.cpp Zobrazit soubor

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

+ 71
- 71
src/Game.cpp Zobrazit soubor

64
 
64
 
65
     // Set up Renderer
65
     // Set up Renderer
66
     mRender = new Render();
66
     mRender = new Render();
67
-    mRender->initTextures(gOpenRaider->mDataDir, &mTextureStart, &mTextureLevelOffset);
67
+    mRender->initTextures(getOpenRaider().mDataDir, &mTextureStart, &mTextureLevelOffset);
68
 
68
 
69
     // Enable Renderer
69
     // Enable Renderer
70
     mRender->setMode(Render::modeLoadScreen);
70
     mRender->setMode(Render::modeLoadScreen);
84
 
84
 
85
     mWorld.destroy();
85
     mWorld.destroy();
86
     mRender->ClearWorld();
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
 int Game::loadLevel(const char *level) {
90
 int Game::loadLevel(const char *level) {
94
     mName = bufferString("%s", level);
94
     mName = bufferString("%s", level);
95
 
95
 
96
     // Load the level pak into TombRaider
96
     // Load the level pak into TombRaider
97
-    gOpenRaider->mConsole->print("Loading %s", mName);
97
+    getConsole().print("Loading %s", mName);
98
     int error = mTombRaider.Load(mName);
98
     int error = mTombRaider.Load(mName);
99
     if (error != 0) {
99
     if (error != 0) {
100
         return error;
100
         return error;
115
         tmp[dir + 8] = '\0';
115
         tmp[dir + 8] = '\0';
116
         error = mTombRaider.loadSFX(tmp);
116
         error = mTombRaider.loadSFX(tmp);
117
         if (error != 0) {
117
         if (error != 0) {
118
-            gOpenRaider->mConsole->print("Could not load %s", tmp);
118
+            getConsole().print("Could not load %s", tmp);
119
         }
119
         }
120
         delete [] tmp;
120
         delete [] tmp;
121
     }
121
     }
133
 
133
 
134
     // Check if the level contains Lara
134
     // Check if the level contains Lara
135
     if (mLara == NULL) {
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
         return -1;
137
         return -1;
138
     }
138
     }
139
 
139
 
187
 
187
 
188
 int Game::command(std::vector<char *> *args) {
188
 int Game::command(std::vector<char *> *args) {
189
     if (args->size() < 1) {
189
     if (args->size() < 1) {
190
-        gOpenRaider->mConsole->print("Invalid use of game-command!");
190
+        getConsole().print("Invalid use of game-command!");
191
         return -1;
191
         return -1;
192
     }
192
     }
193
 
193
 
198
             if (strcmp(mode, "wireframe") == 0) {
198
             if (strcmp(mode, "wireframe") == 0) {
199
                 if (mLoaded) {
199
                 if (mLoaded) {
200
                     mRender->setMode(Render::modeWireframe);
200
                     mRender->setMode(Render::modeWireframe);
201
-                    gOpenRaider->mConsole->print("Wireframe mode");
201
+                    getConsole().print("Wireframe mode");
202
                 } else {
202
                 } else {
203
-                    gOpenRaider->mConsole->print("Load a level to set this mode!");
203
+                    getConsole().print("Load a level to set this mode!");
204
                     return -2;
204
                     return -2;
205
                 }
205
                 }
206
             } else if (strcmp(mode, "solid") == 0) {
206
             } else if (strcmp(mode, "solid") == 0) {
207
                 if (mLoaded) {
207
                 if (mLoaded) {
208
                     mRender->setMode(Render::modeSolid);
208
                     mRender->setMode(Render::modeSolid);
209
-                    gOpenRaider->mConsole->print("Solid mode");
209
+                    getConsole().print("Solid mode");
210
                 } else {
210
                 } else {
211
-                    gOpenRaider->mConsole->print("Load a level to set this mode!");
211
+                    getConsole().print("Load a level to set this mode!");
212
                     return -3;
212
                     return -3;
213
                 }
213
                 }
214
             } else if (strcmp(mode, "texture") == 0) {
214
             } else if (strcmp(mode, "texture") == 0) {
215
                 if (mLoaded) {
215
                 if (mLoaded) {
216
                     mRender->setMode(Render::modeTexture);
216
                     mRender->setMode(Render::modeTexture);
217
-                    gOpenRaider->mConsole->print("Texture mode");
217
+                    getConsole().print("Texture mode");
218
                 } else {
218
                 } else {
219
-                    gOpenRaider->mConsole->print("Load a level to set this mode!");
219
+                    getConsole().print("Load a level to set this mode!");
220
                     return -4;
220
                     return -4;
221
                 }
221
                 }
222
             } else if (strcmp(mode, "vertexlight") == 0) {
222
             } else if (strcmp(mode, "vertexlight") == 0) {
223
                 if (mLoaded) {
223
                 if (mLoaded) {
224
                     mRender->setMode(Render::modeVertexLight);
224
                     mRender->setMode(Render::modeVertexLight);
225
-                    gOpenRaider->mConsole->print("Vertexlight mode");
225
+                    getConsole().print("Vertexlight mode");
226
                 } else {
226
                 } else {
227
-                    gOpenRaider->mConsole->print("Load a level to set this mode!");
227
+                    getConsole().print("Load a level to set this mode!");
228
                     return -5;
228
                     return -5;
229
                 }
229
                 }
230
             } else if (strcmp(mode, "titlescreen") == 0) {
230
             } else if (strcmp(mode, "titlescreen") == 0) {
231
                 mRender->setMode(Render::modeLoadScreen);
231
                 mRender->setMode(Render::modeLoadScreen);
232
-                gOpenRaider->mConsole->print("Titlescreen mode");
232
+                getConsole().print("Titlescreen mode");
233
             } else {
233
             } else {
234
-                gOpenRaider->mConsole->print("Invalid use of mode command (%s)!", mode);
234
+                getConsole().print("Invalid use of mode command (%s)!", mode);
235
                 return -6;
235
                 return -6;
236
             }
236
             }
237
         } else {
237
         } else {
238
-            gOpenRaider->mConsole->print("Invalid use of mode command!");
238
+            getConsole().print("Invalid use of mode command!");
239
             return -7;
239
             return -7;
240
         }
240
         }
241
     } else if (strcmp(cmd, "move") == 0) {
241
     } else if (strcmp(cmd, "move") == 0) {
244
                 char *move = args->at(1);
244
                 char *move = args->at(1);
245
                 if (strcmp(move, "walk") == 0) {
245
                 if (strcmp(move, "walk") == 0) {
246
                     mLara->moveType = worldMoveType_walk;
246
                     mLara->moveType = worldMoveType_walk;
247
-                    gOpenRaider->mConsole->print("Lara is walking...");
247
+                    getConsole().print("Lara is walking...");
248
                 } else if (strcmp(move, "fly") == 0) {
248
                 } else if (strcmp(move, "fly") == 0) {
249
                     mLara->moveType = worldMoveType_fly;
249
                     mLara->moveType = worldMoveType_fly;
250
-                    gOpenRaider->mConsole->print("Lara is flying...");
250
+                    getConsole().print("Lara is flying...");
251
                 } else if (strcmp(move, "noclip") == 0) {
251
                 } else if (strcmp(move, "noclip") == 0) {
252
                     mLara->moveType = worldMoveType_noClipping;
252
                     mLara->moveType = worldMoveType_noClipping;
253
-                    gOpenRaider->mConsole->print("Lara is noclipping...");
253
+                    getConsole().print("Lara is noclipping...");
254
                 } else {
254
                 } else {
255
-                    gOpenRaider->mConsole->print("Invalid use of move command (%s)!", move);
255
+                    getConsole().print("Invalid use of move command (%s)!", move);
256
                     return -8;
256
                     return -8;
257
                 }
257
                 }
258
             } else {
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
                 return -9;
260
                 return -9;
261
             }
261
             }
262
         } else {
262
         } else {
263
-            gOpenRaider->mConsole->print("Invalid use of move command!");
263
+            getConsole().print("Invalid use of move command!");
264
             return -10;
264
             return -10;
265
         }
265
         }
266
     } else if (strcmp(cmd, "sound") == 0) {
266
     } else if (strcmp(cmd, "sound") == 0) {
267
         if (args->size() > 1) {
267
         if (args->size() > 1) {
268
-            gOpenRaider->mSound->play(atoi(args->at(1)));
268
+            getOpenRaider().mSound->play(atoi(args->at(1)));
269
         } else {
269
         } else {
270
-            gOpenRaider->mConsole->print("Invalid use of sound command!");
270
+            getConsole().print("Invalid use of sound command!");
271
             return -11;
271
             return -11;
272
         }
272
         }
273
     } else if (strcmp(cmd, "animate") == 0) {
273
     } else if (strcmp(cmd, "animate") == 0) {
285
                                 m->setAnimation(0);
285
                                 m->setAnimation(0);
286
                     }
286
                     }
287
                 } else {
287
                 } else {
288
-                    gOpenRaider->mConsole->print("Animations need to be enabled!");
288
+                    getConsole().print("Animations need to be enabled!");
289
                 }
289
                 }
290
             } else if (c == 'p') {
290
             } else if (c == 'p') {
291
                 // Step all skeletal models to their previous animation
291
                 // Step all skeletal models to their previous animation
299
                                 m->setAnimation(m->model->animation.size() - 1);
299
                                 m->setAnimation(m->model->animation.size() - 1);
300
                     }
300
                     }
301
                 } else {
301
                 } else {
302
-                    gOpenRaider->mConsole->print("Animations need to be enabled!");
302
+                    getConsole().print("Animations need to be enabled!");
303
                 }
303
                 }
304
             } else {
304
             } else {
305
                 // Enable or disable animating all skeletal models
305
                 // Enable or disable animating all skeletal models
306
                 bool b;
306
                 bool b;
307
                 if (readBool(args->at(1), &b) < 0) {
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
                     return -12;
309
                     return -12;
310
                 }
310
                 }
311
                 if (b)
311
                 if (b)
312
                     mRender->setFlags(Render::fAnimateAllModels);
312
                     mRender->setFlags(Render::fAnimateAllModels);
313
                 else
313
                 else
314
                     mRender->clearFlags(Render::fAnimateAllModels);
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
         } else {
317
         } else {
318
-            gOpenRaider->mConsole->print("Invalid use of animate command!");
318
+            getConsole().print("Invalid use of animate command!");
319
             return -13;
319
             return -13;
320
         }
320
         }
321
     } else if (strcmp(cmd, "help") == 0) {
321
     } else if (strcmp(cmd, "help") == 0) {
322
         if (args->size() < 2) {
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
         } else if (strcmp(args->at(1), "sound") == 0) {
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
         } else if (strcmp(args->at(1), "move") == 0) {
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
         } else if (strcmp(args->at(1), "mode") == 0) {
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
         } else if (strcmp(args->at(1), "animate") == 0) {
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
         } else {
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
             return -14;
359
             return -14;
360
         }
360
         }
361
     } else {
361
     } else {
362
-        gOpenRaider->mConsole->print("Invalid use of game-command (%s)!", cmd);
362
+        getConsole().print("Invalid use of game-command (%s)!", cmd);
363
         return -15;
363
         return -15;
364
     }
364
     }
365
 
365
 
390
     {
390
     {
391
         mTombRaider.getSoundSample(i, &riffSz, &riff);
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
         //if (((i + 1) == TR_SOUND_F_PISTOL) && (id > 0))
395
         //if (((i + 1) == TR_SOUND_F_PISTOL) && (id > 0))
396
         //{
396
         //{
404
         //pos[0] = sound[i].x;
404
         //pos[0] = sound[i].x;
405
         //pos[1] = sound[i].y;
405
         //pos[1] = sound[i].y;
406
         //pos[2] = sound[i].z;
406
         //pos[2] = sound[i].z;
407
-        //gOpenRaider->mSound->SourceAt(id, pos);
407
+        //getOpenRaider().mSound->SourceAt(id, pos);
408
 
408
 
409
         //printf(".");
409
         //printf(".");
410
         //fflush(stdout);
410
         //fflush(stdout);
868
                     }
868
                     }
869
 
869
 
870
                     mRender->setFlags(Render::fRenderPonytail);
870
                     mRender->setFlags(Render::fRenderPonytail);
871
-                    gOpenRaider->mConsole->print("Found known ponytail");
871
+                    getConsole().print("Found known ponytail");
872
                 }
872
                 }
873
                 break; // ?
873
                 break; // ?
874
             case TR_VERSION_1:
874
             case TR_VERSION_1:
890
                     r_model->ponyOff2 = 0;
890
                     r_model->ponyOff2 = 0;
891
 
891
 
892
                     mRender->setFlags(Render::fRenderPonytail);
892
                     mRender->setFlags(Render::fRenderPonytail);
893
-                    gOpenRaider->mConsole->print("Found ponytail?");
893
+                    getConsole().print("Found ponytail?");
894
                 }
894
                 }
895
                 break;
895
                 break;
896
         }
896
         }
1009
             //   if (frame_offset + 8 > _tombraider.NumFrames())
1009
             //   if (frame_offset + 8 > _tombraider.NumFrames())
1010
             if (frame_offset > mTombRaider.NumFrames())
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
                         frame_offset, mTombRaider.NumFrames());
1013
                         frame_offset, mTombRaider.NumFrames());
1014
 
1014
 
1015
                 // Mongoose 2002.08.15, Attempt to skip more likely bad animation data
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
                 return; //continue;
1017
                 return; //continue;
1018
             }
1018
             }
1019
 
1019
 
1366
 
1366
 
1367
         if (!mTombRaider.isRoomValid(index))
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
             mWorld.addRoom(0x0);
1370
             mWorld.addRoom(0x0);
1371
             mRender->addRoom(0x0);
1371
             mRender->addRoom(0x0);
1372
 
1372
 
1585
 
1585
 
1586
             if (texture > (int)TextureLimit)
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
                         index, t, texture);
1589
                         index, t, texture);
1590
                 texture = TextureLimit - 1;
1590
                 texture = TextureLimit - 1;
1591
             }
1591
             }
1619
 
1619
 
1620
             if (texture > (int)TextureLimit)
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
                         index, r, texture);
1623
                         index, r, texture);
1624
                 texture = TextureLimit - 1;
1624
                 texture = TextureLimit - 1;
1625
             }
1625
             }

+ 22
- 24
src/Menu.cpp Zobrazit soubor

47
 
47
 
48
 void Menu::displayMapList() {
48
 void Menu::displayMapList() {
49
     // Estimate displayable number of items
49
     // Estimate displayable number of items
50
-    int items = (gOpenRaider->mWindow->mHeight - 110) / 25;
50
+    int items = (getWindow().mHeight - 110) / 25;
51
 
51
 
52
     // Select which part of the list to show
52
     // Select which part of the list to show
53
     int min, max;
53
     int min, max;
56
     else
56
     else
57
         min = 0;
57
         min = 0;
58
 
58
 
59
-    if ((mCursor + (items / 2)) < gOpenRaider->mMapList.size())
59
+    if ((mCursor + (items / 2)) < getOpenRaider().mMapList.size())
60
         max = mCursor + (items / 2);
60
         max = mCursor + (items / 2);
61
     else
61
     else
62
-        max = gOpenRaider->mMapList.size();
62
+        max = getOpenRaider().mMapList.size();
63
 
63
 
64
     while ((max - min) < items) {
64
     while ((max - min) < items) {
65
         if (min > 0)
65
         if (min > 0)
66
             min--;
66
             min--;
67
-        else if (max < ((int)gOpenRaider->mMapList.size()))
67
+        else if (max < ((int)getOpenRaider().mMapList.size()))
68
             max++;
68
             max++;
69
         else
69
         else
70
             break;
70
             break;
73
     mMin = min;
73
     mMin = min;
74
 
74
 
75
     for (int i = 0; i < (max - min); i++) {
75
     for (int i = 0; i < (max - min); i++) {
76
-        char *map = gOpenRaider->mMapList[i + min];
76
+        char *map = getOpenRaider().mMapList[i + min];
77
         if ((i + min) == (int)mCursor)
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
         else
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
 void Menu::display() {
84
 void Menu::display() {
85
-    Window *window = gOpenRaider->mWindow;
86
-
87
     if (mVisible) {
85
     if (mVisible) {
88
         // Draw half-transparent *overlay*
86
         // Draw half-transparent *overlay*
89
         glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
87
         glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
90
         glDisable(GL_TEXTURE_2D);
88
         glDisable(GL_TEXTURE_2D);
91
-        glRecti(0, 0, window->mWidth, window->mHeight);
89
+        glRecti(0, 0, getWindow().mWidth, getWindow().mHeight);
92
         glEnable(GL_TEXTURE_2D);
90
         glEnable(GL_TEXTURE_2D);
93
 
91
 
94
         // Draw heading text
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
         } else {
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
             } else {
101
             } else {
104
                 // draw *play button* above list
102
                 // draw *play button* above list
105
                 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
103
                 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
106
                 glDisable(GL_TEXTURE_2D);
104
                 glDisable(GL_TEXTURE_2D);
107
                 glRecti(25, 25, 100, 75);
105
                 glRecti(25, 25, 100, 75);
108
                 glEnable(GL_TEXTURE_2D);
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
                 displayMapList();
109
                 displayMapList();
112
             }
110
             }
122
         if (mCursor > 0)
120
         if (mCursor > 0)
123
             mCursor--;
121
             mCursor--;
124
         else
122
         else
125
-            mCursor = gOpenRaider->mMapList.size() - 1;
123
+            mCursor = getOpenRaider().mMapList.size() - 1;
126
     } else if (key == down) {
124
     } else if (key == down) {
127
-        if (mCursor < (gOpenRaider->mMapList.size() - 1))
125
+        if (mCursor < (getOpenRaider().mMapList.size() - 1))
128
             mCursor++;
126
             mCursor++;
129
         else
127
         else
130
             mCursor = 0;
128
             mCursor = 0;
131
     } else if (key == right) {
129
     } else if (key == right) {
132
         int i = 10;
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
         while (i-- > 0)
133
         while (i-- > 0)
136
             handleKeyboard(down, true);
134
             handleKeyboard(down, true);
137
     } else if (key == left) {
135
     } else if (key == left) {
141
         while (i-- > 0)
139
         while (i-- > 0)
142
             handleKeyboard(up, true);
140
             handleKeyboard(up, true);
143
     } else if (key == enter) {
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
             setVisible(false);
144
             setVisible(false);
147
         delete [] tmp;
145
         delete [] tmp;
148
     }
146
     }
149
 }
147
 }
150
 
148
 
151
 void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
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
     if ((!released) || (button != leftmouse))
152
     if ((!released) || (button != leftmouse))
155
         return;
153
         return;

+ 102
- 136
src/OpenRaider.cpp Zobrazit soubor

15
 #include "config.h"
15
 #include "config.h"
16
 #include "Console.h"
16
 #include "Console.h"
17
 #include "Game.h"
17
 #include "Game.h"
18
+#include "main.h"
18
 #include "math/math.h"
19
 #include "math/math.h"
19
 #include "Menu.h"
20
 #include "Menu.h"
20
 #include "Sound.h"
21
 #include "Sound.h"
21
 #include "TombRaider.h"
22
 #include "TombRaider.h"
22
-#include "Window.h"
23
 #include "utils/strings.h"
23
 #include "utils/strings.h"
24
 #include "utils/time.h"
24
 #include "utils/time.h"
25
 #include "OpenRaider.h"
25
 #include "OpenRaider.h"
34
     mDataDir = NULL;
34
     mDataDir = NULL;
35
     mMapListFilled = false;
35
     mMapListFilled = false;
36
 
36
 
37
-    mMenu = new Menu();
38
-    mConsole = new Console();
39
     mSound = new Sound();
37
     mSound = new Sound();
40
-    mWindow = new WindowSDL();
41
-    mGame = new Game();
42
 
38
 
43
     for (int i = 0; i < ActionEventCount; i++)
39
     for (int i = 0; i < ActionEventCount; i++)
44
         keyBindings[i] = unknown;
40
         keyBindings[i] = unknown;
48
 }
44
 }
49
 
45
 
50
 OpenRaider::~OpenRaider() {
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
     if (mSound)
47
     if (mSound)
61
         delete mSound;
48
         delete mSound;
62
 
49
 
63
-    if (mWindow)
64
-        delete mWindow;
65
-
66
     if (mBaseDir)
50
     if (mBaseDir)
67
         delete mBaseDir;
51
         delete mBaseDir;
68
 
52
 
86
     assert(config[0] != '\0');
70
     assert(config[0] != '\0');
87
 
71
 
88
     char *configFile = fullPath(config, 0);
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
     FILE *f = fopen(configFile, "r");
75
     FILE *f = fopen(configFile, "r");
92
     if (f == NULL) {
76
     if (f == NULL) {
93
-        mConsole->print("Could not open file!");
77
+        getConsole().print("Could not open file!");
94
         return -1;
78
         return -1;
95
     }
79
     }
96
 
80
 
98
     while (fgets(buffer, 256, f) != NULL) {
82
     while (fgets(buffer, 256, f) != NULL) {
99
         int error = command(buffer);
83
         int error = command(buffer);
100
         if (error != 0) {
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
 
132
 
149
     if (strcmp(command, "set") == 0) {
133
     if (strcmp(command, "set") == 0) {
150
         if (args->size() != 2) {
134
         if (args->size() != 2) {
151
-            mConsole->print("Invalid use of set-command");
135
+            getConsole().print("Invalid use of set-command");
152
             return -2;
136
             return -2;
153
         } else {
137
         } else {
154
             return set(args->at(0), args->at(1));
138
             return set(args->at(0), args->at(1));
155
         }
139
         }
156
     } else if (strcmp(command, "bind") == 0) {
140
     } else if (strcmp(command, "bind") == 0) {
157
         if (args->size() != 2) {
141
         if (args->size() != 2) {
158
-            mConsole->print("Invalid use of bind-command");
142
+            getConsole().print("Invalid use of bind-command");
159
             return -3;
143
             return -3;
160
         } else {
144
         } else {
161
             return bind(args->at(0), args->at(1));
145
             return bind(args->at(0), args->at(1));
164
         exit(0);
148
         exit(0);
165
     } else if (strcmp(command, "help") == 0) {
149
     } else if (strcmp(command, "help") == 0) {
166
         if (args->size() == 0) {
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
         } else if (args->size() == 1) {
159
         } else if (args->size() == 1) {
176
             return help(args->at(0));
160
             return help(args->at(0));
177
         } else {
161
         } else {
178
-            mConsole->print("Invalid use of help-command");
162
+            getConsole().print("Invalid use of help-command");
179
             return -4;
163
             return -4;
180
         }
164
         }
181
     } else if (strcmp(command, "load") == 0) {
165
     } else if (strcmp(command, "load") == 0) {
182
         char *tmp = bufferString("%s/%s", mPakDir, args->at(0));
166
         char *tmp = bufferString("%s/%s", mPakDir, args->at(0));
183
-        int error = mGame->loadLevel(tmp);
167
+        int error = getGame().loadLevel(tmp);
184
         delete [] tmp;
168
         delete [] tmp;
185
         return error;
169
         return error;
186
     } else if (strcmp(command, "game") == 0) {
170
     } else if (strcmp(command, "game") == 0) {
187
-        return mGame->command(args);
171
+        return getGame().command(args);
188
     } else {
172
     } else {
189
-        mConsole->print("Unknown command: %s ", command);
173
+        getConsole().print("Unknown command: %s ", command);
190
         return -1;
174
         return -1;
191
     }
175
     }
192
 
176
 
198
     assert(cmd[0] != '\0');
182
     assert(cmd[0] != '\0');
199
 
183
 
200
     if (strcmp(cmd, "set") == 0) {
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
     } else if (strcmp(cmd, "bind") == 0) {
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
     } else if (strcmp(cmd, "load") == 0) {
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
     } else if (strcmp(cmd, "game") == 0) {
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
     } else {
225
     } else {
242
-        mConsole->print("No help available for %s", cmd);
226
+        getConsole().print("No help available for %s", cmd);
243
         return -1;
227
         return -1;
244
     }
228
     }
245
 
229
 
304
         // value has format like "\"1024x768\""
288
         // value has format like "\"1024x768\""
305
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
289
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
306
         if (sscanf(value, "\"%dx%d\"", &w, &h) != 2) {
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
             return -2;
292
             return -2;
309
         }
293
         }
310
-        mWindow->setSize(w, h);
294
+        getWindow().setSize(w, h);
311
     } else if (strcmp(var, "fullscreen") == 0) {
295
     } else if (strcmp(var, "fullscreen") == 0) {
312
         bool fullscreen = false;
296
         bool fullscreen = false;
313
         if (readBool(value, &fullscreen) != 0) {
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
             return -3;
299
             return -3;
316
         }
300
         }
317
-        mWindow->setFullscreen(fullscreen);
301
+        getWindow().setFullscreen(fullscreen);
318
     } else if (strcmp(var, "gldriver") == 0) {
302
     } else if (strcmp(var, "gldriver") == 0) {
319
-        mWindow->setDriver(value);
303
+        getWindow().setDriver(value);
320
     } else if (strcmp(var, "audio") == 0) {
304
     } else if (strcmp(var, "audio") == 0) {
321
         bool audio = false;
305
         bool audio = false;
322
         if (readBool(value, &audio) != 0) {
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
             return -4;
308
             return -4;
325
         }
309
         }
326
         mSound->setEnabled(audio);
310
         mSound->setEnabled(audio);
327
     } else if (strcmp(var, "volume") == 0) {
311
     } else if (strcmp(var, "volume") == 0) {
328
         float vol = 1.0f;
312
         float vol = 1.0f;
329
         if (sscanf(value, "%f", &vol) != 1) {
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
             return -5;
315
             return -5;
332
         }
316
         }
333
         mSound->setVolume(vol);
317
         mSound->setVolume(vol);
334
     } else if (strcmp(var, "mouse_x") == 0) {
318
     } else if (strcmp(var, "mouse_x") == 0) {
335
         float sense = 1.0f;
319
         float sense = 1.0f;
336
         if (sscanf(value, "%f", &sense) != 1) {
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
             return -6;
322
             return -6;
339
         }
323
         }
340
         mCameraRotationDeltaX = OR_DEG_TO_RAD(sense);
324
         mCameraRotationDeltaX = OR_DEG_TO_RAD(sense);
341
     } else if (strcmp(var, "mouse_y") == 0) {
325
     } else if (strcmp(var, "mouse_y") == 0) {
342
         float sense = 1.0f;
326
         float sense = 1.0f;
343
         if (sscanf(value, "%f", &sense) != 1) {
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
             return -7;
329
             return -7;
346
         }
330
         }
347
         mCameraRotationDeltaY = OR_DEG_TO_RAD(sense);
331
         mCameraRotationDeltaY = OR_DEG_TO_RAD(sense);
348
     } else if (strcmp(var, "fps") == 0) {
332
     } else if (strcmp(var, "fps") == 0) {
349
         bool fps = false;
333
         bool fps = false;
350
         if (readBool(value, &fps) != 0) {
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
             return -8;
336
             return -8;
353
         }
337
         }
354
         mFPS = fps;
338
         mFPS = fps;
364
         char *quotes = stringReplace(value, "\"", "");
348
         char *quotes = stringReplace(value, "\"", "");
365
         char *tmp = expandDirectoryNames(quotes);
349
         char *tmp = expandDirectoryNames(quotes);
366
         if (tmp == NULL) {
350
         if (tmp == NULL) {
367
-            mWindow->setFont(quotes);
351
+            getWindow().setFont(quotes);
368
         } else {
352
         } else {
369
-            mWindow->setFont(tmp);
353
+            getWindow().setFont(tmp);
370
             delete [] tmp;
354
             delete [] tmp;
371
         }
355
         }
372
         delete [] quotes;
356
         delete [] quotes;
373
     } else {
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
         return -1;
359
         return -1;
376
     }
360
     }
377
 
361
 
409
     } else if (strcmp(tmp, "holster") == 0) {
393
     } else if (strcmp(tmp, "holster") == 0) {
410
         return bind(holsterAction, key);
394
         return bind(holsterAction, key);
411
     } else {
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
         return -1;
397
         return -1;
414
     }
398
     }
415
 }
399
 }
427
             || ((c >= 'a') && (c <= 'z'))) {
411
             || ((c >= 'a') && (c <= 'z'))) {
428
             keyBindings[action] = (KeyboardButton)c;
412
             keyBindings[action] = (KeyboardButton)c;
429
         } else {
413
         } else {
430
-            mConsole->print("bind-\'\'-Error: Unknown key (%s)", key);
414
+            getConsole().print("bind-\'\'-Error: Unknown key (%s)", key);
431
             return -1;
415
             return -1;
432
         }
416
         }
433
     } else if ((key[0] == '\"') && (key[length - 1] == '\"')) {
417
     } else if ((key[0] == '\"') && (key[length - 1] == '\"')) {
540
         } else if (strcmp(tmp, "rightmouse") == 0) {
524
         } else if (strcmp(tmp, "rightmouse") == 0) {
541
             keyBindings[action] = rightmouse;
525
             keyBindings[action] = rightmouse;
542
         } else {
526
         } else {
543
-            mConsole->print("bind-\"\"-Error: Unknown key (%s)", key);
527
+            getConsole().print("bind-\"\"-Error: Unknown key (%s)", key);
544
             delete [] tmp;
528
             delete [] tmp;
545
             return -2;
529
             return -2;
546
         }
530
         }
547
         delete [] tmp;
531
         delete [] tmp;
548
     } else {
532
     } else {
549
-        mConsole->print("bind-Error: Unknown key (%s)", key);
533
+        getConsole().print("bind-Error: Unknown key (%s)", key);
550
         return -3;
534
         return -3;
551
     }
535
     }
552
     return 0;
536
     return 0;
589
                         // Just load relative filename
573
                         // Just load relative filename
590
                         mMapList.push_back(bufferString("%s", (fullPathMap + strlen(mPakDir) + 1)));
574
                         mMapList.push_back(bufferString("%s", (fullPathMap + strlen(mPakDir) + 1)));
591
                     } else {
575
                     } else {
592
-                        mConsole->print("Error: pak file '%s' %s",
576
+                        getConsole().print("Error: pak file '%s' %s",
593
                                 fullPathMap, (error == -1) ? "not found" : "invalid");
577
                                 fullPathMap, (error == -1) ? "not found" : "invalid");
594
                     }
578
                     }
595
                 }
579
                 }
600
         }
584
         }
601
         closedir(pakDir);
585
         closedir(pakDir);
602
     } else {
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
     assert(mInit == false);
602
     assert(mInit == false);
619
     assert(mRunning == false);
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
     // Initialize sound
605
     // Initialize sound
634
     if (mSound->initialize() != 0)
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
     mInit = true;
609
     mInit = true;
644
 
610
 
657
         clock_t startTime = systemTimerGet();
623
         clock_t startTime = systemTimerGet();
658
 
624
 
659
         // Get keyboard and mouse input
625
         // Get keyboard and mouse input
660
-        mWindow->eventHandling();
626
+        getWindow().eventHandling();
661
 
627
 
662
         // Clear screen
628
         // Clear screen
663
         glClearColor(0.00f, 0.00f, 0.00f, 1.0f);
629
         glClearColor(0.00f, 0.00f, 0.00f, 1.0f);
664
         glClear(GL_COLOR_BUFFER_BIT);
630
         glClear(GL_COLOR_BUFFER_BIT);
665
 
631
 
666
         // Draw game scene
632
         // Draw game scene
667
-        mGame->display();
633
+        getGame().display();
668
 
634
 
669
         // Draw 2D overlays (console and menu)
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
         // Draw FPS counter
641
         // Draw FPS counter
676
         if (mFPS)
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
         // Put new frame on screen
647
         // Put new frame on screen
682
-        mWindow->swapBuffersGL();
648
+        getWindow().swapBuffersGL();
683
 
649
 
684
         // Fill map list after first render pass,
650
         // Fill map list after first render pass,
685
         // so menu *loading screen* is visible
651
         // so menu *loading screen* is visible
703
     assert(mRunning == true);
669
     assert(mRunning == true);
704
 
670
 
705
     if ((keyBindings[menuAction] == key) && pressed) {
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
         if ((keyBindings[consoleAction] == key) && pressed) {
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
             for (int i = forwardAction; i < ActionEventCount; i++) {
677
             for (int i = forwardAction; i < ActionEventCount; i++) {
712
                 if (keyBindings[i] == key) {
678
                 if (keyBindings[i] == key) {
713
-                    mGame->handleAction((ActionEvents)i, pressed);
679
+                    getGame().handleAction((ActionEvents)i, pressed);
714
                 }
680
                 }
715
             }
681
             }
716
         } else {
682
         } else {
717
-            mConsole->handleKeyboard(key, pressed);
683
+            getConsole().handleKeyboard(key, pressed);
718
         }
684
         }
719
     } else {
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
 void OpenRaider::handleText(char *text, bool notFinished) {
692
 void OpenRaider::handleText(char *text, bool notFinished) {
729
     assert(mInit == true);
695
     assert(mInit == true);
730
     assert(mRunning == true);
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
     assert(mInit == true);
705
     assert(mInit == true);
740
     assert(mRunning == true);
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
         for (int i = forwardAction; i < ActionEventCount; i++) {
711
         for (int i = forwardAction; i < ActionEventCount; i++) {
746
             if (keyBindings[i] == button) {
712
             if (keyBindings[i] == button) {
747
-                mGame->handleAction((ActionEvents)i, !released);
713
+                getGame().handleAction((ActionEvents)i, !released);
748
             }
714
             }
749
         }
715
         }
750
     }
716
     }
755
     assert(mInit == true);
721
     assert(mInit == true);
756
     assert(mRunning == true);
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
     assert(mInit == true);
731
     assert(mInit == true);
766
     assert(mRunning == true);
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 Zobrazit soubor

36
     if (!a || !b)
36
     if (!a || !b)
37
         return false; // error really
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
             a->pos[1],
40
             a->pos[1],
41
             a->pos[2],
41
             a->pos[2],
42
             1.0f);
42
             1.0f);
43
-    distB = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
43
+    distB = getGame().mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
44
             b->pos[1],
44
             b->pos[1],
45
             b->pos[2],
45
             b->pos[2],
46
             1.0f);
46
             1.0f);
57
     if (!a || !b)
57
     if (!a || !b)
58
         return false; // error really
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
             a->pos[1],
61
             a->pos[1],
62
             a->pos[2],
62
             a->pos[2],
63
             128.0f);
63
             128.0f);
64
-    distB = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
64
+    distB = getGame().mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
65
             b->pos[1],
65
             b->pos[1],
66
             b->pos[2],
66
             b->pos[2],
67
             128.0f);
67
             128.0f);
117
 
117
 
118
 void Render::screenShot(char *filenameBase)
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
 unsigned int Render::getFlags() {
123
 unsigned int Render::getFlags() {
234
 
234
 
235
 void Render::ClearWorld()
235
 void Render::ClearWorld()
236
 {
236
 {
237
-    gOpenRaider->mGame->mLara = NULL;
237
+    getGame().mLara = NULL;
238
 
238
 
239
     mRoomRenderList.clear();
239
     mRoomRenderList.clear();
240
 
240
 
509
 
509
 
510
     index = -1;
510
     index = -1;
511
 
511
 
512
-    if (gOpenRaider->mGame->mLara)
512
+    if (getGame().mLara)
513
     {
513
     {
514
         float yaw;
514
         float yaw;
515
         int sector;
515
         int sector;
516
         float camOffsetH = 0.0f;
516
         float camOffsetH = 0.0f;
517
 
517
 
518
 
518
 
519
-        switch (gOpenRaider->mGame->mLara->moveType)
519
+        switch (getGame().mLara->moveType)
520
         {
520
         {
521
             case worldMoveType_fly:
521
             case worldMoveType_fly:
522
             case worldMoveType_noClipping:
522
             case worldMoveType_noClipping:
529
                 break;
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
         // Mongoose 2002.08.24, New 3rd person camera hack
539
         // Mongoose 2002.08.24, New 3rd person camera hack
540
         camPos[0] = curPos[0];
540
         camPos[0] = curPos[0];
544
         camPos[0] -= (1024.0f * sinf(yaw));
544
         camPos[0] -= (1024.0f * sinf(yaw));
545
         camPos[2] -= (1024.0f * cosf(yaw));
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
         // Handle camera out of world
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
             camPos[0] = curPos[0] + (64.0f * sinf(yaw));
552
             camPos[0] = curPos[0] + (64.0f * sinf(yaw));
553
             camPos[1] -= 64.0f;
553
             camPos[1] -= 64.0f;
554
             camPos[2] = curPos[2] + (64.0f * cosf(yaw));
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
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
560
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
561
     glLoadIdentity();
561
     glLoadIdentity();
562
 
562
 
563
     // Setup view in OpenGL with camera
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
     // Mongoose 2002.08.13, Quick fix to render OpenRaider upside down
567
     // Mongoose 2002.08.13, Quick fix to render OpenRaider upside down
568
 
568
 
569
     gluLookAt(camPos[0], camPos[1], camPos[2], atPos[0], atPos[1], atPos[2], 0.0f, -1.0f, 0.0f);
569
     gluLookAt(camPos[0], camPos[1], camPos[2], atPos[0], atPos[1], atPos[2], 0.0f, -1.0f, 0.0f);
572
     updateViewVolume();
572
     updateViewVolume();
573
 
573
 
574
     // Let's see the LoS -- should be event controled
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
         // Draw in solid colors
579
         // Draw in solid colors
580
         glDisable(GL_TEXTURE_2D);
580
         glDisable(GL_TEXTURE_2D);
581
         glDisable(GL_CULL_FACE);
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
             vec3_t u, v; //, s, t;
585
             vec3_t u, v; //, s, t;
586
 
586
 
587
-            // Center of gOpenRaider->mGame->mLara
587
+            // Center of getGame().mLara
588
             u[0] = curPos[0];
588
             u[0] = curPos[0];
589
             u[1] = curPos[1] - 512.0f;
589
             u[1] = curPos[1] - 512.0f;
590
             u[2] = curPos[2];
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
             // Test tracing of aim
597
             // Test tracing of aim
598
             renderTrace(0, u, v); // v = target
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
         while (route)
603
         while (route)
604
         {
604
         {
642
     {
642
     {
643
         entity_t *e;
643
         entity_t *e;
644
         std::vector<entity_t *> entityRenderList;
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
         for (unsigned int i = 0; i < entities->size(); i++)
647
         for (unsigned int i = 0; i < entities->size(); i++)
648
         {
648
         {
649
             e = entities->at(i);
649
             e = entities->at(i);
650
 
650
 
651
             // Mongoose 2002.03.26, Don't show lara to it's own player
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
                 continue;
654
                 continue;
655
             }
655
             }
759
     float x = 0.0f, y = 0.0f, z = -160.0f;
759
     float x = 0.0f, y = 0.0f, z = -160.0f;
760
     float w, h;
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
     else
764
     else
765
-        w = h = (float)gOpenRaider->mWindow->mHeight;
765
+        w = h = (float)getWindow().mHeight;
766
 
766
 
767
 
767
 
768
     if (mTexture.getTextureCount() <= 0)
768
     if (mTexture.getTextureCount() <= 0)
956
 
956
 
957
 void Render::drawSkyMesh(float scale)
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
     if (!model)
962
     if (!model)
973
     glTranslated(0.0, 1000.0, 0.0);
973
     glTranslated(0.0, 1000.0, 0.0);
974
     glScaled(scale, scale, scale);
974
     glScaled(scale, scale, scale);
975
     //drawModel(model);
975
     //drawModel(model);
976
-    //drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mSkyMesh), );
976
+    //drawModelMesh(getGame().mWorld.getMesh(mSkyMesh), );
977
     glPopMatrix();
977
     glPopMatrix();
978
     glEnable(GL_DEPTH_TEST);
978
     glEnable(GL_DEPTH_TEST);
979
 }
979
 }
989
 
989
 
990
 
990
 
991
     // Draw lara or other player model ( move to entity rendering method )
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
         if (mdl)
996
         if (mdl)
997
         {
997
         {
998
 
998
 
999
             // Mongoose 2002.03.22, Test 'idle' aniamtions
999
             // Mongoose 2002.03.22, Test 'idle' aniamtions
1000
-            if (!gOpenRaider->mGame->mLara->moving)
1000
+            if (!getGame().mLara->moving)
1001
             {
1001
             {
1002
                 frame = mdl->getIdleAnimation();
1002
                 frame = mdl->getIdleAnimation();
1003
 
1003
 
1023
         glPushMatrix();
1023
         glPushMatrix();
1024
 
1024
 
1025
 #ifdef USING_FPS_CAMERA
1025
 #ifdef USING_FPS_CAMERA
1026
-        gOpenRaider->mGame->mCamera->getPosition(curPos);
1026
+        getGame().mCamera->getPosition(curPos);
1027
         glTranslated(curPos[0], curPos[1], curPos[2]);
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
         glTranslated(0, 500, 1200);
1029
         glTranslated(0, 500, 1200);
1030
 #else
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
 #endif
1033
 #endif
1034
 
1034
 
1035
-        drawModel(static_cast<SkeletalModel *>(gOpenRaider->mGame->mLara->tmpHook));
1035
+        drawModel(static_cast<SkeletalModel *>(getGame().mLara->tmpHook));
1036
         glPopMatrix();
1036
         glPopMatrix();
1037
     }
1037
     }
1038
 
1038
 
1041
     {
1041
     {
1042
         std::vector<sprite_seq_t *> *sprites;
1042
         std::vector<sprite_seq_t *> *sprites;
1043
 
1043
 
1044
-        sprites = gOpenRaider->mGame->mWorld.getSprites();
1044
+        sprites = getGame().mWorld.getSprites();
1045
 
1045
 
1046
         for (unsigned int i = 0; i < sprites->size(); i++)
1046
         for (unsigned int i = 0; i < sprites->size(); i++)
1047
         {
1047
         {
1161
 
1161
 
1162
                 if (tag2)
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
                     {
1204
                     {
1205
                         glPushMatrix();
1205
                         glPushMatrix();
1206
                         glTranslatef(mdl->ponyOff2, 0.0, 0.0);
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
                                 Render::skeletalMesh);
1208
                                 Render::skeletalMesh);
1209
                         glPopMatrix();
1209
                         glPopMatrix();
1210
 
1210
 
1211
                         glPushMatrix();
1211
                         glPushMatrix();
1212
                         glTranslatef(-mdl->ponyOff2, 0.0, 0.0);
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
                                 Render::skeletalMesh);
1214
                                 Render::skeletalMesh);
1215
                         glPopMatrix();
1215
                         glPopMatrix();
1216
                     }
1216
                     }
1217
                     else
1217
                     else
1218
                     {
1218
                     {
1219
-                        drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mdl->ponytailMeshId + i),
1219
+                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1220
                                 Render::skeletalMesh);
1220
                                 Render::skeletalMesh);
1221
                     }
1221
                     }
1222
                 }
1222
                 }
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
     // Cycle frames ( cheap hack from old ent state based system )
1236
     // Cycle frames ( cheap hack from old ent state based system )
1554
     glTranslated(sprite->pos[0], sprite->pos[1], sprite->pos[2]);
1554
     glTranslated(sprite->pos[0], sprite->pos[1], sprite->pos[2]);
1555
 
1555
 
1556
     // Sprites must always face camera, because they have no depth  =)
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
     switch (mMode)
1559
     switch (mMode)
1560
     {
1560
     {
1612
     if (!mesh)
1612
     if (!mesh)
1613
         return;
1613
         return;
1614
 
1614
 
1615
-    r_mesh = gOpenRaider->mGame->mWorld.getMesh(mesh->index);
1615
+    r_mesh = getGame().mWorld.getMesh(mesh->index);
1616
 
1616
 
1617
     if (!r_mesh)
1617
     if (!r_mesh)
1618
         return;
1618
         return;
1862
         return;
1862
         return;
1863
     }
1863
     }
1864
 
1864
 
1865
-    model = gOpenRaider->mGame->mWorld.getModel(index);
1865
+    model = getGame().mWorld.getModel(index);
1866
 
1866
 
1867
     if (model)
1867
     if (model)
1868
     {
1868
     {

+ 5
- 5
src/WindowSDL.cpp Zobrazit soubor

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

+ 80
- 7
src/main.cpp Zobrazit soubor

12
 #include "config.h"
12
 #include "config.h"
13
 #include "main.h"
13
 #include "main.h"
14
 #include "utils/time.h"
14
 #include "utils/time.h"
15
+#include "WindowSDL.h"
15
 
16
 
17
+Console *gConsole = NULL;
18
+Game *gGame = NULL;
19
+Menu *gMenu = NULL;
16
 OpenRaider *gOpenRaider = NULL;
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
     if (gOpenRaider)
53
     if (gOpenRaider)
20
         delete gOpenRaider;
54
         delete gOpenRaider;
21
 
55
 
56
+    if (gWindow)
57
+        delete gWindow;
58
+
22
     printf("\nThanks for testing %s\n", VERSION);
59
     printf("\nThanks for testing %s\n", VERSION);
23
     printf("Build date: %s @ %s\n", __DATE__, __TIME__);
60
     printf("Build date: %s @ %s\n", __DATE__, __TIME__);
24
     printf("Build host: %s\n", BUILD_HOST);
61
     printf("Build host: %s\n", BUILD_HOST);
29
 int main(int argc, char *argv[]) {
66
 int main(int argc, char *argv[]) {
30
     const char *config = NULL;
67
     const char *config = NULL;
31
 
68
 
32
-    systemTimerReset();
33
-
34
     // Handle arguments
69
     // Handle arguments
35
     if (argc == 1) {
70
     if (argc == 1) {
36
         // Use default rc file path
71
         // Use default rc file path
62
     }
97
     }
63
 
98
 
64
     // Create globals
99
     // Create globals
65
-    atexit(cleanupHandler);
66
     printf("Initializing %s\n", VERSION);
100
     printf("Initializing %s\n", VERSION);
101
+    atexit(cleanupHandler);
67
     gOpenRaider = new OpenRaider();
102
     gOpenRaider = new OpenRaider();
103
+    gWindow = new WindowSDL();
104
+    gConsole = new Console();
105
+    gMenu = new Menu();
106
+    gGame = new Game();
68
 
107
 
69
     // Try to load a configuration
108
     // Try to load a configuration
70
     if (gOpenRaider->loadConfig(config) != 0) {
109
     if (gOpenRaider->loadConfig(config) != 0) {
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
     // Enter Main loop
155
     // Enter Main loop
83
-    gOpenRaider->mConsole->print("Starting %s", VERSION);
156
+    gConsole->print("Starting %s", VERSION);
84
     gOpenRaider->run();
157
     gOpenRaider->run();
85
 
158
 
86
     return 0;
159
     return 0;

Loading…
Zrušit
Uložit