Browse Source

Added TombRaider level loader

Thomas Buck 10 years ago
parent
commit
556892812d
7 changed files with 8253 additions and 5 deletions
  1. 6
    0
      include/Game.h
  2. 1921
    0
      include/TombRaider.h
  3. 1
    0
      src/CMakeLists.txt
  4. 23
    3
      src/Game.cpp
  5. 4
    1
      src/Menu.cpp
  6. 17
    1
      src/OpenRaider.cpp
  7. 6281
    0
      src/TombRaider.cpp

+ 6
- 0
include/Game.h View File

@@ -9,6 +9,7 @@
9 9
 #define _GAME_H_
10 10
 
11 11
 #include "global.h"
12
+#include "TombRaider.h"
12 13
 
13 14
 /*!
14 15
  * \brief Game abstraction
@@ -16,6 +17,7 @@
16 17
 class Game {
17 18
 public:
18 19
 
20
+    // Throw exception with negative integer error code if fails
19 21
     Game(const char *level);
20 22
 
21 23
     ~Game();
@@ -26,8 +28,12 @@ public:
26 28
 
27 29
     void display();
28 30
 
31
+    void percentCallback(int percent);
32
+
29 33
 private:
30 34
 
35
+    char *mName;
36
+    TombRaider mTombRaider;
31 37
 };
32 38
 
33 39
 #endif

+ 1921
- 0
include/TombRaider.h
File diff suppressed because it is too large
View File


+ 1
- 0
src/CMakeLists.txt View File

@@ -37,6 +37,7 @@ set (SRCS ${SRCS} "main.cpp")
37 37
 set (SRCS ${SRCS} "Menu.cpp")
38 38
 set (SRCS ${SRCS} "OpenRaider.cpp")
39 39
 set (SRCS ${SRCS} "Sound.cpp")
40
+set (SRCS ${SRCS} "TombRaider.cpp")
40 41
 set (SRCS ${SRCS} "Window.cpp")
41 42
 
42 43
 # Select available Windowing library

+ 23
- 3
src/Game.cpp View File

@@ -14,13 +14,33 @@
14 14
 #endif
15 15
 
16 16
 #include "main.h"
17
-#include "Window.h"
17
+#include "Console.h"
18 18
 #include "Game.h"
19
+#include "utils/strings.h"
19 20
 
21
+void percentCallbackTrampoline(int percent, void *data) {
22
+    Game *self = static_cast<Game *>(data);
23
+    self->percentCallback(percent);
24
+}
25
+
26
+void Game::percentCallback(int percent) {
27
+
28
+}
29
+
30
+// Throw exception with negative integer error code if fails
20 31
 Game::Game(const char *level) {
32
+    mName = bufferString("%s", level);
33
+
34
+    gOpenRaider->mConsole->print("Loading %s", mName);
35
+    int error = mTombRaider.Load(mName, percentCallbackTrampoline, this);
36
+    if (error != 0) {
37
+        throw error;
38
+    }
21 39
 }
22 40
 
23 41
 Game::~Game() {
42
+    if (mName)
43
+        delete [] mName;
24 44
 }
25 45
 
26 46
 void Game::handleAction(ActionEvents action, bool isFinished) {
@@ -32,7 +52,7 @@ void Game::handleMouseMotion(int xrel, int yrel) {
32 52
 }
33 53
 
34 54
 void Game::display() {
35
-    unsigned char color[4] = {0xFF, 0xFF, 0xFF, 0xFF};
36
-    gOpenRaider->mWindow->drawText(10, 10, 1.50f, color, "Game");
55
+    glClearColor(0.00f, 0.70f, 0.00f, 1.0f);
56
+    glClear(GL_COLOR_BUFFER_BIT);
37 57
 }
38 58
 

+ 4
- 1
src/Menu.cpp View File

@@ -148,7 +148,10 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
148 148
         while (i-- > 0)
149 149
             handleKeyboard(up, true);
150 150
     } else if (key == enter) {
151
-
151
+        char *tmp = bufferString("load %s", gOpenRaider->mMapList[mCursor]);
152
+        if (gOpenRaider->command(tmp) == 0)
153
+            setVisible(false);
154
+        delete [] tmp;
152 155
     }
153 156
 }
154 157
 

+ 17
- 1
src/OpenRaider.cpp View File

@@ -161,6 +161,7 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
161 161
     } else if (strcmp(command, "help") == 0) {
162 162
         if (args->size() == 0) {
163 163
             mConsole->print("Available commands:");
164
+            mConsole->print("  load");
164 165
             mConsole->print("  set");
165 166
             mConsole->print("  bind");
166 167
             mConsole->print("  help");
@@ -170,7 +171,19 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
170 171
             return help(args->at(0));
171 172
         } else {
172 173
             mConsole->print("Invalid use of help-command");
173
-            return -5;
174
+            return -4;
175
+        }
176
+    } else if (strcmp(command, "load") == 0) {
177
+        if (mGame)
178
+            delete mGame;
179
+        char *tmp = bufferString("%s%s", mPakDir, args->at(0));
180
+        try {
181
+            mGame = new Game(tmp);
182
+            delete [] tmp;
183
+            return 0;
184
+        } catch (int error) {
185
+            delete [] tmp;
186
+            return error;
174 187
         }
175 188
     } else {
176 189
         mConsole->print("Unknown command: %s ", command);
@@ -216,6 +229,9 @@ int OpenRaider::help(const char *cmd) {
216 229
         mConsole->print("Key-Format:");
217 230
         mConsole->print("  'a' or '1'    for character/number keys");
218 231
         mConsole->print("  \"leftctrl\"  for symbols and special keys");
232
+    } else if (strcmp(cmd, "load") == 0) {
233
+        mConsole->print("load-Command Usage:");
234
+        mConsole->print("  load levelfile.name");
219 235
     } else {
220 236
         mConsole->print("No help available for %s", cmd);
221 237
         return -1;

+ 6281
- 0
src/TombRaider.cpp
File diff suppressed because it is too large
View File


Loading…
Cancel
Save