15# define NTDDI_VERSION NTDDI_WINXP
16# define _WIN32_WINNT 0x501
17# define _WIN32_WINDOWS 0x501
19# define _WIN32_IE_ 0x0600
24# define _CRT_SECURE_NO_DEPRECATE
25# define _CRT_SECURE_NO_WARNINGS
26# define _CRT_NONSTDC_NO_WARNINGS
35# define __STDC_LIMIT_MACROS
40# include <SupportDefs.h>
42# define _DEFAULT_SOURCE
71#include <source_location>
79#if defined(UNIX) || defined(__MINGW32__)
80# include <sys/types.h>
84#if defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER))
88#if __GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1)
89# define NOACCESS(args) __attribute__ ((access (none, args)))
91# define NOACCESS(args)
95# define WIN32_LEAN_AND_MEAN
100# define EMPTY_BASES __declspec(empty_bases)
110# pragma warning(disable: 4244)
111# pragma warning(disable: 4761)
112# pragma warning(disable: 4200)
113# pragma warning(disable: 4355)
115# pragma warning(disable: 4291)
116# pragma warning(disable: 4996)
117# pragma warning(disable: 6308)
118# pragma warning(disable: 6011)
119# pragma warning(disable: 6326)
120# pragma warning(disable: 6031)
121# pragma warning(disable: 6246)
125# if defined(_WIN32) && !defined(_WIN64)
130 typedef _W64
int INT_PTR, *PINT_PTR;
131 typedef _W64
unsigned int UINT_PTR, *PUINT_PTR;
135# define fseek _fseeki64
139# if defined(WITH_ZLIB)
140# if !defined(ZEXPORT)
141# define ZEXPORT CDECL
146# if defined(WITH_FREETYPE)
147# if !defined(FT_EXPORT)
148# define FT_EXPORT( x ) extern "C" x CDECL
153# if defined(WITH_LIBLZMA)
154# if !defined(LZMA_API_STATIC)
155# define LZMA_API_STATIC
160# define S_ISDIR(mode) (mode & S_IFDIR)
161# define S_ISREG(mode) (mode & S_IFREG)
165#if !defined(STRGEN) && !defined(SETTINGSGEN)
167 char *getcwd(
char *buf,
size_t size);
169 std::string
FS2OTTD(
const std::wstring &name);
170 std::wstring
OTTD2FS(
const std::string &name);
171# elif defined(WITH_ICONV)
172 std::string
FS2OTTD(
const std::string &name);
173 std::string
OTTD2FS(
const std::string &name);
175 template <
typename T> std::string
FS2OTTD(T name) {
return name; }
176 template <
typename T> std::string
OTTD2FS(T name) {
return name; }
182# define PATHSEPCHAR '\\'
185# define PATHSEPCHAR '/'
189# define PACK_N(type_dec, n) __pragma(pack(push, n)) type_dec; __pragma(pack(pop))
190#elif defined(__MINGW32__)
191# define PRAGMA(x) _Pragma(#x)
192# define PACK_N(type_dec, n) PRAGMA(pack(push, n)) type_dec; PRAGMA(pack(pop))
194# define PACK_N(type_dec, n) type_dec __attribute__((__packed__, aligned(n)))
196#define PACK(type_dec) PACK_N(type_dec, 1)
226#if !defined(_DEBUG) || defined(NO_DEBUG_INLINE)
231#define debug_inline inline
232#elif defined(__clang__) || defined(__GNUC__)
233#define debug_inline [[gnu::always_inline]] inline
240#define debug_inline inline
244#if (!defined(UNIX) && !defined(__HAIKU__)) || defined(__QNXNTO__) || defined(__CYGWIN__)
245 typedef unsigned int uint;
248#if !defined(WITH_PERSONAL_DIR)
249# define PERSONAL_DIR ""
253#if defined(WITH_PERSONAL_DIR) && defined(UNIX) && !defined(__APPLE__) && !defined(__EMSCRIPTEN__)
258static_assert(
sizeof(uint64_t) == 8);
259static_assert(
sizeof(uint32_t) == 4);
260static_assert(
sizeof(uint16_t) == 2);
261static_assert(
sizeof(uint8_t) == 1);
262static_assert(SIZE_MAX >= UINT32_MAX);
265#define M_PI_2 1.57079632679489661923
266#define M_PI 3.14159265358979323846
269template <
typename T,
size_t N>
270char (&ArraySizeHelper(T (&array)[N]))[N];
280#define lengthof(array) (sizeof(ArraySizeHelper(array)))
288#define cpp_sizeof(base, variable) (sizeof(std::declval<base>().variable))
292#if defined(__APPLE__)
293# define GetString OTTD_GetString
294# define DrawString OTTD_DrawString
295# define CloseConnection OTTD_CloseConnection
298#if defined(__GNUC__) || defined(__clang__)
299# define GNU_TARGET(x) [[gnu::target(x)]]
301# define GNU_TARGET(x)
305#define FMT_HEADER_ONLY
307[[noreturn]]
void NOT_REACHED(
const std::source_location location = std::source_location::current());
308[[noreturn]]
void AssertFailedError(
const char *expression,
const std::source_location location = std::source_location::current());
311#if defined(NDEBUG) && defined(WITH_ASSERT)
313# define assert(expression) do { if (!(expression)) [[unlikely]] AssertFailedError(#expression); } while (false)
318#define JSON_ASSERT(x) assert(x)
322#elif defined(PATH_MAX) && PATH_MAX > 0
324# define MAX_PATH PATH_MAX
334inline void free(
const void *ptr)
336 free(
const_cast<void *
>(ptr));
343#define MAX_UVALUE(type) (static_cast<type>(~static_cast<type>(0)))
345#if defined(_MSC_VER) && !defined(_DEBUG)
346# define IGNORE_UNINITIALIZED_WARNING_START __pragma(warning(push)) __pragma(warning(disable:4700))
347# define IGNORE_UNINITIALIZED_WARNING_STOP __pragma(warning(pop))
348#elif defined(__GNUC__) && !defined(_DEBUG)
349# define HELPER0(x) #x
350# define HELPER1(x) HELPER0(GCC diagnostic ignored x)
351# define HELPER2(y) HELPER1(#y)
352#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
353# define IGNORE_UNINITIALIZED_WARNING_START \
354 _Pragma("GCC diagnostic push") \
355 _Pragma(HELPER2(-Wuninitialized)) \
356 _Pragma(HELPER2(-Wmaybe-uninitialized))
357# define IGNORE_UNINITIALIZED_WARNING_STOP _Pragma("GCC diagnostic pop")
361#ifndef IGNORE_UNINITIALIZED_WARNING_START
362# define IGNORE_UNINITIALIZED_WARNING_START
363# 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.