소스 검색

Maplist now in Menu

Thomas Buck 10 년 전
부모
커밋
e36e6e5ee3
7개의 변경된 파일118개의 추가작업 그리고 186개의 파일을 삭제
  1. 3
    0
      ChangeLog
  2. 8
    0
      include/Menu.h
  3. 0
    8
      include/OpenRaider.h
  4. 92
    11
      src/Menu.cpp
  5. 14
    75
      src/OpenRaider.cpp
  6. 1
    14
      src/Render.cpp
  7. 0
    78
      src/World.cpp

+ 3
- 0
ChangeLog 파일 보기

@@ -2,6 +2,9 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+	[ 20140416 ]
6
+	* Map list now stored in Menu
7
+
5 8
 	[ 20140405 ]
6 9
 	* "Ported" all commands from old source
7 10
 	* Slimmed down Camera considerably

+ 8
- 0
include/Menu.h 파일 보기

@@ -38,6 +38,10 @@ public:
38 38
 
39 39
 private:
40 40
 
41
+    void loadPakFolderRecursive(const char *dir);
42
+
43
+    void fillMapList();
44
+
41 45
     void displayMapList();
42 46
 
43 47
     bool mVisible;
@@ -45,6 +49,10 @@ private:
45 49
     unsigned int mMin;
46 50
 
47 51
     WindowString mainText;
52
+
53
+    bool mMapListFilled;
54
+    bool mFirstPass;
55
+    std::vector<char *> mMapList;
48 56
 };
49 57
 
50 58
 #endif

+ 0
- 8
include/OpenRaider.h 파일 보기

@@ -58,10 +58,6 @@ public:
58 58
     void handleMouseScroll(int xrel, int yrel);
59 59
 
60 60
     //! \fixme should be private
61
-
62
-    bool mMapListFilled;
63
-    std::vector<char *> mMapList;
64
-
65 61
     char *mBaseDir;
66 62
     char *mPakDir;
67 63
     char *mAudioDir;
@@ -81,10 +77,6 @@ private:
81 77
 
82 78
     int bind(ActionEvents action, const char *key);
83 79
 
84
-    void loadPakFolderRecursive(const char *dir);
85
-
86
-    void fillMapList();
87
-
88 80
     bool mRunning;
89 81
     bool mFPS;
90 82
 

+ 92
- 11
src/Menu.cpp 파일 보기

@@ -5,6 +5,9 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include <assert.h>
9
+#include <dirent.h>
10
+
8 11
 #ifdef __APPLE__
9 12
 #include <OpenGL/gl.h>
10 13
 #else
@@ -31,10 +34,18 @@ Menu::Menu() {
31 34
     mainText.y = 10;
32 35
     mainText.w = 0;
33 36
     mainText.h = 0;
37
+
38
+    mMapListFilled = false;
39
+    mFirstPass = false;
34 40
 }
35 41
 
36 42
 Menu::~Menu() {
37 43
     delete [] mainText.text;
44
+
45
+    while (mMapList.size() > 0) {
46
+        delete [] mMapList.back();
47
+        mMapList.pop_back();
48
+    }
38 49
 }
39 50
 
40 51
 void Menu::setVisible(bool visible) {
@@ -45,6 +56,66 @@ bool Menu::isVisible() {
45 56
     return mVisible;
46 57
 }
47 58
 
59
+void Menu::loadPakFolderRecursive(const char *dir) {
60
+    struct dirent entry;
61
+    struct dirent *ep = NULL;
62
+    DIR *pakDir;
63
+
64
+    assert(dir != NULL);
65
+    assert(dir[0] != '\0');
66
+
67
+    pakDir = opendir(dir);
68
+    if (pakDir != NULL) {
69
+        readdir_r(pakDir, &entry, &ep);
70
+        while (ep != NULL) {
71
+            if (ep->d_type == DT_DIR) {
72
+                if ((strcmp(".", ep->d_name) != 0)
73
+                 && (strcmp("..", ep->d_name) != 0)) {
74
+                    char *tmp = bufferString("%s%s", dir, ep->d_name);
75
+                    char *next = fullPath(tmp, '/');
76
+                    loadPakFolderRecursive(next);
77
+                    delete next;
78
+                    delete tmp;
79
+                }
80
+            } else {
81
+                char *fullPathMap = bufferString("%s%s", dir, ep->d_name);
82
+
83
+                char *lowerPath = bufferString("%s", fullPathMap);
84
+                for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
85
+
86
+                // Check for valid extension
87
+                if (stringEndsWith(lowerPath, ".phd")
88
+                     || stringEndsWith(lowerPath, ".tr2")
89
+                     || stringEndsWith(lowerPath, ".tr4")
90
+                     || stringEndsWith(lowerPath, ".trc")) {
91
+                    int error = TombRaider::checkMime(fullPathMap);
92
+                    if (error == 0) {
93
+                        // Just load relative filename
94
+                        mMapList.push_back(bufferString("%s", (fullPathMap + strlen(getOpenRaider().mPakDir) + 1)));
95
+                    } else {
96
+                        getConsole().print("Error: pak file '%s' %s",
97
+                                fullPathMap, (error == -1) ? "not found" : "invalid");
98
+                    }
99
+                }
100
+
101
+                delete [] lowerPath;
102
+                delete [] fullPathMap;
103
+            }
104
+            readdir_r(pakDir, &entry, &ep);
105
+        }
106
+        closedir(pakDir);
107
+    } else {
108
+        getConsole().print("Could not open PAK dir %s!", dir);
109
+    }
110
+}
111
+
112
+void Menu::fillMapList() {
113
+    char *tmp = fullPath(getOpenRaider().mPakDir, '/');
114
+    loadPakFolderRecursive(tmp);
115
+    delete [] tmp;
116
+    mMapListFilled = true;
117
+}
118
+
48 119
 void Menu::displayMapList() {
49 120
     // Estimate displayable number of items
50 121
     int items = (getWindow().mHeight - 110) / 25;
@@ -56,15 +127,15 @@ void Menu::displayMapList() {
56 127
     else
57 128
         min = 0;
58 129
 
59
-    if ((mCursor + (items / 2)) < getOpenRaider().mMapList.size())
130
+    if ((mCursor + (items / 2)) < mMapList.size())
60 131
         max = mCursor + (items / 2);
61 132
     else
62
-        max = getOpenRaider().mMapList.size();
133
+        max = mMapList.size();
63 134
 
64 135
     while ((max - min) < items) {
65 136
         if (min > 0)
66 137
             min--;
67
-        else if (max < ((int)getOpenRaider().mMapList.size()))
138
+        else if (max < ((int)mMapList.size()))
68 139
             max++;
69 140
         else
70 141
             break;
@@ -73,7 +144,7 @@ void Menu::displayMapList() {
73 144
     mMin = min;
74 145
 
75 146
     for (int i = 0; i < (max - min); i++) {
76
-        char *map = getOpenRaider().mMapList[i + min];
147
+        char *map = mMapList[i + min];
77 148
         if ((i + min) == (int)mCursor)
78 149
             getWindow().drawText(25, 100 + (25 * i), 0.75f, RED, "%s", map);
79 150
         else
@@ -93,10 +164,10 @@ void Menu::display() {
93 164
         mainText.x = (getWindow().mWidth / 2) - (mainText.w / 2);
94 165
         getWindow().writeString(&mainText);
95 166
 
96
-        if (!getOpenRaider().mMapListFilled) {
167
+        if (!mMapListFilled) {
97 168
             getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");
98 169
         } else {
99
-            if (getOpenRaider().mMapList.size() == 0) {
170
+            if (mMapList.size() == 0) {
100 171
                 getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, RED, "No maps found! See README.md");
101 172
             } else {
102 173
                 // draw *play button* above list
@@ -109,6 +180,16 @@ void Menu::display() {
109 180
                 displayMapList();
110 181
             }
111 182
         }
183
+
184
+        // Fill map list after first render pass,
185
+        // so menu *loading screen* is visible
186
+        if (mFirstPass) {
187
+            if (!mMapListFilled) {
188
+                fillMapList();
189
+            }
190
+        } else {
191
+            mFirstPass = true;
192
+        }
112 193
     }
113 194
 }
114 195
 
@@ -120,16 +201,16 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
120 201
         if (mCursor > 0)
121 202
             mCursor--;
122 203
         else
123
-            mCursor = getOpenRaider().mMapList.size() - 1;
204
+            mCursor = mMapList.size() - 1;
124 205
     } else if (key == downKey) {
125
-        if (mCursor < (getOpenRaider().mMapList.size() - 1))
206
+        if (mCursor < (mMapList.size() - 1))
126 207
             mCursor++;
127 208
         else
128 209
             mCursor = 0;
129 210
     } else if (key == rightKey) {
130 211
         int i = 10;
131
-        if (mCursor > (getOpenRaider().mMapList.size() - 11))
132
-            i = getOpenRaider().mMapList.size() - 1 - mCursor;
212
+        if (mCursor > (mMapList.size() - 11))
213
+            i = mMapList.size() - 1 - mCursor;
133 214
         while (i-- > 0)
134 215
             handleKeyboard(downKey, true);
135 216
     } else if (key == leftKey) {
@@ -139,7 +220,7 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
139 220
         while (i-- > 0)
140 221
             handleKeyboard(upKey, true);
141 222
     } else if (key == enterKey) {
142
-        char *tmp = bufferString("load %s", getOpenRaider().mMapList[mCursor]);
223
+        char *tmp = bufferString("load %s", mMapList[mCursor]);
143 224
         if (getOpenRaider().command(tmp) == 0) {
144 225
             setVisible(false);
145 226
         } else {

+ 14
- 75
src/OpenRaider.cpp 파일 보기

@@ -8,7 +8,6 @@
8 8
 #include <cstdio>
9 9
 #include <cstring>
10 10
 #include <assert.h>
11
-#include <dirent.h>
12 11
 
13 12
 #include "WindowSDL.h"
14 13
 
@@ -31,7 +30,6 @@ OpenRaider::OpenRaider() {
31 30
     mPakDir = NULL;
32 31
     mAudioDir = NULL;
33 32
     mDataDir = NULL;
34
-    mMapListFilled = false;
35 33
 
36 34
     for (int i = 0; i < ActionEventCount; i++)
37 35
         keyBindings[i] = unknownKey;
@@ -49,11 +47,6 @@ OpenRaider::~OpenRaider() {
49 47
 
50 48
     if (mDataDir)
51 49
         delete mDataDir;
52
-
53
-    while (mMapList.size() > 0) {
54
-        delete [] mMapList.back();
55
-        mMapList.pop_back();
56
-    }
57 50
 }
58 51
 
59 52
 int OpenRaider::initialize() {
@@ -90,6 +83,10 @@ int OpenRaider::initialize() {
90 83
         return -5;
91 84
     }
92 85
 
86
+#ifdef DEBUG
87
+    mFPS = true;
88
+#endif
89
+
93 90
     getMenu().setVisible(true);
94 91
     systemTimerReset();
95 92
 
@@ -1070,69 +1067,6 @@ int OpenRaider::bind(ActionEvents action, const char *key) {
1070 1067
     return 0;
1071 1068
 }
1072 1069
 
1073
-void OpenRaider::loadPakFolderRecursive(const char *dir) {
1074
-    struct dirent entry;
1075
-    struct dirent *ep = NULL;
1076
-    DIR *pakDir;
1077
-
1078
-    assert(dir != NULL);
1079
-    assert(dir[0] != '\0');
1080
-    assert(mRunning == true);
1081
-
1082
-    pakDir = opendir(dir);
1083
-    if (pakDir != NULL) {
1084
-        readdir_r(pakDir, &entry, &ep);
1085
-        while (ep != NULL) {
1086
-            if (ep->d_type == DT_DIR) {
1087
-                if ((strcmp(".", ep->d_name) != 0)
1088
-                 && (strcmp("..", ep->d_name) != 0)) {
1089
-                    char *tmp = bufferString("%s%s", dir, ep->d_name);
1090
-                    char *next = fullPath(tmp, '/');
1091
-                    loadPakFolderRecursive(next);
1092
-                    delete next;
1093
-                    delete tmp;
1094
-                }
1095
-            } else {
1096
-                char *fullPathMap = bufferString("%s%s", dir, ep->d_name);
1097
-
1098
-                char *lowerPath = bufferString("%s", fullPathMap);
1099
-                for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
1100
-
1101
-                // Check for valid extension
1102
-                if (stringEndsWith(lowerPath, ".phd")
1103
-                     || stringEndsWith(lowerPath, ".tr2")
1104
-                     || stringEndsWith(lowerPath, ".tr4")
1105
-                     || stringEndsWith(lowerPath, ".trc")) {
1106
-                    int error = TombRaider::checkMime(fullPathMap);
1107
-                    if (error == 0) {
1108
-                        // Just load relative filename
1109
-                        mMapList.push_back(bufferString("%s", (fullPathMap + strlen(mPakDir) + 1)));
1110
-                    } else {
1111
-                        getConsole().print("Error: pak file '%s' %s",
1112
-                                fullPathMap, (error == -1) ? "not found" : "invalid");
1113
-                    }
1114
-                }
1115
-
1116
-                delete [] lowerPath;
1117
-                delete [] fullPathMap;
1118
-            }
1119
-            readdir_r(pakDir, &entry, &ep);
1120
-        }
1121
-        closedir(pakDir);
1122
-    } else {
1123
-        getConsole().print("Could not open PAK dir %s!", dir);
1124
-    }
1125
-}
1126
-
1127
-void OpenRaider::fillMapList() {
1128
-    assert(mRunning == true);
1129
-
1130
-    char *tmp = fullPath(mPakDir, '/');
1131
-    loadPakFolderRecursive(tmp);
1132
-    delete [] tmp;
1133
-    mMapListFilled = true;
1134
-}
1135
-
1136 1070
 void OpenRaider::run() {
1137 1071
     assert(mRunning == false);
1138 1072
 
@@ -1169,16 +1103,21 @@ void OpenRaider::frame() {
1169 1103
     if (mFPS)
1170 1104
         getWindow().drawText(10, getWindow().mHeight - 20, 0.5f, OR_BLUE, "%dFPS", fps);
1171 1105
 
1106
+#ifdef DEBUG
1107
+    // Draw debug infos
1108
+    if (getGame().isLoaded()) {
1109
+        for (int i = 0; i < 3; i++) {
1110
+            getWindow().drawText(10, getWindow().mHeight - ((4 - i) * 20), 0.5f, OR_BLUE, "%.2f (%.2f)",
1111
+                getGame().mLara->pos[i] / 256.0f, getGame().mLara->angles[i]);
1112
+        }
1113
+    }
1114
+#endif
1115
+
1172 1116
     getWindow().glExit2D();
1173 1117
 
1174 1118
     // Put new frame on screen
1175 1119
     getWindow().swapBuffersGL();
1176 1120
 
1177
-    // Fill map list after first render pass,
1178
-    // so menu *loading screen* is visible
1179
-    if (!mMapListFilled)
1180
-        fillMapList();
1181
-
1182 1121
     // Calculate FPS display value
1183 1122
     fpsCount++;
1184 1123
     fpsSum += (systemTimerGet() - startTime);

+ 1
- 14
src/Render.cpp 파일 보기

@@ -408,11 +408,6 @@ void Render::display()
408 408
     RenderRoom *room;
409 409
     int index;
410 410
 
411
-
412
-#ifdef DEBUG_MATRIX
413
-    gl_test_reset();
414
-#endif
415
-
416 411
     switch (mMode)
417 412
     {
418 413
         case Render::modeDisabled:
@@ -638,14 +633,6 @@ void Render::display()
638 633
     if (mMode == Render::modeWireframe)
639 634
         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
640 635
 
641
-    // Mongoose 2002.01.01, Test matrix ops
642
-#ifdef DEBUG_MATRIX
643
-    if (gl_test_val())
644
-    {
645
-        printf("ERROR in matrix stack %i\n", gl_test_val());
646
-    }
647
-#endif
648
-
649 636
     glFlush();
650 637
 }
651 638
 
@@ -965,7 +952,7 @@ void Render::drawModel(SkeletalModel *model)
965 952
 
966 953
     if (animation->frame.empty())
967 954
     {
968
-#ifdef DEBUG_RENDER
955
+#ifdef DEBUG
969 956
         printf("ERROR: No boneframes?!?!  *** %i:%i ***\n",
970 957
                 mdl->id, bframe);
971 958
 #endif

+ 0
- 78
src/World.cpp 파일 보기

@@ -209,41 +209,9 @@ bool World::isWall(int room, int sector) {
209 209
 bool World::getHeightAtPosition(int index, float x, float *y, float z)
210 210
 {
211 211
     room_mesh_t *room = mRooms[index];
212
-
213
-#ifdef OBSOLETE_USING_BOXES
214
-    unsigned int i;
215
-    float zmax, xmax, zmin, xmin;
216
-
217
-
218
-    if (!room)
219
-    {
220
-        return false;
221
-    }
222
-
223
-    // Mongoose 2002.08.14, It's 0302 - give me a fucking break --
224
-    //   this works albeit poorly  =)
225
-    for (i = 0; (int)i < room->num_boxes; ++i)
226
-    {
227
-        xmax = room->boxes[i].c.pos[0];
228
-        xmin = room->boxes[i].a.pos[0];
229
-        zmax = room->boxes[i].c.pos[2];
230
-        zmin = room->boxes[i].a.pos[2];
231
-
232
-        if (x < xmax && x > xmin && z < zmax && z > zmin)
233
-        {
234
-            //printf("%f %f %f %f\n", xmax, xmin, zmax, zmin);
235
-
236
-            *y =  room->boxes[i].a.pos[1]; // hhmm...room->pos[1] +
237
-            return true;
238
-        }
239
-    }
240
-
241
-    return false;
242
-#else
243 212
     int sector;
244 213
     sector_t *sect;
245 214
 
246
-
247 215
     if (!room)
248 216
     {
249 217
         return false;
@@ -262,7 +230,6 @@ bool World::getHeightAtPosition(int index, float x, float *y, float z)
262 230
     *y = sect->floor;
263 231
 
264 232
     return true;
265
-#endif
266 233
 }
267 234
 
268 235
 
@@ -300,10 +267,6 @@ std::vector<room_mesh_t *> *World::getRooms()
300 267
 #endif
301 268
 
302 269
 
303
-////////////////////////////////////////////////////////////
304
-// Public Mutators
305
-////////////////////////////////////////////////////////////
306
-
307 270
 void World::setFlag(WorldFlag flag)
308 271
 {
309 272
     mFlags |= flag;
@@ -575,22 +538,9 @@ void World::moveEntity(entity_t *e, char movement)
575 538
 
576 539
     if (room == -1) // Will we hit a portal?
577 540
     {
578
-#define ADJ_ROOM_CHECK
579
-#ifdef ADJ_ROOM_CHECK
580 541
         room = getAdjoiningRoom(e->room,
581 542
                 e->pos[0],  e->pos[1], e->pos[2],
582 543
                 x, y, z);
583
-#else
584
-        if (!(mFlags & fEnableHopping))
585
-        {
586
-            mFlags |= fEnableHopping;
587
-            room = getRoomByLocation(e->room, x, y, z);
588
-            printf("Hopped\n");
589
-            mFlags ^= fEnableHopping;
590
-        }
591
-
592
-        //room = getRoomByLocation(x, y, z);
593
-#endif
594 544
 
595 545
         if (room > -1)
596 546
         {
@@ -660,16 +610,6 @@ void World::moveEntity(entity_t *e, char movement)
660 610
         {
661 611
             case worldMoveType_fly:
662 612
             case worldMoveType_swim:
663
-#ifdef DIVE_GAP
664
-                // Clips to top of water, waiting for DIVE event
665
-                if (h < floor)
666
-                    e->pos[1] = floor;
667
-                else if (h > ceiling)
668
-                    e->pos[1] = ceiling;
669
-                else
670
-                    e->pos[1] = y;
671
-#endif
672
-
673 613
                 // Don't fall out of world, avoid a movement that does
674 614
                 if (h > y - camHeight)
675 615
                 {
@@ -704,13 +644,6 @@ void World::moveEntity(entity_t *e, char movement)
704 644
                 e->pos[1] = y;
705 645
                 e->pos[2] = z;
706 646
         }
707
-
708
-#ifdef OBSOLETE
709
-        m_text->SetString(1,"Room %2i  Sector %2i %sPos %.0f %.0f %.0f Yaw %.0f",
710
-                room, sector,
711
-                wall ? " Wall " : " ",
712
-                e->pos[0], e->pos[1], e->pos[2], e->angles[1]);
713
-#endif
714 647
     }
715 648
     else
716 649
     {
@@ -722,14 +655,3 @@ void World::moveEntity(entity_t *e, char movement)
722 655
     e->moving = true;
723 656
 }
724 657
 
725
-
726
-////////////////////////////////////////////////////////////
727
-// Private Accessors
728
-////////////////////////////////////////////////////////////
729
-
730
-
731
-////////////////////////////////////////////////////////////
732
-// Private Mutators
733
-////////////////////////////////////////////////////////////
734
-
735
-

Loading…
취소
저장