From f8d1e96ae7ac9a3483ff0a214796455946d7880f Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 3 Sep 2014 16:25:45 -0700 Subject: Use static casts instead of C casts, add floor-cast functions --- src/Globals.h | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/Globals.h') diff --git a/src/Globals.h b/src/Globals.h index 0926457da..8bf7a0f0c 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -226,10 +226,10 @@ template class SizeChecker; // CRT stuff: #include -#include -#include -#include -#include +#include +#include +#include +#include @@ -400,6 +400,38 @@ T Clamp(T a_Value, T a_Min, T a_Max) +/** Floors a_Value, then casts it to C (an int by default) */ +template +C FloorD(double a_Value) +{ + return static_cast(std::floor(a_Value)); +} + +/** Floors a_Value, then casts it to C (an int by default) */ +template +C FloorF(double a_Value) +{ + return static_cast(std::floorf(a_Value)); +} + +/** Ciels a_Value, then casts it to C (an int by default) */ +template +C CeilD(double a_Value) +{ + return static_cast(std::ceil(a_Value)); +} + +/** Ciels a_Value, then casts it to C (an int by default) */ +template +C CeilF(double a_Value) +{ + return static_cast(std::ceilf(a_Value)); +} + + + + + #ifndef TOLUA_TEMPLATE_BIND #define TOLUA_TEMPLATE_BIND(x) #endif -- cgit v1.2.3 From 76b37acb421bf10e094182b2e9be111eb29c46f1 Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 3 Sep 2014 16:51:38 -0700 Subject: Float/Ciel: If it's going to use C++11, it might as well take advantage of it --- src/Globals.h | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'src/Globals.h') diff --git a/src/Globals.h b/src/Globals.h index 8bf7a0f0c..9959d92a9 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -400,34 +400,20 @@ T Clamp(T a_Value, T a_Min, T a_Max) -/** Floors a_Value, then casts it to C (an int by default) */ -template -C FloorD(double a_Value) +/** Floors a value, then casts it to C (an int by default) */ +template +typename std::enable_if::value, C>::type FloorC(T a_Value) { return static_cast(std::floor(a_Value)); } -/** Floors a_Value, then casts it to C (an int by default) */ -template -C FloorF(double a_Value) -{ - return static_cast(std::floorf(a_Value)); -} - -/** Ciels a_Value, then casts it to C (an int by default) */ -template -C CeilD(double a_Value) +/** Ceils a value, then casts it to C (an int by default) */ +template +typename std::enable_if::value, C>::type CeilC(T a_Value) { return static_cast(std::ceil(a_Value)); } -/** Ciels a_Value, then casts it to C (an int by default) */ -template -C CeilF(double a_Value) -{ - return static_cast(std::ceilf(a_Value)); -} - -- cgit v1.2.3 From a47d9e53344144d7584c37bbac742cf2187492fe Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 10 Oct 2014 09:58:54 +0200 Subject: Fixed MSVC compilation. --- src/Globals.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/Globals.h') diff --git a/src/Globals.h b/src/Globals.h index 9959d92a9..4ee1352eb 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -51,6 +51,9 @@ #define NORETURN __declspec(noreturn) + // Use non-standard defines in + #define _USE_MATH_DEFINES + #elif defined(__GNUC__) // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)? -- cgit v1.2.3 From 473c0425d374132c097045a84e03510bc8a7876b Mon Sep 17 00:00:00 2001 From: tycho Date: Fri, 10 Oct 2014 15:33:19 +0100 Subject: Moved a few objects to unique_ptr --- src/Globals.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/Globals.h') diff --git a/src/Globals.h b/src/Globals.h index 4ee1352eb..5c5a8b3d2 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -419,6 +419,12 @@ typename std::enable_if::value, C>::type CeilC(T a_Value) +//temporary replacement for std::make_unique until we get c++14 +template< class T, class... Args > +std::unique_ptr make_unique( Args&&... args ) +{ + return std::unique_ptr(new T(args...)); +} #ifndef TOLUA_TEMPLATE_BIND @@ -436,3 +442,4 @@ typename std::enable_if::value, C>::type CeilC(T a_Value) #include "BlockInfo.h" + -- cgit v1.2.3 From 6a448be88ce2d8eba3d127989978a1045b54ea6f Mon Sep 17 00:00:00 2001 From: worktycho Date: Sun, 12 Oct 2014 12:17:29 +0100 Subject: Fix spaces --- src/Globals.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Globals.h') diff --git a/src/Globals.h b/src/Globals.h index 5c5a8b3d2..b84607355 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -420,8 +420,8 @@ typename std::enable_if::value, C>::type CeilC(T a_Value) //temporary replacement for std::make_unique until we get c++14 -template< class T, class... Args > -std::unique_ptr make_unique( Args&&... args ) +template +std::unique_ptr make_unique(Args&&... args) { return std::unique_ptr(new T(args...)); } -- cgit v1.2.3 From ee23fd5b9eb3e33a38a65c9a61592c45f1aa5ba0 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 19 Oct 2014 18:52:24 +0200 Subject: Removed obsolete tr1::shared_ptr. --- src/Globals.h | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/Globals.h') diff --git a/src/Globals.h b/src/Globals.h index b84607355..e0a25ed83 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -361,19 +361,8 @@ void inline LOGD(const char* a_Format, ...) #define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0)) #endif -// Allow both Older versions of MSVC and newer versions of everything use a shared_ptr: -// Note that we cannot typedef, because C++ doesn't allow (partial) templates to be typedeffed. -#if (defined(_MSC_VER) && (_MSC_VER < 1600)) - // MSVC before 2010 doesn't have std::shared_ptr, but has std::tr1::shared_ptr, defined in included earlier - #define SharedPtr std::tr1::shared_ptr -#elif (defined(_MSC_VER) || (__cplusplus >= 201103L)) - // C++11 has std::shared_ptr in , included earlier - #define SharedPtr std::shared_ptr -#else - // C++03 has std::tr1::shared_ptr in - #include - #define SharedPtr std::tr1::shared_ptr -#endif +// Unified shared ptr from before C++11. Also no silly undercores. +#define SharedPtr std::shared_ptr -- cgit v1.2.3 From 154c329a259d937270a23fcbadfa2c01400db0c3 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 23 Oct 2014 10:53:18 +0200 Subject: Removed the "conditional expression is constant" warning. MSVC spits out many of these on its own std libraries. --- src/Globals.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Globals.h') diff --git a/src/Globals.h b/src/Globals.h index e0a25ed83..582f5fdaa 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -17,7 +17,6 @@ #pragma warning(disable:4100) // Unreferenced formal parameter // Useful warnings from warning level 4: - #pragma warning(3 : 4127) // Conditional expression is constant #pragma warning(3 : 4189) // Local variable is initialized but not referenced #pragma warning(3 : 4245) // Conversion from 'type1' to 'type2', signed/unsigned mismatch #pragma warning(3 : 4310) // Cast truncates constant value @@ -26,7 +25,10 @@ #pragma warning(3 : 4701) // Potentially unitialized local variable used #pragma warning(3 : 4702) // Unreachable code #pragma warning(3 : 4706) // Assignment within conditional expression - + + // 2014-10-23 xoft: Disabled this because the new C++11 headers in MSVC produce tons of these warnings uselessly + // #pragma warning(3 : 4127) // Conditional expression is constant + // Disabling this warning, because we know what we're doing when we're doing this: #pragma warning(disable: 4355) // 'this' used in initializer list -- cgit v1.2.3