Skip to content

Commit

Permalink
Fixed some issues for the build for VS2015
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Thibault Schueller committed Apr 27, 2016
1 parent 8c89d88 commit 8c934af
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 32 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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})
Expand Down
7 changes: 4 additions & 3 deletions cmake/ReaperGL.cmake
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions cmake/compiler/msvc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions cmake/platform/unix.cmake
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 19 additions & 4 deletions src/core/Assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 35 additions & 6 deletions src/core/DynamicLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/DynamicLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/core/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h>
#elif defined(linux) || defined(__linux) || defined(__linux__)
#define REAPERGL_PLATFORM_LINUX
#elif defined(__APPLE__) || defined(__MACH__)
Expand Down
11 changes: 11 additions & 0 deletions src/core/StackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "StackTrace.h"

#if defined(REAPERGL_PLATFORM_LINUX)

#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <cxxabi.h> // This may be invalid on windows
Expand Down Expand Up @@ -50,3 +52,12 @@ void printStacktrace()
std::cerr << " unknown" << std::endl;
}
}

#elif defined(REAPERGL_PLATFORM_WINDOWS) || defined(REAPERGL_PLATFORM_MACOSX)

void printStacktrace()
{
AssertUnreachable();
}

#endif
2 changes: 1 addition & 1 deletion src/core/VectorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct vec2 {
vec2(vtype X, vtype Y) : x(X), y(Y) {}
};

using uvec2 = vec2<uint>;
using uvec2 = vec2<unsigned int>;
using u8vec2 = vec2<u8>;

#include "VectorTypes.inl"
Expand Down
2 changes: 1 addition & 1 deletion src/game/map/MapInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
2 changes: 1 addition & 1 deletion src/game/module/PathModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PathUpdater::PathUpdater(AbstractWorldUpdater* worldUpdater, MapInfo& mapInfo)
PathUpdater::~PathUpdater()
{}

void PathUpdater::update(float dt, ModuleAccessor<MovementModule> movementModuleAccessor)
void PathUpdater::update(float /*dt*/, ModuleAccessor<MovementModule> /*movementModuleAccessor*/)
{
debugPathFinder();
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/pathing/BreadthFirstSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 4 additions & 2 deletions src/game/pathing/CostMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "CostMap.h"

#include <algorithm>

template <typename T>
T clamp(T value, T lower, T upper)
{
Expand Down Expand Up @@ -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<float>(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<CostType>(maximalCost() * hardness * falloff);
}
}
}
6 changes: 3 additions & 3 deletions src/math/Spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void Spline::addControlPoint(const glm::vec3& point, float weight)
void Spline::build()
{
_knotsVector = std::vector<float>(_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)
Expand All @@ -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<double>(i) / static_cast<double>(knots - 2 * (_degree - 1) - 3);
_knotsVector[_degree + i] = static_cast<float>(i) / static_cast<float>(knots - 2 * (_degree - 1) - 3);
}

glm::vec3 Spline::eval(float t) const
Expand All @@ -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<unsigned int>(i), _degree, t) * _ctPoints[i].weight;
result += _ctPoints[i].pos * coeff;
sum += coeff;
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "Camera.h"

#define _USE_MATH_DEFINES
#include <cmath>

#include <glm/gtx/transform.hpp>
Expand Down

0 comments on commit 8c934af

Please sign in to comment.