Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rwgame build and run on windows #130

Merged
merged 3 commits into from
Jul 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "external/inih"]
path = external/inih
url = https://github.com/benhoyt/inih.git
[submodule "external/mman-win32"]
path = external/mman-win32
url = https://github.com/witwall/mman-win32.git
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ option(TESTS_NODATA "Build tests for no-data testing")
#
# Build configuration
#
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release" FORCE)
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still work for non-makefile generators like Visual Studio?


if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_definitions(-DRW_LINUX)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_definitions(-DRW_OSX)
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
add_definitions(-DRW_FREEBSD)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_definitions(-DRW_WINDOWS)
set(BULLET_ROOT "$ENV{BULLET_ROOT}")
include_directories("$ENV{BULLET_ROOT}/src")
else ()
message(FATAL_ERROR "Unknown platform \"${CMAKE_SYSTEM_NAME}\". please update CMakeLists.txt.")
endif ()
Expand All @@ -41,6 +48,10 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-array-member-paren-init")
endif()

if(MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
endif()

# Make GLM use radians
add_definitions(-DGLM_FORCE_RADIANS)

Expand Down
3 changes: 3 additions & 0 deletions cmake/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
set(EXTERNAL_PREFIX "${CMAKE_BINARY_DIR}/external")

include(inih.cmake)
if(MINGW)
include(mman-win32.cmake)
endif()
28 changes: 28 additions & 0 deletions cmake/external/mman-win32.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include(ExternalProject)
SET(MMAN_W32_DIR ${PROJECT_SOURCE_DIR}/external/mman-win32)

SET(MMAN_W32_SOURCES
${MMAN_W32_DIR}/mman.c)
file(GLOB MMAN_W32_HEADERS
${MMAN_W32_DIR}/mman.h)

add_library(mman
${MMAN_W32_SOURCES})
find_path(MINGWW64_ROOT NAMES include/sys/time.h PATH_SUFFIXES i686-w64-mingw32 mingw mingw32 )
if (MINGWW64_ROOT)
message(STATUS "MINGWW64_ROOT found - ${MINGWW64_ROOT}")
else()
message(FATAL_ERROR "MINGWW64_ROOT not found")
endif()

target_include_directories(mman INTERFACE SYSTEM ${MMAN_W32_DIR})
set_target_properties( mman
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${MINGWW64_ROOT}/lib"
LIBRARY_OUTPUT_DIRECTORY "${MINGWW64_ROOT}/lib"
)
add_custom_command(
TARGET mman
COMMAND ${CMAKE_COMMAND} -E copy "${MMAN_W32_HEADERS}" "${MINGWW64_ROOT}/include/sys"
COMMENT "Installing headers for libmman-win32..."
)
1 change: 1 addition & 0 deletions external/mman-win32
Submodule mman-win32 added at b7ec37
4 changes: 4 additions & 0 deletions rwengine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ add_library(rwengine
${RENDERWARE_HEADERS}
)

if(MINGW)
add_definitions(-D _USE_MATH_DEFINES)
endif()

target_link_libraries(rwengine
rwlib
${MAD_LIBRARY}
Expand Down
5 changes: 4 additions & 1 deletion rwengine/include/data/ObjectData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <glm/glm.hpp>

#include <data/PathData.hpp>
#ifdef RW_WINDOWS
#include <rw_mingw.hpp>
#endif

typedef uint16_t ObjectID;

Expand Down Expand Up @@ -96,7 +99,7 @@ struct VehicleData : public ObjectInformation

VehicleData()
: ObjectInformation(_class("CARS")) { }

enum VehicleClass
{
IGNORE = 0,
Expand Down
3 changes: 3 additions & 0 deletions rwengine/include/render/ViewFrustum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define _VIEWFRUSTUM_HPP_
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#ifdef RW_WINDOWS
#include <rw_mingw.hpp>
#endif

class ViewFrustum
{
Expand Down
3 changes: 3 additions & 0 deletions rwengine/include/rw_mingw.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#undef IGNORE
#undef near
#undef far
3 changes: 3 additions & 0 deletions rwengine/src/ai/TrafficDirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include <glm/gtx/string_cast.hpp>
#include <glm/gtx/norm.hpp>
#ifdef RW_WINDOWS
#include <rw_mingw.hpp>
#endif

TrafficDirector::TrafficDirector(AIGraph* g, GameWorld* w)
: graph( g ), world( w ), pedDensity(1.f), carDensity(1.f),
Expand Down
12 changes: 9 additions & 3 deletions rwengine/src/engine/GameData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#include <sstream>
#include <algorithm>

#ifndef RW_WINDOWS
#include <dirent.h>
#else
#include <platform/msdirent.h>
#endif
#include <sys/types.h>

/**
Expand All @@ -30,7 +34,7 @@
*/
std::string findPathRealCase(const std::string& base, const std::string& path)
{
#ifndef _WIN32
#ifndef RW_WINDOWS
size_t endslash = path.find("/");
bool isDirectory = true;
if(endslash == path.npos) {
Expand Down Expand Up @@ -65,7 +69,7 @@ std::string findPathRealCase(const std::string& base, const std::string& path)
return "";
#else
// Is anything other than Windows likely to fall here?
return path;
return base + "/" + path;
#endif
}

Expand Down Expand Up @@ -133,7 +137,9 @@ void GameData::parseDAT(const std::string& path)
for(std::string line, cmd; std::getline(datfile, line);)
{
if(line.size() == 0 || line[0] == '#') continue;
line.erase(line.size()-1);
#ifndef RW_WINDOWS
line.erase(line.size()-1);
#endif

size_t space = line.find_first_of(' ');
if(space != line.npos)
Expand Down
3 changes: 3 additions & 0 deletions rwengine/src/engine/GameWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

#include <data/CutsceneData.hpp>
#include <loaders/LoaderCutsceneDAT.hpp>
#ifdef RW_WINDOWS
#include <rw_mingw.hpp>
#endif

#include <render/ViewCamera.hpp>

Expand Down
5 changes: 4 additions & 1 deletion rwengine/src/engine/SaveGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,8 +1216,11 @@ bool SaveGame::loadGame(GameState& state, const std::string& file)

return true;
}

#ifndef RW_WINDOWS
#include <dirent.h>
#else
#include <platform/msdirent.h>
#endif
bool SaveGame::getSaveInfo(const std::string& file, BasicState *basicState)
{
std::FILE* loadFile = std::fopen(file.c_str(), "rb");
Expand Down
3 changes: 3 additions & 0 deletions rwengine/src/render/ObjectRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include <objects/PickupObject.hpp>
#include <objects/CutsceneObject.hpp>
#include <items/InventoryItem.hpp>
#ifdef RW_WINDOWS
#include <rw_mingw.hpp>
#endif

constexpr float kDrawDistanceFactor = 1.0f;
constexpr float kWorldDrawDistanceFactor = kDrawDistanceFactor;
Expand Down
8 changes: 8 additions & 0 deletions rwgame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_executable(rwgame

include_directories(SYSTEM
${BULLET_INCLUDE_DIR}
${OPENAL_INCLUDE_DIR}
)
include_directories(
"${CMAKE_SOURCE_DIR}/rwengine/include"
Expand All @@ -35,5 +36,12 @@ target_link_libraries(rwgame
${BULLET_LIBRARIES}
${SDL2_LIBRARY}
)
if(MINGW)
add_definitions(-D _USE_MATH_DEFINES)
target_link_libraries(rwgame
iconv
mman
ws2_32)
endif()

install(TARGETS rwgame RUNTIME DESTINATION "${BIN_DIR}")
2 changes: 1 addition & 1 deletion rwgame/GameConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string GameConfig::getDefaultConfigPath()
return std::string(home) + "/Library/Preferences/" + kConfigDirectoryName;

#else
#error Dont know how to find default config path
return ".";
#endif

// Well now we're stuck.
Expand Down
12 changes: 7 additions & 5 deletions rwgame/debug/TcpSocket.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <vector>

Expand Down Expand Up @@ -65,15 +63,19 @@ size_t TcpSocket::send(const std::string& str)

void TcpSocket::disconnect()
{
close(sock);
#ifndef RW_WINDOWS
close(sock);
#else
closesocket(sock);
#endif
sock = -1;
}


std::string TcpSocket::getRemoteAddress() const
char* TcpSocket::getRemoteAddress() const
{
char buffer[INET_ADDRSTRLEN+1] = { };
return inet_ntop(AF_INET, &addr, buffer, INET_ADDRSTRLEN+1);
return inet_ntoa(addr.sin_addr);
}


Expand Down
9 changes: 7 additions & 2 deletions rwgame/debug/TcpSocket.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#pragma once

#include <string>
#ifndef RW_WINDOWS
#include <netinet/in.h>

#include <sys/socket.h>
#include <arpa/inet.h>
#else
#include <ws2tcpip.h>
#endif

class TcpSocket
{
Expand All @@ -17,7 +22,7 @@ class TcpSocket
size_t send(const std::string& str);
void disconnect();

std::string getRemoteAddress() const;
char* getRemoteAddress() const;
short getRemotePort() const;

private:
Expand Down
5 changes: 5 additions & 0 deletions rwlib/source/platform/FileIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

#include <algorithm>
#include <fstream>
#ifndef RW_WINDOWS
#include <dirent.h>
#else
#include <platform/msdirent.h>
#endif

#include <sys/stat.h>
#include <sys/types.h>

Expand Down
Loading