Visual Studio 2013 Compatibility

This commit is contained in:
dalkon 2013-11-12 13:47:53 +01:00 committed by Eduardo Bart
parent d3e97d33c7
commit c9597d6682
11 changed files with 67 additions and 18 deletions

View File

@ -351,8 +351,13 @@ void Map::setShowZone(tileflags_t zone, bool show)
void Map::setShowZones(bool show) void Map::setShowZones(bool show)
{ {
#ifdef _MSC_VER
static const uint32 defaultZoneFlags
= TILESTATE_HOUSE | TILESTATE_PROTECTIONZONE;
#else
static constexpr uint32 defaultZoneFlags static constexpr uint32 defaultZoneFlags
= TILESTATE_HOUSE | TILESTATE_PROTECTIONZONE; = TILESTATE_HOUSE | TILESTATE_PROTECTIONZONE;
#endif
if(!show) if(!show)
m_zoneFlags = 0; m_zoneFlags = 0;
else if(m_zoneFlags == 0) else if(m_zoneFlags == 0)

View File

@ -1934,7 +1934,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
if(g_game.getFeature(Otc::GameThingMarks)) { if(g_game.getFeature(Otc::GameThingMarks)) {
msg->getU8(); // creature type for summons msg->getU8(); // creature type for summons
uint8 mark = msg->getU8(); // mark mark = msg->getU8(); // mark
msg->getU16(); // helpers msg->getU16(); // helpers
if(creature) { if(creature) {

View File

@ -23,11 +23,11 @@
#ifndef FRAMEWORK_CONST_H #ifndef FRAMEWORK_CONST_H
#define FRAMEWORK_CONST_H #define FRAMEWORK_CONST_H
#include "stdext/compiler.h"
#define DEG_TO_RAD (acos(-1)/180.0) #define DEG_TO_RAD (acos(-1)/180.0)
#define RAD_TO_DEC (180.0/acos(-1)) #define RAD_TO_DEC (180.0/acos(-1))
#define BUILD_COMPILER "gcc " __VERSION__
#ifndef BUILD_COMMIT #ifndef BUILD_COMMIT
#define BUILD_COMMIT "devel" #define BUILD_COMMIT "devel"
#endif #endif
@ -52,9 +52,13 @@
namespace Fw 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 pi = 3.14159265;
constexpr float MIN_ALPHA = 0.003f; constexpr float MIN_ALPHA = 0.003f;
#endif
enum Key : unsigned char { enum Key : unsigned char {
KeyUnknown = 0, KeyUnknown = 0,
KeyEscape = 1, KeyEscape = 1,

View File

@ -103,7 +103,7 @@ inline void glEnableVertexAttribArray (GLuint index) { }
inline void glDisableVertexAttribArray (GLuint index) { } inline void glDisableVertexAttribArray (GLuint index) { }
#else #else
#define GLEW_STATIC //#define GLEW_STATIC
#include <GL/glew.h> #include <GL/glew.h>
#endif #endif

View File

@ -246,7 +246,7 @@ std::string Platform::getOSName()
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi); bOsVersionInfoEx = VerifyVersionInfo(&osvi, 0, 0);
if(!bOsVersionInfoEx) if(!bOsVersionInfoEx)
return std::string(); return std::string();

View File

@ -691,12 +691,12 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
if(newMousePos.x >= 32767) if(newMousePos.x >= 32767)
newMousePos.x = 0; newMousePos.x = 0;
else else
newMousePos.x = std::min(newMousePos.x, m_size.width()); newMousePos.x = std::min<int32>(newMousePos.x, m_size.width());
if(newMousePos.y >= 32767) if(newMousePos.y >= 32767)
newMousePos.y = 0; newMousePos.y = 0;
else else
newMousePos.y = std::min(newMousePos.y, m_size.height()); newMousePos.y = std::min<int32>(newMousePos.y, m_size.height());
m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos; m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos;
m_inputEvent.mousePos = newMousePos; m_inputEvent.mousePos = newMousePos;
@ -746,8 +746,8 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
internalRestoreGLContext(); internalRestoreGLContext();
Size size = Size(LOWORD(lParam), HIWORD(lParam)); Size size = Size(LOWORD(lParam), HIWORD(lParam));
size.setWidth(std::max(std::min(size.width(), 7680), 32)); size.setWidth(std::max<int32>(std::min<int32>(size.width(), 7680), 32));
size.setHeight(std::max(std::min(size.height(), 4320), 32)); size.setHeight(std::max<int32>(std::min<int32>(size.height(), 4320), 32));
if(m_visible && (forceResize || m_size != size)) { if(m_visible && (forceResize || m_size != size)) {
m_size = size; m_size = size;

View File

@ -25,10 +25,23 @@
#ifdef __clang__ #ifdef __clang__
// clang is supported // clang is supported
#define BUILD_COMPILER "clang " __VERSION__
#elif defined(__GNUC__) #elif defined(__GNUC__)
#if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) #if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#error "Sorry, you need gcc 4.6 or greater to compile." #error "Sorry, you need gcc 4.6 or greater to compile."
#endif #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 #else
#error "Compiler not supported." #error "Compiler not supported."
#endif #endif
@ -44,12 +57,8 @@
#define unlikely(x) (x) #define unlikely(x) (x)
#endif #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." #error "C++0x is required to compile this application. Try updating your compiler."
#endif #endif
#ifdef _MSC_VER
#warning "MSVC lacks some C++11 features used in this application; compilation is most likely to fail."
#endif
#endif #endif

View File

@ -22,14 +22,24 @@
#include "demangle.h" #include "demangle.h"
#ifdef _MSC_VER
#include <windows.h>
#include <dbghelp.h>
#else
#include <cxxabi.h> #include <cxxabi.h>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#endif
namespace stdext { namespace stdext {
const char* demangle_name(const char* name) 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; size_t len;
int status; int status;
static char buffer[1024]; static char buffer[1024];
@ -39,6 +49,7 @@ const char* demangle_name(const char* name)
free(demangled); free(demangled);
} }
return buffer; return buffer;
#endif
} }
} }

View File

@ -55,8 +55,14 @@ template<int N> struct expand_snprintf {
template<typename Tuple, typename... Args> static int call(char *s, size_t maxlen, const char *format, const Tuple& tuple, const Args&... args) { template<typename Tuple, typename... Args> static int call(char *s, size_t maxlen, const char *format, const Tuple& tuple, const Args&... args) {
return expand_snprintf<N-1>::call(s, maxlen, format, tuple, sprintf_cast(std::get<N-1>(tuple)), args...); }}; return expand_snprintf<N-1>::call(s, maxlen, format, tuple, sprintf_cast(std::get<N-1>(tuple)), args...); }};
template<> struct expand_snprintf<0> { template<> struct expand_snprintf<0> {
#ifdef _MSC_VER
template<typename Tuple, typename... Args> static int call(char *s, size_t maxlen, const char *format, const Tuple& tuple, const Args&... args) { template<typename Tuple, typename... Args> 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<typename Tuple, typename... Args> 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 // Improved snprintf that accepts std::string and other types
template<typename... Args> template<typename... Args>

View File

@ -22,7 +22,11 @@
#include "time.h" #include "time.h"
#include <boost/chrono.hpp> #include <boost/chrono.hpp>
#ifdef _MSC_VER
#include <thread>
#else
#include <unistd.h> #include <unistd.h>
#endif
namespace stdext { namespace stdext {
@ -42,12 +46,20 @@ ticks_t micros() {
void millisleep(size_t ms) void millisleep(size_t ms)
{ {
#ifdef _MSC_VER
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
#else
usleep(ms * 1000); usleep(ms * 1000);
#endif
}; };
void microsleep(size_t us) void microsleep(size_t us)
{ {
#ifdef _MSC_VER
std::this_thread::sleep_for(std::chrono::microseconds(us));
#else
usleep(us); usleep(us);
#endif
}; };
} }

View File

@ -172,9 +172,11 @@ enum TiXmlEncoding
TIXML_ENCODING_UTF8, TIXML_ENCODING_UTF8,
TIXML_ENCODING_LEGACY TIXML_ENCODING_LEGACY
}; };
#ifdef _MSC_VER
static const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
#else
constexpr TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; constexpr TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
#endif
/** TiXmlBase is a base class for every class in TinyXml. /** TiXmlBase is a base class for every class in TinyXml.
It does little except to establish that TinyXml classes It does little except to establish that TinyXml classes
can be printed and provide some utility functions. can be printed and provide some utility functions.