20 #define _USE_MATH_DEFINES
29 #define _CRTDBG_MAP_ALLOC
32 #define DEBUG_CLIENTBLOCK new(_CLIENT_BLOCK, __FILE__, __LINE__)
33 #define new DEBUG_CLIENTBLOCK
38 #define UNREACHABLE_INTRINSIC __assume(false)
40 #elif defined(__GNUC__)
45 #define UNREACHABLE_INTRINSIC __builtin_unreachable()
49 #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler"
59 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
60 TypeName(const TypeName &) = delete; \
61 TypeName & operator =(const TypeName &) = delete
65 #define UNUSED_VAR(X) (void)(X)
72 #define UNUSED UNUSED_VAR
81 #define NOMINMAX // Windows SDK defines min and max macros, messing up with our std::min and std::max usage.
82 #define WIN32_LEAN_AND_MEAN
83 #define _WIN32_WINNT 0x0501 // We want to target Windows XP with Service Pack 2 & Windows Server 2003 with Service Pack 1 and higher.
86 #define PLATFORM_CRYPTOGRAPHY (_WIN32_WINNT >= 0x0602)
95 #endif // GetFreeSpace
97 #define PLATFORM_CRYPTOGRAPHY 0
99 #include <arpa/inet.h>
123 #include <condition_variable>
136 #include <type_traits>
137 #include <unordered_map>
138 #include <unordered_set>
162 template <
typename T,
size_t Size>
165 static_assert(
sizeof(T) == Size,
"Check the size of integral types");
194 std::string_view a_Format,
eLogLevel, fmt::format_args a_ArgList
197 fmt::vprint(a_Format, a_ArgList);
203 std::string_view a_Format,
eLogLevel, fmt::printf_args a_ArgList
206 fmt::vprintf(a_Format, a_ArgList);
213 fmt::print(
"{}\n", a_Message);
228 #define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X)))
232 #define MiB * 1024 * 1024
235 #define FAST_FLOOR_DIV(x, div) (((x) - (((x) < 0) ? ((div) - 1) : 0)) / (div))
247 cAssertFailure(
const AString & aExpression,
const AString & aFileName,
int aLineNumber):
248 mExpression(aExpression),
249 mFileName(aFileName),
250 mLineNumber(aLineNumber)
254 const AString & expression()
const {
return mExpression; }
255 const AString & fileName()
const {
return mFileName; }
256 int lineNumber()
const {
return mLineNumber; }
262 #define ASSERT(x) do { if (!(x)) { throw cAssertFailure(#x, __FILE__, __LINE__);} } while (0)
266 #define VERIFY(x) (!!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), std::abort(), 0))
268 #else // TEST_GLOBALS
273 #define ASSERT(x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), std::abort(), 0))
277 #define VERIFY(x) (!!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), std::abort(), 0))
279 #endif // else TEST_GLOBALS
283 #define UNREACHABLE(x) UNREACHABLE_INTRINSIC
285 #define UNREACHABLE(x) ( FLOGERROR("Hit unreachable code: {0}, file {1}, line {2}", #x, __FILE__, __LINE__), std::abort(), 0)
297 return std::unique_ptr<T>(
new std::remove_extent_t<T>[a_Size]);
303 return std::unique_ptr<T>(
new T);
332 template <
typename T>
333 T
Clamp(T a_Value, T a_Min, T a_Max)
335 return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value);
343 template <
typename C =
int,
typename T>
344 typename std::enable_if<std::is_arithmetic<T>::value, C>::type
FloorC(T a_Value)
346 return static_cast<C
>(std::floor(a_Value));
350 template <
typename C =
int,
typename T>
351 typename std::enable_if<std::is_arithmetic<T>::value, C>::type
CeilC(T a_Value)
353 return static_cast<C
>(std::ceil(a_Value));
361 using cTickTime = std::chrono::duration<signed int, std::ratio_multiply<std::chrono::milliseconds::period, std::ratio<50>>>;
364 using cTickTimeLong = std::chrono::duration<signed long long int, cTickTime::period>;
367 constexpr
cTickTimeLong operator ""_tick(
const unsigned long long a_Ticks)
375 #ifndef TOLUA_TEMPLATE_BIND
376 #define TOLUA_TEMPLATE_BIND(x)
379 #ifdef TOLUA_EXPOSITION
380 #error TOLUA_EXPOSITION should never actually be defined
383 template <
typename T>
387 return static_cast<std::make_unsigned_t<T>
>(a_Val);