ソースを参照

Prepared for Windows support

Thomas Buck 10年前
コミット
e841776fe1

+ 54
- 49
CMakeLists.txt ファイルの表示

@@ -15,8 +15,8 @@ site_name (OpenRaider_HOSTNAME)
15 15
 
16 16
 # Set a default build type if none was specified
17 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 20
 endif()
21 21
 
22 22
 #################################################################
@@ -30,17 +30,18 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
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 35
     set (WARNINGS "${WARNINGS} -Weverything -Wno-padded -Wno-packed")
36 36
     set (WARNINGS "${WARNINGS} -Wno-global-constructors -Wno-exit-time-destructors")
37 37
     set (WARNINGS "${WARNINGS} -Wno-documentation-unknown-command -Wno-c++98-compat-pedantic")
38 38
     set (WARNINGS "${WARNINGS} -Wno-missing-prototypes -Wno-missing-variable-declarations")
39 39
     set (WARNINGS "${WARNINGS} -Wno-disabled-macro-expansion")
40
-
41 40
     set (WARNINGS "${WARNINGS} -Wno-shorten-64-to-32 -Wno-sign-conversion")
42
-else()
41
+elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
43 42
     set (WARNINGS "${WARNINGS} -Wall -Wextra -Wpedantic")
43
+elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
44
+    # TODO Visual C++ compiler flags?
44 45
 endif()
45 46
 
46 47
 # Flags for all builds
@@ -72,53 +73,57 @@ add_custom_target (setup "${PROJECT_SOURCE_DIR}/cmake/setup.sh"
72 73
 #################################################################
73 74
 
74 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 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 128
 # Clean doc files
124 129
 set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "doc")

+ 7
- 0
ChangeLog.md ファイルの表示

@@ -2,6 +2,13 @@
2 2
 
3 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 12
     [ 20140505 ]
6 13
     * Moved setup of Room, Portal, Box, Sector, ... into their
7 14
       Constructors.

+ 2
- 0
README.md ファイルの表示

@@ -50,6 +50,8 @@ Get, compile and install freealut like this:
50 50
 
51 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 55
 ## Building
54 56
 
55 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 ファイルの表示

@@ -0,0 +1,101 @@
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 ファイルの表示

@@ -11,6 +11,12 @@
11 11
 
12 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 20
 #include "TombRaiderData.h"
15 21
 
16 22
 /*!

+ 4
- 0
include/Window.h ファイルの表示

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

+ 3
- 0
include/WindowSDL.h ファイルの表示

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

+ 4
- 0
include/math/math.h ファイルの表示

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

+ 4
- 0
include/utils/strings.h ファイルの表示

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

+ 4
- 0
include/utils/tga.h ファイルの表示

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

+ 11
- 7
src/CMakeLists.txt ファイルの表示

@@ -60,13 +60,14 @@ set (SRCS ${SRCS} "Window.cpp")
60 60
 set (SRCS ${SRCS} "World.cpp")
61 61
 
62 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 65
     set (SRCS ${SRCS} "SoundAL.cpp")
65 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 72
 # Select available Windowing library
72 73
 if (SDL2_FOUND AND SDL2TTF_FOUND)
@@ -74,7 +75,7 @@ if (SDL2_FOUND AND SDL2TTF_FOUND)
74 75
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
75 76
 else (SDL2_FOUND AND SDL2TTF_FOUND)
76 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 79
 endif (SDL2_FOUND AND SDL2TTF_FOUND)
79 80
 
80 81
 #################################################################
@@ -140,6 +141,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
140 141
     if (NOT "${SSE_FOUND_MSG}" STREQUAL "")
141 142
         message (STATUS "Enabled${SSE_FOUND_MSG}...")
142 143
     endif (NOT "${SSE_FOUND_MSG}" STREQUAL "")
144
+# TODO support SSE with other compilers than Clang
143 145
 endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
144 146
 
145 147
 # Apply Flags
@@ -198,7 +200,9 @@ endif (NOT APPLE)
198 200
 #################################################################
199 201
 
200 202
 # Add Math Library
201
-set (LIBS ${LIBS} m)
203
+if (UNIX)
204
+    set (LIBS ${LIBS} m)
205
+endif (UNIX)
202 206
 
203 207
 # Add utils Library
204 208
 set (LIBS ${LIBS} OpenRaider_math)

+ 3
- 0
src/Console.cpp ファイルの表示

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

+ 3
- 0
src/Game.cpp ファイルの表示

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

+ 59
- 4
src/Menu.cpp ファイルの表示

@@ -6,11 +6,19 @@
6 6
  */
7 7
 
8 8
 #include <assert.h>
9
-#include <dirent.h>
10 9
 #include <cctype>
11 10
 
11
+#ifdef WIN32
12
+#include <Windows.h>
13
+#else
14
+#include <dirent.h>
15
+#endif
16
+
12 17
 #ifdef __APPLE__
13 18
 #include <OpenGL/gl.h>
19
+#elif defined WIN32
20
+#include <GL/glew.h>
21
+#include <GL/wglew.h>
14 22
 #else
15 23
 #include <GL/gl.h>
16 24
 #endif
@@ -57,14 +65,60 @@ bool Menu::isVisible() {
57 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 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 118
     struct dirent entry;
62 119
     struct dirent *ep = NULL;
63 120
     DIR *pakDir;
64 121
 
65
-    assert(dir != NULL);
66
-    assert(dir[0] != '\0');
67
-
68 122
     pakDir = opendir(dir);
69 123
     if (pakDir != NULL) {
70 124
         readdir_r(pakDir, &entry, &ep);
@@ -108,6 +162,7 @@ void Menu::loadPakFolderRecursive(const char *dir) {
108 162
     } else {
109 163
         getConsole().print("Could not open PAK dir %s!", dir);
110 164
     }
165
+#endif
111 166
 }
112 167
 
113 168
 void Menu::fillMapList() {

+ 3
- 0
src/Mesh.cpp ファイルの表示

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

+ 2
- 3
src/OpenRaider.cpp ファイルの表示

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

+ 7
- 3
src/Render.cpp ファイルの表示

@@ -10,6 +10,9 @@
10 10
 
11 11
 #ifdef __APPLE__
12 12
 #include <OpenGL/gl.h>
13
+#elif defined WIN32
14
+#include <gl/glew.h>
15
+#include <gl/wglew.h>
13 16
 #else
14 17
 #include <GL/gl.h>
15 18
 #endif
@@ -23,6 +26,7 @@
23 26
 #include "Game.h"
24 27
 #include "OpenRaider.h"
25 28
 #include "Render.h"
29
+#include "utils/strings.h"
26 30
 
27 31
 bool compareEntites(const void *voidA, const void *voidB)
28 32
 {
@@ -94,7 +98,7 @@ void Render::loadTexture(unsigned char *image,
94 98
 
95 99
 
96 100
 int Render::initTextures(char *textureDir) {
97
-    char filename[128];
101
+    char *filename;
98 102
     unsigned int numTextures = 0;
99 103
     unsigned char color[4];
100 104
 
@@ -113,10 +117,10 @@ int Render::initTextures(char *textureDir) {
113 117
         numTextures++;
114 118
 
115 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 121
     if (mTexture.loadTGA(filename) > -1)
119 122
         numTextures++;
123
+    delete [] filename;
120 124
 
121 125
     return numTextures;
122 126
 }

+ 52
- 0
src/SoundNull.cpp ファイルの表示

@@ -0,0 +1,52 @@
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 ファイルの表示

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

+ 7
- 2
src/Texture.cpp ファイルの表示

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

+ 3
- 0
src/Window.cpp ファイルの表示

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

+ 4
- 1
src/main.cpp ファイルの表示

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

+ 20
- 1
src/utils/strings.cpp ファイルの表示

@@ -13,6 +13,8 @@
13 13
 
14 14
 #if defined(unix) || defined(__APPLE__) || defined(__linux__)
15 15
 #include <wordexp.h>
16
+#elif defined(WIN32)
17
+#include <Windows.h>
16 18
 #endif
17 19
 
18 20
 #include "utils/strings.h"
@@ -119,7 +121,6 @@ char *bufferString(const char *string, ...) {
119 121
 
120 122
 char *fullPath(const char *path, char end) {
121 123
     unsigned int lenPath;
122
-    wordexp_t word;
123 124
     char *dir;
124 125
 
125 126
     assert(path != NULL);
@@ -128,6 +129,8 @@ char *fullPath(const char *path, char end) {
128 129
     if (path[0] == '~') {
129 130
 #if defined(unix) || defined(__APPLE__) || defined(__linux__)
130 131
 
132
+        wordexp_t word;
133
+
131 134
 #ifdef __APPLE__
132 135
         // Workaround for Mac OS X. See:
133 136
         // http://stackoverflow.com/questions/20534788/why-does-wordexp-fail-with-wrde-syntax-on-os-x
@@ -164,6 +167,22 @@ char *fullPath(const char *path, char end) {
164 167
         }
165 168
 
166 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 186
 #else
168 187
         printf("WARNING: Tilde expansion not supported on this platform:\n\t%s\n", path);
169 188
         lenPath = strlen(path);

+ 27
- 2
src/utils/time.cpp ファイルの表示

@@ -5,10 +5,12 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
-#include <sys/time.h>
9
-
10 8
 #include "utils/time.h"
11 9
 
10
+#if defined(unix) || defined(__APPLE__) || defined (__linux__)
11
+
12
+#include <sys/time.h>
13
+
12 14
 struct timeval system_timer_start;
13 15
 struct timeval system_timer_stop;
14 16
 struct timezone system_timer_zone;
@@ -23,3 +25,26 @@ void systemTimerReset() {
23 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
+

読み込み中…
キャンセル
保存