Browse Source

Prepared for Windows support

Thomas Buck 10 years ago
parent
commit
e841776fe1

+ 54
- 49
CMakeLists.txt View File

15
 
15
 
16
 # Set a default build type if none was specified
16
 # Set a default build type if none was specified
17
 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
17
 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
18
-    message(STATUS "Setting build type to 'Debug' as none was specified.")
19
-    set(CMAKE_BUILD_TYPE Debug)
18
+    message (STATUS "Setting build type to 'Debug' as none was specified.")
19
+    set (CMAKE_BUILD_TYPE Debug)
20
 endif()
20
 endif()
21
 
21
 
22
 #################################################################
22
 #################################################################
30
 
30
 
31
 #################################################################
31
 #################################################################
32
 
32
 
33
-# Build warnings
34
-if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
33
+# Compiler specific flags
34
+if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
35
     set (WARNINGS "${WARNINGS} -Weverything -Wno-padded -Wno-packed")
35
     set (WARNINGS "${WARNINGS} -Weverything -Wno-padded -Wno-packed")
36
     set (WARNINGS "${WARNINGS} -Wno-global-constructors -Wno-exit-time-destructors")
36
     set (WARNINGS "${WARNINGS} -Wno-global-constructors -Wno-exit-time-destructors")
37
     set (WARNINGS "${WARNINGS} -Wno-documentation-unknown-command -Wno-c++98-compat-pedantic")
37
     set (WARNINGS "${WARNINGS} -Wno-documentation-unknown-command -Wno-c++98-compat-pedantic")
38
     set (WARNINGS "${WARNINGS} -Wno-missing-prototypes -Wno-missing-variable-declarations")
38
     set (WARNINGS "${WARNINGS} -Wno-missing-prototypes -Wno-missing-variable-declarations")
39
     set (WARNINGS "${WARNINGS} -Wno-disabled-macro-expansion")
39
     set (WARNINGS "${WARNINGS} -Wno-disabled-macro-expansion")
40
-
41
     set (WARNINGS "${WARNINGS} -Wno-shorten-64-to-32 -Wno-sign-conversion")
40
     set (WARNINGS "${WARNINGS} -Wno-shorten-64-to-32 -Wno-sign-conversion")
42
-else()
41
+elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
43
     set (WARNINGS "${WARNINGS} -Wall -Wextra -Wpedantic")
42
     set (WARNINGS "${WARNINGS} -Wall -Wextra -Wpedantic")
43
+elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
44
+    # TODO Visual C++ compiler flags?
44
 endif()
45
 endif()
45
 
46
 
46
 # Flags for all builds
47
 # Flags for all builds
72
 #################################################################
73
 #################################################################
73
 
74
 
74
 # Target for running cppcheck
75
 # Target for running cppcheck
75
-set (CHECK_STD "--std=c++11" "--std=posix")
76
-set (CHECK_FLAGS "--quiet" "--force")
77
-set (CHECK_NORMAL "--enable=information,warning,performance,portability")
78
-set (CHECK_FULL "--enable=all")
79
-set (CHECK_CONFIG "--check-config")
80
-add_custom_target (check echo "Running cppcheck..."
81
-    COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_STD} ${CHECK_NORMAL} ${PROJECT_SOURCE_DIR}
82
-)
83
-add_custom_target (checkFull echo "Running full cppcheck..."
84
-    COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_STD} ${CHECK_FULL} ${PROJECT_SOURCE_DIR}
85
-)
86
-add_custom_target (checkConfig echo "Checking cppcheck config..."
87
-    COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_CONFIG} ${PROJECT_SOURCE_DIR}
88
-)
76
+if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
77
+    set (CHECK_STD "--std=c++11" "--std=posix")
78
+    set (CHECK_FLAGS "--quiet" "--force")
79
+    set (CHECK_NORMAL "--enable=information,warning,performance,portability")
80
+    set (CHECK_FULL "--enable=all")
81
+    set (CHECK_CONFIG "--check-config")
82
+    add_custom_target (check echo "Running cppcheck..."
83
+        COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_STD} ${CHECK_NORMAL} ${PROJECT_SOURCE_DIR}
84
+    )
85
+    add_custom_target (checkFull echo "Running full cppcheck..."
86
+        COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_STD} ${CHECK_FULL} ${PROJECT_SOURCE_DIR}
87
+    )
88
+    add_custom_target (checkConfig echo "Checking cppcheck config..."
89
+        COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_CONFIG} ${PROJECT_SOURCE_DIR}
90
+    )
91
+endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
89
 
92
 
90
 #################################################################
93
 #################################################################
91
 
94
 
92
 # Generate Doxygen Documentation
95
 # Generate Doxygen Documentation
93
-find_package (Doxygen)
94
-if (DOXYGEN_FOUND)
95
-    # Configure the Template Doxyfile for our specific project
96
-    configure_file (cmake/Doxyfile.in 
97
-        ${PROJECT_BINARY_DIR}/Doxyfile  @ONLY IMMEDIATE)
98
-
99
-    # Add a custom target to run Doxygen when ever the project is built
100
-    add_custom_target (doc
101
-  	    COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
102
-  		SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
103
-
104
-    # Add custom target to create local documentation without graphs
105
-    add_custom_target (docLocal
106
-        COMMAND sed -i '' "s/HAVE_DOT               = YES/HAVE_DOT               = NO/g" Doxyfile
107
-        COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
108
-        COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
109
-        COMMAND sed -i '' "s/HAVE_DOT               = NO/HAVE_DOT               = YES/g" Doxyfile
110
-        SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
111
-
112
-    # Add custom target to create local documentation with call and caller graphs
113
-    add_custom_target (docLocalFull
114
-        COMMAND sed -i '' "s/CALL_GRAPH             = NO/CALL_GRAPH             = YES/g" Doxyfile
115
-        COMMAND sed -i '' "s/CALLER_GRAPH           = NO/CALLER_GRAPH           = YES/g" Doxyfile
116
-        COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
117
-        COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
118
-        COMMAND sed -i '' "s/CALL_GRAPH             = YES/CALL_GRAPH             = NO/g" Doxyfile
119
-        COMMAND sed -i '' "s/CALLER_GRAPH           = YES/CALLER_GRAPH           = NO/g" Doxyfile
120
-        SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
121
-endif (DOXYGEN_FOUND)
96
+if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
97
+    find_package (Doxygen)
98
+    if (DOXYGEN_FOUND)
99
+        # Configure the Template Doxyfile for our specific project
100
+        configure_file (cmake/Doxyfile.in 
101
+            ${PROJECT_BINARY_DIR}/Doxyfile  @ONLY IMMEDIATE)
102
+
103
+        # Add a custom target to run Doxygen when ever the project is built
104
+        add_custom_target (doc
105
+            COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
106
+            SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
107
+
108
+        # Add custom target to create local documentation without graphs
109
+        add_custom_target (docLocal
110
+            COMMAND sed -i '' "s/HAVE_DOT               = YES/HAVE_DOT               = NO/g" Doxyfile
111
+            COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
112
+            COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
113
+            COMMAND sed -i '' "s/HAVE_DOT               = NO/HAVE_DOT               = YES/g" Doxyfile
114
+            SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
115
+
116
+        # Add custom target to create local documentation with call and caller graphs
117
+        add_custom_target (docLocalFull
118
+            COMMAND sed -i '' "s/CALL_GRAPH             = NO/CALL_GRAPH             = YES/g" Doxyfile
119
+            COMMAND sed -i '' "s/CALLER_GRAPH           = NO/CALLER_GRAPH           = YES/g" Doxyfile
120
+            COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
121
+            COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
122
+            COMMAND sed -i '' "s/CALL_GRAPH             = YES/CALL_GRAPH             = NO/g" Doxyfile
123
+            COMMAND sed -i '' "s/CALLER_GRAPH           = YES/CALLER_GRAPH           = NO/g" Doxyfile
124
+            SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
125
+    endif (DOXYGEN_FOUND)
126
+endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
122
 
127
 
123
 # Clean doc files
128
 # Clean doc files
124
 set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "doc")
129
 set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "doc")

+ 7
- 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
+    [ 20140507 ]
6
+    * Prepared for Windows support using Visual C++
7
+      - Wrote utils/time implementation for Windows
8
+      - Audio output optional, added Null Sound implementation
9
+      - Added support for getting home folder location in Windows
10
+      - Added support for recursively looking for level paks in Windows
11
+
5
     [ 20140505 ]
12
     [ 20140505 ]
6
     * Moved setup of Room, Portal, Box, Sector, ... into their
13
     * Moved setup of Room, Portal, Box, Sector, ... into their
7
       Constructors.
14
       Constructors.

+ 2
- 0
README.md View File

50
 
50
 
51
 Linux Distributions will probably provide an ALUT library ready to install with their package manager, so you won't need to compile freealut.
51
 Linux Distributions will probably provide an ALUT library ready to install with their package manager, so you won't need to compile freealut.
52
 
52
 
53
+Sound support is optional now, however. If cmake can’t find OpenAL and ALUT, Audio will be deactivated. If you want to explicitly deactivate it, call cmake with `-DENABLE_AUDIO=NO`.
54
+
53
 ## Building
55
 ## Building
54
 
56
 
55
 Do a standard cmake out-of-source build to get a debug configuration and then run the resulting executable:
57
 Do a standard cmake out-of-source build to get a debug configuration and then run the resulting executable:

+ 101
- 0
include/SoundNull.h View File

1
+/*!
2
+ * \file include/SoundNull.h
3
+ * \brief This is the null audio manager Header
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _SOUND_NULL_H_
9
+#define _SOUND_NULL_H_
10
+
11
+#include "Sound.h"
12
+
13
+/*!
14
+ * \brief This is the null audio manager
15
+ */
16
+class SoundNull : public Sound {
17
+public:
18
+
19
+    /*!
20
+     * \brief Constructs an object of SoundNull
21
+     */
22
+    SoundNull();
23
+
24
+    /*!
25
+     * \brief Deconstructs an object of SoundNull
26
+     */
27
+    virtual ~SoundNull();
28
+
29
+    /*!
30
+     * \brief Initialize sound system
31
+     * \returns 0 on success or < 0 error flags
32
+     */
33
+    virtual int initialize();
34
+
35
+    virtual void setEnabled(bool on);
36
+
37
+    /*!
38
+     * \brief Set the volume
39
+     * \param vol new source gain
40
+     */
41
+    virtual void setVolume(float vol);
42
+
43
+    /*!
44
+     * \brief Get number of registered sources
45
+     * \returns number of registered sources
46
+     */
47
+    virtual int registeredSources();
48
+
49
+    /*!
50
+     * \brief Remove all loaded sounds
51
+     */
52
+    virtual void clear();
53
+
54
+    /*!
55
+     * \brief Move listener and repositions them
56
+     * \param pos New position for listener
57
+     * \param angle New orientation for listener
58
+     */
59
+    virtual void listenAt(float pos[3], float angle[3]);
60
+
61
+    /*!
62
+     * \brief Move sound source to position
63
+     * \param source valid source id
64
+     * \param pos new position for source
65
+     */
66
+    virtual void sourceAt(int source, float pos[3]);
67
+
68
+    /*!
69
+     * \brief Load wav file from disk
70
+     * \param filename not NULL!
71
+     * \param source not NULL! Returns new source ID or -1 on error.
72
+     * \param flags set options. Use SoundFlags enum bitwise OR-ed
73
+     * \returns 0 for no error or < 0 error flag
74
+     */
75
+    virtual int addFile(const char *filename, int *source, unsigned int flags);
76
+
77
+    /*!
78
+     * \brief Load wav file from buffer
79
+     * \param wav not NULL! Is a valid waveform buffer!
80
+     * \param length length of wav buffer
81
+     * \param source not NULL! Returns new source ID or -1 on error.
82
+     * \param flags set options. Use SoundFlags enum bitwise OR-ed
83
+     * \returns 0 for no error or < 0 error flag
84
+     */
85
+    virtual int addWave(unsigned char *wav, unsigned int length, int *source, unsigned int flags);
86
+
87
+    /*!
88
+     * \brief Play sound source
89
+     * \param source sound source to play
90
+     */
91
+    virtual void play(int source);
92
+
93
+    /*!
94
+     * \brief Stop playing sound source
95
+     * \param source sound source to stop
96
+     */
97
+    virtual void stop(int source);
98
+};
99
+
100
+#endif
101
+

+ 6
- 0
include/TombRaider.h View File

11
 
11
 
12
 #include <cstdint>
12
 #include <cstdint>
13
 
13
 
14
+#ifdef WIN32
15
+typedef uint8_t u_int8_t;
16
+typedef uint16_t u_int16_t;
17
+typedef uint32_t u_int32_t;
18
+#endif
19
+
14
 #include "TombRaiderData.h"
20
 #include "TombRaiderData.h"
15
 
21
 
16
 /*!
22
 /*!

+ 4
- 0
include/Window.h View File

8
 #ifndef _WINDOW_H_
8
 #ifndef _WINDOW_H_
9
 #define _WINDOW_H_
9
 #define _WINDOW_H_
10
 
10
 
11
+#ifdef WIN32
12
+#define __attribute__(x)
13
+#endif
14
+
11
 #include <ctime>
15
 #include <ctime>
12
 
16
 
13
 #include "global.h"
17
 #include "global.h"

+ 3
- 0
include/WindowSDL.h View File

14
 #ifdef __APPLE__
14
 #ifdef __APPLE__
15
 #include <OpenGL/gl.h>
15
 #include <OpenGL/gl.h>
16
 #include <OpenGL/glu.h>
16
 #include <OpenGL/glu.h>
17
+#elif defined WIN32
18
+#include <gl/glew.h>
19
+#include <gl/wglew.h>
17
 #else
20
 #else
18
 #include <GL/gl.h>
21
 #include <GL/gl.h>
19
 #include <GL/glu.h>
22
 #include <GL/glu.h>

+ 4
- 0
include/math/math.h View File

12
 #ifndef _MATH_MATH_H
12
 #ifndef _MATH_MATH_H
13
 #define _MATH_MATH_H
13
 #define _MATH_MATH_H
14
 
14
 
15
+#ifndef M_PI
16
+#define M_PI 3.14159265358979323846
17
+#endif
18
+
15
 #define OR_PI           ((float)M_PI) //!< pi
19
 #define OR_PI           ((float)M_PI) //!< pi
16
 #define OR_2_PI         (OR_PI * 2.0f) //!< pi*2
20
 #define OR_2_PI         (OR_PI * 2.0f) //!< pi*2
17
 #define OR_PI_OVER_4    (OR_PI / 4.0f) //!< pi/4
21
 #define OR_PI_OVER_4    (OR_PI / 4.0f) //!< pi/4

+ 4
- 0
include/utils/strings.h View File

9
 #ifndef _UTILS_STRINGS_H_
9
 #ifndef _UTILS_STRINGS_H_
10
 #define _UTILS_STRINGS_H_
10
 #define _UTILS_STRINGS_H_
11
 
11
 
12
+#ifdef WIN32
13
+#define __attribute__(x)
14
+#endif
15
+
12
 #include <cstdarg>
16
 #include <cstdarg>
13
 #include <vector>
17
 #include <vector>
14
 
18
 

+ 4
- 0
include/utils/tga.h View File

8
 #ifndef _UTILS_TGA_H
8
 #ifndef _UTILS_TGA_H
9
 #define _UTILS_TGA_H
9
 #define _UTILS_TGA_H
10
 
10
 
11
+#ifdef WIN32
12
+#define __attribute__(x)
13
+#endif
14
+
11
 /*!
15
 /*!
12
  * \brief Possible TGA image types
16
  * \brief Possible TGA image types
13
  */
17
  */

+ 11
- 7
src/CMakeLists.txt View File

60
 set (SRCS ${SRCS} "World.cpp")
60
 set (SRCS ${SRCS} "World.cpp")
61
 
61
 
62
 # Select available Sound library
62
 # Select available Sound library
63
-if (OPENAL_FOUND AND ALUT_FOUND)
63
+option (ENABLE_AUDIO "Enable Sound Output" YES)
64
+if (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
64
     set (SRCS ${SRCS} "SoundAL.cpp")
65
     set (SRCS ${SRCS} "SoundAL.cpp")
65
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_AL")
66
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_AL")
66
-else (OPENAL_FOUND AND ALUT_FOUND)
67
-    # Currently only OpenAL support
68
-    message (FATAL_ERROR "OpenAL and ALUT are required!")
69
-endif (OPENAL_FOUND AND ALUT_FOUND)
67
+else (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
68
+    set (SRCS ${SRCS} "SoundNull.cpp")
69
+    message (STATUS "Disabled Sound support (no OpenAL and ALUT)!")
70
+endif (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
70
 
71
 
71
 # Select available Windowing library
72
 # Select available Windowing library
72
 if (SDL2_FOUND AND SDL2TTF_FOUND)
73
 if (SDL2_FOUND AND SDL2TTF_FOUND)
74
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
75
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
75
 else (SDL2_FOUND AND SDL2TTF_FOUND)
76
 else (SDL2_FOUND AND SDL2TTF_FOUND)
76
     # Currently only SDL2 support
77
     # Currently only SDL2 support
77
-    message (FATAL_ERROR "SDL2 and SDL2-TTF are required!")
78
+    message (FATAL_ERROR "SDL2 and SDL2-TTF are required at the moment!")
78
 endif (SDL2_FOUND AND SDL2TTF_FOUND)
79
 endif (SDL2_FOUND AND SDL2TTF_FOUND)
79
 
80
 
80
 #################################################################
81
 #################################################################
140
     if (NOT "${SSE_FOUND_MSG}" STREQUAL "")
141
     if (NOT "${SSE_FOUND_MSG}" STREQUAL "")
141
         message (STATUS "Enabled${SSE_FOUND_MSG}...")
142
         message (STATUS "Enabled${SSE_FOUND_MSG}...")
142
     endif (NOT "${SSE_FOUND_MSG}" STREQUAL "")
143
     endif (NOT "${SSE_FOUND_MSG}" STREQUAL "")
144
+# TODO support SSE with other compilers than Clang
143
 endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
145
 endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
144
 
146
 
145
 # Apply Flags
147
 # Apply Flags
198
 #################################################################
200
 #################################################################
199
 
201
 
200
 # Add Math Library
202
 # Add Math Library
201
-set (LIBS ${LIBS} m)
203
+if (UNIX)
204
+    set (LIBS ${LIBS} m)
205
+endif (UNIX)
202
 
206
 
203
 # Add utils Library
207
 # Add utils Library
204
 set (LIBS ${LIBS} OpenRaider_math)
208
 set (LIBS ${LIBS} OpenRaider_math)

+ 3
- 0
src/Console.cpp View File

7
 
7
 
8
 #ifdef __APPLE__
8
 #ifdef __APPLE__
9
 #include <OpenGL/gl.h>
9
 #include <OpenGL/gl.h>
10
+#elif defined WIN32
11
+#include <gl/glew.h>
12
+#include <gl/wglew.h>
10
 #else
13
 #else
11
 #include <GL/gl.h>
14
 #include <GL/gl.h>
12
 #endif
15
 #endif

+ 3
- 0
src/Game.cpp View File

7
 
7
 
8
 #ifdef __APPLE__
8
 #ifdef __APPLE__
9
 #include <OpenGL/gl.h>
9
 #include <OpenGL/gl.h>
10
+#elif defined WIN32
11
+#include <gl/glew.h>
12
+#include <gl/wglew.h>
10
 #else
13
 #else
11
 #include <GL/gl.h>
14
 #include <GL/gl.h>
12
 #endif
15
 #endif

+ 59
- 4
src/Menu.cpp View File

6
  */
6
  */
7
 
7
 
8
 #include <assert.h>
8
 #include <assert.h>
9
-#include <dirent.h>
10
 #include <cctype>
9
 #include <cctype>
11
 
10
 
11
+#ifdef WIN32
12
+#include <Windows.h>
13
+#else
14
+#include <dirent.h>
15
+#endif
16
+
12
 #ifdef __APPLE__
17
 #ifdef __APPLE__
13
 #include <OpenGL/gl.h>
18
 #include <OpenGL/gl.h>
19
+#elif defined WIN32
20
+#include <GL/glew.h>
21
+#include <GL/wglew.h>
14
 #else
22
 #else
15
 #include <GL/gl.h>
23
 #include <GL/gl.h>
16
 #endif
24
 #endif
57
     return mVisible;
65
     return mVisible;
58
 }
66
 }
59
 
67
 
68
+#ifdef WIN32
69
+void loadPakFolderHelper(std::list<char *> &list) {
70
+    WIN32_FIND_DATA fd;
71
+    char *tmp = bufferString("%s\\*", list.at(0));
72
+    HANDLE hFind = FindFirstFile(tmp, &fd);
73
+    do {
74
+        if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
75
+            list.push_back(bufferString("%s\\%s", list.at(0), fd.cFileName));
76
+        } else {
77
+            char *fullPathMap = bufferString("%s\\%s", list.at(0), fd.cFileName);
78
+
79
+            char *lowerPath = bufferString("%s", fullPathMap);
80
+            for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
81
+
82
+            // Check for valid extension
83
+            if (stringEndsWith(lowerPath, ".phd")
84
+                 || stringEndsWith(lowerPath, ".tr2")
85
+                 || stringEndsWith(lowerPath, ".tr4")
86
+                 || stringEndsWith(lowerPath, ".trc")) {
87
+                int error = TombRaider::checkMime(fullPathMap);
88
+                if (error == 0) {
89
+                    // Just load relative filename
90
+                    mMapList.push_back(bufferString("%s", (fullPathMap + strlen(getOpenRaider().mPakDir) + 1)));
91
+                } else {
92
+                    getConsole().print("Error: pak file '%s' %s",
93
+                            fullPathMap, (error == -1) ? "not found" : "invalid");
94
+                }
95
+            }
96
+
97
+            delete [] lowerPath;
98
+            delete [] fullPathMap;
99
+        }
100
+    } while (FindNextFile(hFind, &fd) != 0);
101
+    FindClose(hFind);
102
+    delete [] tmp;
103
+    delete [] list.at(0);
104
+    list.pop_front();
105
+}
106
+#endif
107
+
60
 void Menu::loadPakFolderRecursive(const char *dir) {
108
 void Menu::loadPakFolderRecursive(const char *dir) {
109
+    assert(dir != NULL);
110
+    assert(dir[0] != '\0');
111
+#ifdef WIN32
112
+    std::list<char *> list;
113
+    list.push_back(bufferString("%s", dir));
114
+    do {
115
+        loadPakFolderHelper(list);
116
+    } while (list.size() > 0);
117
+#else
61
     struct dirent entry;
118
     struct dirent entry;
62
     struct dirent *ep = NULL;
119
     struct dirent *ep = NULL;
63
     DIR *pakDir;
120
     DIR *pakDir;
64
 
121
 
65
-    assert(dir != NULL);
66
-    assert(dir[0] != '\0');
67
-
68
     pakDir = opendir(dir);
122
     pakDir = opendir(dir);
69
     if (pakDir != NULL) {
123
     if (pakDir != NULL) {
70
         readdir_r(pakDir, &entry, &ep);
124
         readdir_r(pakDir, &entry, &ep);
108
     } else {
162
     } else {
109
         getConsole().print("Could not open PAK dir %s!", dir);
163
         getConsole().print("Could not open PAK dir %s!", dir);
110
     }
164
     }
165
+#endif
111
 }
166
 }
112
 
167
 
113
 void Menu::fillMapList() {
168
 void Menu::fillMapList() {

+ 3
- 0
src/Mesh.cpp View File

10
 
10
 
11
 #ifdef __APPLE__
11
 #ifdef __APPLE__
12
 #include <OpenGL/gl.h>
12
 #include <OpenGL/gl.h>
13
+#elif defined WIN32
14
+#include <gl/glew.h>
15
+#include <gl/wglew.h>
13
 #else
16
 #else
14
 #include <GL/gl.h>
17
 #include <GL/gl.h>
15
 #endif
18
 #endif

+ 2
- 3
src/OpenRaider.cpp View File

133
         }
133
         }
134
     }
134
     }
135
 
135
 
136
-    char *strtokState;
137
-    char *token = strtok_r(cmd, " \t", &strtokState);
136
+    char *token = strtok(cmd, " \t");
138
     if (token != NULL) {
137
     if (token != NULL) {
139
         // token is the command to execute
138
         // token is the command to execute
140
         // get arguments
139
         // get arguments
141
         std::vector<char *> args;
140
         std::vector<char *> args;
142
         char *next;
141
         char *next;
143
-        while ((next = strtok_r(NULL, " \t", &strtokState)) != NULL) {
142
+        while ((next = strtok(NULL, " \t")) != NULL) {
144
             args.push_back(next);
143
             args.push_back(next);
145
         }
144
         }
146
 
145
 

+ 7
- 3
src/Render.cpp View File

10
 
10
 
11
 #ifdef __APPLE__
11
 #ifdef __APPLE__
12
 #include <OpenGL/gl.h>
12
 #include <OpenGL/gl.h>
13
+#elif defined WIN32
14
+#include <gl/glew.h>
15
+#include <gl/wglew.h>
13
 #else
16
 #else
14
 #include <GL/gl.h>
17
 #include <GL/gl.h>
15
 #endif
18
 #endif
23
 #include "Game.h"
26
 #include "Game.h"
24
 #include "OpenRaider.h"
27
 #include "OpenRaider.h"
25
 #include "Render.h"
28
 #include "Render.h"
29
+#include "utils/strings.h"
26
 
30
 
27
 bool compareEntites(const void *voidA, const void *voidB)
31
 bool compareEntites(const void *voidA, const void *voidB)
28
 {
32
 {
94
 
98
 
95
 
99
 
96
 int Render::initTextures(char *textureDir) {
100
 int Render::initTextures(char *textureDir) {
97
-    char filename[128];
101
+    char *filename;
98
     unsigned int numTextures = 0;
102
     unsigned int numTextures = 0;
99
     unsigned char color[4];
103
     unsigned char color[4];
100
 
104
 
113
         numTextures++;
117
         numTextures++;
114
 
118
 
115
     //! \fixme Error Checking. Return negative error code, check in calling place too
119
     //! \fixme Error Checking. Return negative error code, check in calling place too
116
-    snprintf(filename, 126, "%s/%s", textureDir, "splash.tga");
117
-    filename[127] = 0;
120
+    filename = bufferString("%s/%s", textureDir, "splash.tga");
118
     if (mTexture.loadTGA(filename) > -1)
121
     if (mTexture.loadTGA(filename) > -1)
119
         numTextures++;
122
         numTextures++;
123
+    delete [] filename;
120
 
124
 
121
     return numTextures;
125
     return numTextures;
122
 }
126
 }

+ 52
- 0
src/SoundNull.cpp View File

1
+/*!
2
+ * \file src/SoundNull.cpp
3
+ * \brief This is the null audio manager Implementation
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "SoundNull.h"
9
+
10
+SoundNull::SoundNull() {
11
+}
12
+
13
+SoundNull::~SoundNull() {
14
+}
15
+
16
+int SoundNull::initialize() {
17
+    return 0;
18
+}
19
+
20
+void SoundNull::setEnabled(bool on) {
21
+}
22
+
23
+void SoundNull::setVolume(float vol) {
24
+}
25
+
26
+int SoundNull::registeredSources() {
27
+    return 0;
28
+}
29
+
30
+void SoundNull::clear() {
31
+}
32
+
33
+void SoundNull::listenAt(float pos[3], float angle[3]) {
34
+}
35
+
36
+void SoundNull::sourceAt(int source, float pos[3]) {
37
+}
38
+
39
+int SoundNull::addFile(const char *filename, int *source, unsigned int flags) {
40
+    return 0;
41
+}
42
+
43
+int SoundNull::addWave(unsigned char *wav, unsigned int length, int *source, unsigned int flags) {
44
+    return 0;
45
+}
46
+
47
+void SoundNull::play(int source) {
48
+}
49
+
50
+void SoundNull::stop(int source) {
51
+}
52
+

+ 3
- 0
src/Sprite.cpp View File

8
 #ifdef __APPLE__
8
 #ifdef __APPLE__
9
 #include <OpenGL/gl.h>
9
 #include <OpenGL/gl.h>
10
 #include <OpenGL/glu.h>
10
 #include <OpenGL/glu.h>
11
+#elif defined WIN32
12
+#include <gl/glew.h>
13
+#include <gl/wglew.h>
11
 #else
14
 #else
12
 #include <GL/gl.h>
15
 #include <GL/gl.h>
13
 #include <GL/glu.h>
16
 #include <GL/glu.h>

+ 7
- 2
src/Texture.cpp View File

14
 
14
 
15
 #ifdef __APPLE__
15
 #ifdef __APPLE__
16
 #include <OpenGL/gl.h>
16
 #include <OpenGL/gl.h>
17
+#elif defined WIN32
18
+#include <gl/glew.h>
19
+#include <gl/wglew.h>
17
 #else
20
 #else
18
 #include <GL/gl.h>
21
 #include <GL/gl.h>
19
 #endif
22
 #endif
20
 
23
 
24
+#include "utils/strings.h"
21
 #include "utils/tga.h"
25
 #include "utils/tga.h"
22
 #include "Texture.h"
26
 #include "Texture.h"
23
 
27
 
287
     FILE *f;
291
     FILE *f;
288
     int sz = width * height;
292
     int sz = width * height;
289
     unsigned char *image = new unsigned char[sz * 3];
293
     unsigned char *image = new unsigned char[sz * 3];
290
-    char filename[1024];
294
+    char *filename = NULL;
291
     static int count = 0;
295
     static int count = 0;
292
     bool done = false;
296
     bool done = false;
293
 
297
 
297
 
301
 
298
     // Don't overwrite files
302
     // Don't overwrite files
299
     while (!done) {
303
     while (!done) {
300
-        snprintf(filename, 1024, "%s-%04i.tga", base, count++);
304
+        filename = bufferString("%s-%04i.tga", base, count++);
301
 
305
 
302
         f = fopen(filename, "rb");
306
         f = fopen(filename, "rb");
303
 
307
 
313
     tgaSaveFilename(image, width, height, 0, "%s", filename);
317
     tgaSaveFilename(image, width, height, 0, "%s", filename);
314
     printf("Took screenshot '%s'.\n", filename);
318
     printf("Took screenshot '%s'.\n", filename);
315
 
319
 
320
+    delete [] filename;
316
     delete [] image;
321
     delete [] image;
317
 }
322
 }
318
 
323
 

+ 3
- 0
src/Window.cpp View File

12
 
12
 
13
 #ifdef __APPLE__
13
 #ifdef __APPLE__
14
 #include <OpenGL/gl.h>
14
 #include <OpenGL/gl.h>
15
+#elif defined WIN32
16
+#include <gl/glew.h>
17
+#include <gl/wglew.h>
15
 #else
18
 #else
16
 #include <GL/gl.h>
19
 #include <GL/gl.h>
17
 #endif
20
 #endif

+ 4
- 1
src/main.cpp View File

17
 #ifdef USING_AL
17
 #ifdef USING_AL
18
 #include "SoundAL.h"
18
 #include "SoundAL.h"
19
 #else
19
 #else
20
-#error No Sound Library selected!
20
+#include "SoundNull.h"
21
 #endif
21
 #endif
22
 
22
 
23
 #ifdef USING_SDL
23
 #ifdef USING_SDL
36
 
36
 
37
 #ifdef USING_AL
37
 #ifdef USING_AL
38
 SoundAL gSound;
38
 SoundAL gSound;
39
+#else
40
+#warn Sound output deactivated!
41
+SoundNull gSound;
39
 #endif
42
 #endif
40
 
43
 
41
 #ifdef USING_SDL
44
 #ifdef USING_SDL

+ 20
- 1
src/utils/strings.cpp View File

13
 
13
 
14
 #if defined(unix) || defined(__APPLE__) || defined(__linux__)
14
 #if defined(unix) || defined(__APPLE__) || defined(__linux__)
15
 #include <wordexp.h>
15
 #include <wordexp.h>
16
+#elif defined(WIN32)
17
+#include <Windows.h>
16
 #endif
18
 #endif
17
 
19
 
18
 #include "utils/strings.h"
20
 #include "utils/strings.h"
119
 
121
 
120
 char *fullPath(const char *path, char end) {
122
 char *fullPath(const char *path, char end) {
121
     unsigned int lenPath;
123
     unsigned int lenPath;
122
-    wordexp_t word;
123
     char *dir;
124
     char *dir;
124
 
125
 
125
     assert(path != NULL);
126
     assert(path != NULL);
128
     if (path[0] == '~') {
129
     if (path[0] == '~') {
129
 #if defined(unix) || defined(__APPLE__) || defined(__linux__)
130
 #if defined(unix) || defined(__APPLE__) || defined(__linux__)
130
 
131
 
132
+        wordexp_t word;
133
+
131
 #ifdef __APPLE__
134
 #ifdef __APPLE__
132
         // Workaround for Mac OS X. See:
135
         // Workaround for Mac OS X. See:
133
         // http://stackoverflow.com/questions/20534788/why-does-wordexp-fail-with-wrde-syntax-on-os-x
136
         // http://stackoverflow.com/questions/20534788/why-does-wordexp-fail-with-wrde-syntax-on-os-x
164
         }
167
         }
165
 
168
 
166
         wordfree(&word);
169
         wordfree(&word);
170
+#elif defined(WIN32)
171
+        WCHAR newPath[MAX_PATH];
172
+        if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, newPath)) {
173
+            lenPath = strlen(newPath);
174
+            unsigned int lenPath2 = strlen(path);
175
+            dir = new char[lenPath + lenPath2 + 2]; // space for end char
176
+            strncpy(dir, newPath, lenPath);
177
+            dir[lenPath] = '\\';
178
+            strncpy((dir + lenPath + 1), (path + 1), lenPath2 - 1);
179
+            lenPath += lenPath2;
180
+        } else {
181
+            printf("WARNING: Could not get home folder location for tilde expansion!\n");
182
+            lenPath = strlen(path);
183
+            dir = new char[lenPath + 2]; // space for end char
184
+            strncpy(dir, path, lenPath);
185
+        }
167
 #else
186
 #else
168
         printf("WARNING: Tilde expansion not supported on this platform:\n\t%s\n", path);
187
         printf("WARNING: Tilde expansion not supported on this platform:\n\t%s\n", path);
169
         lenPath = strlen(path);
188
         lenPath = strlen(path);

+ 27
- 2
src/utils/time.cpp View File

5
  * \author xythobuz
5
  * \author xythobuz
6
  */
6
  */
7
 
7
 
8
-#include <sys/time.h>
9
-
10
 #include "utils/time.h"
8
 #include "utils/time.h"
11
 
9
 
10
+#if defined(unix) || defined(__APPLE__) || defined (__linux__)
11
+
12
+#include <sys/time.h>
13
+
12
 struct timeval system_timer_start;
14
 struct timeval system_timer_start;
13
 struct timeval system_timer_stop;
15
 struct timeval system_timer_stop;
14
 struct timezone system_timer_zone;
16
 struct timezone system_timer_zone;
23
     gettimeofday(&system_timer_start, &system_timer_zone);
25
     gettimeofday(&system_timer_start, &system_timer_zone);
24
 }
26
 }
25
 
27
 
28
+#elif defined(WIN32)
29
+
30
+#include <Windows.h>
31
+
32
+DWORD system_timer_start = 0;
33
+
34
+unsigned long systemTimerGet() {
35
+    return GetTickCount() - system_timer_start;
36
+}
37
+
38
+void systemTimerReset() {
39
+    system_timer_start = GetTickCount();
40
+}
41
+
42
+#else
43
+#warn "No support for timer on this platform!"
44
+
45
+unsigned long systemTimerGet() { return 0; }
46
+
47
+void systemTimerReset() { }
48
+
49
+#endif
50
+

Loading…
Cancel
Save