15# define NTDDI_VERSION NTDDI_WIN7
16# define _WIN32_WINNT 0x0601
21# define _CRT_SECURE_NO_DEPRECATE
22# define _CRT_SECURE_NO_WARNINGS
23# define _CRT_NONSTDC_NO_WARNINGS
32# define __STDC_LIMIT_MACROS
37# include <SupportDefs.h>
39# define _DEFAULT_SOURCE
68#include <source_location>
76#if defined(UNIX) || defined(__MINGW32__)
77# include <sys/types.h>
81#if defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER))
85#if __GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1)
86# define NOACCESS(args) __attribute__ ((access (none, args)))
88# define NOACCESS(args)
92# define WIN32_LEAN_AND_MEAN
97# define EMPTY_BASES __declspec(empty_bases)
107# pragma warning(disable: 4244)
108# pragma warning(disable: 4761)
109# pragma warning(disable: 4200)
110# pragma warning(disable: 4355)
112# pragma warning(disable: 4291)
113# pragma warning(disable: 4996)
114# pragma warning(disable: 6308)
115# pragma warning(disable: 6011)
116# pragma warning(disable: 6326)
117# pragma warning(disable: 6031)
118# pragma warning(disable: 6246)
122# if defined(_WIN32) && !defined(_WIN64)
127 typedef _W64
int INT_PTR, *PINT_PTR;
128 typedef _W64
unsigned int UINT_PTR, *PUINT_PTR;
132# define fseek _fseeki64
136# if defined(WITH_ZLIB)
137# if !defined(ZEXPORT)
138# define ZEXPORT CDECL
143# if defined(WITH_FREETYPE)
144# if !defined(FT_EXPORT)
145# define FT_EXPORT( x ) extern "C" x CDECL
150# if defined(WITH_LIBLZMA)
151# if !defined(LZMA_API_STATIC)
152# define LZMA_API_STATIC
157# define S_ISDIR(mode) (mode & S_IFDIR)
158# define S_ISREG(mode) (mode & S_IFREG)
162#if !defined(STRGEN) && !defined(SETTINGSGEN)
164 char *getcwd(
char *buf,
size_t size);
166 std::string
FS2OTTD(
const std::wstring &name);
167 std::wstring
OTTD2FS(
const std::string &name);
168# elif defined(WITH_ICONV)
169 std::string
FS2OTTD(
const std::string &name);
170 std::string
OTTD2FS(
const std::string &name);
172 template <
typename T> std::string
FS2OTTD(T name) {
return name; }
173 template <
typename T> std::string
OTTD2FS(T name) {
return name; }
179# define PATHSEPCHAR '\\'
182# define PATHSEPCHAR '/'
186# define PACK_N(type_dec, n) __pragma(pack(push, n)) type_dec; __pragma(pack(pop))
187#elif defined(__MINGW32__)
188# define PRAGMA(x) _Pragma(#x)
189# define PACK_N(type_dec, n) PRAGMA(pack(push, n)) type_dec; PRAGMA(pack(pop))
191# define PACK_N(type_dec, n) type_dec __attribute__((__packed__, aligned(n)))
193#define PACK(type_dec) PACK_N(type_dec, 1)
223#if !defined(_DEBUG) || defined(NO_DEBUG_INLINE)
228#define debug_inline inline
229#elif defined(__clang__) || defined(__GNUC__)
230#define debug_inline [[gnu::always_inline]] inline
237#define debug_inline inline
241#if (!defined(UNIX) && !defined(__HAIKU__)) || defined(__QNXNTO__) || defined(__CYGWIN__)
242 typedef unsigned int uint;
245#if !defined(WITH_PERSONAL_DIR)
246# define PERSONAL_DIR ""
250#if defined(WITH_PERSONAL_DIR) && defined(UNIX) && !defined(__APPLE__) && !defined(__EMSCRIPTEN__)
255static_assert(
sizeof(uint64_t) == 8);
256static_assert(
sizeof(uint32_t) == 4);
257static_assert(
sizeof(uint16_t) == 2);
258static_assert(
sizeof(uint8_t) == 1);
259static_assert(SIZE_MAX >= UINT32_MAX);
262#define M_PI_2 1.57079632679489661923
263#define M_PI 3.14159265358979323846
266template <
typename T,
size_t N>
267char (&ArraySizeHelper(T (&array)[N]))[N];
277#define lengthof(array) (sizeof(ArraySizeHelper(array)))
285#define cpp_sizeof(base, variable) (sizeof(std::declval<base>().variable))
289#if defined(__APPLE__)
290# define GetString OTTD_GetString
291# define DrawString OTTD_DrawString
292# define CloseConnection OTTD_CloseConnection
295#if defined(__GNUC__) || defined(__clang__)
296# define GNU_TARGET(x) [[gnu::target(x)]]
298# define GNU_TARGET(x)
302#define FMT_HEADER_ONLY
304[[noreturn]]
void NOT_REACHED(
const std::source_location location = std::source_location::current());
305[[noreturn]]
void AssertFailedError(
const char *expression,
const std::source_location location = std::source_location::current());
308#if defined(NDEBUG) && defined(WITH_ASSERT)
310# define assert(expression) do { if (!(expression)) [[unlikely]] AssertFailedError(#expression); } while (false)
315#define JSON_ASSERT(x) assert(x)
319#elif defined(PATH_MAX) && PATH_MAX > 0
321# define MAX_PATH PATH_MAX
331inline void free(
const void *ptr)
333 free(
const_cast<void *
>(ptr));
336#if defined(_MSC_VER) && !defined(_DEBUG)
337# define IGNORE_UNINITIALIZED_WARNING_START __pragma(warning(push)) __pragma(warning(disable:4700))
338# define IGNORE_UNINITIALIZED_WARNING_STOP __pragma(warning(pop))
339#elif defined(__GNUC__) && !defined(_DEBUG)
340# define HELPER0(x) #x
341# define HELPER1(x) HELPER0(GCC diagnostic ignored x)
342# define HELPER2(y) HELPER1(#y)
343#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
344# define IGNORE_UNINITIALIZED_WARNING_START \
345 _Pragma("GCC diagnostic push") \
346 _Pragma(HELPER2(-Wuninitialized)) \
347 _Pragma(HELPER2(-Wmaybe-uninitialized))
348# define IGNORE_UNINITIALIZED_WARNING_STOP _Pragma("GCC diagnostic pop")
352#ifndef IGNORE_UNINITIALIZED_WARNING_START
353# define IGNORE_UNINITIALIZED_WARNING_START
354# define IGNORE_UNINITIALIZED_WARNING_STOP
OSX is different on some places.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
std::wstring OTTD2FS(const std::string &name)
Convert from OpenTTD's encoding to a wide string.
std::string FS2OTTD(const std::wstring &name)
Convert to OpenTTD's encoding from a wide string.