use SDL2's platform defines to normalise platform guards

This commit is contained in:
IntelOrca 2016-01-13 22:37:13 +00:00
parent e68ae821db
commit cdee534eb1
21 changed files with 83 additions and 65 deletions

View File

@ -21,13 +21,15 @@
#ifndef _ADDRESSES_H_
#define _ADDRESSES_H_
#include "common.h"
#ifdef _MSC_VER
#pragma warning(disable : 4731)
#endif
#define RCT2_ADDRESS(address, type) ((type*)(address))
#define RCT2_GLOBAL(address, type) (*((type*)(address)))
#ifdef _WIN32
#ifdef __WINDOWS__
#define RCT2_CALLPROC(address) (((void(*)())(address))())
#define RCT2_CALLFUNC(address, returnType) (((returnType(*)())(address))())
@ -46,7 +48,7 @@
#define RCT2_CALLFUNC_4(address, returnType, a1, a2, a3, a4, v1, v2, v3, v4)
#define RCT2_CALLFUNC_5(address, returnType, a1, a2, a3, a4, a5, v1, v2, v3, v4, v5)
#define RCT2_CALLFUNC_6(address, returnType, a1, a2, a3, a4, a5, a6, v1, v2, v3, v4, v5, v6)
#endif // _WIN32
#endif // __WINDOWS__
#define RCT2_CALLPROC_1(address, a1, v1) RCT2_CALLFUNC_1(address, void, a1, v1)
#define RCT2_CALLPROC_2(address, a1, a2, v1, v2) RCT2_CALLFUNC_2(address, void, a1, a2, v1, v2)

View File

@ -86,7 +86,7 @@ void audio_populate_devices()
safe_strncpy(systemAudioDevices[i].name, utf8Name, AUDIO_DEVICE_NAME_SIZE);
}
#ifndef __linux__
#ifndef __LINUX__
gAudioDeviceCount++;
gAudioDevices = malloc(gAudioDeviceCount * sizeof(audio_device));
safe_strncpy(gAudioDevices[0].name, language_get_string(5510), AUDIO_DEVICE_NAME_SIZE);
@ -94,7 +94,7 @@ void audio_populate_devices()
#else
gAudioDevices = malloc(gAudioDeviceCount * sizeof(audio_device));
memcpy(gAudioDevices, systemAudioDevices, gAudioDeviceCount * sizeof(audio_device));
#endif // __linux__
#endif // __LINUX__
free(systemAudioDevices);
}

View File

@ -510,7 +510,7 @@ namespace CommandLine
static bool HandleSpecialArgument(const char * argument)
{
#if defined(__APPLE__) && defined(__MACH__)
#ifdef __MACOSX__
if (String::Equals(argument, "-NSDocumentRevisionsDebugMode"))
{
return true;

View File

@ -895,7 +895,7 @@ void config_apply_to_old_addresses()
#define CTRL 0x200
#define ALT 0x400
#define CMD 0x800
#if defined(__APPLE__) && defined(__MACH__)
#ifdef __MACOSX__
#define PLATFORM_MODIFIER CMD
#else
#define PLATFORM_MODIFIER CTRL

View File

@ -19,7 +19,7 @@ namespace Path
utf8 * GetAbsolute(utf8 *buffer, size_t bufferSize, const utf8 * relativePath)
{
#if _WIN32
#if __WINDOWS__
wchar_t * relativePathW = utf8_to_widechar(relativePath);
wchar_t absolutePathW[MAX_PATH];
DWORD length = GetFullPathNameW(relativePathW, Util::CountOf(absolutePathW), absolutePathW, NULL);

View File

@ -18,11 +18,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifdef _WIN32
#include "common.h"
#ifdef __WINDOWS__
#include <windows.h>
#else
#include <sys/mman.h>
#endif // _WIN32
#endif // __WINDOWS__
#include "hook.h"
#include "platform/platform.h"
@ -200,19 +203,19 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in
data[i++] = 0xC3; // retn
#ifdef _WIN32
#ifdef __WINDOWS__
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 // _WIN32
#endif // __WINDOWS__
}
void addhook(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister)
{
if (!g_hooktableaddress) {
size_t size = g_maxhooks * 100;
#ifdef _WIN32
#ifdef __WINDOWS__
g_hooktableaddress = VirtualAllocEx(GetCurrentProcess(), NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
#else
g_hooktableaddress = mmap(NULL, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
@ -221,7 +224,7 @@ void addhook(int address, int newaddress, int stacksize, int registerargs[], int
perror("mmap");
exit(1);
}
#endif // _WIN32
#endif // __WINDOWS__
}
if (g_hooktableoffset > g_maxhooks) {
return;
@ -235,12 +238,12 @@ void addhook(int address, int newaddress, int stacksize, int registerargs[], int
i += 4;
data[i++] = 0xC3; // retn
#ifdef _WIN32
#ifdef __WINDOWS__
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 // _WIN32
#endif // __WINDOWS__
hookfunc(hookaddress, newaddress, stacksize, registerargs, registersreturned, eaxDestinationRegister);
g_hooktableoffset++;
}

View File

@ -1391,7 +1391,7 @@ void title_handle_keyboard_input()
gInputPlaceObjectModifier |= PLACE_OBJECT_MODIFIER_COPY_Z;
if (gKeysState[SDL_SCANCODE_LALT] || gKeysState[SDL_SCANCODE_RALT])
gInputPlaceObjectModifier |= 4;
#if defined(__APPLE__) && defined(__MACH__)
#ifdef __MACOSX__
if (gKeysState[SDL_SCANCODE_LGUI] || gKeysState[SDL_SCANCODE_RGUI]) {
gInputPlaceObjectModifier |= 8;
}
@ -1456,7 +1456,7 @@ void game_handle_keyboard_input()
if (gKeysState[SDL_SCANCODE_LALT] || gKeysState[SDL_SCANCODE_RALT]) {
gInputPlaceObjectModifier |= 4;
}
#if defined(__APPLE__) && defined(__MACH__)
#ifdef __MACOSX__
if (gKeysState[SDL_SCANCODE_LGUI] || gKeysState[SDL_SCANCODE_RGUI]) {
gInputPlaceObjectModifier |= 8;
}
@ -1661,7 +1661,7 @@ void game_handle_key_scroll()
if (shortcutKey & ALT) {
if (!gKeysState[SDL_SCANCODE_LALT] && !gKeysState[SDL_SCANCODE_RALT]) continue;
}
#if defined(__APPLE__) && defined(__MACH__)
#ifdef __MACOSX__
if (shortcutKey & CMD) {
if (!gKeysState[SDL_SCANCODE_LGUI] && !gKeysState[SDL_SCANCODE_RGUI]) continue;
}

View File

@ -97,7 +97,7 @@ void keyboard_shortcut_format_string(char *buffer, uint16 shortcutKey)
strcat(buffer, formatBuffer);
}
if (shortcutKey & 0x400) {
#if defined(__APPLE__) && defined(__MACH__)
#ifdef __MACOSX__
format_string(formatBuffer, STR_OPTION_PLUS, NULL);
#else
format_string(formatBuffer, STR_ALT_PLUS, NULL);

View File

@ -18,12 +18,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifdef _WIN32
#include "../common.h"
#ifdef __WINDOWS__
#include <windows.h>
#else
#include <iconv.h>
#include <errno.h>
#endif // _WIN32
#endif // __WINDOWS__
#include "../addresses.h"
#include "../config.h"
#include "../game.h"
@ -936,7 +939,7 @@ int win1252_to_utf8(utf8string dst, const char *src, size_t maxBufferLength)
{
size_t srcLength = strlen(src);
#ifdef _WIN32
#ifdef __WINDOWS__
utf16 stackBuffer[256];
utf16 *heapBuffer = NULL;
utf16 *intermediateBuffer = stackBuffer;
@ -1005,7 +1008,7 @@ int win1252_to_utf8(utf8string dst, const char *src, size_t maxBufferLength)
//log_warning("converted %s of size %d, %d", dst, byte_diff, strlen(dst));
int result = byte_diff;
free(buffer_orig);
#endif // _WIN32
#endif // __WINDOWS__
return result;
}

View File

@ -10,11 +10,12 @@ void http_dispose() { }
#else
#include <SDL.h>
#include "../core/Math.hpp"
// cURL includes windows.h, but we don't need all of it.
#define WIN32_LEAN_AND_MEAN
#ifdef __WINDOWS__
// cURL includes windows.h, but we don't need all of it.
#define WIN32_LEAN_AND_MEAN
#endif
#include <curl/curl.h>
#define MIME_TYPE_APPLICATION_JSON "application/json"
@ -117,7 +118,7 @@ http_json_response *http_request_json(const http_json_request *request)
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true);
#ifdef _WIN32
#ifdef __WINDOWS__
// On GNU/Linux (and OS X), curl will use the system certs by default
curl_easy_setopt(curl, CURLOPT_CAINFO, "curl-ca-bundle.crt");
#endif

View File

@ -306,7 +306,7 @@ bool NetworkConnection::SetNonBlocking(bool on)
bool NetworkConnection::SetNonBlocking(SOCKET socket, bool on)
{
#ifdef _WIN32
#ifdef __WINDOWS__
u_long nonblocking = on;
return ioctlsocket(socket, FIONBIO, &nonblocking) == 0;
#else
@ -429,7 +429,7 @@ Network::~Network()
bool Network::Init()
{
#ifdef _WIN32
#ifdef __WINDOWS__
if (!wsa_initialized) {
log_verbose("Initialising WSA");
WSADATA wsa_data;
@ -468,7 +468,7 @@ void Network::Close()
game_command_queue.clear();
player_list.clear();
#ifdef _WIN32
#ifdef __WINDOWS__
if (wsa_initialized) {
WSACleanup();
wsa_initialized = false;
@ -1249,7 +1249,7 @@ NetworkPlayer* Network::AddPlayer(const char* name)
void Network::PrintError()
{
#ifdef _WIN32
#ifdef __WINDOWS__
wchar_t *s = NULL;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, LAST_SOCKET_ERROR(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&s, 0, NULL);
fprintf(stderr, "%S\n", s);

View File

@ -63,7 +63,7 @@ extern "C" {
#ifndef DISABLE_NETWORK
#ifdef _WIN32
#ifdef __WINDOWS__
#include <winsock2.h>
#include <ws2tcpip.h>
#define LAST_SOCKET_ERROR() WSAGetLastError()
@ -88,7 +88,7 @@ extern "C" {
#define LAST_SOCKET_ERROR() errno
#define closesocket close
#define ioctlsocket ioctl
#endif // _WIN32
#endif // __WINDOWS__
// Fixes issues on OS X
#if defined(_RCT2_H_) && !defined(_MSC_VER)

View File

@ -517,7 +517,7 @@ bool openrct2_setup_rct2_segment()
if (err != 0)
{
err = errno;
#ifdef __linux__
#ifdef __LINUX__
// On Linux ENOMEM means all requested range is unmapped
if (err != ENOMEM)
{
@ -527,7 +527,7 @@ bool openrct2_setup_rct2_segment()
#else
pagesMissing = true;
perror("mincore");
#endif // __linux__
#endif // __LINUX__
} else {
for (int i = 0; i < numPages; i++)
{

View File

@ -18,13 +18,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#if defined(__linux__)
#include "../common.h"
#ifdef __LINUX__
#include "platform.h"
#include <dlfcn.h>
#include <stdlib.h>
#include <fontconfig/fontconfig.h>
#include "../util/util.h"
#include "fontconfig/fontconfig.h"
#include "platform.h"
// See http://syprog.blogspot.ru/2011/12/listing-loaded-shared-objects-in-linux.html
struct lmap {

View File

@ -21,20 +21,21 @@
#ifndef _PLATFORM_H_
#define _PLATFORM_H_
#ifdef _WIN32
#include "../common.h"
#ifdef __WINDOWS__
#define HAVE_MATH_H
#endif // _WIN32
#endif // __WINDOWS__
#include <SDL.h>
#include "../common.h"
#include "../drawing/font.h"
#ifndef MAX_PATH
#define MAX_PATH 260
#endif
#if defined(__APPLE__) && defined(__MACH__)
#ifdef __MACOSX__
#define KEYBOARD_PRIMARY_MODIFIER KMOD_GUI
#else
#define KEYBOARD_PRIMARY_MODIFIER KMOD_CTRL
@ -171,7 +172,7 @@ bool platform_check_steam_overlay_attached();
datetime64 platform_get_datetime_now_utc();
// Windows specific definitions
#ifdef _WIN32
#ifdef __WINDOWS__
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@ -179,6 +180,6 @@ datetime64 platform_get_datetime_now_utc();
int windows_get_registry_install_info(rct2_install_info *installInfo, char *source, char *font, uint8 charset);
HWND windows_get_window_handle();
#endif // _WIN32
#endif // __WINDOWS__
#endif

View File

@ -902,7 +902,7 @@ void platform_set_cursor(char cursor)
static void platform_load_cursors()
{
RCT2_GLOBAL(0x14241BC, uint32) = 2;
#ifdef _WIN32
#ifdef __WINDOWS__
HINSTANCE hInst = RCT2_GLOBAL(RCT2_ADDRESS_HINSTANCE, HINSTANCE);
RCT2_GLOBAL(RCT2_ADDRESS_HCURSOR_ARROW, HCURSOR) = LoadCursor(hInst, MAKEINTRESOURCE(0x74));
RCT2_GLOBAL(RCT2_ADDRESS_HCURSOR_BLANK, HCURSOR) = LoadCursor(hInst, MAKEINTRESOURCE(0xA1));
@ -933,7 +933,7 @@ static void platform_load_cursors()
RCT2_GLOBAL(RCT2_ADDRESS_HCURSOR_HAND_CLOSED, HCURSOR) = LoadCursor(hInst, MAKEINTRESOURCE(0xA5));
#else
STUB();
#endif // _WIN32
#endif // __WINDOWS__
_cursors[0] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
_cursors[1] = SDL_CreateCursor(blank_cursor_data, blank_cursor_mask, 32, 32, BLANK_CURSOR_HOTX, BLANK_CURSOR_HOTY);

View File

@ -18,7 +18,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifdef _WIN32
#include "../common.h"
#ifdef __WINDOWS__
#include <windows.h>
#include <psapi.h>

View File

@ -498,7 +498,7 @@ const utf8 *get_file_path(int pathId)
*/
void get_system_info()
{
#ifdef _WIN32
#ifdef __WINDOWS__
OSVERSIONINFO versionInfo;
SYSTEM_INFO sysInfo;
MEMORYSTATUS memInfo;
@ -510,12 +510,12 @@ void get_system_info()
RCT2_GLOBAL(RCT2_ADDRESS_OS_MINOR_VERSION, uint32) = versionInfo.dwMinorVersion;
RCT2_GLOBAL(RCT2_ADDRESS_OS_BUILD_NUMBER, uint32) = versionInfo.dwBuildNumber;
} else {
#endif // _WIN32
#endif // __WINDOWS__
RCT2_GLOBAL(RCT2_ADDRESS_OS_PLATFORM_ID, uint32) = -1;
RCT2_GLOBAL(RCT2_ADDRESS_OS_MAJOR_VERSION, uint32) = 0;
RCT2_GLOBAL(RCT2_ADDRESS_OS_MINOR_VERSION, uint32) = 0;
RCT2_GLOBAL(RCT2_ADDRESS_OS_BUILD_NUMBER, uint32) = 0;
#ifdef _WIN32
#ifdef __WINDOWS__
}
GetSystemInfo(&sysInfo);
@ -558,7 +558,7 @@ void get_system_info()
RCT2_GLOBAL(0x01423C20, uint32) = (SDL_HasMMX() == SDL_TRUE);
#else
STUB();
#endif // _WIN32
#endif // __WINDOWS__
}
@ -595,12 +595,12 @@ void get_local_time()
*/
void *rct2_malloc(size_t numBytes)
{
#ifdef _WIN32
#ifdef __WINDOWS__
return RCT2_CALLFUNC_1(0x004068B2, void*, size_t, numBytes);
#else
//log_warning("call rct's function");
return malloc(numBytes);
#endif // _WIN32
#endif // __WINDOWS__
}
/**
@ -610,12 +610,12 @@ void *rct2_malloc(size_t numBytes)
*/
void *rct2_realloc(void *block, size_t numBytes)
{
#ifdef _WIN32
#ifdef __WINDOWS__
return RCT2_CALLFUNC_2(0x004068BD, void*, void*, size_t, block, numBytes);
#else
//log_warning("call rct's function");
return realloc(block, numBytes);
#endif // _WIN32
#endif // __WINDOWS__
}
/**
@ -624,10 +624,10 @@ void *rct2_realloc(void *block, size_t numBytes)
*/
void rct2_free(void *block)
{
#ifdef _WIN32
#ifdef __WINDOWS__
RCT2_CALLPROC_1(0x004068CD, void*, block);
#else
//log_warning("call rct's function");
free(block);
#endif // _WIN32
#endif // __WINDOWS__
}

View File

@ -21,6 +21,8 @@
#ifndef _RCT2_H_
#define _RCT2_H_
#include <SDL_platform.h>
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif

View File

@ -1,18 +1,20 @@
#ifndef _VERSION_H_
#define _VERSION_H_
#include "common.h"
#define OPENRCT2_NAME "OpenRCT2"
#define OPENRCT2_VERSION "0.0.4"
#define OPENRCT2_ARCHITECTURE "x86"
// Platform
#ifdef _WIN32
#ifdef __WINDOWS__
#define OPENRCT2_PLATFORM "Windows"
#endif // _WIN32
#ifdef __linux__
#endif
#ifdef __LINUX__
#define OPENRCT2_PLATFORM "Linux"
#endif
#if defined(__APPLE__) && defined(__MACH__)
#ifdef __MACOSX__
#define OPENRCT2_PLATFORM "OS X"
#endif
#ifndef OPENRCT2_PLATFORM

View File

@ -522,7 +522,7 @@ static void window_options_mouseup(rct_window *w, int widgetIndex)
break;
case WIDX_HARDWARE_DISPLAY_CHECKBOX:
gConfigGeneral.hardware_display ^= 1;
#ifdef _WIN32
#ifdef __WINDOWS__
// Windows is apparently able to switch to hardware rendering on the fly although
// using the same window in an unaccelerated and accelerated context is unsupported by SDL2
gHardwareDisplay = gConfigGeneral.hardware_display;
@ -1316,11 +1316,11 @@ static void window_options_invalidate(rct_window *w)
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = STR_SOUND_NONE;
}
else {
#ifndef __linux__
#ifndef __LINUX__
if (currentSoundDevice == 0)
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = 5510;
else
#endif // __linux__
#endif // __LINUX__
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = 1170;
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 2, uint32) = (uint32)gAudioDevices[currentSoundDevice].name;