Browse Source

Recursively search for level paks

Thomas Buck 10 years ago
parent
commit
74b9337201
5 changed files with 59 additions and 60 deletions
  1. 5
    0
      ChangeLog
  2. 0
    3
      README.md
  3. 1
    30
      data/OpenRaider.init
  4. 2
    0
      include/OpenRaider.h
  5. 51
    27
      src/OpenRaider.cpp

+ 5
- 0
ChangeLog View File

5
 
5
 
6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
7
 
7
 
8
+	[ 20140221 ]
9
+	* Removed the `Map` command. Now the PakDir command causes
10
+	  a recursive search of the specified directory. Every file found
11
+	  is added to the map list if it validates.
12
+
8
 	[ 20140216 ]
13
 	[ 20140216 ]
9
 	* Removed the FastCard option. Not necessary on todays hardware?!
14
 	* Removed the FastCard option. Not necessary on todays hardware?!
10
 	* Removed UNICODE_SUPPORT, not working this way with SDL2
15
 	* Removed UNICODE_SUPPORT, not working this way with SDL2

+ 0
- 3
README.md View File

82
 You can use paks from any Tomb Raider version supported and most user made paks for Tomb Raider.
82
 You can use paks from any Tomb Raider version supported and most user made paks for Tomb Raider.
83
 Only PHD, TR1, TR2, TR3, and TR4 paks are supported as of this writing.
83
 Only PHD, TR1, TR2, TR3, and TR4 paks are supported as of this writing.
84
 
84
 
85
-Edit 'Map' lines in your OpenRaider.init as needed.
86
-I suggest removing all your Map=... lines to begin with, since no maps are bundled with this release.
87
-
88
 ### Sound FXs
85
 ### Sound FXs
89
 
86
 
90
 Setting up external sound SFX, for TR2 and TR3 paks only.
87
 Setting up external sound SFX, for TR2 and TR3 paks only.

+ 1
- 30
data/OpenRaider.init View File

30
 MapDebug=false
30
 MapDebug=false
31
 ModelDebug=false
31
 ModelDebug=false
32
 DumpTexture=false
32
 DumpTexture=false
33
+
33
 #Script=tr3/tombPC.dat
34
 #Script=tr3/tombPC.dat
34
 #Music=tr4/039_TR4_Title_Q10.wav
35
 #Music=tr4/039_TR4_Title_Q10.wav
35
 #Music=tr4/103_A3_Out_Night.wav
36
 #Music=tr4/103_A3_Out_Night.wav
36
 #Music=tr4/108_A8_Coastal.wav
37
 #Music=tr4/108_A8_Coastal.wav
37
-#Map=custom/Yvel.tr2
38
-#Map=custom/villa2.phd
39
-#Map=custom/fenician1.phd
40
-#Map=custom/1984.tr2
41
-#Map=custom/bigchamber.tr4
42
-#Map=custom/cleopal.tr4
43
-#Map=custom/khysos.tr4
44
-#Map=custom/Nasa.tr2
45
-#Map=custom/mansionfrost.tr2
46
-#Map=tr1/gym.phd
47
-#Map=tr1/level1.phd
48
-#Map=tr1/level2.phd
49
-#Map=tr2/unwater.tr2
50
-#Map=tr3/willsden.tr2
51
-#Map=tr3/undersea.tr2
52
-#Map=tr3/scotland.tr2
53
-#Map=tr3/HOUSE.TR2
54
-#Map=tr3/zoo.tr2
55
-#Map=tr3/slinc.tr2
56
-#Map=tr3/temple.tr2
57
-#Map=tr3/shore.tr2
58
-#Map=tr3/chunnel.tr2
59
-#Map=tr4/angkor1.tr4
60
-#Map=tr4/ang_race.tr4
61
-#Map=tr4/karnak1.tr4
62
-#Map=tr4/lake.tr4
63
-#Map=tr4/settomb1.tr4
64
-#Map=tr4/settomb2.tr4
65
-#Map=tr4/title.tr4
66
-#Map=tr5/demo.trc
67
 
38
 
68
 [OpenRaider.Console]
39
 [OpenRaider.Console]
69
 bind +console 96
40
 bind +console 96

+ 2
- 0
include/OpenRaider.h View File

197
      */
197
      */
198
     void loadLevel(char *filename);
198
     void loadLevel(char *filename);
199
 
199
 
200
+    void loadPakFolderRecursive(const char *dir);
201
+
200
     static OpenRaider *mInstance; //!< Singleton use
202
     static OpenRaider *mInstance; //!< Singleton use
201
     TombRaider m_tombraider;      //!< Tombraider data support
203
     TombRaider m_tombraider;      //!< Tombraider data support
202
     Sound mSound;                 //!< 3d Audio support
204
     Sound mSound;                 //!< 3d Audio support

+ 51
- 27
src/OpenRaider.cpp View File

12
 #include <unistd.h>
12
 #include <unistd.h>
13
 #include <math.h>
13
 #include <math.h>
14
 #include <sys/types.h>
14
 #include <sys/types.h>
15
+#include <dirent.h>
15
 
16
 
16
 #ifdef DEBUG_MEMORY
17
 #ifdef DEBUG_MEMORY
17
 #include <memory_test.h>
18
 #include <memory_test.h>
3332
 }
3333
 }
3333
 
3334
 
3334
 
3335
 
3336
+void OpenRaider::loadPakFolderRecursive(const char *dir) {
3337
+    struct dirent *ep;
3338
+    DIR *pakDir;
3339
+
3340
+    pakDir = opendir(dir);
3341
+    if (pakDir != NULL) {
3342
+        while ((ep = readdir(pakDir)) != NULL) {
3343
+            if (ep->d_type == DT_DIR) {
3344
+                if ((strcmp(".", ep->d_name) != 0)
3345
+                 && (strcmp("..", ep->d_name) != 0)) {
3346
+                    char *tmp = bufferString("%s%s", dir, ep->d_name);
3347
+                    char *next = fullPath(tmp, '/');
3348
+                    loadPakFolderRecursive(next);
3349
+                    delete next;
3350
+                    delete tmp;
3351
+                }
3352
+            } else {
3353
+                /*!
3354
+                 * \fixme Currently just tries to validate every file
3355
+                 * in the pak folders. Should check the exstension to
3356
+                 * see if it could be a level pak...
3357
+                 */
3358
+
3359
+                char *fullPathMap = bufferString("%s%s", dir, ep->d_name);
3360
+
3361
+                if (m_tombraider.checkMime(fullPathMap) == 0) {
3362
+                    printf("Validated pak: '%s'\n", fullPathMap);
3363
+                    delete [] fullPathMap;
3364
+
3365
+                    // Just load relative filename
3366
+                    mMapList.pushBack(bufferString("%s", (fullPathMap + strlen(m_pakDir))));
3367
+                } else {
3368
+                    printf("ERROR: pak file '%s' not found or invalid\n", fullPathMap);
3369
+
3370
+                    delete [] fullPathMap;
3371
+                }
3372
+            }
3373
+        }
3374
+        closedir(pakDir);
3375
+    } else {
3376
+        printf("Could not open PAK dir %s!\n", dir);
3377
+    }
3378
+}
3379
+
3380
+
3335
 void OpenRaider::handleCommand(char *cmd, unsigned int mode)
3381
 void OpenRaider::handleCommand(char *cmd, unsigned int mode)
3336
 {
3382
 {
3337
     bool b;
3383
     bool b;
3405
                 }
3451
                 }
3406
 
3452
 
3407
                 m_pakDir = fullPath(cmd, '/');
3453
                 m_pakDir = fullPath(cmd, '/');
3454
+
3455
+                // Recursively search for level paks instead of
3456
+                // naming individual levels 2014-02-21 xythobuz
3457
+
3458
+                loadPakFolderRecursive(m_pakDir);
3408
             }
3459
             }
3409
             else if (rc_command("HomeDir", cmd))
3460
             else if (rc_command("HomeDir", cmd))
3410
             {
3461
             {
3437
                     m_flags ^= OpenRaider_DebugMap;
3488
                     m_flags ^= OpenRaider_DebugMap;
3438
                 }
3489
                 }
3439
             }
3490
             }
3440
-            else if (rc_command("Map", cmd))
3441
-            {
3442
-                if (cmd[0])
3443
-                {
3444
-                    char *fullPathMap;
3445
-
3446
-
3447
-                    fullPathMap = bufferString("%s%s", m_pakDir, cmd);
3448
-
3449
-                    if (m_tombraider.checkMime(fullPathMap) == 0)
3450
-                    {
3451
-                        printf("Validated pak: '%s'\n",
3452
-                                fullPathMap);
3453
-                        delete [] fullPathMap;
3454
-
3455
-                        /* Just load relative filename */
3456
-                        mMapList.pushBack(bufferString("%s", cmd));
3457
-                    }
3458
-                    else
3459
-                    {
3460
-                        printf("ERROR: pak file '%s' not found or invalid\n",
3461
-                                fullPathMap);
3462
-
3463
-                        delete [] fullPathMap;
3464
-                    }
3465
-                }
3466
-            }
3467
             // Mongoose 2001.12.31, Added music list back
3491
             // Mongoose 2001.12.31, Added music list back
3468
             else if (rc_command("Music", cmd))
3492
             else if (rc_command("Music", cmd))
3469
             {
3493
             {

Loading…
Cancel
Save