From c9597d668236a227dc72e154f2bff6ce63468192 Mon Sep 17 00:00:00 2001 From: dalkon Date: Tue, 12 Nov 2013 13:47:53 +0100 Subject: [PATCH] Visual Studio 2013 Compatibility --- src/client/map.cpp | 5 +++++ src/client/protocolgameparse.cpp | 2 +- src/framework/const.h | 10 +++++++--- src/framework/graphics/glutil.h | 2 +- src/framework/platform/win32platform.cpp | 2 +- src/framework/platform/win32window.cpp | 8 ++++---- src/framework/stdext/compiler.h | 19 ++++++++++++++----- src/framework/stdext/demangle.cpp | 11 +++++++++++ src/framework/stdext/format.h | 8 +++++++- src/framework/stdext/time.cpp | 12 ++++++++++++ src/framework/xml/tinyxml.h | 6 ++++-- 11 files changed, 67 insertions(+), 18 deletions(-) diff --git a/src/client/map.cpp b/src/client/map.cpp index e612d834..132b3209 100644 --- a/src/client/map.cpp +++ b/src/client/map.cpp @@ -351,8 +351,13 @@ void Map::setShowZone(tileflags_t zone, bool show) void Map::setShowZones(bool show) { +#ifdef _MSC_VER + static const uint32 defaultZoneFlags + = TILESTATE_HOUSE | TILESTATE_PROTECTIONZONE; +#else static constexpr uint32 defaultZoneFlags = TILESTATE_HOUSE | TILESTATE_PROTECTIONZONE; +#endif if(!show) m_zoneFlags = 0; else if(m_zoneFlags == 0) diff --git a/src/client/protocolgameparse.cpp b/src/client/protocolgameparse.cpp index 42fa82ff..f1af16d8 100644 --- a/src/client/protocolgameparse.cpp +++ b/src/client/protocolgameparse.cpp @@ -1934,7 +1934,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) if(g_game.getFeature(Otc::GameThingMarks)) { msg->getU8(); // creature type for summons - uint8 mark = msg->getU8(); // mark + mark = msg->getU8(); // mark msg->getU16(); // helpers if(creature) { diff --git a/src/framework/const.h b/src/framework/const.h index 1dc5f190..52f96373 100644 --- a/src/framework/const.h +++ b/src/framework/const.h @@ -23,11 +23,11 @@ #ifndef FRAMEWORK_CONST_H #define FRAMEWORK_CONST_H +#include "stdext/compiler.h" + #define DEG_TO_RAD (acos(-1)/180.0) #define RAD_TO_DEC (180.0/acos(-1)) -#define BUILD_COMPILER "gcc " __VERSION__ - #ifndef BUILD_COMMIT #define BUILD_COMMIT "devel" #endif @@ -52,9 +52,13 @@ namespace Fw { +#ifdef _MSC_VER + static const float pi = 3.14159265; + static const float MIN_ALPHA = 0.003f; +#else constexpr float pi = 3.14159265; constexpr float MIN_ALPHA = 0.003f; - +#endif enum Key : unsigned char { KeyUnknown = 0, KeyEscape = 1, diff --git a/src/framework/graphics/glutil.h b/src/framework/graphics/glutil.h index a0f73b8d..7650477d 100644 --- a/src/framework/graphics/glutil.h +++ b/src/framework/graphics/glutil.h @@ -103,7 +103,7 @@ inline void glEnableVertexAttribArray (GLuint index) { } inline void glDisableVertexAttribArray (GLuint index) { } #else -#define GLEW_STATIC +//#define GLEW_STATIC #include #endif diff --git a/src/framework/platform/win32platform.cpp b/src/framework/platform/win32platform.cpp index 9096cedd..c8398468 100644 --- a/src/framework/platform/win32platform.cpp +++ b/src/framework/platform/win32platform.cpp @@ -246,7 +246,7 @@ std::string Platform::getOSName() ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi); + bOsVersionInfoEx = VerifyVersionInfo(&osvi, 0, 0); if(!bOsVersionInfoEx) return std::string(); diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index ed90da15..cb66d528 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -691,12 +691,12 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar if(newMousePos.x >= 32767) newMousePos.x = 0; else - newMousePos.x = std::min(newMousePos.x, m_size.width()); + newMousePos.x = std::min(newMousePos.x, m_size.width()); if(newMousePos.y >= 32767) newMousePos.y = 0; else - newMousePos.y = std::min(newMousePos.y, m_size.height()); + newMousePos.y = std::min(newMousePos.y, m_size.height()); m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos; m_inputEvent.mousePos = newMousePos; @@ -746,8 +746,8 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar internalRestoreGLContext(); Size size = Size(LOWORD(lParam), HIWORD(lParam)); - size.setWidth(std::max(std::min(size.width(), 7680), 32)); - size.setHeight(std::max(std::min(size.height(), 4320), 32)); + size.setWidth(std::max(std::min(size.width(), 7680), 32)); + size.setHeight(std::max(std::min(size.height(), 4320), 32)); if(m_visible && (forceResize || m_size != size)) { m_size = size; diff --git a/src/framework/stdext/compiler.h b/src/framework/stdext/compiler.h index 93d9f372..8d401890 100644 --- a/src/framework/stdext/compiler.h +++ b/src/framework/stdext/compiler.h @@ -25,10 +25,23 @@ #ifdef __clang__ // clang is supported + #define BUILD_COMPILER "clang " __VERSION__ #elif defined(__GNUC__) #if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) #error "Sorry, you need gcc 4.6 or greater to compile." #endif + #define BUILD_COMPILER "gcc " __VERSION__ +#elif defined(_MSC_VER) + #if _MSC_VER < 1800 + #error "You need Visual Studio 2013 or greater to compile." + #endif + #pragma warning(disable:4244) // conversion from 'A' to 'B', possible loss of data + #pragma warning(disable:4305) // 'initializing' : truncation from 'A' to 'B' + #pragma warning(disable:4146) // unary minus operator applied to unsigned type, result still unsigned + #pragma warning(disable:4800) // 'A' : forcing value to bool 'true' or 'false' (performance warning) + + #define BUILD_COMPILER "msvc12" + #define __PRETTY_FUNCTION__ __FUNCDNAME__ #else #error "Compiler not supported." #endif @@ -44,12 +57,8 @@ #define unlikely(x) (x) #endif -#if !defined(__GXX_EXPERIMENTAL_CXX0X__) +#if !defined(_MSC_VER) && !defined(__GXX_EXPERIMENTAL_CXX0X__) #error "C++0x is required to compile this application. Try updating your compiler." #endif -#ifdef _MSC_VER -#warning "MSVC lacks some C++11 features used in this application; compilation is most likely to fail." -#endif - #endif diff --git a/src/framework/stdext/demangle.cpp b/src/framework/stdext/demangle.cpp index 13f6bf0e..74fbf9f8 100644 --- a/src/framework/stdext/demangle.cpp +++ b/src/framework/stdext/demangle.cpp @@ -22,14 +22,24 @@ #include "demangle.h" +#ifdef _MSC_VER +#include +#include +#else #include #include #include +#endif namespace stdext { const char* demangle_name(const char* name) { +#ifdef _MSC_VER + static char buffer[1024]; + UnDecorateSymbolName(name, buffer, sizeof(buffer), UNDNAME_COMPLETE); + return &buffer[6]; +#else size_t len; int status; static char buffer[1024]; @@ -39,6 +49,7 @@ const char* demangle_name(const char* name) free(demangled); } return buffer; +#endif } } diff --git a/src/framework/stdext/format.h b/src/framework/stdext/format.h index 60471ac3..006523ec 100644 --- a/src/framework/stdext/format.h +++ b/src/framework/stdext/format.h @@ -55,8 +55,14 @@ template struct expand_snprintf { template static int call(char *s, size_t maxlen, const char *format, const Tuple& tuple, const Args&... args) { return expand_snprintf::call(s, maxlen, format, tuple, sprintf_cast(std::get(tuple)), args...); }}; template<> struct expand_snprintf<0> { +#ifdef _MSC_VER template static int call(char *s, size_t maxlen, const char *format, const Tuple& tuple, const Args&... args) { - return snprintf(s, maxlen, format, args...); }}; + return _snprintf(s, maxlen, format, args...); } +#else + template static int call(char *s, size_t maxlen, const char *format, const Tuple& tuple, const Args&... args) { + return snprintf(s, maxlen, format, args...); } +#endif +}; // Improved snprintf that accepts std::string and other types template diff --git a/src/framework/stdext/time.cpp b/src/framework/stdext/time.cpp index 95b47b93..ac7c2ba4 100644 --- a/src/framework/stdext/time.cpp +++ b/src/framework/stdext/time.cpp @@ -22,7 +22,11 @@ #include "time.h" #include +#ifdef _MSC_VER +#include +#else #include +#endif namespace stdext { @@ -42,12 +46,20 @@ ticks_t micros() { void millisleep(size_t ms) { +#ifdef _MSC_VER + std::this_thread::sleep_for(std::chrono::milliseconds(ms)); +#else usleep(ms * 1000); +#endif }; void microsleep(size_t us) { +#ifdef _MSC_VER + std::this_thread::sleep_for(std::chrono::microseconds(us)); +#else usleep(us); +#endif }; } diff --git a/src/framework/xml/tinyxml.h b/src/framework/xml/tinyxml.h index b8a3f96c..d457a01b 100644 --- a/src/framework/xml/tinyxml.h +++ b/src/framework/xml/tinyxml.h @@ -172,9 +172,11 @@ enum TiXmlEncoding TIXML_ENCODING_UTF8, TIXML_ENCODING_LEGACY }; - +#ifdef _MSC_VER +static const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; +#else constexpr TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; - +#endif /** TiXmlBase is a base class for every class in TinyXml. It does little except to establish that TinyXml classes can be printed and provide some utility functions.