Browse Source

Started reimplementing game engine commands

Thomas Buck 11 years ago
parent
commit
841824229e
4 changed files with 77 additions and 10 deletions
  1. 2
    0
      include/Game.h
  2. 62
    3
      src/Game.cpp
  3. 12
    5
      src/OpenRaider.cpp
  4. 1
    2
      src/Texture.cpp

+ 2
- 0
include/Game.h View File

42
 
42
 
43
     void display();
43
     void display();
44
 
44
 
45
+    int command(std::vector<char *> *args);
46
+
45
     World mWorld;
47
     World mWorld;
46
     entity_t *mLara;
48
     entity_t *mLara;
47
     Render *mRender;
49
     Render *mRender;

+ 62
- 3
src/Game.cpp View File

16
 #include <algorithm>
16
 #include <algorithm>
17
 #include <map>
17
 #include <map>
18
 #include <vector>
18
 #include <vector>
19
+#include <cstdlib>
19
 
20
 
20
 #include "main.h"
21
 #include "main.h"
21
 #include "Console.h"
22
 #include "Console.h"
111
                 break;
112
                 break;
112
             }
113
             }
113
         }
114
         }
114
-        strcpy(tmp + dir, "MAIN.SFX\0"); // overwrite the name itself with MAIN.SFX
115
+        strcpy(tmp + dir, "MAIN.SFX"); // overwrite the name itself with MAIN.SFX
116
+        tmp[dir + 8] = '\0';
115
         error = mTombRaider.loadSFX(tmp);
117
         error = mTombRaider.loadSFX(tmp);
116
         if (error != 0) {
118
         if (error != 0) {
117
             gOpenRaider->mConsole->print("Could not load %s", tmp);
119
             gOpenRaider->mConsole->print("Could not load %s", tmp);
130
     // Free pak file
132
     // Free pak file
131
     mTombRaider.reset();
133
     mTombRaider.reset();
132
 
134
 
135
+    // Check if the level contains Lara
136
+    if (mLara == NULL) {
137
+        gOpenRaider->mConsole->print("Can't find Lara entity in level pak!");
138
+        return -1;
139
+    }
140
+
133
     mLoaded = true;
141
     mLoaded = true;
134
     mRender->setMode(Render::modeVertexLight);
142
     mRender->setMode(Render::modeVertexLight);
135
     return 0;
143
     return 0;
151
 
159
 
152
 void Game::handleMouseMotion(int xrel, int yrel) {
160
 void Game::handleMouseMotion(int xrel, int yrel) {
153
     if (mLoaded) {
161
     if (mLoaded) {
162
+        // Move Camera on X Axis
154
         if (xrel > 0)
163
         if (xrel > 0)
155
             while (xrel-- > 0)
164
             while (xrel-- > 0)
156
                 mCamera->command(CAMERA_ROTATE_RIGHT);
165
                 mCamera->command(CAMERA_ROTATE_RIGHT);
158
             while (xrel++ < 0)
167
             while (xrel++ < 0)
159
                 mCamera->command(CAMERA_ROTATE_LEFT);
168
                 mCamera->command(CAMERA_ROTATE_LEFT);
160
 
169
 
170
+        // Move Camera on Y Axis
161
         if (yrel > 0)
171
         if (yrel > 0)
162
             while (yrel-- > 0)
172
             while (yrel-- > 0)
163
                 mCamera->command(CAMERA_ROTATE_UP);
173
                 mCamera->command(CAMERA_ROTATE_UP);
165
             while (yrel++ < 0)
175
             while (yrel++ < 0)
166
                 mCamera->command(CAMERA_ROTATE_DOWN);
176
                 mCamera->command(CAMERA_ROTATE_DOWN);
167
 
177
 
178
+        // Fix Laras rotation
168
         if (mLara) {
179
         if (mLara) {
169
             mLara->angles[1] = mCamera->getRadianYaw();
180
             mLara->angles[1] = mCamera->getRadianYaw();
170
             mLara->angles[2] = mCamera->getRadianPitch();
181
             mLara->angles[2] = mCamera->getRadianPitch();
176
     mRender->Display();
187
     mRender->Display();
177
 }
188
 }
178
 
189
 
190
+int Game::command(std::vector<char *> *args) {
191
+    if (args->size() < 1) {
192
+        gOpenRaider->mConsole->print("Invalid use of game-command!");
193
+        return -1;
194
+    }
195
+
196
+    char *cmd = args->at(0);
197
+    if (strcmp(cmd, "noclip") == 0) {
198
+        mLara->moveType = worldMoveType_noClipping;
199
+        gOpenRaider->mConsole->print("Lara is noclipping...");
200
+    } else if (strcmp(cmd, "fly") == 0) {
201
+        mLara->moveType = worldMoveType_fly;
202
+        gOpenRaider->mConsole->print("Lara is flying...");
203
+    } else if (strcmp(cmd, "walk") == 0) {
204
+        mLara->moveType = worldMoveType_walk;
205
+        gOpenRaider->mConsole->print("Lara is walking...");
206
+    } else if (strcmp(cmd, "sound") == 0) {
207
+        if (args->size() > 1) {
208
+            gOpenRaider->mSound->play(atoi(args->at(1)));
209
+        } else {
210
+            gOpenRaider->mConsole->print("Invalid use of sound command!");
211
+            return -2;
212
+        }
213
+    } else if (strcmp(cmd, "help") == 0) {
214
+        if (args->size() < 2) {
215
+            gOpenRaider->mConsole->print("game-command Usage:");
216
+            gOpenRaider->mConsole->print("  game COMMAND");
217
+            gOpenRaider->mConsole->print("Available commands:");
218
+            gOpenRaider->mConsole->print("  walk");
219
+            gOpenRaider->mConsole->print("  fly");
220
+            gOpenRaider->mConsole->print("  noclip");
221
+            gOpenRaider->mConsole->print("  sound INT");
222
+        } else if (strcmp(args->at(1), "sound") == 0) {
223
+            gOpenRaider->mConsole->print("game-sound-command Usage:");
224
+            gOpenRaider->mConsole->print("  game sound INT");
225
+            gOpenRaider->mConsole->print("Where INT is a valid sound ID integer");
226
+        } else {
227
+            gOpenRaider->mConsole->print("No help available for game %s.", args->at(1));
228
+            return -3;
229
+        }
230
+    } else {
231
+        gOpenRaider->mConsole->print("Invalid use of game-command (%s)!", cmd);
232
+        return -4;
233
+    }
234
+
235
+    return 0;
236
+}
237
+
179
 void Game::processPakSounds()
238
 void Game::processPakSounds()
180
 {
239
 {
181
     unsigned char *riff;
240
     unsigned char *riff;
700
                     r_model->ponyOff2 = 0;
759
                     r_model->ponyOff2 = 0;
701
 
760
 
702
                     mRender->setFlags(Render::fRenderPonytail);
761
                     mRender->setFlags(Render::fRenderPonytail);
703
-                    gOpenRaider->mConsole->print("Found ponytail?\n");
762
+                    gOpenRaider->mConsole->print("Found ponytail?");
704
                 }
763
                 }
705
                 break;
764
                 break;
706
         }
765
         }
822
             //   if (frame_offset + 8 > _tombraider.NumFrames())
881
             //   if (frame_offset + 8 > _tombraider.NumFrames())
823
             if (frame_offset > mTombRaider.NumFrames())
882
             if (frame_offset > mTombRaider.NumFrames())
824
             {
883
             {
825
-                gOpenRaider->mConsole->print("WARNING: Bad animation frame %i > %i\n",
884
+                gOpenRaider->mConsole->print("WARNING: Bad animation frame %i > %i",
826
                         frame_offset, mTombRaider.NumFrames());
885
                         frame_offset, mTombRaider.NumFrames());
827
 
886
 
828
                 // Mongoose 2002.08.15, Attempt to skip more likely bad animation data
887
                 // Mongoose 2002.08.15, Attempt to skip more likely bad animation data

+ 12
- 5
src/OpenRaider.cpp View File

166
     } else if (strcmp(command, "help") == 0) {
166
     } else if (strcmp(command, "help") == 0) {
167
         if (args->size() == 0) {
167
         if (args->size() == 0) {
168
             mConsole->print("Available commands:");
168
             mConsole->print("Available commands:");
169
-            mConsole->print("  load");
170
-            mConsole->print("  set");
171
-            mConsole->print("  bind");
172
-            mConsole->print("  help");
173
-            mConsole->print("  quit");
169
+            mConsole->print("  load - load a level");
170
+            mConsole->print("  set  - set a parameter");
171
+            mConsole->print("  bind - bind a keyboard/mouse action");
172
+            mConsole->print("  game - send a command to the game engine");
173
+            mConsole->print("  help - print command help");
174
+            mConsole->print("  quit - exit OpenRaider");
174
             mConsole->print("Use help COMMAND to get additional info");
175
             mConsole->print("Use help COMMAND to get additional info");
175
         } else if (args->size() == 1) {
176
         } else if (args->size() == 1) {
176
             return help(args->at(0));
177
             return help(args->at(0));
183
         int error = mGame->loadLevel(tmp);
184
         int error = mGame->loadLevel(tmp);
184
         delete [] tmp;
185
         delete [] tmp;
185
         return error;
186
         return error;
187
+    } else if (strcmp(command, "game") == 0) {
188
+        return mGame->command(args);
186
     } else {
189
     } else {
187
         mConsole->print("Unknown command: %s ", command);
190
         mConsole->print("Unknown command: %s ", command);
188
         return -1;
191
         return -1;
192
 }
195
 }
193
 
196
 
194
 int OpenRaider::help(const char *cmd) {
197
 int OpenRaider::help(const char *cmd) {
198
+    assert(cmd != NULL);
199
+
195
     if (strcmp(cmd, "set") == 0) {
200
     if (strcmp(cmd, "set") == 0) {
196
         mConsole->print("set-Command Usage:");
201
         mConsole->print("set-Command Usage:");
197
         mConsole->print("  set VAR VAL");
202
         mConsole->print("  set VAR VAL");
230
     } else if (strcmp(cmd, "load") == 0) {
235
     } else if (strcmp(cmd, "load") == 0) {
231
         mConsole->print("load-Command Usage:");
236
         mConsole->print("load-Command Usage:");
232
         mConsole->print("  load levelfile.name");
237
         mConsole->print("  load levelfile.name");
238
+    } else if (strcmp(cmd, "game") == 0) {
239
+        mConsole->print("Use \"game help\" for more info");
233
     } else {
240
     } else {
234
         mConsole->print("No help available for %s", cmd);
241
         mConsole->print("No help available for %s", cmd);
235
         return -1;
242
         return -1;

+ 1
- 2
src/Texture.cpp View File

72
 }
72
 }
73
 
73
 
74
 void Texture::clearFlag(TextureFlag flag) {
74
 void Texture::clearFlag(TextureFlag flag) {
75
-    mFlags |= flag;
76
-    mFlags ^= flag;
75
+    mFlags &= ~flag;
77
 }
76
 }
78
 
77
 
79
 void Texture::reset() {
78
 void Texture::reset() {

Loading…
Cancel
Save