Pārlūkot izejas kodu

Maplist now in Menu

Thomas Buck 10 gadus atpakaļ
vecāks
revīzija
e36e6e5ee3
7 mainītis faili ar 118 papildinājumiem un 186 dzēšanām
  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 Parādīt failu

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

+ 8
- 0
include/Menu.h Parādīt failu

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

+ 0
- 8
include/OpenRaider.h Parādīt failu

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

+ 92
- 11
src/Menu.cpp Parādīt failu

5
  * \author xythobuz
5
  * \author xythobuz
6
  */
6
  */
7
 
7
 
8
+#include <assert.h>
9
+#include <dirent.h>
10
+
8
 #ifdef __APPLE__
11
 #ifdef __APPLE__
9
 #include <OpenGL/gl.h>
12
 #include <OpenGL/gl.h>
10
 #else
13
 #else
31
     mainText.y = 10;
34
     mainText.y = 10;
32
     mainText.w = 0;
35
     mainText.w = 0;
33
     mainText.h = 0;
36
     mainText.h = 0;
37
+
38
+    mMapListFilled = false;
39
+    mFirstPass = false;
34
 }
40
 }
35
 
41
 
36
 Menu::~Menu() {
42
 Menu::~Menu() {
37
     delete [] mainText.text;
43
     delete [] mainText.text;
44
+
45
+    while (mMapList.size() > 0) {
46
+        delete [] mMapList.back();
47
+        mMapList.pop_back();
48
+    }
38
 }
49
 }
39
 
50
 
40
 void Menu::setVisible(bool visible) {
51
 void Menu::setVisible(bool visible) {
45
     return mVisible;
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
 void Menu::displayMapList() {
119
 void Menu::displayMapList() {
49
     // Estimate displayable number of items
120
     // Estimate displayable number of items
50
     int items = (getWindow().mHeight - 110) / 25;
121
     int items = (getWindow().mHeight - 110) / 25;
56
     else
127
     else
57
         min = 0;
128
         min = 0;
58
 
129
 
59
-    if ((mCursor + (items / 2)) < getOpenRaider().mMapList.size())
130
+    if ((mCursor + (items / 2)) < mMapList.size())
60
         max = mCursor + (items / 2);
131
         max = mCursor + (items / 2);
61
     else
132
     else
62
-        max = getOpenRaider().mMapList.size();
133
+        max = mMapList.size();
63
 
134
 
64
     while ((max - min) < items) {
135
     while ((max - min) < items) {
65
         if (min > 0)
136
         if (min > 0)
66
             min--;
137
             min--;
67
-        else if (max < ((int)getOpenRaider().mMapList.size()))
138
+        else if (max < ((int)mMapList.size()))
68
             max++;
139
             max++;
69
         else
140
         else
70
             break;
141
             break;
73
     mMin = min;
144
     mMin = min;
74
 
145
 
75
     for (int i = 0; i < (max - min); i++) {
146
     for (int i = 0; i < (max - min); i++) {
76
-        char *map = getOpenRaider().mMapList[i + min];
147
+        char *map = mMapList[i + min];
77
         if ((i + min) == (int)mCursor)
148
         if ((i + min) == (int)mCursor)
78
             getWindow().drawText(25, 100 + (25 * i), 0.75f, RED, "%s", map);
149
             getWindow().drawText(25, 100 + (25 * i), 0.75f, RED, "%s", map);
79
         else
150
         else
93
         mainText.x = (getWindow().mWidth / 2) - (mainText.w / 2);
164
         mainText.x = (getWindow().mWidth / 2) - (mainText.w / 2);
94
         getWindow().writeString(&mainText);
165
         getWindow().writeString(&mainText);
95
 
166
 
96
-        if (!getOpenRaider().mMapListFilled) {
167
+        if (!mMapListFilled) {
97
             getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");
168
             getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");
98
         } else {
169
         } else {
99
-            if (getOpenRaider().mMapList.size() == 0) {
170
+            if (mMapList.size() == 0) {
100
                 getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, RED, "No maps found! See README.md");
171
                 getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, RED, "No maps found! See README.md");
101
             } else {
172
             } else {
102
                 // draw *play button* above list
173
                 // draw *play button* above list
109
                 displayMapList();
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
         if (mCursor > 0)
201
         if (mCursor > 0)
121
             mCursor--;
202
             mCursor--;
122
         else
203
         else
123
-            mCursor = getOpenRaider().mMapList.size() - 1;
204
+            mCursor = mMapList.size() - 1;
124
     } else if (key == downKey) {
205
     } else if (key == downKey) {
125
-        if (mCursor < (getOpenRaider().mMapList.size() - 1))
206
+        if (mCursor < (mMapList.size() - 1))
126
             mCursor++;
207
             mCursor++;
127
         else
208
         else
128
             mCursor = 0;
209
             mCursor = 0;
129
     } else if (key == rightKey) {
210
     } else if (key == rightKey) {
130
         int i = 10;
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
         while (i-- > 0)
214
         while (i-- > 0)
134
             handleKeyboard(downKey, true);
215
             handleKeyboard(downKey, true);
135
     } else if (key == leftKey) {
216
     } else if (key == leftKey) {
139
         while (i-- > 0)
220
         while (i-- > 0)
140
             handleKeyboard(upKey, true);
221
             handleKeyboard(upKey, true);
141
     } else if (key == enterKey) {
222
     } else if (key == enterKey) {
142
-        char *tmp = bufferString("load %s", getOpenRaider().mMapList[mCursor]);
223
+        char *tmp = bufferString("load %s", mMapList[mCursor]);
143
         if (getOpenRaider().command(tmp) == 0) {
224
         if (getOpenRaider().command(tmp) == 0) {
144
             setVisible(false);
225
             setVisible(false);
145
         } else {
226
         } else {

+ 14
- 75
src/OpenRaider.cpp Parādīt failu

8
 #include <cstdio>
8
 #include <cstdio>
9
 #include <cstring>
9
 #include <cstring>
10
 #include <assert.h>
10
 #include <assert.h>
11
-#include <dirent.h>
12
 
11
 
13
 #include "WindowSDL.h"
12
 #include "WindowSDL.h"
14
 
13
 
31
     mPakDir = NULL;
30
     mPakDir = NULL;
32
     mAudioDir = NULL;
31
     mAudioDir = NULL;
33
     mDataDir = NULL;
32
     mDataDir = NULL;
34
-    mMapListFilled = false;
35
 
33
 
36
     for (int i = 0; i < ActionEventCount; i++)
34
     for (int i = 0; i < ActionEventCount; i++)
37
         keyBindings[i] = unknownKey;
35
         keyBindings[i] = unknownKey;
49
 
47
 
50
     if (mDataDir)
48
     if (mDataDir)
51
         delete mDataDir;
49
         delete mDataDir;
52
-
53
-    while (mMapList.size() > 0) {
54
-        delete [] mMapList.back();
55
-        mMapList.pop_back();
56
-    }
57
 }
50
 }
58
 
51
 
59
 int OpenRaider::initialize() {
52
 int OpenRaider::initialize() {
90
         return -5;
83
         return -5;
91
     }
84
     }
92
 
85
 
86
+#ifdef DEBUG
87
+    mFPS = true;
88
+#endif
89
+
93
     getMenu().setVisible(true);
90
     getMenu().setVisible(true);
94
     systemTimerReset();
91
     systemTimerReset();
95
 
92
 
1070
     return 0;
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
 void OpenRaider::run() {
1070
 void OpenRaider::run() {
1137
     assert(mRunning == false);
1071
     assert(mRunning == false);
1138
 
1072
 
1169
     if (mFPS)
1103
     if (mFPS)
1170
         getWindow().drawText(10, getWindow().mHeight - 20, 0.5f, OR_BLUE, "%dFPS", fps);
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
     getWindow().glExit2D();
1116
     getWindow().glExit2D();
1173
 
1117
 
1174
     // Put new frame on screen
1118
     // Put new frame on screen
1175
     getWindow().swapBuffersGL();
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
     // Calculate FPS display value
1121
     // Calculate FPS display value
1183
     fpsCount++;
1122
     fpsCount++;
1184
     fpsSum += (systemTimerGet() - startTime);
1123
     fpsSum += (systemTimerGet() - startTime);

+ 1
- 14
src/Render.cpp Parādīt failu

408
     RenderRoom *room;
408
     RenderRoom *room;
409
     int index;
409
     int index;
410
 
410
 
411
-
412
-#ifdef DEBUG_MATRIX
413
-    gl_test_reset();
414
-#endif
415
-
416
     switch (mMode)
411
     switch (mMode)
417
     {
412
     {
418
         case Render::modeDisabled:
413
         case Render::modeDisabled:
638
     if (mMode == Render::modeWireframe)
633
     if (mMode == Render::modeWireframe)
639
         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
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
     glFlush();
636
     glFlush();
650
 }
637
 }
651
 
638
 
965
 
952
 
966
     if (animation->frame.empty())
953
     if (animation->frame.empty())
967
     {
954
     {
968
-#ifdef DEBUG_RENDER
955
+#ifdef DEBUG
969
         printf("ERROR: No boneframes?!?!  *** %i:%i ***\n",
956
         printf("ERROR: No boneframes?!?!  *** %i:%i ***\n",
970
                 mdl->id, bframe);
957
                 mdl->id, bframe);
971
 #endif
958
 #endif

+ 0
- 78
src/World.cpp Parādīt failu

209
 bool World::getHeightAtPosition(int index, float x, float *y, float z)
209
 bool World::getHeightAtPosition(int index, float x, float *y, float z)
210
 {
210
 {
211
     room_mesh_t *room = mRooms[index];
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
     int sector;
212
     int sector;
244
     sector_t *sect;
213
     sector_t *sect;
245
 
214
 
246
-
247
     if (!room)
215
     if (!room)
248
     {
216
     {
249
         return false;
217
         return false;
262
     *y = sect->floor;
230
     *y = sect->floor;
263
 
231
 
264
     return true;
232
     return true;
265
-#endif
266
 }
233
 }
267
 
234
 
268
 
235
 
300
 #endif
267
 #endif
301
 
268
 
302
 
269
 
303
-////////////////////////////////////////////////////////////
304
-// Public Mutators
305
-////////////////////////////////////////////////////////////
306
-
307
 void World::setFlag(WorldFlag flag)
270
 void World::setFlag(WorldFlag flag)
308
 {
271
 {
309
     mFlags |= flag;
272
     mFlags |= flag;
575
 
538
 
576
     if (room == -1) // Will we hit a portal?
539
     if (room == -1) // Will we hit a portal?
577
     {
540
     {
578
-#define ADJ_ROOM_CHECK
579
-#ifdef ADJ_ROOM_CHECK
580
         room = getAdjoiningRoom(e->room,
541
         room = getAdjoiningRoom(e->room,
581
                 e->pos[0],  e->pos[1], e->pos[2],
542
                 e->pos[0],  e->pos[1], e->pos[2],
582
                 x, y, z);
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
         if (room > -1)
545
         if (room > -1)
596
         {
546
         {
660
         {
610
         {
661
             case worldMoveType_fly:
611
             case worldMoveType_fly:
662
             case worldMoveType_swim:
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
                 // Don't fall out of world, avoid a movement that does
613
                 // Don't fall out of world, avoid a movement that does
674
                 if (h > y - camHeight)
614
                 if (h > y - camHeight)
675
                 {
615
                 {
704
                 e->pos[1] = y;
644
                 e->pos[1] = y;
705
                 e->pos[2] = z;
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
     else
648
     else
716
     {
649
     {
722
     e->moving = true;
655
     e->moving = true;
723
 }
656
 }
724
 
657
 
725
-
726
-////////////////////////////////////////////////////////////
727
-// Private Accessors
728
-////////////////////////////////////////////////////////////
729
-
730
-
731
-////////////////////////////////////////////////////////////
732
-// Private Mutators
733
-////////////////////////////////////////////////////////////
734
-
735
-

Notiek ielāde…
Atcelt
Saglabāt