Browse Source

World now also service

Thomas Buck 10 years ago
parent
commit
e9c7c9c42f
6 changed files with 88 additions and 82 deletions
  1. 1
    7
      include/Game.h
  2. 0
    2
      include/OpenRaider.h
  3. 14
    6
      include/main.h
  4. 43
    54
      src/Game.cpp
  5. 13
    13
      src/Render.cpp
  6. 17
    0
      src/main.cpp

+ 1
- 7
include/Game.h View File

@@ -8,7 +8,7 @@
8 8
 #ifndef _GAME_H_
9 9
 #define _GAME_H_
10 10
 
11
-#include <list>
11
+#include <vector>
12 12
 
13 13
 #include "Camera.h"
14 14
 #include "global.h"
@@ -16,10 +16,6 @@
16 16
 #include "TombRaider.h"
17 17
 #include "World.h"
18 18
 
19
-typedef enum {
20
-    Flag_DebugModel = (1 << 0)
21
-} GameFlags;
22
-
23 19
 /*!
24 20
  * \brief Game abstraction
25 21
  */
@@ -45,7 +41,6 @@ public:
45 41
     int command(std::vector<char *> *args);
46 42
 
47 43
     //! \fixme should be private
48
-    World mWorld;
49 44
     entity_t *mLara;
50 45
     Render *mRender;
51 46
     Camera *mCamera;
@@ -65,7 +60,6 @@ private:
65 60
 
66 61
     bool mLoaded;
67 62
     char *mName;
68
-    unsigned int mFlags;
69 63
     TombRaider mTombRaider;
70 64
 
71 65
     unsigned int mTextureStart;

+ 0
- 2
include/OpenRaider.h View File

@@ -41,8 +41,6 @@ public:
41 41
 
42 42
     int command(const char *command);
43 43
 
44
-    int initialize();
45
-
46 44
     void run();
47 45
 
48 46
     void handleKeyboard(KeyboardButton key, bool pressed);

+ 14
- 6
include/main.h View File

@@ -1,6 +1,6 @@
1 1
 /*!
2 2
  * \file include/main.h
3
- * \brief Where main() is
3
+ * \brief Service locator
4 4
  *
5 5
  * \author xythobuz
6 6
  */
@@ -13,13 +13,21 @@
13 13
 #include "OpenRaider.h"
14 14
 #include "Sound.h"
15 15
 #include "Window.h"
16
+#include "World.h"
17
+
18
+Console &getConsole();
19
+
20
+Game &getGame();
21
+
22
+Menu &getMenu();
16 23
 
17
-Console    &getConsole();
18
-Game       &getGame();
19
-Menu       &getMenu();
20 24
 OpenRaider &getOpenRaider();
21
-Sound      &getSound();
22
-Window     &getWindow();
25
+
26
+Sound &getSound();
27
+
28
+Window &getWindow();
29
+
30
+World &getWorld();
23 31
 
24 32
 /*!
25 33
  * \brief Program entry point

+ 43
- 54
src/Game.cpp View File

@@ -13,7 +13,6 @@
13 13
 
14 14
 #include <algorithm>
15 15
 #include <map>
16
-#include <vector>
17 16
 #include <cstdlib>
18 17
 
19 18
 #include "main.h"
@@ -34,7 +33,6 @@ Game::Game() {
34 33
     mLoaded = false;
35 34
     mName = NULL;
36 35
     mLara = NULL;
37
-    mFlags = 0;
38 36
 
39 37
     mTextureStart = 0;
40 38
     mTextureLevelOffset = 0;
@@ -70,7 +68,7 @@ int Game::initialize() {
70 68
     mRender->setMode(Render::modeLoadScreen);
71 69
 
72 70
     // Enable World Hopping
73
-    mWorld.setFlag(World::fEnableHopping);
71
+    getWorld().setFlag(World::fEnableHopping);
74 72
 
75 73
     return 0;
76 74
 }
@@ -82,7 +80,7 @@ void Game::destroy() {
82 80
     mLoaded = false;
83 81
     mRender->setMode(Render::modeDisabled);
84 82
 
85
-    mWorld.destroy();
83
+    getWorld().destroy();
86 84
     mRender->ClearWorld();
87 85
     getSound().clear(); // Remove all previously loaded sounds
88 86
 }
@@ -146,13 +144,13 @@ int Game::loadLevel(const char *level) {
146 144
 void Game::handleAction(ActionEvents action, bool isFinished) {
147 145
     if (mLoaded) {
148 146
         if (action == forwardAction) {
149
-            mWorld.moveEntity(mLara, 'f');
147
+            getWorld().moveEntity(mLara, 'f');
150 148
         } else if (action == backwardAction) {
151
-            mWorld.moveEntity(mLara, 'b');
149
+            getWorld().moveEntity(mLara, 'b');
152 150
         } else if (action == leftAction) {
153
-            mWorld.moveEntity(mLara, 'l');
151
+            getWorld().moveEntity(mLara, 'l');
154 152
         } else if (action == rightAction) {
155
-            mWorld.moveEntity(mLara, 'r');
153
+            getWorld().moveEntity(mLara, 'r');
156 154
         }
157 155
     }
158 156
 }
@@ -493,7 +491,7 @@ void Game::processSprites()
493 491
                 s_index = sprite_sequence[j].offset;
494 492
 
495 493
                 r_mesh = new sprite_seq_t;
496
-                mWorld.addSprite(r_mesh);
494
+                getWorld().addSprite(r_mesh);
497 495
                 r_mesh->num_sprites = -sprite_sequence[j].negative_length;
498 496
                 r_mesh->sprite = new sprite_t[r_mesh->num_sprites];
499 497
 
@@ -737,7 +735,7 @@ void Game::processMoveable(int index, int i, int *ent,
737 735
     }
738 736
 
739 737
     //! \fixme Check here and see if we already have one for object_id later
740
-    // if (mWorld.isCachedSkeletalModel(moveable[index].object_id))
738
+    // if (getWorld().isCachedSkeletalModel(moveable[index].object_id))
741 739
     // {
742 740
     //   thing->modelId = mRender->add(sModel);
743 741
     //   return;
@@ -835,9 +833,9 @@ void Game::processMoveable(int index, int i, int *ent,
835 833
     if (!found)
836 834
     {
837 835
         sModel->model = r_model;
838
-        mWorld.addEntity(thing);
836
+        getWorld().addEntity(thing);
839 837
 
840
-        k = mWorld.addModel(r_model);
838
+        k = getWorld().addModel(r_model);
841 839
 
842 840
         cache.push_back(j);
843 841
         cache2.push_back(r_model);
@@ -901,22 +899,19 @@ void Game::processMoveable(int index, int i, int *ent,
901 899
         delete r_model;
902 900
         c_model = cache2[foundIndex];
903 901
         sModel->model = c_model;
904
-        mWorld.addEntity(thing);
905
-        mWorld.addModel(c_model);
902
+        getWorld().addEntity(thing);
903
+        getWorld().addModel(c_model);
906 904
         printf("c");
907 905
         return;
908 906
     }
909 907
 
910 908
     int aloop = mTombRaider.getNumAnimsForMoveable(index);
911 909
 
912
-#ifdef DEBUG
913
-    if (mFlags & Flag_DebugModel)
914
-    {
915
-        printf("\nanimation = %i, num_animations = %i\n",
916
-                moveable[index].animation, aloop);
917
-        printf("\nitem[%i].flags = %i\nentity[%i]\n",
918
-                i, item[i].flags, thing->id);
919
-    }
910
+#ifdef DEBUG_MOVEABLE
911
+    printf("\nanimation = %i, num_animations = %i\n",
912
+            moveable[index].animation, aloop);
913
+    printf("\nitem[%i].flags = %i\nentity[%i]\n",
914
+            i, item[i].flags, thing->id);
920 915
 #endif
921 916
 
922 917
     //a = moveable[index].animation;
@@ -933,28 +928,25 @@ void Game::processMoveable(int index, int i, int *ent,
933 928
         frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
934 929
         animation_frame->rate = animation[a].frame_rate;
935 930
 
936
-#ifdef DEBUG
937
-        if (mFlags & Flag_DebugModel)
938
-        {
939
-            printf("animation[%i] state and unknowns = %i, %i, %i, %i, %i\n",
940
-                    a, animation[a].state_id, animation[a].unknown1,
941
-                    animation[a].unknown2, animation[a].unknown3,
942
-                    animation[a].unknown4);
943
-            printf("animation[%i].frame_rate = %i\n",
944
-                    a, animation[a].frame_rate);
945
-            printf("animation[%i].next_animation = %i\n",
946
-                    a, animation[a].next_animation);
947
-            printf("animation[%i].frame_offset = %u\n",
948
-                    a, animation[a].frame_offset);
949
-            printf("animation[%i].anim_command = %i\n",
950
-                    a, animation[a].anim_command);
951
-            printf("animation[%i].num_anim_commands = %i\n",
952
-                    a, animation[a].num_anim_commands);
953
-            printf("animation[%i].state_change_offset = %i\n",
954
-                    a, animation[a].state_change_offset);
955
-            printf("              frame_offset = %u\n",
956
-                    frame_offset);
957
-        }
931
+#ifdef DEBUG_MOVEABLE
932
+        printf("animation[%i] state and unknowns = %i, %i, %i, %i, %i\n",
933
+                a, animation[a].state_id, animation[a].unknown1,
934
+                animation[a].unknown2, animation[a].unknown3,
935
+                animation[a].unknown4);
936
+        printf("animation[%i].frame_rate = %i\n",
937
+                a, animation[a].frame_rate);
938
+        printf("animation[%i].next_animation = %i\n",
939
+                a, animation[a].next_animation);
940
+        printf("animation[%i].frame_offset = %u\n",
941
+                a, animation[a].frame_offset);
942
+        printf("animation[%i].anim_command = %i\n",
943
+                a, animation[a].anim_command);
944
+        printf("animation[%i].num_anim_commands = %i\n",
945
+                a, animation[a].num_anim_commands);
946
+        printf("animation[%i].state_change_offset = %i\n",
947
+                a, animation[a].state_change_offset);
948
+        printf("              frame_offset = %u\n",
949
+                frame_offset);
958 950
 #endif
959 951
 
960 952
         // Get all the frames for aniamtion
@@ -997,12 +989,9 @@ void Game::processMoveable(int index, int i, int *ent,
997 989
                 }
998 990
             }
999 991
 
1000
-#ifdef DEBUG
1001
-            if (mFlags & Flag_DebugModel)
1002
-            {
1003
-                printf("animation[%i].boneframe[%u] = offset %u, step %i\n",
1004
-                        a, f, frame_offset, frame_step);
1005
-            }
992
+#ifdef DEBUG_MOVEABLE
993
+            printf("animation[%i].boneframe[%u] = offset %u, step %i\n",
994
+                    a, f, frame_offset, frame_step);
1006 995
 #endif
1007 996
 
1008 997
             // Mongoose 2002.08.15, Was
@@ -1165,7 +1154,7 @@ void Game::processModels()
1165 1154
         if (index < 0 || !mTombRaider.isMeshValid(index))
1166 1155
         {
1167 1156
             //! \fixme allow sparse lists with matching ids instead?
1168
-            mWorld.addMesh(NULL); // Filler, to make meshes array ids align
1157
+            getWorld().addMesh(NULL); // Filler, to make meshes array ids align
1169 1158
             //printf("x");
1170 1159
             //fflush(stdout);
1171 1160
             return;
@@ -1347,7 +1336,7 @@ void Game::processModels()
1347 1336
         std::sort(mesh->texturedRectangles.begin(), mesh->texturedRectangles.end(), compareFaceTextureId);
1348 1337
         std::sort(mesh->coloredRectangles.begin(), mesh->coloredRectangles.end(), compareFaceTextureId);
1349 1338
 
1350
-        mWorld.addMesh(mesh);
1339
+        getWorld().addMesh(mesh);
1351 1340
         //printf(".");
1352 1341
         //fflush(stdout);
1353 1342
     }
@@ -1367,7 +1356,7 @@ void Game::processRooms()
1367 1356
         if (!mTombRaider.isRoomValid(index))
1368 1357
         {
1369 1358
             getConsole().print("WARNING: Handling invalid vertex array in room");
1370
-            mWorld.addRoom(0x0);
1359
+            getWorld().addRoom(0x0);
1371 1360
             mRender->addRoom(0x0);
1372 1361
 
1373 1362
             //printf("x");
@@ -1908,7 +1897,7 @@ void Game::processRooms()
1908 1897
             r_mesh->sprites.push_back(sprite);
1909 1898
         }
1910 1899
 
1911
-        mWorld.addRoom(r_mesh);
1900
+        getWorld().addRoom(r_mesh);
1912 1901
 
1913 1902
         rRoom->room = r_mesh;
1914 1903
         mRender->addRoom(rRoom);

+ 13
- 13
src/Render.cpp View File

@@ -544,10 +544,10 @@ void Render::Display()
544 544
         camPos[0] -= (1024.0f * sinf(yaw));
545 545
         camPos[2] -= (1024.0f * cosf(yaw));
546 546
 
547
-        sector = getGame().mWorld.getSector(index, camPos[0], camPos[2]);
547
+        sector = getWorld().getSector(index, camPos[0], camPos[2]);
548 548
 
549 549
         // Handle camera out of world
550
-        if (sector < 0 || getGame().mWorld.isWall(index, sector))
550
+        if (sector < 0 || getWorld().isWall(index, sector))
551 551
         {
552 552
             camPos[0] = curPos[0] + (64.0f * sinf(yaw));
553 553
             camPos[1] -= 64.0f;
@@ -642,7 +642,7 @@ void Render::Display()
642 642
     {
643 643
         entity_t *e;
644 644
         std::vector<entity_t *> entityRenderList;
645
-        std::vector<entity_t *> *entities = getGame().mWorld.getEntities();
645
+        std::vector<entity_t *> *entities = getWorld().getEntities();
646 646
 
647 647
         for (unsigned int i = 0; i < entities->size(); i++)
648 648
         {
@@ -956,7 +956,7 @@ void Render::buildRoomRenderList(RenderRoom *rRoom)
956 956
 
957 957
 void Render::drawSkyMesh(float scale)
958 958
 {
959
-    skeletal_model_t *model = getGame().mWorld.getModel(mSkyMesh);
959
+    skeletal_model_t *model = getWorld().getModel(mSkyMesh);
960 960
 
961 961
 
962 962
     if (!model)
@@ -973,7 +973,7 @@ void Render::drawSkyMesh(float scale)
973 973
     glTranslated(0.0, 1000.0, 0.0);
974 974
     glScaled(scale, scale, scale);
975 975
     //drawModel(model);
976
-    //drawModelMesh(getGame().mWorld.getMesh(mSkyMesh), );
976
+    //drawModelMesh(getWorld().getMesh(mSkyMesh), );
977 977
     glPopMatrix();
978 978
     glEnable(GL_DEPTH_TEST);
979 979
 }
@@ -1041,7 +1041,7 @@ void Render::drawObjects()
1041 1041
     {
1042 1042
         std::vector<sprite_seq_t *> *sprites;
1043 1043
 
1044
-        sprites = getGame().mWorld.getSprites();
1044
+        sprites = getWorld().getSprites();
1045 1045
 
1046 1046
         for (unsigned int i = 0; i < sprites->size(); i++)
1047 1047
         {
@@ -1161,7 +1161,7 @@ void Render::drawModel(SkeletalModel *model)
1161 1161
 
1162 1162
                 if (tag2)
1163 1163
                 {
1164
-                    drawModelMesh(getGame().mWorld.getMesh(tag2->mesh), Render::skeletalMesh);
1164
+                    drawModelMesh(getWorld().getMesh(tag2->mesh), Render::skeletalMesh);
1165 1165
                 }
1166 1166
             }
1167 1167
         }
@@ -1204,19 +1204,19 @@ void Render::drawModel(SkeletalModel *model)
1204 1204
                     {
1205 1205
                         glPushMatrix();
1206 1206
                         glTranslatef(mdl->ponyOff2, 0.0, 0.0);
1207
-                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1207
+                        drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i),
1208 1208
                                 Render::skeletalMesh);
1209 1209
                         glPopMatrix();
1210 1210
 
1211 1211
                         glPushMatrix();
1212 1212
                         glTranslatef(-mdl->ponyOff2, 0.0, 0.0);
1213
-                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1213
+                        drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i),
1214 1214
                                 Render::skeletalMesh);
1215 1215
                         glPopMatrix();
1216 1216
                     }
1217 1217
                     else
1218 1218
                     {
1219
-                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1219
+                        drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i),
1220 1220
                                 Render::skeletalMesh);
1221 1221
                     }
1222 1222
                 }
@@ -1230,7 +1230,7 @@ void Render::drawModel(SkeletalModel *model)
1230 1230
             }
1231 1231
         }
1232 1232
 
1233
-        drawModelMesh(getGame().mWorld.getMesh(tag->mesh), Render::skeletalMesh);
1233
+        drawModelMesh(getWorld().getMesh(tag->mesh), Render::skeletalMesh);
1234 1234
     }
1235 1235
 
1236 1236
     // Cycle frames ( cheap hack from old ent state based system )
@@ -1612,7 +1612,7 @@ void Render::drawRoomModel(static_model_t *mesh)
1612 1612
     if (!mesh)
1613 1613
         return;
1614 1614
 
1615
-    r_mesh = getGame().mWorld.getMesh(mesh->index);
1615
+    r_mesh = getWorld().getMesh(mesh->index);
1616 1616
 
1617 1617
     if (!r_mesh)
1618 1618
         return;
@@ -1862,7 +1862,7 @@ void Render::ViewModel(entity_t *ent, int index)
1862 1862
         return;
1863 1863
     }
1864 1864
 
1865
-    model = getGame().mWorld.getModel(index);
1865
+    model = getWorld().getModel(index);
1866 1866
 
1867 1867
     if (model)
1868 1868
     {

+ 17
- 0
src/main.cpp View File

@@ -8,6 +8,7 @@
8 8
 #include <cstdlib>
9 9
 #include <cstdio>
10 10
 #include <cstring>
11
+#include <assert.h>
11 12
 
12 13
 #include "config.h"
13 14
 #include "main.h"
@@ -20,31 +21,43 @@ Menu *gMenu = NULL;
20 21
 OpenRaider *gOpenRaider = NULL;
21 22
 Sound *gSound = NULL;
22 23
 Window *gWindow = NULL;
24
+World *gWorld = NULL;
23 25
 
24 26
 Console &getConsole() {
27
+    assert(gConsole != NULL);
25 28
     return *gConsole;
26 29
 }
27 30
 
28 31
 Game &getGame() {
32
+    assert(gGame != NULL);
29 33
     return *gGame;
30 34
 }
31 35
 
32 36
 Menu &getMenu() {
37
+    assert(gMenu != NULL);
33 38
     return *gMenu;
34 39
 }
35 40
 
36 41
 OpenRaider &getOpenRaider() {
42
+    assert(gOpenRaider != NULL);
37 43
     return *gOpenRaider;
38 44
 }
39 45
 
40 46
 Sound &getSound() {
47
+    assert(gSound != NULL);
41 48
     return *gSound;
42 49
 }
43 50
 
44 51
 Window &getWindow() {
52
+    assert(gWindow != NULL);
45 53
     return *gWindow;
46 54
 }
47 55
 
56
+World &getWorld() {
57
+    assert(gWorld != NULL);
58
+    return *gWorld;
59
+}
60
+
48 61
 void cleanupHandler(void) {
49 62
     if (gConsole)
50 63
         delete gConsole;
@@ -55,6 +68,9 @@ void cleanupHandler(void) {
55 68
     if (gMenu)
56 69
         delete gMenu;
57 70
 
71
+    if (gWorld)
72
+        delete gWorld;
73
+
58 74
     if (gOpenRaider)
59 75
         delete gOpenRaider;
60 76
 
@@ -110,6 +126,7 @@ int main(int argc, char *argv[]) {
110 126
     gOpenRaider = new OpenRaider();
111 127
     gWindow = new WindowSDL();
112 128
     gSound = new Sound();
129
+    gWorld = new World();
113 130
     gConsole = new Console();
114 131
     gMenu = new Menu();
115 132
     gGame = new Game();

Loading…
Cancel
Save