Sfoglia il codice sorgente

Added TombRaider level loader

Thomas Buck 11 anni fa
parent
commit
556892812d
7 ha cambiato i file con 8253 aggiunte e 5 eliminazioni
  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 Vedi File

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

+ 1921
- 0
include/TombRaider.h
File diff soppresso perché troppo grande
Vedi File


+ 1
- 0
src/CMakeLists.txt Vedi File

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

+ 23
- 3
src/Game.cpp Vedi File

14
 #endif
14
 #endif
15
 
15
 
16
 #include "main.h"
16
 #include "main.h"
17
-#include "Window.h"
17
+#include "Console.h"
18
 #include "Game.h"
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
 Game::Game(const char *level) {
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
 Game::~Game() {
41
 Game::~Game() {
42
+    if (mName)
43
+        delete [] mName;
24
 }
44
 }
25
 
45
 
26
 void Game::handleAction(ActionEvents action, bool isFinished) {
46
 void Game::handleAction(ActionEvents action, bool isFinished) {
32
 }
52
 }
33
 
53
 
34
 void Game::display() {
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 Vedi File

148
         while (i-- > 0)
148
         while (i-- > 0)
149
             handleKeyboard(up, true);
149
             handleKeyboard(up, true);
150
     } else if (key == enter) {
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 Vedi File

161
     } else if (strcmp(command, "help") == 0) {
161
     } else if (strcmp(command, "help") == 0) {
162
         if (args->size() == 0) {
162
         if (args->size() == 0) {
163
             mConsole->print("Available commands:");
163
             mConsole->print("Available commands:");
164
+            mConsole->print("  load");
164
             mConsole->print("  set");
165
             mConsole->print("  set");
165
             mConsole->print("  bind");
166
             mConsole->print("  bind");
166
             mConsole->print("  help");
167
             mConsole->print("  help");
170
             return help(args->at(0));
171
             return help(args->at(0));
171
         } else {
172
         } else {
172
             mConsole->print("Invalid use of help-command");
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
     } else {
188
     } else {
176
         mConsole->print("Unknown command: %s ", command);
189
         mConsole->print("Unknown command: %s ", command);
216
         mConsole->print("Key-Format:");
229
         mConsole->print("Key-Format:");
217
         mConsole->print("  'a' or '1'    for character/number keys");
230
         mConsole->print("  'a' or '1'    for character/number keys");
218
         mConsole->print("  \"leftctrl\"  for symbols and special keys");
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
     } else {
235
     } else {
220
         mConsole->print("No help available for %s", cmd);
236
         mConsole->print("No help available for %s", cmd);
221
         return -1;
237
         return -1;

+ 6281
- 0
src/TombRaider.cpp
File diff soppresso perché troppo grande
Vedi File


Loading…
Annulla
Salva