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))
86# define WIN32_LEAN_AND_MEAN
91# define EMPTY_BASES __declspec(empty_bases)
101# pragma warning(disable: 4244)
102# pragma warning(disable: 4761)
103# pragma warning(disable: 4200)
104# pragma warning(disable: 4355)
106# pragma warning(disable: 4291)
107# pragma warning(disable: 4996)
108# pragma warning(disable: 6308)
109# pragma warning(disable: 6011)
110# pragma warning(disable: 6326)
111# pragma warning(disable: 6031)
112# pragma warning(disable: 6246)
116# if defined(_WIN32) && !defined(_WIN64)
121 typedef _W64
int INT_PTR, *PINT_PTR;
122 typedef _W64
unsigned int UINT_PTR, *PUINT_PTR;
126# define fseek _fseeki64
130# if defined(WITH_ZLIB)
131# if !defined(ZEXPORT)
132# define ZEXPORT CDECL
137# if defined(WITH_FREETYPE)
138# if !defined(FT_EXPORT)
139# define FT_EXPORT( x ) extern "C" x CDECL
144# if defined(WITH_LIBLZMA)
145# if !defined(LZMA_API_STATIC)
146# define LZMA_API_STATIC
151# define S_ISDIR(mode) (mode & S_IFDIR)
152# define S_ISREG(mode) (mode & S_IFREG)
156#if !defined(STRGEN) && !defined(SETTINGSGEN)
158 char *getcwd(
char *buf,
size_t size);
160 std::string
FS2OTTD(
const std::wstring &name);
161 std::wstring
OTTD2FS(
const std::string &name);
162# elif defined(WITH_ICONV)
163 std::string
FS2OTTD(
const std::string &name);
164 std::string
OTTD2FS(
const std::string &name);
166 template <
typename T> std::string
FS2OTTD(T name) {
return name; }
167 template <
typename T> std::string
OTTD2FS(T name) {
return name; }
173# define PATHSEPCHAR '\\'
176# define PATHSEPCHAR '/'
180# define PACK_N(type_dec, n) __pragma(pack(push, n)) type_dec; __pragma(pack(pop))
181#elif defined(__MINGW32__)
182# define PRAGMA(x) _Pragma(#x)
183# define PACK_N(type_dec, n) PRAGMA(pack(push, n)) type_dec; PRAGMA(pack(pop))
185# define PACK_N(type_dec, n) type_dec __attribute__((__packed__, aligned(n)))
187#define PACK(type_dec) PACK_N(type_dec, 1)
217#if !defined(_DEBUG) || defined(NO_DEBUG_INLINE)
222#define debug_inline inline
223#elif defined(__clang__) || defined(__GNUC__)
224#define debug_inline [[gnu::always_inline]] inline
231#define debug_inline inline
235#if (!defined(UNIX) && !defined(__HAIKU__)) || defined(__QNXNTO__) || defined(__CYGWIN__)
236 typedef unsigned int uint;
239#if !defined(WITH_PERSONAL_DIR)
240# define PERSONAL_DIR ""
244#if defined(WITH_PERSONAL_DIR) && defined(UNIX) && !defined(__APPLE__) && !defined(__EMSCRIPTEN__)
249static_assert(
sizeof(uint64_t) == 8);
250static_assert(
sizeof(uint32_t) == 4);
251static_assert(
sizeof(uint16_t) == 2);
252static_assert(
sizeof(uint8_t) == 1);
253static_assert(SIZE_MAX >= UINT32_MAX);
256#define M_PI_2 1.57079632679489661923
257#define M_PI 3.14159265358979323846
260template <
typename T,
size_t N>
261char (&ArraySizeHelper(T (&array)[N]))[N];
271#define lengthof(array) (sizeof(ArraySizeHelper(array)))
279#define cpp_sizeof(base, variable) (sizeof(std::declval<base>().variable))
283#if defined(__APPLE__)
284# define GetString OTTD_GetString
285# define DrawString OTTD_DrawString
286# define CloseConnection OTTD_CloseConnection
289#if defined(__GNUC__) || defined(__clang__)
290# define GNU_TARGET(x) [[gnu::target(x)]]
292# define GNU_TARGET(x)
295[[noreturn]]
void NOT_REACHED(
const std::source_location location = std::source_location::current());
296[[noreturn]]
void AssertFailedError(
const char *expression,
const std::source_location location = std::source_location::current());
299#if defined(NDEBUG) && defined(WITH_ASSERT)
301# define assert(expression) do { if (!(expression)) [[unlikely]] AssertFailedError(#expression); } while (false)
306#define JSON_ASSERT(x) assert(x)
310#elif defined(PATH_MAX) && PATH_MAX > 0
312# define MAX_PATH PATH_MAX
318#if defined(_MSC_VER) && !defined(_DEBUG)
319# define IGNORE_UNINITIALIZED_WARNING_START __pragma(warning(push)) __pragma(warning(disable:4700))
320# define IGNORE_UNINITIALIZED_WARNING_STOP __pragma(warning(pop))
321#elif defined(__GNUC__) && !defined(_DEBUG)
322# define HELPER0(x) #x
323# define HELPER1(x) HELPER0(GCC diagnostic ignored x)
324# define HELPER2(y) HELPER1(#y)
325#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
326# define IGNORE_UNINITIALIZED_WARNING_START \
327 _Pragma("GCC diagnostic push") \
328 _Pragma(HELPER2(-Wuninitialized)) \
329 _Pragma(HELPER2(-Wmaybe-uninitialized))
330# define IGNORE_UNINITIALIZED_WARNING_STOP _Pragma("GCC diagnostic pop")
334#ifndef IGNORE_UNINITIALIZED_WARNING_START
335# define IGNORE_UNINITIALIZED_WARNING_START
336# define IGNORE_UNINITIALIZED_WARNING_STOP
OSX is different on some places.
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.