Update to 14.0-beta1
This commit is contained in:
+91
-182
@@ -35,11 +35,6 @@
|
||||
# include <unistd.h>
|
||||
# define _DEFAULT_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
# define TROUBLED_INTS
|
||||
#endif
|
||||
|
||||
#if defined(__HAIKU__) || defined(__CYGWIN__)
|
||||
# include <strings.h> /* strncasecmp */
|
||||
#endif
|
||||
|
||||
/* It seems that we need to include stdint.h before anything else
|
||||
@@ -47,106 +42,49 @@
|
||||
* does not have stdint.h.
|
||||
* For OSX the inclusion is already done in osx_stdafx.h. */
|
||||
#if !defined(__APPLE__) && (!defined(_MSC_VER) || _MSC_VER >= 1600)
|
||||
# if defined(SUNOS)
|
||||
/* SunOS/Solaris does not have stdint.h, but inttypes.h defines everything
|
||||
* stdint.h defines and we need. */
|
||||
# include <inttypes.h>
|
||||
# else
|
||||
# define __STDC_LIMIT_MACROS
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The conditions for these constants to be available are way too messy; so check them one by one */
|
||||
#if !defined(UINT64_MAX)
|
||||
# define UINT64_MAX (18446744073709551615ULL)
|
||||
#endif
|
||||
#if !defined(INT64_MAX)
|
||||
# define INT64_MAX (9223372036854775807LL)
|
||||
#endif
|
||||
#if !defined(INT64_MIN)
|
||||
# define INT64_MIN (-INT64_MAX - 1)
|
||||
#endif
|
||||
#if !defined(UINT32_MAX)
|
||||
# define UINT32_MAX (4294967295U)
|
||||
#endif
|
||||
#if !defined(INT32_MAX)
|
||||
# define INT32_MAX (2147483647)
|
||||
#endif
|
||||
#if !defined(INT32_MIN)
|
||||
# define INT32_MIN (-INT32_MAX - 1)
|
||||
#endif
|
||||
#if !defined(UINT16_MAX)
|
||||
# define UINT16_MAX (65535U)
|
||||
#endif
|
||||
#if !defined(INT16_MAX)
|
||||
# define INT16_MAX (32767)
|
||||
#endif
|
||||
#if !defined(INT16_MIN)
|
||||
# define INT16_MIN (-INT16_MAX - 1)
|
||||
#endif
|
||||
#if !defined(UINT8_MAX)
|
||||
# define UINT8_MAX (255)
|
||||
#endif
|
||||
#if !defined(INT8_MAX)
|
||||
# define INT8_MAX (127)
|
||||
#endif
|
||||
#if !defined(INT8_MIN)
|
||||
# define INT8_MIN (-INT8_MAX - 1)
|
||||
# define __STDC_LIMIT_MACROS
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <climits>
|
||||
#include <cassert>
|
||||
#include <cwchar>
|
||||
#include <deque>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <span>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t)-1)
|
||||
#endif
|
||||
#include <type_traits>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#if defined(UNIX) || defined(__MINGW32__)
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if defined(__OS2__)
|
||||
# include <types.h>
|
||||
# define strcasecmp stricmp
|
||||
#endif
|
||||
|
||||
#if defined(SUNOS) || defined(HPUX) || defined(__CYGWIN__)
|
||||
# include <alloca.h>
|
||||
#endif
|
||||
|
||||
/* Stuff for GCC */
|
||||
#if defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER))
|
||||
# define NORETURN __attribute__ ((noreturn))
|
||||
# define CDECL
|
||||
# define __int64 long long
|
||||
/* Warn about functions using 'printf' format syntax. First argument determines which parameter
|
||||
* is the format string, second argument is start of values passed to printf. */
|
||||
# define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
|
||||
# define WARN_TIME_FORMAT(string) __attribute__ ((format (strftime, string, 0)))
|
||||
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
|
||||
# define FINAL final
|
||||
# else
|
||||
# define FINAL
|
||||
# endif
|
||||
|
||||
/* Use fallthrough attribute where supported */
|
||||
# if __GNUC__ >= 7
|
||||
# if __cplusplus > 201402L // C++17
|
||||
# define FALLTHROUGH [[fallthrough]]
|
||||
# else
|
||||
# define FALLTHROUGH __attribute__((fallthrough))
|
||||
# endif
|
||||
# else
|
||||
# define FALLTHROUGH
|
||||
# endif
|
||||
#endif /* __GNUC__ || __clang__ */
|
||||
|
||||
#if __GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1)
|
||||
@@ -155,24 +93,17 @@
|
||||
# define NOACCESS(args)
|
||||
#endif
|
||||
|
||||
#if defined(__WATCOMC__)
|
||||
# define NORETURN
|
||||
# define CDECL
|
||||
# define WARN_FORMAT(string, args)
|
||||
# define WARN_TIME_FORMAT(string)
|
||||
# define FINAL
|
||||
# define FALLTHROUGH
|
||||
# include <malloc.h>
|
||||
#endif /* __WATCOMC__ */
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
# include <malloc.h> // alloca()
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
# define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
// See https://learn.microsoft.com/en-us/cpp/cpp/empty-bases?view=msvc-170
|
||||
# define EMPTY_BASES __declspec(empty_bases)
|
||||
#else
|
||||
# define EMPTY_BASES
|
||||
#endif
|
||||
|
||||
/* Stuff for MSVC */
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
@@ -192,7 +123,6 @@
|
||||
# pragma warning(disable: 6011) // code analyzer: Dereferencing NULL pointer 'pfGetAddrInfo': Lines: 995, 996, 998, 999, 1001
|
||||
# pragma warning(disable: 6326) // code analyzer: potential comparison of a constant with another constant
|
||||
# pragma warning(disable: 6031) // code analyzer: Return value ignored: 'ReadFile'
|
||||
# pragma warning(disable: 6255) // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
|
||||
# pragma warning(disable: 6246) // code analyzer: Local declaration of 'statspec' hides declaration of the same name in outer scope. For additional information, see previous declaration at ...
|
||||
|
||||
# if (_MSC_VER == 1500) // Addresses item #13 on http://blogs.msdn.com/b/vcblog/archive/2008/08/11/tr1-fixes-in-vc9-sp1.aspx, for Visual Studio 2008
|
||||
@@ -200,23 +130,11 @@
|
||||
# include <intrin.h>
|
||||
# endif
|
||||
|
||||
# include <malloc.h> // alloca()
|
||||
# define NORETURN __declspec(noreturn)
|
||||
# if (_MSC_VER < 1900)
|
||||
# define inline __forceinline
|
||||
# endif
|
||||
|
||||
# define CDECL _cdecl
|
||||
# define WARN_FORMAT(string, args)
|
||||
# define WARN_TIME_FORMAT(string)
|
||||
# define FINAL final
|
||||
|
||||
/* fallthrough attribute, VS 2017 */
|
||||
# if (_MSC_VER >= 1910) || defined(__clang__)
|
||||
# define FALLTHROUGH [[fallthrough]]
|
||||
# else
|
||||
# define FALLTHROUGH
|
||||
# endif
|
||||
|
||||
# if defined(_WIN32) && !defined(_WIN64)
|
||||
# if !defined(_W64)
|
||||
@@ -252,10 +170,6 @@
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# define strcasecmp stricmp
|
||||
# define strncasecmp strnicmp
|
||||
# define strtoull _strtoui64
|
||||
|
||||
/* MSVC doesn't have these :( */
|
||||
# define S_ISDIR(mode) (mode & S_IFDIR)
|
||||
# define S_ISREG(mode) (mode & S_IFREG)
|
||||
@@ -284,7 +198,7 @@
|
||||
# endif /* _WIN32 or WITH_ICONV */
|
||||
#endif /* STRGEN || SETTINGSGEN */
|
||||
|
||||
#if defined(_WIN32) || defined(__OS2__) && !defined(__INNOTEK_LIBC__)
|
||||
#if defined(_WIN32)
|
||||
# define PATHSEP "\\"
|
||||
# define PATHSEPCHAR '\\'
|
||||
#else
|
||||
@@ -292,7 +206,7 @@
|
||||
# define PATHSEPCHAR '/'
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) || defined(__WATCOMC__)
|
||||
#if defined(_MSC_VER)
|
||||
# define PACK_N(type_dec, n) __pragma(pack(push, n)) type_dec; __pragma(pack(pop))
|
||||
#elif defined(__MINGW32__)
|
||||
# define PRAGMA(x) _Pragma(#x)
|
||||
@@ -302,58 +216,58 @@
|
||||
#endif
|
||||
#define PACK(type_dec) PACK_N(type_dec, 1)
|
||||
|
||||
/* MSVCRT of course has to have a different syntax for long long *sigh* */
|
||||
#if defined(_MSC_VER)
|
||||
# define OTTD_PRINTF64 "%I64d"
|
||||
# define OTTD_PRINTF64U "%I64u"
|
||||
# define OTTD_PRINTFHEX64 "%I64x"
|
||||
# define PRINTF_SIZE "%Iu"
|
||||
# define PRINTF_SIZEX "%IX"
|
||||
#elif defined(__MINGW32__)
|
||||
# define OTTD_PRINTF64 "%I64d"
|
||||
# define OTTD_PRINTF64U "%I64llu"
|
||||
# define OTTD_PRINTFHEX64 "%I64x"
|
||||
# define PRINTF_SIZE "%Iu"
|
||||
# define PRINTF_SIZEX "%IX"
|
||||
/*
|
||||
* When making a (pure) debug build, the compiler will by default disable
|
||||
* inlining of functions. This has a detremental effect on the performance of
|
||||
* debug builds, especially when more and more trivial (wrapper) functions get
|
||||
* added to the code base.
|
||||
* Take for example the savegame called "Wentbourne", when running this game
|
||||
* for 100 ticks with the null video driver a number of fairly trivial
|
||||
* functions show up on top. The most common one is the implicit conversion
|
||||
* operator of TileIndex to unsigned int, which takes up over 5% of the total
|
||||
* run time and functionally does absolutely nothing. The remaining functions
|
||||
* for the top 5 are GB, GetTileType, Map::Size and IsTileType to a total of
|
||||
* about 12.5% of the game's total run time.
|
||||
* It is possible to still force inlining in the most commonly used compilers,
|
||||
* but that is at the cost of some problems with debugging due to the forced
|
||||
* inlining. However, the performance benefit can be enormous; when forcing
|
||||
* inlining for the previously mentioned top 5, the debug build ran about 15%
|
||||
* quicker.
|
||||
* The following debug_inline annotation may be added to functions comply
|
||||
* with the following preconditions:
|
||||
* 1: the function takes more than 0.5% of a profiled debug runtime
|
||||
* 2: the function does not modify the game state
|
||||
* 3: the function does not contain selection or iteration statements,
|
||||
* i.e. no if, switch, for, do, while, etcetera.
|
||||
* 4: the function is one line of code, excluding assertions.
|
||||
* 5: the function is defined in a header file.
|
||||
* The debug_inline annotation must be placed in front of the function, i.e.
|
||||
* before the optional static or constexpr modifier.
|
||||
*/
|
||||
#if !defined(_DEBUG) || defined(NO_DEBUG_INLINE)
|
||||
/*
|
||||
* Do not force inlining when not in debug. This way we do not work against
|
||||
* any carefully designed compiler optimizations.
|
||||
*/
|
||||
#define debug_inline inline
|
||||
#elif defined(__clang__) || defined(__GNUC__)
|
||||
#define debug_inline [[gnu::always_inline]] inline
|
||||
#else
|
||||
# define OTTD_PRINTF64 "%lld"
|
||||
# define OTTD_PRINTF64U "%llu"
|
||||
# define OTTD_PRINTFHEX64 "%llx"
|
||||
# define PRINTF_SIZE "%zu"
|
||||
# define PRINTF_SIZEX "%zX"
|
||||
/*
|
||||
* MSVC explicitly disables inlining, even forced inlining, in debug builds
|
||||
* so __forceinline makes no difference compared to inline. Other unknown
|
||||
* compilers can also just fallback to a normal inline.
|
||||
*/
|
||||
#define debug_inline inline
|
||||
#endif
|
||||
|
||||
typedef unsigned char byte;
|
||||
typedef uint8_t byte;
|
||||
|
||||
/* This is already defined in unix, but not in QNX Neutrino (6.x) or Cygwin. */
|
||||
#if (!defined(UNIX) && !defined(__HAIKU__)) || defined(__QNXNTO__) || defined(__CYGWIN__)
|
||||
typedef unsigned int uint;
|
||||
#endif
|
||||
|
||||
#if defined(TROUBLED_INTS)
|
||||
/* Haiku's types for uint32/int32/uint64/int64 are different than what
|
||||
* they are on other platforms; not in length, but how to print them.
|
||||
* So make them more like the other platforms, to make printf() etc a
|
||||
* little bit easier. */
|
||||
# define uint32 uint32_ugly_hack
|
||||
# define int32 int32_ugly_hack
|
||||
# define uint64 uint64_ugly_hack
|
||||
# define int64 int64_ugly_hack
|
||||
typedef unsigned int uint32_ugly_hack;
|
||||
typedef signed int int32_ugly_hack;
|
||||
typedef unsigned __int64 uint64_ugly_hack;
|
||||
typedef signed __int64 int64_ugly_hack;
|
||||
#else
|
||||
typedef unsigned char uint8;
|
||||
typedef signed char int8;
|
||||
typedef unsigned short uint16;
|
||||
typedef signed short int16;
|
||||
typedef unsigned int uint32;
|
||||
typedef signed int int32;
|
||||
typedef unsigned __int64 uint64;
|
||||
typedef signed __int64 int64;
|
||||
#endif /* !TROUBLED_INTS */
|
||||
|
||||
#if !defined(WITH_PERSONAL_DIR)
|
||||
# define PERSONAL_DIR ""
|
||||
#endif
|
||||
@@ -364,10 +278,10 @@ typedef unsigned char byte;
|
||||
#endif
|
||||
|
||||
/* Check if the types have the bitsizes like we are using them */
|
||||
static_assert(sizeof(uint64) == 8);
|
||||
static_assert(sizeof(uint32) == 4);
|
||||
static_assert(sizeof(uint16) == 2);
|
||||
static_assert(sizeof(uint8) == 1);
|
||||
static_assert(sizeof(uint64_t) == 8);
|
||||
static_assert(sizeof(uint32_t) == 4);
|
||||
static_assert(sizeof(uint16_t) == 2);
|
||||
static_assert(sizeof(uint8_t) == 1);
|
||||
static_assert(SIZE_MAX >= UINT32_MAX);
|
||||
|
||||
#ifndef M_PI_2
|
||||
@@ -426,32 +340,27 @@ static_assert(SIZE_MAX >= UINT32_MAX);
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
# define likely(x) __builtin_expect(!!(x), 1)
|
||||
# define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
# define GNU_TARGET(x) [[gnu::target(x)]]
|
||||
#else
|
||||
# define likely(x) (x)
|
||||
# define unlikely(x) (x)
|
||||
# define GNU_TARGET(x)
|
||||
#endif /* __GNUC__ || __clang__ */
|
||||
|
||||
/* For the FMT library we only want to use the headers, not link to some library. */
|
||||
#define FMT_HEADER_ONLY
|
||||
|
||||
void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
|
||||
void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
|
||||
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
|
||||
[[noreturn]] void NotReachedError(int line, const char *file);
|
||||
[[noreturn]] void AssertFailedError(int line, const char *file, const char *expression);
|
||||
#define NOT_REACHED() NotReachedError(__LINE__, __FILE__)
|
||||
|
||||
/* For non-debug builds with assertions enabled use the special assertion handler. */
|
||||
#if defined(NDEBUG) && defined(WITH_ASSERT)
|
||||
# undef assert
|
||||
# define assert(expression) if (unlikely(!(expression))) error("Assertion failed at line %i of %s: %s", __LINE__, __FILE__, #expression);
|
||||
# define assert(expression) do { if (!(expression)) [[unlikely]] AssertFailedError(__LINE__, __FILE__, #expression); } while (false)
|
||||
#endif
|
||||
|
||||
#if defined(OPENBSD)
|
||||
/* OpenBSD uses strcasecmp(3) */
|
||||
# define _stricmp strcasecmp
|
||||
#endif
|
||||
/* Define JSON_ASSERT, which is used by nlohmann-json. Otherwise the header-file
|
||||
* will re-include assert.h, and reset the assert macro. */
|
||||
#define JSON_ASSERT(x) assert(x)
|
||||
|
||||
#if defined(MAX_PATH)
|
||||
/* It's already defined, no need to override */
|
||||
@@ -467,7 +376,7 @@ void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
|
||||
* Version of the standard free that accepts const pointers.
|
||||
* @param ptr The data to free.
|
||||
*/
|
||||
static inline void free(const void *ptr)
|
||||
inline void free(const void *ptr)
|
||||
{
|
||||
free(const_cast<void *>(ptr));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user