From 8c934afa591629157232ec0c2e3e11f372770979 Mon Sep 17 00:00:00 2001 From: Thibault Schueller Date: Wed, 27 Apr 2016 20:41:35 +0200 Subject: [PATCH] Fixed some issues for the build for VS2015 Most of the renderer source has to be commented out in the CMakeLists.txt, but overall the major problems are solved, except from library linking. There are still some warnings concerning GCC pragmas. --- CMakeLists.txt | 4 +-- cmake/ReaperGL.cmake | 7 +++-- cmake/compiler/msvc.cmake | 8 ++--- cmake/platform/unix.cmake | 7 +++++ src/core/Assert.h | 23 +++++++++++--- src/core/Debugger.cpp | 4 +-- src/core/DynamicLibrary.cpp | 41 +++++++++++++++++++++---- src/core/DynamicLibrary.h | 3 +- src/core/Platform.h | 3 ++ src/core/StackTrace.cpp | 11 +++++++ src/core/VectorTypes.h | 2 +- src/game/map/MapInfo.cpp | 2 +- src/game/module/PathModule.cpp | 2 +- src/game/pathing/BreadthFirstSearch.cpp | 2 +- src/game/pathing/CostMap.cpp | 6 ++-- src/math/Spline.cpp | 6 ++-- src/renderer/Camera.cpp | 1 + 17 files changed, 100 insertions(+), 32 deletions(-) create mode 100644 cmake/platform/unix.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index aae3abd1..4b5e56a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ if (WIN32) elseif(APPLE OR UNIX) set(VK_PLATFORM "VK_USE_PLATFORM_XCB_KHR") find_package(XCB REQUIRED) - set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${LIBXCB_LIBRARIES} -ldl) + set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${LIBXCB_LIBRARIES}) set(PLATFORM_INCLUDES ${PLATFORM_INCLUDES} ${LIBXCB_INCLUDE_DIR}) endif() @@ -180,7 +180,7 @@ target_link_libraries(${REAPER_BIN} ${GLBINDING_LIBRARY_RELEASE} ${ASSIMP_LIBRARIES} ${LIBUNWIND_LIBRARIES} - ${OPENEXR_LIBRARIES} -lglbinding -lpthread + ${OPENEXR_LIBRARIES} ${PLATFORM_LIBRARIES}) set_target_properties(${REAPER_BIN} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT ${REAPER_PCH}) diff --git a/cmake/ReaperGL.cmake b/cmake/ReaperGL.cmake index 90263311..0beed399 100644 --- a/cmake/ReaperGL.cmake +++ b/cmake/ReaperGL.cmake @@ -1,4 +1,5 @@ include(${CMAKE_SOURCE_DIR}/cmake/compiler/msvc.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/platform/unix.cmake) set(CXX_STANDARD_REQUIRED ON) @@ -21,10 +22,10 @@ macro(add_vs_source_tree input_files path_to_strip) # changes /'s to \\'s string(REPLACE "/" "\\" GROUP "${GROUP}") # group into "Source Files" and "Header Files" - if ("${FILE}" MATCHES ".*\\.cpp" OR "${FILE}" MATCHES ".*\\.inl") + if ("${FILE}" MATCHES ".*\\.cpp" OR "${FILE}" MATCHES ".*\\.inl" OR "${FILE}" MATCHES ".*\\.h" OR "${FILE}" MATCHES ".*\\.hpp") set(GROUP "Source Files\\${GROUP}") - elseif("${FILE}" MATCHES ".*\\.h" OR "${FILE}" MATCHES ".*\\.hpp") - set(GROUP "Header Files\\${GROUP}") + #elseif("${FILE}" MATCHES ".*\\.h" OR "${FILE}" MATCHES ".*\\.hpp") + # set(GROUP "Header Files\\${GROUP}") else() set(GROUP "Other Files\\${GROUP}") endif() diff --git a/cmake/compiler/msvc.cmake b/cmake/compiler/msvc.cmake index 9ba9a9f8..52956613 100644 --- a/cmake/compiler/msvc.cmake +++ b/cmake/compiler/msvc.cmake @@ -3,10 +3,10 @@ if(MSVC) message(FATAL_ERROR "This version of Visual Studio is not supported") endif() - set(REAPERGL_DEPS_LOCATION $ENV{REAPERGL_DEPS_LOCATION} CACHE PATH "Path to dependencies folder") - if (REAPERGL_DEPS_LOCATION STREQUAL "") - message(FATAL_ERROR "Please add the location of the dependencies folder") - endif() + #set(REAPERGL_DEPS_LOCATION $ENV{REAPERGL_DEPS_LOCATION} CACHE PATH "Path to dependencies folder") + #if (REAPERGL_DEPS_LOCATION STREQUAL "") + # message(FATAL_ERROR "Please add the location of the dependencies folder") + #endif() #set(BOOST_ROOT ${REAPERGL_DEPS_LOCATION}/boost CACHE PATH "boost location") #add_definitions(-D_CRT_SECURE_NO_WARNINGS) diff --git a/cmake/platform/unix.cmake b/cmake/platform/unix.cmake new file mode 100644 index 00000000..e1d75267 --- /dev/null +++ b/cmake/platform/unix.cmake @@ -0,0 +1,7 @@ +if(UNIX) + set(PLATFORM_LIBRARIES_UNIX -lglbinding -lpthread -ldl) + set(PLATFORM_INCLUDES_UNIX "") + + set(PLATFORM_LIBRARIES PLATFORM_LIBRARIES_UNIX CACHE PATH "Additional platform-specific libraries") + set(PLATFORM_INCLUDES PLATFORM_INCLUDES_UNIX CACHE PATH "Additional platform-specific includes") +endif() diff --git a/src/core/Assert.h b/src/core/Assert.h index 8997f245..b90505c7 100644 --- a/src/core/Assert.h +++ b/src/core/Assert.h @@ -47,12 +47,27 @@ inline void AssertImpl(bool condition, const char* file, const char* func, int l std::cerr << "ASSERT MESSAGE " << message << std::endl; } +// Macro overloading code (yuck) +// http://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments +// http://stackoverflow.com/questions/9183993/msvc-variadic-macro-expansion + +#define GLUE(x, y) x y + +#define RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, count, ...) count +#define EXPAND_ARGS(args) RETURN_ARG_COUNT args +#define COUNT_ARGS_MAX5(...) EXPAND_ARGS((__VA_ARGS__, 5, 4, 3, 2, 1, 0)) + +#define OVERLOAD_MACRO2(name, count) name##count +#define OVERLOAD_MACRO1(name, count) OVERLOAD_MACRO2(name, count) +#define OVERLOAD_MACRO(name, count) OVERLOAD_MACRO1(name, count) + +#define CALL_OVERLOAD(name, ...) GLUE(OVERLOAD_MACRO(name, COUNT_ARGS_MAX5(__VA_ARGS__)), (__VA_ARGS__)) + #define Assert1(condition) AssertImpl(condition, __FILE__, __FUNCTION__, __LINE__) #define Assert2(condition, message) AssertImpl(condition, __FILE__, __FUNCTION__, __LINE__, message) -#define AssertUnreachable() AssertImpl(false, __FILE__, __FUNCTION__, __LINE__) -// http://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments -#define OVERLOADED_MACRO(_1, _2, NAME, ...) NAME -#define Assert(...) OVERLOADED_MACRO(__VA_ARGS__, Assert2, Assert1) (__VA_ARGS__) +// Actual macros +#define Assert(...) CALL_OVERLOAD(Assert, __VA_ARGS__) +#define AssertUnreachable() AssertImpl(false, __FILE__, __FUNCTION__, __LINE__) #endif // REAPER_ASSERT_INCLUDED diff --git a/src/core/Debugger.cpp b/src/core/Debugger.cpp index 429a200a..72694c4d 100644 --- a/src/core/Debugger.cpp +++ b/src/core/Debugger.cpp @@ -10,9 +10,9 @@ #if defined(REAPERGL_PLATFORM_WINDOWS) // Does not check for remote debugger -inline bool isInDebugger() +bool isInDebugger() { - return IsDebuggerPresent(); + return IsDebuggerPresent() == TRUE; } #elif defined(REAPERGL_PLATFORM_LINUX) diff --git a/src/core/DynamicLibrary.cpp b/src/core/DynamicLibrary.cpp index c6ba684f..350b1876 100644 --- a/src/core/DynamicLibrary.cpp +++ b/src/core/DynamicLibrary.cpp @@ -50,19 +50,48 @@ namespace dynlib namespace dynlib { - LibHandle load(const std::string& /*library*/) + static std::string getErrorString() { - AssertUnreachable(); + //Get the error message, if any. + DWORD errorMessageID = ::GetLastError(); + if (errorMessageID == 0) + return std::string(); //No error message has been recorded + + LPSTR messageBuffer = nullptr; + size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); + + std::string message(messageBuffer, size); + + //Free the buffer. + LocalFree(messageBuffer); + + return message; } - LibSym getSymbol(LibHandle /*handle*/, const std::string& /*name*/) + LibHandle load(const std::string& library) { - AssertUnreachable(); + HMODULE handle = nullptr; + + handle = LoadLibrary(library.c_str()); + Assert(handle != nullptr, getErrorString()); + + return handle; } - void close(LibHandle /*handle*/) + LibSym getSymbol(LibHandle handle, const std::string& name) + { + FARPROC sym = nullptr; + + sym = GetProcAddress(handle, name.c_str()); + Assert(sym != nullptr, getErrorString()); + + return sym; + } + + void close(LibHandle handle) { - AssertUnreachable(); + FreeLibrary(handle); } } diff --git a/src/core/DynamicLibrary.h b/src/core/DynamicLibrary.h index ee32ee9f..f5beb98d 100644 --- a/src/core/DynamicLibrary.h +++ b/src/core/DynamicLibrary.h @@ -15,8 +15,7 @@ using LibSym = void*; #elif defined(REAPERGL_PLATFORM_WINDOWS) using LibHandle = HMODULE; - using LibSym = void*; - static_assert(false, "check true type for LibSym"); + using LibSym = FARPROC; #endif namespace dynlib diff --git a/src/core/Platform.h b/src/core/Platform.h index df6f1e7c..c1fec1cd 100644 --- a/src/core/Platform.h +++ b/src/core/Platform.h @@ -11,6 +11,9 @@ // Identify the operating system. #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__MINGW32__) #define REAPERGL_PLATFORM_WINDOWS + #define WIN32_LEAN_AND_MEAN + #define NOMINMAX + #include #elif defined(linux) || defined(__linux) || defined(__linux__) #define REAPERGL_PLATFORM_LINUX #elif defined(__APPLE__) || defined(__MACH__) diff --git a/src/core/StackTrace.cpp b/src/core/StackTrace.cpp index 001e7488..09e29c55 100644 --- a/src/core/StackTrace.cpp +++ b/src/core/StackTrace.cpp @@ -7,6 +7,8 @@ #include "StackTrace.h" +#if defined(REAPERGL_PLATFORM_LINUX) + #define UNW_LOCAL_ONLY #include #include // This may be invalid on windows @@ -50,3 +52,12 @@ void printStacktrace() std::cerr << " unknown" << std::endl; } } + +#elif defined(REAPERGL_PLATFORM_WINDOWS) || defined(REAPERGL_PLATFORM_MACOSX) + +void printStacktrace() +{ + AssertUnreachable(); +} + +#endif diff --git a/src/core/VectorTypes.h b/src/core/VectorTypes.h index 9867a76a..4dc01152 100644 --- a/src/core/VectorTypes.h +++ b/src/core/VectorTypes.h @@ -17,7 +17,7 @@ struct vec2 { vec2(vtype X, vtype Y) : x(X), y(Y) {} }; -using uvec2 = vec2; +using uvec2 = vec2; using u8vec2 = vec2; #include "VectorTypes.inl" diff --git a/src/game/map/MapInfo.cpp b/src/game/map/MapInfo.cpp index 94cadb72..8fc2c197 100644 --- a/src/game/map/MapInfo.cpp +++ b/src/game/map/MapInfo.cpp @@ -32,7 +32,7 @@ void MapInfo::load(MapDescriptor* mapDescriptor) (*_cells)[it].flags = CellFlags::Pathable | CellFlags::Constructible; } - for (uint i = 0; i < mapDescriptor->accesses.size(); ++i) + for (unsigned int i = 0; i < mapDescriptor->accesses.size(); ++i) { const MapAccess& access = mapDescriptor->accesses[i]; diff --git a/src/game/module/PathModule.cpp b/src/game/module/PathModule.cpp index c0b70f0c..f2f86e17 100644 --- a/src/game/module/PathModule.cpp +++ b/src/game/module/PathModule.cpp @@ -22,7 +22,7 @@ PathUpdater::PathUpdater(AbstractWorldUpdater* worldUpdater, MapInfo& mapInfo) PathUpdater::~PathUpdater() {} -void PathUpdater::update(float dt, ModuleAccessor movementModuleAccessor) +void PathUpdater::update(float /*dt*/, ModuleAccessor /*movementModuleAccessor*/) { debugPathFinder(); } diff --git a/src/game/pathing/BreadthFirstSearch.cpp b/src/game/pathing/BreadthFirstSearch.cpp index f1b71e1f..e5d14042 100644 --- a/src/game/pathing/BreadthFirstSearch.cpp +++ b/src/game/pathing/BreadthFirstSearch.cpp @@ -21,7 +21,7 @@ namespace pathing uvec2 next; Assert(goal < graph.size, "goal is out of bounds"); - Assert(graph[goal].bfs & to_underlying(NodeInfo::Pathable), "goal is not pathable"); + Assert((graph[goal].bfs & to_underlying(NodeInfo::Pathable)) != 0, "goal is not pathable"); frontier.push(goal); while (!frontier.empty()) diff --git a/src/game/pathing/CostMap.cpp b/src/game/pathing/CostMap.cpp index 21ce6877..40b93e7f 100644 --- a/src/game/pathing/CostMap.cpp +++ b/src/game/pathing/CostMap.cpp @@ -7,6 +7,8 @@ #include "CostMap.h" +#include + template T clamp(T value, T lower, T upper) { @@ -54,11 +56,11 @@ void paintCost(CostMap& map, Index position, Brush& brush) { Index relative = current - position; // float radius2 = brush.radius * brush.radius; - const float distance = relative.x * relative.x + relative.y * relative.y; + const float distance = static_cast(relative.x * relative.x + relative.y * relative.y); const float falloff = 1.f / (1.f + distance); const float hardness = 1.f - (1.f / (1.f + brush.hardness * 0.1f)); - map.costs[toKey(current, map.size)] = maximalCost() * hardness * falloff; + map.costs[toKey(current, map.size)] = static_cast(maximalCost() * hardness * falloff); } } } diff --git a/src/math/Spline.cpp b/src/math/Spline.cpp index af3e8dec..9cf3b0f6 100644 --- a/src/math/Spline.cpp +++ b/src/math/Spline.cpp @@ -27,7 +27,7 @@ void Spline::addControlPoint(const glm::vec3& point, float weight) void Spline::build() { _knotsVector = std::vector(_ctPoints.size() + _degree + 1); - unsigned int knots = _knotsVector.size(); + std::size_t knots = _knotsVector.size(); // Increase surface bounds order for (unsigned int i = 0; i <= _degree; ++i) @@ -37,7 +37,7 @@ void Spline::build() } // Eval interior knots for (unsigned int i = 0; i < (knots - 2 * (_degree - 1) - 3); ++i) - _knotsVector[_degree + i] = static_cast(i) / static_cast(knots - 2 * (_degree - 1) - 3); + _knotsVector[_degree + i] = static_cast(i) / static_cast(knots - 2 * (_degree - 1) - 3); } glm::vec3 Spline::eval(float t) const @@ -48,7 +48,7 @@ glm::vec3 Spline::eval(float t) const for (std::size_t i = 0; i <_ctPoints.size(); ++i) { - coeff = evalSplinePrimitive(i, _degree, t) * _ctPoints[i].weight; + coeff = evalSplinePrimitive(static_cast(i), _degree, t) * _ctPoints[i].weight; result += _ctPoints[i].pos * coeff; sum += coeff; } diff --git a/src/renderer/Camera.cpp b/src/renderer/Camera.cpp index be1fdf08..56f39580 100644 --- a/src/renderer/Camera.cpp +++ b/src/renderer/Camera.cpp @@ -7,6 +7,7 @@ #include "Camera.h" +#define _USE_MATH_DEFINES #include #include