Thomas Buck 10 년 전
부모
커밋
202282beef
8개의 변경된 파일101개의 추가작업 그리고 62개의 파일을 삭제
  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 파일 보기

@@ -2,6 +2,10 @@
2 2
 
3 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 9
     [ 20140519 ]
6 10
     * No longer crashes simply by walking in the wrong place
7 11
     * Added walk Action, supposed to switch to slow walking/sidesteps

+ 2
- 0
include/Texture.h 파일 보기

@@ -122,6 +122,8 @@ public:
122 122
      */
123 123
     int loadTGA(const char *filename);
124 124
 
125
+    int loadPCX(const char *filename);
126
+
125 127
     /*!
126 128
      * \brief Resets all texture data
127 129
      */

+ 12
- 0
include/config.h.in 파일 보기

@@ -17,9 +17,21 @@
17 17
 #define DEFAULT_HEIGHT 480
18 18
 
19 19
 #cmakedefine USING_AL
20
+
20 21
 #cmakedefine HAVE_EXECINFO_H
21 22
 #cmakedefine HAVE_BACKTRACE
22 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 36
 #endif
25 37
 

+ 2
- 2
include/global.h 파일 보기

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

+ 14
- 0
src/CMakeLists.txt 파일 보기

@@ -85,12 +85,26 @@ endif (SDL2_FOUND AND SDL2TTF_FOUND)
85 85
 # Check for header/function presence
86 86
 include (CheckIncludeFiles)
87 87
 include (CheckFunctionExists)
88
+include (CheckSymbolExists)
88 89
 
89 90
 # backtrace() for assert with call stack output
90 91
 check_include_files (execinfo.h HAVE_EXECINFO_H)
91 92
 check_function_exists (backtrace HAVE_BACKTRACE)
92 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 110
 # Configuration Header file

+ 51
- 45
src/Menu.cpp 파일 보기

@@ -7,16 +7,22 @@
7 7
 
8 8
 #include <cctype>
9 9
 
10
-#ifndef WIN32
11
-#include <dirent.h>
12
-#endif
13
-
14 10
 #include "global.h"
15 11
 #include "Console.h"
16 12
 #include "Menu.h"
17 13
 #include "OpenRaider.h"
18 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 26
 Menu::Menu() {
21 27
     mVisible = false;
22 28
     mCursor = 0;
@@ -55,54 +61,14 @@ bool Menu::isVisible() {
55 61
 
56 62
 #ifdef WIN32
57 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 66
 #endif
95 67
 
96 68
 void Menu::loadPakFolderRecursive(const char *dir) {
97 69
     assert(dir != NULL);
98 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 72
     struct dirent entry;
107 73
     struct dirent *ep = NULL;
108 74
     DIR *pakDir;
@@ -150,6 +116,46 @@ void Menu::loadPakFolderRecursive(const char *dir) {
150 116
     } else {
151 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 159
 #endif
154 160
 }
155 161
 

+ 12
- 11
src/Render.cpp 파일 보기

@@ -101,18 +101,19 @@ int Render::initTextures(char *textureDir) {
101 101
     if (mTexture.loadColorTexture(color, 32, 32) > -1)
102 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 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 118
     return numTextures;
118 119
 }

+ 4
- 4
src/Texture.cpp 파일 보기

@@ -279,8 +279,7 @@ void Texture::bindTextureId(unsigned int n) {
279 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 283
     unsigned char *image;
285 284
     unsigned int w, h;
286 285
     int id = -1;
@@ -290,7 +289,9 @@ int Texture::loadTGA(const char *filename) {
290 289
         delete [] image;
291 290
     }
292 291
     return id;
293
-#else
292
+}
293
+
294
+int Texture::loadTGA(const char *filename) {
294 295
     FILE *f;
295 296
     unsigned char *image = NULL;
296 297
     unsigned char *image2 = NULL;
@@ -333,7 +334,6 @@ int Texture::loadTGA(const char *filename) {
333 334
     }
334 335
 
335 336
     return id;
336
-#endif
337 337
 }
338 338
 
339 339
 int Texture::nextPower(int seed) {

Loading…
취소
저장