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>
76using namespace std::literals::string_view_literals;
78#if defined(UNIX) || defined(__MINGW32__)
79# include <sys/types.h>
83#if defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER))
88# define WIN32_LEAN_AND_MEAN
93# define EMPTY_BASES __declspec(empty_bases)
103# pragma warning(disable: 4244)
104# pragma warning(disable: 4761)
105# pragma warning(disable: 4200)
106# pragma warning(disable: 4355)
108# pragma warning(disable: 4291)
109# pragma warning(disable: 4996)
110# pragma warning(disable: 6308)
111# pragma warning(disable: 6011)
112# pragma warning(disable: 6326)
113# pragma warning(disable: 6031)
114# pragma warning(disable: 6246)
118# if defined(_WIN32) && !defined(_WIN64)
123 typedef _W64
int INT_PTR, *PINT_PTR;
124 typedef _W64
unsigned int UINT_PTR, *PUINT_PTR;
128# define fseek _fseeki64
132# if defined(WITH_ZLIB)
133# if !defined(ZEXPORT)
134# define ZEXPORT CDECL
139# if defined(WITH_FREETYPE)
140# if !defined(FT_EXPORT)
141# define FT_EXPORT( x ) extern "C" x CDECL
146# if defined(WITH_LIBLZMA)
147# if !defined(LZMA_API_STATIC)
148# define LZMA_API_STATIC
153# define S_ISDIR(mode) (mode & S_IFDIR)
154# define S_ISREG(mode) (mode & S_IFREG)
158#if !defined(STRGEN) && !defined(SETTINGSGEN)
160 std::string
FS2OTTD(std::wstring_view name);
161 std::wstring
OTTD2FS(std::string_view name);
162# elif defined(WITH_ICONV)
163 std::string
FS2OTTD(std::string_view name);
164 std::string
OTTD2FS(std::string_view name);
166 static inline std::string
FS2OTTD(std::string_view name) {
return std::string{name}; }
167 static inline std::string
OTTD2FS(std::string_view name) {
return std::string{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)))
275#if defined(__APPLE__)
276# define GetString OTTD_GetString
277# define DrawString OTTD_DrawString
278# define CloseConnection OTTD_CloseConnection
281#if defined(__GNUC__) || defined(__clang__)
282# define GNU_TARGET(x) [[gnu::target(x)]]
284# define GNU_TARGET(x)
287[[noreturn]]
void NOT_REACHED(
const std::source_location location = std::source_location::current());
288[[noreturn]]
void AssertFailedError(std::string_view expression,
const std::source_location location = std::source_location::current());
291#if defined(NDEBUG) && defined(WITH_ASSERT)
293# define assert(expression) do { if (!(expression)) [[unlikely]] AssertFailedError(#expression); } while (false)
298#define JSON_ASSERT(x) assert(x)
302#elif defined(PATH_MAX) && PATH_MAX > 0
304# define MAX_PATH PATH_MAX
310#if defined(_MSC_VER) && !defined(_DEBUG)
311# define IGNORE_UNINITIALIZED_WARNING_START __pragma(warning(push)) __pragma(warning(disable:4700))
312# define IGNORE_UNINITIALIZED_WARNING_STOP __pragma(warning(pop))
313#elif defined(__GNUC__) && !defined(_DEBUG)
314# define HELPER0(x) #x
315# define HELPER1(x) HELPER0(GCC diagnostic ignored x)
316# define HELPER2(y) HELPER1(#y)
317#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
318# define IGNORE_UNINITIALIZED_WARNING_START \
319 _Pragma("GCC diagnostic push") \
320 _Pragma(HELPER2(-Wuninitialized)) \
321 _Pragma(HELPER2(-Wmaybe-uninitialized))
322# define IGNORE_UNINITIALIZED_WARNING_STOP _Pragma("GCC diagnostic pop")
326#ifndef IGNORE_UNINITIALIZED_WARNING_START
327# define IGNORE_UNINITIALIZED_WARNING_START
328# define IGNORE_UNINITIALIZED_WARNING_STOP
OSX is different on some places.
std::wstring OTTD2FS(std::string_view name)
Convert from OpenTTD's encoding to a wide string.
std::string FS2OTTD(std::wstring_view name)
Convert to OpenTTD's encoding from a wide string.