ソースを参照

World now also service

Thomas Buck 11年前
コミット
e9c7c9c42f
6個のファイルの変更88行の追加82行の削除
  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 ファイルの表示

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

+ 0
- 2
include/OpenRaider.h ファイルの表示

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

+ 14
- 6
include/main.h ファイルの表示

1
 /*!
1
 /*!
2
  * \file include/main.h
2
  * \file include/main.h
3
- * \brief Where main() is
3
+ * \brief Service locator
4
  *
4
  *
5
  * \author xythobuz
5
  * \author xythobuz
6
  */
6
  */
13
 #include "OpenRaider.h"
13
 #include "OpenRaider.h"
14
 #include "Sound.h"
14
 #include "Sound.h"
15
 #include "Window.h"
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
 OpenRaider &getOpenRaider();
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
  * \brief Program entry point
33
  * \brief Program entry point

+ 43
- 54
src/Game.cpp ファイルの表示

13
 
13
 
14
 #include <algorithm>
14
 #include <algorithm>
15
 #include <map>
15
 #include <map>
16
-#include <vector>
17
 #include <cstdlib>
16
 #include <cstdlib>
18
 
17
 
19
 #include "main.h"
18
 #include "main.h"
34
     mLoaded = false;
33
     mLoaded = false;
35
     mName = NULL;
34
     mName = NULL;
36
     mLara = NULL;
35
     mLara = NULL;
37
-    mFlags = 0;
38
 
36
 
39
     mTextureStart = 0;
37
     mTextureStart = 0;
40
     mTextureLevelOffset = 0;
38
     mTextureLevelOffset = 0;
70
     mRender->setMode(Render::modeLoadScreen);
68
     mRender->setMode(Render::modeLoadScreen);
71
 
69
 
72
     // Enable World Hopping
70
     // Enable World Hopping
73
-    mWorld.setFlag(World::fEnableHopping);
71
+    getWorld().setFlag(World::fEnableHopping);
74
 
72
 
75
     return 0;
73
     return 0;
76
 }
74
 }
82
     mLoaded = false;
80
     mLoaded = false;
83
     mRender->setMode(Render::modeDisabled);
81
     mRender->setMode(Render::modeDisabled);
84
 
82
 
85
-    mWorld.destroy();
83
+    getWorld().destroy();
86
     mRender->ClearWorld();
84
     mRender->ClearWorld();
87
     getSound().clear(); // Remove all previously loaded sounds
85
     getSound().clear(); // Remove all previously loaded sounds
88
 }
86
 }
146
 void Game::handleAction(ActionEvents action, bool isFinished) {
144
 void Game::handleAction(ActionEvents action, bool isFinished) {
147
     if (mLoaded) {
145
     if (mLoaded) {
148
         if (action == forwardAction) {
146
         if (action == forwardAction) {
149
-            mWorld.moveEntity(mLara, 'f');
147
+            getWorld().moveEntity(mLara, 'f');
150
         } else if (action == backwardAction) {
148
         } else if (action == backwardAction) {
151
-            mWorld.moveEntity(mLara, 'b');
149
+            getWorld().moveEntity(mLara, 'b');
152
         } else if (action == leftAction) {
150
         } else if (action == leftAction) {
153
-            mWorld.moveEntity(mLara, 'l');
151
+            getWorld().moveEntity(mLara, 'l');
154
         } else if (action == rightAction) {
152
         } else if (action == rightAction) {
155
-            mWorld.moveEntity(mLara, 'r');
153
+            getWorld().moveEntity(mLara, 'r');
156
         }
154
         }
157
     }
155
     }
158
 }
156
 }
493
                 s_index = sprite_sequence[j].offset;
491
                 s_index = sprite_sequence[j].offset;
494
 
492
 
495
                 r_mesh = new sprite_seq_t;
493
                 r_mesh = new sprite_seq_t;
496
-                mWorld.addSprite(r_mesh);
494
+                getWorld().addSprite(r_mesh);
497
                 r_mesh->num_sprites = -sprite_sequence[j].negative_length;
495
                 r_mesh->num_sprites = -sprite_sequence[j].negative_length;
498
                 r_mesh->sprite = new sprite_t[r_mesh->num_sprites];
496
                 r_mesh->sprite = new sprite_t[r_mesh->num_sprites];
499
 
497
 
737
     }
735
     }
738
 
736
 
739
     //! \fixme Check here and see if we already have one for object_id later
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
     //   thing->modelId = mRender->add(sModel);
740
     //   thing->modelId = mRender->add(sModel);
743
     //   return;
741
     //   return;
835
     if (!found)
833
     if (!found)
836
     {
834
     {
837
         sModel->model = r_model;
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
         cache.push_back(j);
840
         cache.push_back(j);
843
         cache2.push_back(r_model);
841
         cache2.push_back(r_model);
901
         delete r_model;
899
         delete r_model;
902
         c_model = cache2[foundIndex];
900
         c_model = cache2[foundIndex];
903
         sModel->model = c_model;
901
         sModel->model = c_model;
904
-        mWorld.addEntity(thing);
905
-        mWorld.addModel(c_model);
902
+        getWorld().addEntity(thing);
903
+        getWorld().addModel(c_model);
906
         printf("c");
904
         printf("c");
907
         return;
905
         return;
908
     }
906
     }
909
 
907
 
910
     int aloop = mTombRaider.getNumAnimsForMoveable(index);
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
 #endif
915
 #endif
921
 
916
 
922
     //a = moveable[index].animation;
917
     //a = moveable[index].animation;
933
         frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
928
         frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
934
         animation_frame->rate = animation[a].frame_rate;
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
 #endif
950
 #endif
959
 
951
 
960
         // Get all the frames for aniamtion
952
         // Get all the frames for aniamtion
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
 #endif
995
 #endif
1007
 
996
 
1008
             // Mongoose 2002.08.15, Was
997
             // Mongoose 2002.08.15, Was
1165
         if (index < 0 || !mTombRaider.isMeshValid(index))
1154
         if (index < 0 || !mTombRaider.isMeshValid(index))
1166
         {
1155
         {
1167
             //! \fixme allow sparse lists with matching ids instead?
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
             //printf("x");
1158
             //printf("x");
1170
             //fflush(stdout);
1159
             //fflush(stdout);
1171
             return;
1160
             return;
1347
         std::sort(mesh->texturedRectangles.begin(), mesh->texturedRectangles.end(), compareFaceTextureId);
1336
         std::sort(mesh->texturedRectangles.begin(), mesh->texturedRectangles.end(), compareFaceTextureId);
1348
         std::sort(mesh->coloredRectangles.begin(), mesh->coloredRectangles.end(), compareFaceTextureId);
1337
         std::sort(mesh->coloredRectangles.begin(), mesh->coloredRectangles.end(), compareFaceTextureId);
1349
 
1338
 
1350
-        mWorld.addMesh(mesh);
1339
+        getWorld().addMesh(mesh);
1351
         //printf(".");
1340
         //printf(".");
1352
         //fflush(stdout);
1341
         //fflush(stdout);
1353
     }
1342
     }
1367
         if (!mTombRaider.isRoomValid(index))
1356
         if (!mTombRaider.isRoomValid(index))
1368
         {
1357
         {
1369
             getConsole().print("WARNING: Handling invalid vertex array in room");
1358
             getConsole().print("WARNING: Handling invalid vertex array in room");
1370
-            mWorld.addRoom(0x0);
1359
+            getWorld().addRoom(0x0);
1371
             mRender->addRoom(0x0);
1360
             mRender->addRoom(0x0);
1372
 
1361
 
1373
             //printf("x");
1362
             //printf("x");
1908
             r_mesh->sprites.push_back(sprite);
1897
             r_mesh->sprites.push_back(sprite);
1909
         }
1898
         }
1910
 
1899
 
1911
-        mWorld.addRoom(r_mesh);
1900
+        getWorld().addRoom(r_mesh);
1912
 
1901
 
1913
         rRoom->room = r_mesh;
1902
         rRoom->room = r_mesh;
1914
         mRender->addRoom(rRoom);
1903
         mRender->addRoom(rRoom);

+ 13
- 13
src/Render.cpp ファイルの表示

544
         camPos[0] -= (1024.0f * sinf(yaw));
544
         camPos[0] -= (1024.0f * sinf(yaw));
545
         camPos[2] -= (1024.0f * cosf(yaw));
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
         // Handle camera out of world
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
             camPos[0] = curPos[0] + (64.0f * sinf(yaw));
552
             camPos[0] = curPos[0] + (64.0f * sinf(yaw));
553
             camPos[1] -= 64.0f;
553
             camPos[1] -= 64.0f;
642
     {
642
     {
643
         entity_t *e;
643
         entity_t *e;
644
         std::vector<entity_t *> entityRenderList;
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
         for (unsigned int i = 0; i < entities->size(); i++)
647
         for (unsigned int i = 0; i < entities->size(); i++)
648
         {
648
         {
956
 
956
 
957
 void Render::drawSkyMesh(float scale)
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
     if (!model)
962
     if (!model)
973
     glTranslated(0.0, 1000.0, 0.0);
973
     glTranslated(0.0, 1000.0, 0.0);
974
     glScaled(scale, scale, scale);
974
     glScaled(scale, scale, scale);
975
     //drawModel(model);
975
     //drawModel(model);
976
-    //drawModelMesh(getGame().mWorld.getMesh(mSkyMesh), );
976
+    //drawModelMesh(getWorld().getMesh(mSkyMesh), );
977
     glPopMatrix();
977
     glPopMatrix();
978
     glEnable(GL_DEPTH_TEST);
978
     glEnable(GL_DEPTH_TEST);
979
 }
979
 }
1041
     {
1041
     {
1042
         std::vector<sprite_seq_t *> *sprites;
1042
         std::vector<sprite_seq_t *> *sprites;
1043
 
1043
 
1044
-        sprites = getGame().mWorld.getSprites();
1044
+        sprites = getWorld().getSprites();
1045
 
1045
 
1046
         for (unsigned int i = 0; i < sprites->size(); i++)
1046
         for (unsigned int i = 0; i < sprites->size(); i++)
1047
         {
1047
         {
1161
 
1161
 
1162
                 if (tag2)
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
                     {
1204
                     {
1205
                         glPushMatrix();
1205
                         glPushMatrix();
1206
                         glTranslatef(mdl->ponyOff2, 0.0, 0.0);
1206
                         glTranslatef(mdl->ponyOff2, 0.0, 0.0);
1207
-                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1207
+                        drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i),
1208
                                 Render::skeletalMesh);
1208
                                 Render::skeletalMesh);
1209
                         glPopMatrix();
1209
                         glPopMatrix();
1210
 
1210
 
1211
                         glPushMatrix();
1211
                         glPushMatrix();
1212
                         glTranslatef(-mdl->ponyOff2, 0.0, 0.0);
1212
                         glTranslatef(-mdl->ponyOff2, 0.0, 0.0);
1213
-                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1213
+                        drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i),
1214
                                 Render::skeletalMesh);
1214
                                 Render::skeletalMesh);
1215
                         glPopMatrix();
1215
                         glPopMatrix();
1216
                     }
1216
                     }
1217
                     else
1217
                     else
1218
                     {
1218
                     {
1219
-                        drawModelMesh(getGame().mWorld.getMesh(mdl->ponytailMeshId + i),
1219
+                        drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i),
1220
                                 Render::skeletalMesh);
1220
                                 Render::skeletalMesh);
1221
                     }
1221
                     }
1222
                 }
1222
                 }
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
     // Cycle frames ( cheap hack from old ent state based system )
1236
     // Cycle frames ( cheap hack from old ent state based system )
1612
     if (!mesh)
1612
     if (!mesh)
1613
         return;
1613
         return;
1614
 
1614
 
1615
-    r_mesh = getGame().mWorld.getMesh(mesh->index);
1615
+    r_mesh = getWorld().getMesh(mesh->index);
1616
 
1616
 
1617
     if (!r_mesh)
1617
     if (!r_mesh)
1618
         return;
1618
         return;
1862
         return;
1862
         return;
1863
     }
1863
     }
1864
 
1864
 
1865
-    model = getGame().mWorld.getModel(index);
1865
+    model = getWorld().getModel(index);
1866
 
1866
 
1867
     if (model)
1867
     if (model)
1868
     {
1868
     {

+ 17
- 0
src/main.cpp ファイルの表示

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

読み込み中…
キャンセル
保存