diff --git a/src/openrct2/Version.h b/src/openrct2/Version.h index 009024a232..f0630a185f 100644 --- a/src/openrct2/Version.h +++ b/src/openrct2/Version.h @@ -38,16 +38,16 @@ #endif // Platform -#ifdef __WINDOWS__ +#ifdef _WIN32 #define OPENRCT2_PLATFORM "Windows" #endif -#ifdef __LINUX__ +#ifdef __linux__ #define OPENRCT2_PLATFORM "Linux" #endif -#ifdef __MACOSX__ +#if (defined(__APPLE__) && defined(__MACH__)) #define OPENRCT2_PLATFORM "macOS" #endif -#ifdef __FREEBSD__ +#ifdef __FreeBSD__ #define OPENRCT2_PLATFORM "FreeBSD" #endif #ifndef OPENRCT2_PLATFORM diff --git a/src/openrct2/audio/audio.cpp b/src/openrct2/audio/audio.cpp index e26e1750e4..66eb49925a 100644 --- a/src/openrct2/audio/audio.cpp +++ b/src/openrct2/audio/audio.cpp @@ -176,7 +176,7 @@ void audio_populate_devices() } } -#ifndef __LINUX__ +#ifndef __linux__ // The first device is always system default on Windows and macOS std::string defaultDevice = language_get_string(STR_OPTIONS_SOUND_VALUE_DEFAULT); devices.insert(devices.begin(), defaultDevice); diff --git a/src/openrct2/cmdline/CommandLine.cpp b/src/openrct2/cmdline/CommandLine.cpp index 918da0d23c..df1f8a59e1 100644 --- a/src/openrct2/cmdline/CommandLine.cpp +++ b/src/openrct2/cmdline/CommandLine.cpp @@ -519,7 +519,7 @@ namespace CommandLine static bool HandleSpecialArgument(const char * argument) { -#ifdef __MACOSX__ +#ifdef __APPLE__ if (String::Equals(argument, "-NSDocumentRevisionsDebugMode")) { return true; diff --git a/src/openrct2/cmdline/RootCommands.cpp b/src/openrct2/cmdline/RootCommands.cpp index 2aa9243f17..e1a828686b 100644 --- a/src/openrct2/cmdline/RootCommands.cpp +++ b/src/openrct2/cmdline/RootCommands.cpp @@ -94,7 +94,7 @@ static exitcode_t HandleCommandJoin(CommandLineArgEnumerator * enumerator); static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator * enumerator); static exitcode_t HandleCommandScanObjects(CommandLineArgEnumerator * enumerator); -#if defined(__WINDOWS__) && !defined(__MINGW32__) +#if defined(_WIN32) && !defined(__MINGW32__) static bool _removeShell = false; @@ -131,7 +131,7 @@ const CommandLineCommand CommandLine::RootCommands[] DefineCommand("scan-objects", "", StandardOptions, HandleCommandScanObjects), DefineCommand("handle-uri", "openrct2://.../", StandardOptions, CommandLine::HandleCommandUri), -#if defined(__WINDOWS__) && !defined(__MINGW32__) +#if defined(_WIN32) && !defined(__MINGW32__) DefineCommand("register-shell", "", RegisterShellOptions, HandleCommandRegisterShell), #endif @@ -400,7 +400,7 @@ static exitcode_t HandleCommandScanObjects(CommandLineArgEnumerator * enumerator return EXITCODE_OK; } -#if defined(__WINDOWS__) && !defined(__MINGW32__) +#if defined(_WIN32) && !defined(__MINGW32__) static exitcode_t HandleCommandRegisterShell(CommandLineArgEnumerator * enumerator) { exitcode_t result = CommandLine::HandleCommandDefault(); @@ -419,7 +419,7 @@ static exitcode_t HandleCommandRegisterShell(CommandLineArgEnumerator * enumerat } return EXITCODE_OK; } -#endif // defined(__WINDOWS__) && !defined(__MINGW32__) +#endif // defined(_WIN32) && !defined(__MINGW32__) static void PrintAbout() { diff --git a/src/openrct2/common.h b/src/openrct2/common.h index 98c034b417..84863348dd 100644 --- a/src/openrct2/common.h +++ b/src/openrct2/common.h @@ -17,8 +17,6 @@ #ifndef _COMMON_H_ #define _COMMON_H_ -#include - #ifndef _USE_MATH_DEFINES #define _USE_MATH_DEFINES #endif @@ -52,7 +50,7 @@ typedef uint64_t uint64; typedef char utf8; typedef utf8* utf8string; typedef const utf8* const_utf8string; -#ifdef __WINDOWS__ +#ifdef _WIN32 typedef wchar_t utf16; typedef utf16* utf16string; #endif diff --git a/src/openrct2/core/FileScanner.cpp b/src/openrct2/core/FileScanner.cpp index 1d97715537..f2efeb689a 100644 --- a/src/openrct2/core/FileScanner.cpp +++ b/src/openrct2/core/FileScanner.cpp @@ -16,7 +16,7 @@ #include "../common.h" -#ifdef __WINDOWS__ +#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include #endif @@ -26,7 +26,7 @@ #include #include #include -#elif defined(__WINDOWS__) +#elif defined(_WIN32) extern "C" { // Windows needs this for widechar <-> utf8 conversion utils #include "../localisation/language.h" @@ -227,7 +227,7 @@ protected: }; -#ifdef __WINDOWS__ +#ifdef _WIN32 class FileScannerWindows final : public FileScannerBase { @@ -286,7 +286,7 @@ private: } }; -#endif // __WINDOWS__ +#endif // _WIN32 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) @@ -362,7 +362,7 @@ private: IFileScanner * Path::ScanDirectory(const std::string &pattern, bool recurse) { -#ifdef __WINDOWS__ +#ifdef _WIN32 return new FileScannerWindows(pattern, recurse); #elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) return new FileScannerUnix(pattern, recurse); diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp index bfddbd121e..ffb8546740 100644 --- a/src/openrct2/core/Guard.cpp +++ b/src/openrct2/core/Guard.cpp @@ -20,7 +20,7 @@ #include "../common.h" -#ifdef __WINDOWS__ +#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include #undef GetMessage @@ -50,14 +50,14 @@ namespace Guard // The default behaviour when an assertion is raised. static ASSERT_BEHAVIOUR _assertBehaviour = -#ifdef __WINDOWS__ +#ifdef _WIN32 ASSERT_BEHAVIOUR::MESSAGE_BOX #else ASSERT_BEHAVIOUR::CASSERT #endif ; -#ifdef __WINDOWS__ +#ifdef _WIN32 static void GetAssertMessage(char * buffer, size_t bufferSize, const char * formattedMessage); static void ForceCrash(); #endif @@ -107,7 +107,7 @@ namespace Guard case ASSERT_BEHAVIOUR::CASSERT: assert(false); break; -#ifdef __WINDOWS__ +#ifdef _WIN32 case ASSERT_BEHAVIOUR::MESSAGE_BOX: { // Show message box if we are not building for testing @@ -137,7 +137,7 @@ namespace Guard Assert_VA(false, message, args); } -#ifdef __WINDOWS__ +#ifdef _WIN32 static void GetAssertMessage(char * buffer, size_t bufferSize, const char * formattedMessage) { String::Set(buffer, bufferSize, ASSERTION_MESSAGE); diff --git a/src/openrct2/core/Path.cpp b/src/openrct2/core/Path.cpp index 81c299686f..17149dc9b5 100644 --- a/src/openrct2/core/Path.cpp +++ b/src/openrct2/core/Path.cpp @@ -88,7 +88,7 @@ namespace Path { lastPathSeperator = ch; } -#ifdef __WINDOWS__ +#ifdef _WIN32 // Windows also allows forward slashes in paths else if (*ch == '/') { @@ -174,7 +174,7 @@ namespace Path utf8 * GetAbsolute(utf8 *buffer, size_t bufferSize, const utf8 * relativePath) { -#ifdef __WINDOWS__ +#ifdef _WIN32 wchar_t * relativePathW = utf8_to_widechar(relativePath); wchar_t absolutePathW[MAX_PATH]; DWORD length = GetFullPathNameW(relativePathW, (DWORD)Util::CountOf(absolutePathW), absolutePathW, NULL); @@ -213,7 +213,7 @@ namespace Path bool Equals(const utf8 * a, const utf8 * b) { bool ignoreCase = false; -#ifdef __WINDOWS__ +#ifdef _WIN32 ignoreCase = true; #endif return String::Equals(a, b, ignoreCase); diff --git a/src/openrct2/drawing/NewDrawing.cpp b/src/openrct2/drawing/NewDrawing.cpp index 63edba8953..83d0bdfdca 100644 --- a/src/openrct2/drawing/NewDrawing.cpp +++ b/src/openrct2/drawing/NewDrawing.cpp @@ -62,7 +62,7 @@ extern "C" // Linux requires a restart. This could be improved in the future by recreating the window, // https://github.com/OpenRCT2/OpenRCT2/issues/2015 bool requiresRestart = true; -#ifdef __WINDOWS__ +#ifdef _WIN32 if (dstEngine != DRAWING_ENGINE_OPENGL) { // Windows is apparently able to switch to hardware rendering on the fly although diff --git a/src/openrct2/localisation/localisation.c b/src/openrct2/localisation/localisation.c index 369f24f83a..903bb18ee1 100644 --- a/src/openrct2/localisation/localisation.c +++ b/src/openrct2/localisation/localisation.c @@ -18,12 +18,12 @@ #include -#ifdef __WINDOWS__ +#ifdef _WIN32 #include #else #include #include -#endif // __WINDOWS__ +#endif // _WIN32 #include "../config/Config.h" #include "../game.h" @@ -1328,7 +1328,7 @@ utf8 *win1252_to_utf8_alloc(const char *src, size_t srcMaxSize) sint32 win1252_to_utf8(utf8string dst, const char *src, size_t srcLength, size_t maxBufferLength) { -#ifdef __WINDOWS__ +#ifdef _WIN32 utf16 stackBuffer[256]; utf16 *heapBuffer = NULL; utf16 *intermediateBuffer = stackBuffer; @@ -1396,7 +1396,7 @@ sint32 win1252_to_utf8(utf8string dst, const char *src, size_t srcLength, size_t //log_warning("converted %s of size %d, %d", dst, byte_diff, strlen(dst)); sint32 result = byte_diff; free(buffer_orig); -#endif // __WINDOWS__ +#endif // _WIN32 return result; } diff --git a/src/openrct2/network/TcpSocket.cpp b/src/openrct2/network/TcpSocket.cpp index dcc17b9eeb..95b2986d51 100644 --- a/src/openrct2/network/TcpSocket.cpp +++ b/src/openrct2/network/TcpSocket.cpp @@ -54,7 +54,7 @@ #define LAST_SOCKET_ERROR() errno #define closesocket close #define ioctlsocket ioctl - #if defined(__LINUX__) + #if defined(__linux__) #define FLAG_NO_PIPE MSG_NOSIGNAL #else #define FLAG_NO_PIPE 0 @@ -457,7 +457,7 @@ private: static bool SetNonBlocking(SOCKET socket, bool on) { -#ifdef __WINDOWS__ +#ifdef _WIN32 u_long nonBlocking = on; return ioctlsocket(socket, FIONBIO, &nonBlocking) == 0; #else @@ -479,7 +479,7 @@ ITcpSocket * CreateTcpSocket() bool InitialiseWSA() { -#ifdef __WINDOWS__ +#ifdef _WIN32 if (!_wsaInitialised) { log_verbose("Initialising WSA"); @@ -499,7 +499,7 @@ bool InitialiseWSA() void DisposeWSA() { -#ifdef __WINDOWS__ +#ifdef _WIN32 if (_wsaInitialised) { WSACleanup(); diff --git a/src/openrct2/network/http.cpp b/src/openrct2/network/http.cpp index 74c0b1a035..f5c015cf2a 100644 --- a/src/openrct2/network/http.cpp +++ b/src/openrct2/network/http.cpp @@ -33,7 +33,7 @@ void http_dispose() { } #include "../core/String.hpp" #include "../Version.h" -#ifdef __WINDOWS__ +#ifdef _WIN32 // cURL includes windows.h, but we don't need all of it. #define WIN32_LEAN_AND_MEAN #endif diff --git a/src/openrct2/platform/linux.c b/src/openrct2/platform/linux.c index 1019439a02..e8d5b0298b 100644 --- a/src/openrct2/platform/linux.c +++ b/src/openrct2/platform/linux.c @@ -18,7 +18,7 @@ // Despite the name, this file contains support for more OSs besides Linux, provided the necessary ifdefs remain small. // Otherwise, they should be spun off into their own files. -#if defined(__LINUX__) || defined(__FREEBSD__) +#if defined(__linux__) || defined(__FREEBSD__) #ifdef __FREEBSD__ #include @@ -42,7 +42,7 @@ void platform_get_exe_path(utf8 *outPath, size_t outSize) { char exePath[MAX_PATH]; -#ifdef __LINUX__ +#ifdef __linux__ ssize_t bytesRead; bytesRead = readlink("/proc/self/exe", exePath, MAX_PATH); if (bytesRead == -1) { diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index dea6d15c8b..88646e3058 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -26,7 +26,7 @@ typedef struct rct2_install_info rct2_install_info; #define MAX_PATH 260 #endif -#ifdef __MACOSX__ +#ifdef __APPLE__ #define KEYBOARD_PRIMARY_MODIFIER KMOD_GUI #else #define KEYBOARD_PRIMARY_MODIFIER KMOD_CTRL @@ -36,7 +36,7 @@ typedef struct rct2_install_info rct2_install_info; #define TOUCH_DOUBLE_TIMEOUT 300 -#ifdef __WINDOWS__ +#ifdef _WIN32 #define PATH_SEPARATOR "\\" #define PLATFORM_NEWLINE "\r\n" #else @@ -48,7 +48,7 @@ typedef struct rct2_install_info rct2_install_info; #define CTRL 0x200 #define ALT 0x400 #define CMD 0x800 -#ifdef __MACOSX__ +#ifdef __APPLE__ #define PLATFORM_MODIFIER CMD #else #define PLATFORM_MODIFIER CTRL @@ -155,7 +155,7 @@ datetime64 platform_get_datetime_now_utc(); void core_init(); // Windows specific definitions -#ifdef __WINDOWS__ +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -169,14 +169,14 @@ void core_init(); // This function cannot be marked as 'static', even though it may seem to be, // as it requires external linkage, which 'static' prevents __declspec(dllexport) sint32 StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, sint32 nCmdShow); -#endif // __WINDOWS__ +#endif // _WIN32 -#if defined(__LINUX__) || defined(__MACOSX__) || defined(__FREEBSD__) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) void platform_posix_sub_user_data_path(char *buffer, size_t size, const char *homedir); void platform_posix_sub_resolve_openrct_data_path(utf8 *out, size_t size); #endif -#ifdef __MACOSX__ +#if defined(__APPLE__) && defined(__MACH__) void macos_disallow_automatic_window_tabbing(); utf8* macos_str_decomp_to_precomp(); #endif diff --git a/src/openrct2/platform/posix.c b/src/openrct2/platform/posix.c index 5ade19fe79..8f15b43b33 100644 --- a/src/openrct2/platform/posix.c +++ b/src/openrct2/platform/posix.c @@ -374,7 +374,7 @@ sint32 platform_enumerate_files_begin(const utf8 *pattern) // macOS uses decomposed Unicode strings (e.g. an 'e' and a combining accent) in filenames // This causes problems with the sprite font, as the font only contains precomposed characters // The block below converts all filename strings to their precomposed form, preventing mojibake -#ifdef __MACOSX__ +#ifdef __APPLE__ utf8* precomp_path = macos_str_decomp_to_precomp(paths[idx]); size_t precomp_len = sizeof(utf8) * min(MAX_PATH, strnlen(precomp_path, MAX_PATH) + 2); paths[idx] = malloc(precomp_len); diff --git a/src/openrct2/platform/windows.c b/src/openrct2/platform/windows.c index ac4c03d566..79c916d29f 100644 --- a/src/openrct2/platform/windows.c +++ b/src/openrct2/platform/windows.c @@ -22,7 +22,7 @@ #include "../common.h" -#ifdef __WINDOWS__ +#ifdef _WIN32 #include #include diff --git a/src/openrct2/rct2/hook.c b/src/openrct2/rct2/hook.c index 7201ceddb7..b0b9068a01 100644 --- a/src/openrct2/rct2/hook.c +++ b/src/openrct2/rct2/hook.c @@ -18,11 +18,11 @@ #ifndef NO_RCT2 -#ifdef __WINDOWS__ +#ifdef _WIN32 #include #else #include -#endif // __WINDOWS__ +#endif // _WIN32 #include "../platform/platform.h" #include "hook.h" @@ -154,19 +154,19 @@ static void hookfunc(uintptr_t address, uintptr_t hookAddress, sint32 stacksize) data[i++] = 0xC3; // retn -#ifdef __WINDOWS__ +#ifdef _WIN32 WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, data, i, 0); #else // We own the pages with PROT_WRITE | PROT_EXEC, we can simply just memcpy the data memcpy((void *)address, data, i); -#endif // __WINDOWS__ +#endif // _WIN32 } void addhook(uintptr_t address, hook_function *function) { if (!_hookTableAddress) { size_t size = _maxHooks * HOOK_BYTE_COUNT; -#ifdef __WINDOWS__ +#ifdef _WIN32 _hookTableAddress = VirtualAllocEx(GetCurrentProcess(), NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); #else _hookTableAddress = mmap(NULL, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); @@ -175,7 +175,7 @@ void addhook(uintptr_t address, hook_function *function) perror("mmap"); exit(1); } -#endif // __WINDOWS__ +#endif // _WIN32 } if (_hookTableOffset > _maxHooks) { return; @@ -189,7 +189,7 @@ void addhook(uintptr_t address, hook_function *function) i += 4; data[i++] = 0xC3; // retn -#ifdef __WINDOWS__ +#ifdef _WIN32 WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, data, i, 0); #else // We own the pages with PROT_WRITE | PROT_EXEC, we can simply just memcpy the data @@ -206,7 +206,7 @@ void addhook(uintptr_t address, hook_function *function) { perror("mprotect"); } -#endif // __WINDOWS__ +#endif // _WIN32 hookfunc(hookaddress, (uintptr_t)function, 0); _hookTableOffset++; } diff --git a/src/openrct2/rct2/interop.c b/src/openrct2/rct2/interop.c index 87a3cf0c0d..fffd685a0a 100644 --- a/src/openrct2/rct2/interop.c +++ b/src/openrct2/rct2/interop.c @@ -18,19 +18,19 @@ #include "../common.h" -#if defined(__WINDOWS__) +#if defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include #endif -#if defined(__unix__) || defined(__MACOSX__) +#if defined(__unix__) || defined(__APPLE__) #include #include #include #include #include #include -#endif // defined(__unix__) || defined(__MACOSX__) +#endif // defined(__unix__) || defined(__APPLE__) #include "../OpenRCT2.h" #include "../util/sawyercoding.h" @@ -39,7 +39,7 @@ #include "hook.h" #include "interop.h" -#if defined(USE_MMAP) && (defined(__unix__) || defined(__MACOSX__)) && !defined(NO_RCT2) +#if defined(USE_MMAP) && (defined(__unix__) || defined(__APPLE__)) && !defined(NO_RCT2) static sint32 fdData = -1; #endif #if !defined(NO_RCT2) @@ -68,7 +68,7 @@ bool rct2_interop_setup_segment() #if !defined(NO_RCT2) UNUSED(segments); #endif -#if defined(USE_MMAP) && (defined(__unix__) || defined(__MACOSX__)) && !defined(NO_RCT2) +#if defined(USE_MMAP) && (defined(__unix__) || defined(__APPLE__)) && !defined(NO_RCT2) #define RDATA_OFFSET 0x004A4000 #define DATASEG_OFFSET 0x005E2000 @@ -116,7 +116,7 @@ bool rct2_interop_setup_segment() perror("mmap"); return false; } -#endif // defined(USE_MMAP) && (defined(__unix__) || defined(__MACOSX__)) +#endif // defined(USE_MMAP) && (defined(__unix__) || defined(__APPLE__)) #if defined(__unix__) && !defined(NO_RCT2) sint32 pageSize = getpagesize(); @@ -128,7 +128,7 @@ bool rct2_interop_setup_segment() if (err != 0) { err = errno; -#ifdef __LINUX__ +#ifdef __linux__ // On Linux ENOMEM means all requested range is unmapped if (err != ENOMEM) { @@ -138,7 +138,7 @@ bool rct2_interop_setup_segment() #else pagesMissing = true; perror("mincore"); -#endif // __LINUX__ +#endif // __linux__ } else { for (sint32 i = 0; i < numPages; i++) { @@ -172,7 +172,7 @@ bool rct2_interop_setup_segment() } #endif // defined(__unix__) -#if defined(USE_MMAP) && defined(__WINDOWS__) +#if defined(USE_MMAP) && defined(_WIN32) segments = VirtualAlloc((void *)(GOOD_PLACE_FOR_DATA_SEGMENT), len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); if ((uintptr_t)segments != GOOD_PLACE_FOR_DATA_SEGMENT) { log_error("VirtualAlloc, segments = %p, GetLastError = 0x%x", segments, GetLastError()); @@ -195,7 +195,7 @@ bool rct2_interop_setup_segment() return false; } fclose(file); -#endif // defined(USE_MMAP) && defined(__WINDOWS__) +#endif // defined(USE_MMAP) && defined(_WIN32) #if !defined(NO_RCT2) && defined(USE_MMAP) // Check that the expected data is at various addresses. @@ -224,7 +224,7 @@ void rct2_interop_setup_hooks() void rct2_interop_dispose() { -#if defined(USE_MMAP) && (defined(__unix__) || defined(__MACOSX__)) && !defined(NO_RCT2) +#if defined(USE_MMAP) && (defined(__unix__) || defined(__APPLE__)) && !defined(NO_RCT2) munmap(segments, 12079104); close(fdData); #endif diff --git a/src/openrct2/windows/options.c b/src/openrct2/windows/options.c index b7bade9dc8..911c619625 100644 --- a/src/openrct2/windows/options.c +++ b/src/openrct2/windows/options.c @@ -1884,11 +1884,11 @@ static void window_options_paint(rct_window *w, rct_drawpixelinfo *dpi) audioDeviceStringId = STR_SOUND_NONE; } else { audioDeviceStringId = STR_STRING; -#ifndef __LINUX__ +#ifndef __linux__ if (gAudioCurrentDevice == 0) { audioDeviceStringId = STR_OPTIONS_SOUND_VALUE_DEFAULT; } -#endif // __LINUX__ +#endif // __linux__ if (audioDeviceStringId == STR_STRING) { audioDeviceName = gAudioDevices[gAudioCurrentDevice].name; }