Browse Source

Added game mode command

Thomas Buck 10 years ago
parent
commit
d4f4ba5d92
6 changed files with 183 additions and 102 deletions
  1. 1
    0
      include/Game.h
  2. 2
    0
      include/OpenRaider.h
  3. 4
    0
      include/Render.h
  4. 1
    0
      include/Window.h
  5. 97
    25
      src/Game.cpp
  6. 78
    77
      src/Render.cpp

+ 1
- 0
include/Game.h View File

@@ -44,6 +44,7 @@ public:
44 44
 
45 45
     int command(std::vector<char *> *args);
46 46
 
47
+    //! \fixme should be private
47 48
     World mWorld;
48 49
     entity_t *mLara;
49 50
     Render *mRender;

+ 2
- 0
include/OpenRaider.h View File

@@ -55,6 +55,8 @@ public:
55 55
 
56 56
     void handleMouseScroll(int xrel, int yrel);
57 57
 
58
+    //! \fixme should be private
59
+
58 60
     Window *mWindow;
59 61
     Sound *mSound;
60 62
     Menu *mMenu;

+ 4
- 0
include/Render.h View File

@@ -212,6 +212,10 @@ public:
212 212
 
213 213
     void addSkeletalModel(SkeletalModel *mdl);
214 214
 
215
+    //! \fixme should be private
216
+
217
+    ViewVolume mViewVolume; //!< View Volume for frustum culling
218
+
215 219
 private:
216 220
 
217 221
     void drawLoadScreen();

+ 1
- 0
include/Window.h View File

@@ -58,6 +58,7 @@ public:
58 58
     virtual void drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...)
59 59
         __attribute__((format(printf, 6, 0))) = 0;
60 60
 
61
+    //! \fixme should be private
61 62
     unsigned int mWidth;
62 63
     unsigned int mHeight;
63 64
 

+ 97
- 25
src/Game.cpp View File

@@ -176,10 +176,8 @@ void Game::handleMouseMotion(int xrel, int yrel) {
176 176
                 mCamera->command(CAMERA_ROTATE_DOWN);
177 177
 
178 178
         // Fix Laras rotation
179
-        if (mLara) {
180
-            mLara->angles[1] = mCamera->getRadianYaw();
181
-            mLara->angles[2] = mCamera->getRadianPitch();
182
-        }
179
+        mLara->angles[1] = mCamera->getRadianYaw();
180
+        mLara->angles[2] = mCamera->getRadianPitch();
183 181
     }
184 182
 }
185 183
 
@@ -194,42 +192,119 @@ int Game::command(std::vector<char *> *args) {
194 192
     }
195 193
 
196 194
     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...");
195
+    if (strcmp(cmd, "mode") == 0) {
196
+        if (args->size() > 1) {
197
+            char *mode = args->at(1);
198
+            if (strcmp(mode, "wireframe") == 0) {
199
+                if (mLoaded) {
200
+                    mRender->setMode(Render::modeWireframe);
201
+                    gOpenRaider->mConsole->print("Wireframe mode");
202
+                } else {
203
+                    gOpenRaider->mConsole->print("Load a level to set this mode!");
204
+                    return -2;
205
+                }
206
+            } else if (strcmp(mode, "solid") == 0) {
207
+                if (mLoaded) {
208
+                    mRender->setMode(Render::modeSolid);
209
+                    gOpenRaider->mConsole->print("Solid mode");
210
+                } else {
211
+                    gOpenRaider->mConsole->print("Load a level to set this mode!");
212
+                    return -3;
213
+                }
214
+            } else if (strcmp(mode, "texture") == 0) {
215
+                if (mLoaded) {
216
+                    mRender->setMode(Render::modeTexture);
217
+                    gOpenRaider->mConsole->print("Texture mode");
218
+                } else {
219
+                    gOpenRaider->mConsole->print("Load a level to set this mode!");
220
+                    return -4;
221
+                }
222
+            } else if (strcmp(mode, "vertexlight") == 0) {
223
+                if (mLoaded) {
224
+                    mRender->setMode(Render::modeVertexLight);
225
+                    gOpenRaider->mConsole->print("Vertexlight mode");
226
+                } else {
227
+                    gOpenRaider->mConsole->print("Load a level to set this mode!");
228
+                    return -5;
229
+                }
230
+            } else if (strcmp(mode, "titlescreen") == 0) {
231
+                mRender->setMode(Render::modeLoadScreen);
232
+                gOpenRaider->mConsole->print("Titlescreen mode");
233
+            } else {
234
+                gOpenRaider->mConsole->print("Invalid use of mode command (%s)!", mode);
235
+                return -6;
236
+            }
237
+        } else {
238
+            gOpenRaider->mConsole->print("Invalid use of mode command!");
239
+            return -7;
240
+        }
241
+    } else if (strcmp(cmd, "move") == 0) {
242
+        if (args->size() > 1) {
243
+            if (mLoaded) {
244
+                char *move = args->at(1);
245
+                if (strcmp(move, "walk") == 0) {
246
+                    mLara->moveType = worldMoveType_walk;
247
+                    gOpenRaider->mConsole->print("Lara is walking...");
248
+                } else if (strcmp(move, "fly") == 0) {
249
+                    mLara->moveType = worldMoveType_fly;
250
+                    gOpenRaider->mConsole->print("Lara is flying...");
251
+                } else if (strcmp(move, "noclip") == 0) {
252
+                    mLara->moveType = worldMoveType_noClipping;
253
+                    gOpenRaider->mConsole->print("Lara is noclipping...");
254
+                } else {
255
+                    gOpenRaider->mConsole->print("Invalid use of move command (%s)!", move);
256
+                    return -8;
257
+                }
258
+            } else {
259
+                gOpenRaider->mConsole->print("Load a level to change the movement type!");
260
+                return -9;
261
+            }
262
+        } else {
263
+            gOpenRaider->mConsole->print("Invalid use of move command!");
264
+            return -10;
265
+        }
206 266
     } else if (strcmp(cmd, "sound") == 0) {
207 267
         if (args->size() > 1) {
208 268
             gOpenRaider->mSound->play(atoi(args->at(1)));
209 269
         } else {
210 270
             gOpenRaider->mConsole->print("Invalid use of sound command!");
211
-            return -2;
271
+            return -11;
212 272
         }
213 273
     } else if (strcmp(cmd, "help") == 0) {
214 274
         if (args->size() < 2) {
215 275
             gOpenRaider->mConsole->print("game-command Usage:");
216 276
             gOpenRaider->mConsole->print("  game COMMAND");
217 277
             gOpenRaider->mConsole->print("Available commands:");
218
-            gOpenRaider->mConsole->print("  walk");
219
-            gOpenRaider->mConsole->print("  fly");
220
-            gOpenRaider->mConsole->print("  noclip");
278
+            gOpenRaider->mConsole->print("  move [walk|fly|noclip]");
221 279
             gOpenRaider->mConsole->print("  sound INT");
280
+            gOpenRaider->mConsole->print("  mode MODE");
222 281
         } else if (strcmp(args->at(1), "sound") == 0) {
223 282
             gOpenRaider->mConsole->print("game-sound-command Usage:");
224 283
             gOpenRaider->mConsole->print("  game sound INT");
225 284
             gOpenRaider->mConsole->print("Where INT is a valid sound ID integer");
285
+        } else if (strcmp(args->at(1), "move") == 0) {
286
+            gOpenRaider->mConsole->print("game-move-command Usage:");
287
+            gOpenRaider->mConsole->print("  game move COMMAND");
288
+            gOpenRaider->mConsole->print("Where COMMAND is one of the following:");
289
+            gOpenRaider->mConsole->print("  walk");
290
+            gOpenRaider->mConsole->print("  fly");
291
+            gOpenRaider->mConsole->print("  noclip");
292
+        } else if (strcmp(args->at(1), "mode") == 0) {
293
+            gOpenRaider->mConsole->print("game-mode-command Usage:");
294
+            gOpenRaider->mConsole->print("  game mode MODE");
295
+            gOpenRaider->mConsole->print("Where MODE is one of the following:");
296
+            gOpenRaider->mConsole->print("  wireframe");
297
+            gOpenRaider->mConsole->print("  solid");
298
+            gOpenRaider->mConsole->print("  texture");
299
+            gOpenRaider->mConsole->print("  vertexlight");
300
+            gOpenRaider->mConsole->print("  titlescreen");
226 301
         } else {
227 302
             gOpenRaider->mConsole->print("No help available for game %s.", args->at(1));
228
-            return -3;
303
+            return -12;
229 304
         }
230 305
     } else {
231 306
         gOpenRaider->mConsole->print("Invalid use of game-command (%s)!", cmd);
232
-        return -4;
307
+        return -13;
233 308
     }
234 309
 
235 310
     return 0;
@@ -737,7 +812,7 @@ void Game::processMoveable(int index, int i, int *ent,
737 812
                     }
738 813
 
739 814
                     mRender->setFlags(Render::fRenderPonytail);
740
-                    printf("Found known ponytail\n");
815
+                    gOpenRaider->mConsole->print("Found known ponytail");
741 816
                 }
742 817
                 break; // ?
743 818
             case TR_VERSION_1:
@@ -766,16 +841,13 @@ void Game::processMoveable(int index, int i, int *ent,
766 841
     }
767 842
     else
768 843
     {
844
+        // Already cached
769 845
         delete r_model;
770
-
771 846
         c_model = cache2[foundIndex];
772 847
         sModel->model = c_model;
773 848
         mWorld.addEntity(thing);
774 849
         mWorld.addModel(c_model);
775
-        //printf("c"); // it's already cached
776
-        //fflush(stdout);
777
-
778
-        //continue;
850
+        printf("c");
779 851
         return;
780 852
     }
781 853
 

+ 78
- 77
src/Render.cpp View File

@@ -30,73 +30,6 @@
30 30
 #include "OpenRaider.h"
31 31
 #include "Render.h"
32 32
 
33
-ViewVolume gViewVolume; /* View volume for frustum culling */
34
-
35
-void Render::drawLoadScreen()
36
-{
37
-    float x = 0.0f, y = 0.0f, z = -160.0f;
38
-    float w = 500.0f, h = 500.0f;
39
-
40
-
41
-    if (mTexture.getTextureCount() <= 0)
42
-        return;
43
-
44
-    // Mongoose 2002.01.01, Rendered while game is loading...
45
-    //! \fixme seperate logo/particle coor later
46
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
47
-    glLoadIdentity();
48
-
49
-    glColor3fv(WHITE);
50
-
51
-    if (mFlags & Render::fGL_Lights)
52
-        glDisable(GL_LIGHTING);
53
-
54
-    // Mongoose 2002.01.01, Draw logo/load screen
55
-    glTranslatef(0.0f, 0.0f, -2000.0f);
56
-    glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
57
-
58
-    glBindTexture(GL_TEXTURE_2D, 2);
59
-
60
-    glBegin(GL_TRIANGLE_STRIP);
61
-    glTexCoord2f(1.0, 1.0);
62
-    glVertex3f(x + w, y + h, z);
63
-    glTexCoord2f(0.0, 1.0);
64
-    glVertex3f(x - w, y + h, z);
65
-    glTexCoord2f(1.0, 0.0);
66
-    glVertex3f(x + w, y - h, z);
67
-    glTexCoord2f(0.0, 0.0);
68
-    glVertex3f(x - w, y - h, z);
69
-    glEnd();
70
-
71
-    if (mFlags & Render::fGL_Lights)
72
-        glEnable(GL_LIGHTING);
73
-
74
-#ifdef USING_EMITTER
75
-    // Mongoose 2002.01.01, Test particle prototype on load screen
76
-    if (mEmitter && mFlags & Render::fParticles)
77
-    {
78
-        glPushMatrix();
79
-        glLoadIdentity();
80
-
81
-        glEnable(GL_BLEND);
82
-        glRotatef(180.0, 1.0, 0.0, 0.0);
83
-        glTranslatef(0.0, -820.0, 575.0);
84
-        glScalef(80.0, 80.0, 80.0);
85
-
86
-        // Update view volume for vising
87
-        updateViewVolume();
88
-        gViewVolume.getFrustum(mEmitter->mFrustum);
89
-        mEmitter->Flags(Emitter::fUseDepthSorting, true);
90
-        mEmitter->Draw();
91
-
92
-        glPopMatrix();
93
-    }
94
-#endif
95
-
96
-    glFlush();
97
-}
98
-
99
-
100 33
 bool compareEntites(const void *voidA, const void *voidB)
101 34
 {
102 35
     entity_t *a = (entity_t *)voidA, *b = (entity_t *)voidB;
@@ -105,11 +38,11 @@ bool compareEntites(const void *voidA, const void *voidB)
105 38
     if (!a || !b)
106 39
         return false; // error really
107 40
 
108
-    distA = gViewVolume.getDistToSphereFromNear(a->pos[0],
41
+    distA = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(a->pos[0],
109 42
             a->pos[1],
110 43
             a->pos[2],
111 44
             1.0f);
112
-    distB = gViewVolume.getDistToSphereFromNear(b->pos[0],
45
+    distB = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
113 46
             b->pos[1],
114 47
             b->pos[2],
115 48
             1.0f);
@@ -126,11 +59,11 @@ bool compareStaticModels(const void *voidA, const void *voidB)
126 59
     if (!a || !b)
127 60
         return false; // error really
128 61
 
129
-    distA = gViewVolume.getDistToSphereFromNear(a->pos[0],
62
+    distA = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(a->pos[0],
130 63
             a->pos[1],
131 64
             a->pos[2],
132 65
             128.0f);
133
-    distB = gViewVolume.getDistToSphereFromNear(b->pos[0],
66
+    distB = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
134 67
             b->pos[1],
135 68
             b->pos[2],
136 69
             128.0f);
@@ -830,6 +763,74 @@ void Render::Display()
830 763
     glFlush();
831 764
 }
832 765
 
766
+void Render::drawLoadScreen()
767
+{
768
+    float x = 0.0f, y = 0.0f, z = -160.0f;
769
+    float w, h;
770
+
771
+    if (gOpenRaider->mWindow->mWidth < gOpenRaider->mWindow->mHeight)
772
+        w = h = (float)gOpenRaider->mWindow->mWidth;
773
+    else
774
+        w = h = (float)gOpenRaider->mWindow->mHeight;
775
+
776
+
777
+    if (mTexture.getTextureCount() <= 0)
778
+        return;
779
+
780
+    // Mongoose 2002.01.01, Rendered while game is loading...
781
+    //! \fixme seperate logo/particle coor later
782
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
783
+    glLoadIdentity();
784
+
785
+    glColor3fv(WHITE);
786
+
787
+    if (mFlags & Render::fGL_Lights)
788
+        glDisable(GL_LIGHTING);
789
+
790
+    // Mongoose 2002.01.01, Draw logo/load screen
791
+    glTranslatef(0.0f, 0.0f, -2000.0f);
792
+    glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
793
+
794
+    glBindTexture(GL_TEXTURE_2D, 2); //! \fixme store texture id somewhere
795
+
796
+    glBegin(GL_TRIANGLE_STRIP);
797
+    glTexCoord2f(1.0, 1.0);
798
+    glVertex3f(x + w, y + h, z);
799
+    glTexCoord2f(0.0, 1.0);
800
+    glVertex3f(x - w, y + h, z);
801
+    glTexCoord2f(1.0, 0.0);
802
+    glVertex3f(x + w, y - h, z);
803
+    glTexCoord2f(0.0, 0.0);
804
+    glVertex3f(x - w, y - h, z);
805
+    glEnd();
806
+
807
+    if (mFlags & Render::fGL_Lights)
808
+        glEnable(GL_LIGHTING);
809
+
810
+#ifdef USING_EMITTER
811
+    // Mongoose 2002.01.01, Test particle prototype on load screen
812
+    if (mEmitter && mFlags & Render::fParticles)
813
+    {
814
+        glPushMatrix();
815
+        glLoadIdentity();
816
+
817
+        glEnable(GL_BLEND);
818
+        glRotatef(180.0, 1.0, 0.0, 0.0);
819
+        glTranslatef(0.0, -820.0, 575.0);
820
+        glScalef(80.0, 80.0, 80.0);
821
+
822
+        // Update view volume for vising
823
+        updateViewVolume();
824
+        mViewVolume.getFrustum(mEmitter->mFrustum);
825
+        mEmitter->Flags(Emitter::fUseDepthSorting, true);
826
+        mEmitter->Draw();
827
+
828
+        glPopMatrix();
829
+    }
830
+#endif
831
+
832
+    glFlush();
833
+}
833 834
 
834 835
 void Render::newRoomRenderList(int index)
835 836
 {
@@ -880,7 +881,7 @@ void Render::newRoomRenderList(int index)
880 881
                     continue;
881 882
 
882 883
                 //room->dist =
883
-                //gViewVolume.getDistToBboxFromNear(room->room->bbox_min,
884
+                //mViewVolume.getDistToBboxFromNear(room->room->bbox_min,
884 885
                 //                                           room->room->bbox_max);
885 886
 
886 887
                 mRoomRenderList.push_back(room);
@@ -919,7 +920,7 @@ void Render::buildRoomRenderList(RenderRoom *rRoom)
919 920
     }
920 921
 
921 922
     //rRoom->dist =
922
-    //gViewVolume.getDistToBboxFromNear(rRoom->room->bbox_min,
923
+    //mViewVolume.getDistToBboxFromNear(rRoom->room->bbox_min,
923 924
     //                                           rRoom->room->bbox_max);
924 925
 
925 926
     /* Add current room to list */
@@ -1894,7 +1895,7 @@ void Render::updateViewVolume()
1894 1895
 
1895 1896
     glGetFloatv(GL_PROJECTION_MATRIX, proj);
1896 1897
     glGetFloatv(GL_MODELVIEW_MATRIX, mdl);
1897
-    gViewVolume.updateFrame(proj, mdl);
1898
+    mViewVolume.updateFrame(proj, mdl);
1898 1899
 }
1899 1900
 
1900 1901
 
@@ -1913,7 +1914,7 @@ bool Render::isVisible(float bbox_min[3], float bbox_max[3])
1913 1914
         draw_bbox_color(bbox_min, bbox_max, true, PINK, RED);
1914 1915
     }
1915 1916
 
1916
-    return gViewVolume.isBboxInFrustum(bbox_min, bbox_max);
1917
+    return mViewVolume.isBboxInFrustum(bbox_min, bbox_max);
1917 1918
 }
1918 1919
 
1919 1920
 
@@ -1929,7 +1930,7 @@ bool Render::isVisible(float x, float y, float z)
1929 1930
         glEnd();
1930 1931
     }
1931 1932
 
1932
-    return (gViewVolume.isPointInFrustum(x, y, z));
1933
+    return (mViewVolume.isPointInFrustum(x, y, z));
1933 1934
 }
1934 1935
 
1935 1936
 
@@ -1945,5 +1946,5 @@ bool Render::isVisible(float x, float y, float z, float radius)
1945 1946
         glEnd();
1946 1947
     }
1947 1948
 
1948
-    return (gViewVolume.isSphereInFrustum(x, y, z, radius));
1949
+    return (mViewVolume.isSphereInFrustum(x, y, z, radius));
1949 1950
 }

Loading…
Cancel
Save