Thomas Buck 11 years ago
parent
commit
202282beef
8 changed files with 101 additions and 62 deletions
  1. 4
    0
      ChangeLog.md
  2. 2
    0
      include/Texture.h
  3. 12
    0
      include/config.h.in
  4. 2
    2
      include/global.h
  5. 14
    0
      src/CMakeLists.txt
  6. 51
    45
      src/Menu.cpp
  7. 12
    11
      src/Render.cpp
  8. 4
    4
      src/Texture.cpp

+ 4
- 0
ChangeLog.md View File

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20140520 ]
6
+    * cmake script checks for presence of functions needed for
7
+      recursive folder traversal
8
+
5
     [ 20140519 ]
9
     [ 20140519 ]
6
     * No longer crashes simply by walking in the wrong place
10
     * No longer crashes simply by walking in the wrong place
7
     * Added walk Action, supposed to switch to slow walking/sidesteps
11
     * Added walk Action, supposed to switch to slow walking/sidesteps

+ 2
- 0
include/Texture.h View File

122
      */
122
      */
123
     int loadTGA(const char *filename);
123
     int loadTGA(const char *filename);
124
 
124
 
125
+    int loadPCX(const char *filename);
126
+
125
     /*!
127
     /*!
126
      * \brief Resets all texture data
128
      * \brief Resets all texture data
127
      */
129
      */

+ 12
- 0
include/config.h.in View File

17
 #define DEFAULT_HEIGHT 480
17
 #define DEFAULT_HEIGHT 480
18
 
18
 
19
 #cmakedefine USING_AL
19
 #cmakedefine USING_AL
20
+
20
 #cmakedefine HAVE_EXECINFO_H
21
 #cmakedefine HAVE_EXECINFO_H
21
 #cmakedefine HAVE_BACKTRACE
22
 #cmakedefine HAVE_BACKTRACE
22
 #cmakedefine HAVE_BACKTRACE_SYMBOLS
23
 #cmakedefine HAVE_BACKTRACE_SYMBOLS
23
 
24
 
25
+#cmakedefine HAVE_DIRENT_H
26
+#cmakedefine HAVE_OPENDIR
27
+#cmakedefine HAVE_READDIR_R
28
+#cmakedefine HAVE_CLOSEDIR
29
+#cmakedefine HAVE_DT_DIR
30
+
31
+#cmakedefine HAVE_WINDOWS_H
32
+#cmakedefine HAVE_FINDFIRSTFILE
33
+#cmakedefine HAVE_FINDNEXTFILE
34
+#cmakedefine HAVE_FINDCLOSE
35
+
24
 #endif
36
 #endif
25
 
37
 

+ 2
- 2
include/global.h View File

18
 #ifdef __APPLE__
18
 #ifdef __APPLE__
19
 #include <OpenGL/gl.h>
19
 #include <OpenGL/gl.h>
20
 #else
20
 #else
21
-#ifdef WIN32
22
-#include <Windows.h>
21
+#ifdef HAVE_WINDOWS_H
22
+#include <windows.h>
23
 #endif
23
 #endif
24
 #include <GL/gl.h>
24
 #include <GL/gl.h>
25
 #endif
25
 #endif

+ 14
- 0
src/CMakeLists.txt View File

85
 # Check for header/function presence
85
 # Check for header/function presence
86
 include (CheckIncludeFiles)
86
 include (CheckIncludeFiles)
87
 include (CheckFunctionExists)
87
 include (CheckFunctionExists)
88
+include (CheckSymbolExists)
88
 
89
 
89
 # backtrace() for assert with call stack output
90
 # backtrace() for assert with call stack output
90
 check_include_files (execinfo.h HAVE_EXECINFO_H)
91
 check_include_files (execinfo.h HAVE_EXECINFO_H)
91
 check_function_exists (backtrace HAVE_BACKTRACE)
92
 check_function_exists (backtrace HAVE_BACKTRACE)
92
 check_function_exists (backtrace_symbols HAVE_BACKTRACE_SYMBOLS)
93
 check_function_exists (backtrace_symbols HAVE_BACKTRACE_SYMBOLS)
93
 
94
 
95
+# readdir() for recursive folder traversal
96
+check_include_files (dirent.h HAVE_DIRENT_H)
97
+check_function_exists (opendir HAVE_OPENDIR)
98
+check_function_exists (readdir_r HAVE_READDIR_R)
99
+check_function_exists (closedir HAVE_CLOSEDIR)
100
+check_symbol_exists (DT_DIR "dirent.h" HAVE_DT_DIR)
101
+
102
+# recursive folder traversal for Windows
103
+check_include_files (windows.h HAVE_WINDOWS_H)
104
+check_function_exists (FindFirstFile HAVE_FINDFIRSTFILE)
105
+check_function_exists (FindNextFile HAVE_FINDNEXTFILE)
106
+check_function_exists (FindClose HAVE_FINDCLOSE)
107
+
94
 #################################################################
108
 #################################################################
95
 
109
 
96
 # Configuration Header file
110
 # Configuration Header file

+ 51
- 45
src/Menu.cpp View File

7
 
7
 
8
 #include <cctype>
8
 #include <cctype>
9
 
9
 
10
-#ifndef WIN32
11
-#include <dirent.h>
12
-#endif
13
-
14
 #include "global.h"
10
 #include "global.h"
15
 #include "Console.h"
11
 #include "Console.h"
16
 #include "Menu.h"
12
 #include "Menu.h"
17
 #include "OpenRaider.h"
13
 #include "OpenRaider.h"
18
 #include "utils/strings.h"
14
 #include "utils/strings.h"
19
 
15
 
16
+#if defined(HAVE_DIRENT_H) && defined(HAVE_OPENDIR) && defined(HAVE_READDIR_R) && defined(HAVE_CLOSEDIR) && defined(HAVE_DT_DIR)
17
+#include <dirent.h>
18
+#define USE_DIRENT
19
+#elif defined(HAVE_WINDOWS_H) && defined(HAVE_FINDFIRSTFILE) && defined(HAVE_FINDNEXTFILE) && defined(HAVE_FINDCLOSE)
20
+#include <windows.h>
21
+#define USE_FINDFILE
22
+#else
23
+#error No support for recursive folder traversal
24
+#endif
25
+
20
 Menu::Menu() {
26
 Menu::Menu() {
21
     mVisible = false;
27
     mVisible = false;
22
     mCursor = 0;
28
     mCursor = 0;
55
 
61
 
56
 #ifdef WIN32
62
 #ifdef WIN32
57
 void Menu::loadPakFolderHelper(std::vector<char *> &list) {
63
 void Menu::loadPakFolderHelper(std::vector<char *> &list) {
58
-    WIN32_FIND_DATA fd;
59
-    char *tmp = bufferString("%s\\*", list.at(0));
60
-    HANDLE hFind = FindFirstFile(tmp, &fd);
61
-    do {
62
-        if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
63
-            list.push_back(bufferString("%s\\%s", list.at(0), fd.cFileName));
64
-        } else {
65
-            char *fullPathMap = bufferString("%s\\%s", list.at(0), fd.cFileName);
66
-
67
-            char *lowerPath = bufferString("%s", fullPathMap);
68
-            for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
69
-
70
-            // Check for valid extension
71
-            if (stringEndsWith(lowerPath, ".phd")
72
-                 || stringEndsWith(lowerPath, ".tr2")
73
-                 || stringEndsWith(lowerPath, ".tr4")
74
-                 || stringEndsWith(lowerPath, ".trc")) {
75
-                int error = TombRaider::checkMime(fullPathMap);
76
-                if (error == 0) {
77
-                    // Just load relative filename
78
-                    mMapList.push_back(bufferString("%s", (fullPathMap + strlen(getOpenRaider().mPakDir) + 1)));
79
-                } else {
80
-                    getConsole().print("Error: pak file '%s' %s",
81
-                            fullPathMap, (error == -1) ? "not found" : "invalid");
82
-                }
83
-            }
84
 
64
 
85
-            delete [] lowerPath;
86
-            delete [] fullPathMap;
87
-        }
88
-    } while (FindNextFile(hFind, &fd) != 0);
89
-    FindClose(hFind);
90
-    delete [] tmp;
91
-    delete [] list.at(0);
92
-    list.erase(list.begin());
93
 }
65
 }
94
 #endif
66
 #endif
95
 
67
 
96
 void Menu::loadPakFolderRecursive(const char *dir) {
68
 void Menu::loadPakFolderRecursive(const char *dir) {
97
     assert(dir != NULL);
69
     assert(dir != NULL);
98
     assert(dir[0] != '\0');
70
     assert(dir[0] != '\0');
99
-#ifdef WIN32
100
-    std::vector<char *> list;
101
-    list.push_back(bufferString("%s", dir));
102
-    do {
103
-        loadPakFolderHelper(list);
104
-    } while (list.size() > 0);
105
-#else
71
+#ifdef USE_DIRENT
106
     struct dirent entry;
72
     struct dirent entry;
107
     struct dirent *ep = NULL;
73
     struct dirent *ep = NULL;
108
     DIR *pakDir;
74
     DIR *pakDir;
150
     } else {
116
     } else {
151
         getConsole().print("Could not open PAK dir %s!", dir);
117
         getConsole().print("Could not open PAK dir %s!", dir);
152
     }
118
     }
119
+#elif defined(USE_FINDFILE)
120
+    std::vector<char *> list;
121
+    list.push_back(bufferString("%s", dir));
122
+    do {
123
+        WIN32_FIND_DATA fd;
124
+        char *tmp = bufferString("%s\\*", list.at(0));
125
+        HANDLE hFind = FindFirstFile(tmp, &fd);
126
+        do {
127
+            if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
128
+                list.push_back(bufferString("%s\\%s", list.at(0), fd.cFileName));
129
+            } else {
130
+                char *fullPathMap = bufferString("%s\\%s", list.at(0), fd.cFileName);
131
+
132
+                char *lowerPath = bufferString("%s", fullPathMap);
133
+                for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
134
+
135
+                // Check for valid extension
136
+                if (stringEndsWith(lowerPath, ".phd")
137
+                     || stringEndsWith(lowerPath, ".tr2")
138
+                     || stringEndsWith(lowerPath, ".tr4")
139
+                     || stringEndsWith(lowerPath, ".trc")) {
140
+                    int error = TombRaider::checkMime(fullPathMap);
141
+                    if (error == 0) {
142
+                        // Just load relative filename
143
+                        mMapList.push_back(bufferString("%s", (fullPathMap + strlen(getOpenRaider().mPakDir) + 1)));
144
+                    } else {
145
+                        getConsole().print("Error: pak file '%s' %s",
146
+                                fullPathMap, (error == -1) ? "not found" : "invalid");
147
+                    }
148
+                }
149
+
150
+                delete [] lowerPath;
151
+                delete [] fullPathMap;
152
+            }
153
+        } while (FindNextFile(hFind, &fd) != 0);
154
+        FindClose(hFind);
155
+        delete [] tmp;
156
+        delete [] list.at(0);
157
+        list.erase(list.begin());
158
+    } while (list.size() > 0);
153
 #endif
159
 #endif
154
 }
160
 }
155
 
161
 

+ 12
- 11
src/Render.cpp View File

101
     if (mTexture.loadColorTexture(color, 32, 32) > -1)
101
     if (mTexture.loadColorTexture(color, 32, 32) > -1)
102
         numTextures++;
102
         numTextures++;
103
 
103
 
104
-#ifdef PCX_PROOF_OF_CONCEPT
105
-    filename = bufferString("/Users/thomas/.OpenRaider/paks/tr2/TITLE.PCX");
106
-    if (mTexture.loadTGA(filename) > -1)
104
+    // Temporary
105
+    filename = bufferString("%s/tr2/TITLE.PCX", getOpenRaider().mPakDir);
106
+    if (mTexture.loadPCX(filename) > -1) {
107
         numTextures++;
107
         numTextures++;
108
-    delete [] filename;
109
-#else
110
-    //! \fixme Error Checking. Return negative error code, check in calling place too
111
-    filename = bufferString("%s/%s", textureDir, "splash.tga");
112
-    if (mTexture.loadTGA(filename) > -1)
113
-        numTextures++;
114
-    delete [] filename;
115
-#endif
108
+        delete [] filename;
109
+    } else {
110
+        delete [] filename;
111
+        //! \fixme Error Checking. Return negative error code, check in calling place too
112
+        filename = bufferString("%s/%s", textureDir, "splash.tga");
113
+        if (mTexture.loadTGA(filename) > -1)
114
+            numTextures++;
115
+        delete [] filename;
116
+    }
116
 
117
 
117
     return numTextures;
118
     return numTextures;
118
 }
119
 }

+ 4
- 4
src/Texture.cpp View File

279
     glBindTexture(GL_TEXTURE_2D, mTextureIds[n]);
279
     glBindTexture(GL_TEXTURE_2D, mTextureIds[n]);
280
 }
280
 }
281
 
281
 
282
-int Texture::loadTGA(const char *filename) {
283
-#ifdef PCX_PROOF_OF_CONCEPT
282
+int Texture::loadPCX(const char *filename) {
284
     unsigned char *image;
283
     unsigned char *image;
285
     unsigned int w, h;
284
     unsigned int w, h;
286
     int id = -1;
285
     int id = -1;
290
         delete [] image;
289
         delete [] image;
291
     }
290
     }
292
     return id;
291
     return id;
293
-#else
292
+}
293
+
294
+int Texture::loadTGA(const char *filename) {
294
     FILE *f;
295
     FILE *f;
295
     unsigned char *image = NULL;
296
     unsigned char *image = NULL;
296
     unsigned char *image2 = NULL;
297
     unsigned char *image2 = NULL;
333
     }
334
     }
334
 
335
 
335
     return id;
336
     return id;
336
-#endif
337
 }
337
 }
338
 
338
 
339
 int Texture::nextPower(int seed) {
339
 int Texture::nextPower(int seed) {

Loading…
Cancel
Save