Browse Source

Added game mode command

Thomas Buck 11 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
 
44
 
45
     int command(std::vector<char *> *args);
45
     int command(std::vector<char *> *args);
46
 
46
 
47
+    //! \fixme should be private
47
     World mWorld;
48
     World mWorld;
48
     entity_t *mLara;
49
     entity_t *mLara;
49
     Render *mRender;
50
     Render *mRender;

+ 2
- 0
include/OpenRaider.h View File

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

+ 4
- 0
include/Render.h View File

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

+ 1
- 0
include/Window.h View File

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

+ 97
- 25
src/Game.cpp View File

176
                 mCamera->command(CAMERA_ROTATE_DOWN);
176
                 mCamera->command(CAMERA_ROTATE_DOWN);
177
 
177
 
178
         // Fix Laras rotation
178
         // Fix Laras rotation
179
-        if (mLara) {
179
+        mLara->angles[1] = mCamera->getRadianYaw();
180
-            mLara->angles[1] = mCamera->getRadianYaw();
180
+        mLara->angles[2] = mCamera->getRadianPitch();
181
-            mLara->angles[2] = mCamera->getRadianPitch();
182
-        }
183
     }
181
     }
184
 }
182
 }
185
 
183
 
194
     }
192
     }
195
 
193
 
196
     char *cmd = args->at(0);
194
     char *cmd = args->at(0);
197
-    if (strcmp(cmd, "noclip") == 0) {
195
+    if (strcmp(cmd, "mode") == 0) {
198
-        mLara->moveType = worldMoveType_noClipping;
196
+        if (args->size() > 1) {
199
-        gOpenRaider->mConsole->print("Lara is noclipping...");
197
+            char *mode = args->at(1);
200
-    } else if (strcmp(cmd, "fly") == 0) {
198
+            if (strcmp(mode, "wireframe") == 0) {
201
-        mLara->moveType = worldMoveType_fly;
199
+                if (mLoaded) {
202
-        gOpenRaider->mConsole->print("Lara is flying...");
200
+                    mRender->setMode(Render::modeWireframe);
203
-    } else if (strcmp(cmd, "walk") == 0) {
201
+                    gOpenRaider->mConsole->print("Wireframe mode");
204
-        mLara->moveType = worldMoveType_walk;
202
+                } else {
205
-        gOpenRaider->mConsole->print("Lara is walking...");
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
     } else if (strcmp(cmd, "sound") == 0) {
266
     } else if (strcmp(cmd, "sound") == 0) {
207
         if (args->size() > 1) {
267
         if (args->size() > 1) {
208
             gOpenRaider->mSound->play(atoi(args->at(1)));
268
             gOpenRaider->mSound->play(atoi(args->at(1)));
209
         } else {
269
         } else {
210
             gOpenRaider->mConsole->print("Invalid use of sound command!");
270
             gOpenRaider->mConsole->print("Invalid use of sound command!");
211
-            return -2;
271
+            return -11;
212
         }
272
         }
213
     } else if (strcmp(cmd, "help") == 0) {
273
     } else if (strcmp(cmd, "help") == 0) {
214
         if (args->size() < 2) {
274
         if (args->size() < 2) {
215
             gOpenRaider->mConsole->print("game-command Usage:");
275
             gOpenRaider->mConsole->print("game-command Usage:");
216
             gOpenRaider->mConsole->print("  game COMMAND");
276
             gOpenRaider->mConsole->print("  game COMMAND");
217
             gOpenRaider->mConsole->print("Available commands:");
277
             gOpenRaider->mConsole->print("Available commands:");
218
-            gOpenRaider->mConsole->print("  walk");
278
+            gOpenRaider->mConsole->print("  move [walk|fly|noclip]");
219
-            gOpenRaider->mConsole->print("  fly");
220
-            gOpenRaider->mConsole->print("  noclip");
221
             gOpenRaider->mConsole->print("  sound INT");
279
             gOpenRaider->mConsole->print("  sound INT");
280
+            gOpenRaider->mConsole->print("  mode MODE");
222
         } else if (strcmp(args->at(1), "sound") == 0) {
281
         } else if (strcmp(args->at(1), "sound") == 0) {
223
             gOpenRaider->mConsole->print("game-sound-command Usage:");
282
             gOpenRaider->mConsole->print("game-sound-command Usage:");
224
             gOpenRaider->mConsole->print("  game sound INT");
283
             gOpenRaider->mConsole->print("  game sound INT");
225
             gOpenRaider->mConsole->print("Where INT is a valid sound ID integer");
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
         } else {
301
         } else {
227
             gOpenRaider->mConsole->print("No help available for game %s.", args->at(1));
302
             gOpenRaider->mConsole->print("No help available for game %s.", args->at(1));
228
-            return -3;
303
+            return -12;
229
         }
304
         }
230
     } else {
305
     } else {
231
         gOpenRaider->mConsole->print("Invalid use of game-command (%s)!", cmd);
306
         gOpenRaider->mConsole->print("Invalid use of game-command (%s)!", cmd);
232
-        return -4;
307
+        return -13;
233
     }
308
     }
234
 
309
 
235
     return 0;
310
     return 0;
737
                     }
812
                     }
738
 
813
 
739
                     mRender->setFlags(Render::fRenderPonytail);
814
                     mRender->setFlags(Render::fRenderPonytail);
740
-                    printf("Found known ponytail\n");
815
+                    gOpenRaider->mConsole->print("Found known ponytail");
741
                 }
816
                 }
742
                 break; // ?
817
                 break; // ?
743
             case TR_VERSION_1:
818
             case TR_VERSION_1:
766
     }
841
     }
767
     else
842
     else
768
     {
843
     {
844
+        // Already cached
769
         delete r_model;
845
         delete r_model;
770
-
771
         c_model = cache2[foundIndex];
846
         c_model = cache2[foundIndex];
772
         sModel->model = c_model;
847
         sModel->model = c_model;
773
         mWorld.addEntity(thing);
848
         mWorld.addEntity(thing);
774
         mWorld.addModel(c_model);
849
         mWorld.addModel(c_model);
775
-        //printf("c"); // it's already cached
850
+        printf("c");
776
-        //fflush(stdout);
777
-
778
-        //continue;
779
         return;
851
         return;
780
     }
852
     }
781
 
853
 

+ 78
- 77
src/Render.cpp View File

30
 #include "OpenRaider.h"
30
 #include "OpenRaider.h"
31
 #include "Render.h"
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
 bool compareEntites(const void *voidA, const void *voidB)
33
 bool compareEntites(const void *voidA, const void *voidB)
101
 {
34
 {
102
     entity_t *a = (entity_t *)voidA, *b = (entity_t *)voidB;
35
     entity_t *a = (entity_t *)voidA, *b = (entity_t *)voidB;
105
     if (!a || !b)
38
     if (!a || !b)
106
         return false; // error really
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
             a->pos[1],
42
             a->pos[1],
110
             a->pos[2],
43
             a->pos[2],
111
             1.0f);
44
             1.0f);
112
-    distB = gViewVolume.getDistToSphereFromNear(b->pos[0],
45
+    distB = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
113
             b->pos[1],
46
             b->pos[1],
114
             b->pos[2],
47
             b->pos[2],
115
             1.0f);
48
             1.0f);
126
     if (!a || !b)
59
     if (!a || !b)
127
         return false; // error really
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
             a->pos[1],
63
             a->pos[1],
131
             a->pos[2],
64
             a->pos[2],
132
             128.0f);
65
             128.0f);
133
-    distB = gViewVolume.getDistToSphereFromNear(b->pos[0],
66
+    distB = gOpenRaider->mGame->mRender->mViewVolume.getDistToSphereFromNear(b->pos[0],
134
             b->pos[1],
67
             b->pos[1],
135
             b->pos[2],
68
             b->pos[2],
136
             128.0f);
69
             128.0f);
830
     glFlush();
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
 void Render::newRoomRenderList(int index)
835
 void Render::newRoomRenderList(int index)
835
 {
836
 {
880
                     continue;
881
                     continue;
881
 
882
 
882
                 //room->dist =
883
                 //room->dist =
883
-                //gViewVolume.getDistToBboxFromNear(room->room->bbox_min,
884
+                //mViewVolume.getDistToBboxFromNear(room->room->bbox_min,
884
                 //                                           room->room->bbox_max);
885
                 //                                           room->room->bbox_max);
885
 
886
 
886
                 mRoomRenderList.push_back(room);
887
                 mRoomRenderList.push_back(room);
919
     }
920
     }
920
 
921
 
921
     //rRoom->dist =
922
     //rRoom->dist =
922
-    //gViewVolume.getDistToBboxFromNear(rRoom->room->bbox_min,
923
+    //mViewVolume.getDistToBboxFromNear(rRoom->room->bbox_min,
923
     //                                           rRoom->room->bbox_max);
924
     //                                           rRoom->room->bbox_max);
924
 
925
 
925
     /* Add current room to list */
926
     /* Add current room to list */
1894
 
1895
 
1895
     glGetFloatv(GL_PROJECTION_MATRIX, proj);
1896
     glGetFloatv(GL_PROJECTION_MATRIX, proj);
1896
     glGetFloatv(GL_MODELVIEW_MATRIX, mdl);
1897
     glGetFloatv(GL_MODELVIEW_MATRIX, mdl);
1897
-    gViewVolume.updateFrame(proj, mdl);
1898
+    mViewVolume.updateFrame(proj, mdl);
1898
 }
1899
 }
1899
 
1900
 
1900
 
1901
 
1913
         draw_bbox_color(bbox_min, bbox_max, true, PINK, RED);
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
         glEnd();
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
         glEnd();
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