diff --git a/src/addresses.h b/src/addresses.h
index a629e53679..7c09c48659 100644
--- a/src/addresses.h
+++ b/src/addresses.h
@@ -21,38 +21,14 @@
#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
-#define RCT2_CALLPROC(address) (((void(*)())(address))())
-#define RCT2_CALLFUNC(address, returnType) (((returnType(*)())(address))())
-
-#define RCT2_CALLFUNC_1(address, returnType, a1, v1) (((returnType(*)(a1))(address))(v1))
-#define RCT2_CALLFUNC_2(address, returnType, a1, a2, v1, v2) (((returnType(*)(a1, a2))(address))(v1, v2))
-#define RCT2_CALLFUNC_3(address, returnType, a1, a2, a3, v1, v2, v3) (((returnType(*)(a1, a2, a3))(address))(v1, v2, v3))
-#define RCT2_CALLFUNC_4(address, returnType, a1, a2, a3, a4, v1, v2, v3, v4) (((returnType(*)(a1, a2, a3, a4))(address))(v1, v2, v3, v4))
-#define RCT2_CALLFUNC_5(address, returnType, a1, a2, a3, a4, a5, v1, v2, v3, v4, v5) (((returnType(*)(a1, a2, a3, a4, a5))(address))(v1, v2, v3, v4, v5))
-#define RCT2_CALLFUNC_6(address, returnType, a1, a2, a3, a4, a5, a6, v1, v2, v3, v4, v5, v6) (((returnType(*)(a1, a2, a3, a4, a5, a6))(address))(v1, v2, v3, v4, v5, v6))
-#else
-#define RCT2_CALLPROC(address)
-#define RCT2_CALLFUNC(address, returnType)
-#define RCT2_CALLFUNC_1(address, returnType, a1, v1)
-#define RCT2_CALLFUNC_2(address, returnType, a1, a2, v1, v2)
-#define RCT2_CALLFUNC_3(address, returnType, a1, a2, a3, v1, v2, v3)
-#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
-
-#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)
-#define RCT2_CALLPROC_3(address, a1, a2, a3, v1, v2, v3) RCT2_CALLFUNC_3(address, void, a1, a2, a3, v1, v2, v3)
-#define RCT2_CALLPROC_4(address, a1, a2, a3, a4, v1, v2, v3, v4) RCT2_CALLFUNC_4(address, void, a1, a2, a3, a4, v1, v2, v3, v4)
-#define RCT2_CALLPROC_5(address, a1, a2, a3, a4, a5, v1, v2, v3, v4, v5) RCT2_CALLFUNC_5(address, void, a1, a2, a3, a4, a5, v1, v2, v3, v4, v5)
#pragma region Memory locations
diff --git a/src/audio/audio.c b/src/audio/audio.c
index 015c2e13b4..9238f70f9d 100644
--- a/src/audio/audio.c
+++ b/src/audio/audio.c
@@ -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);
}
diff --git a/src/cmdline/CommandLine.cpp b/src/cmdline/CommandLine.cpp
index f985a87122..25cf06d449 100644
--- a/src/cmdline/CommandLine.cpp
+++ b/src/cmdline/CommandLine.cpp
@@ -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;
diff --git a/src/config.c b/src/config.c
index 7782719945..a5c95af976 100644
--- a/src/config.c
+++ b/src/config.c
@@ -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
diff --git a/src/core/Path.cpp b/src/core/Path.cpp
index 8b4344d4da..016dac36ef 100644
--- a/src/core/Path.cpp
+++ b/src/core/Path.cpp
@@ -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);
diff --git a/src/drawing/drawing.c b/src/drawing/drawing.c
index d2f8226595..2407f2665c 100644
--- a/src/drawing/drawing.c
+++ b/src/drawing/drawing.c
@@ -338,57 +338,53 @@ void gfx_redraw_screen_rect(short left, short top, short right, short bottom)
* height (dx)
* drawpixelinfo (edi)
*/
-rct_drawpixelinfo* clip_drawpixelinfo(rct_drawpixelinfo* dpi, int left, int width, int top, int height)
+bool clip_drawpixelinfo(rct_drawpixelinfo *dst, rct_drawpixelinfo *src, int x, int y, int width, int height)
{
- rct_drawpixelinfo* newDrawPixelInfo = rct2_malloc(sizeof(rct_drawpixelinfo));
+ int right = x + width;
+ int bottom = y + height;
- int right = left + width;
- int bottom = top + height;
+ dst->bits = src->bits;
+ dst->x = src->x;
+ dst->y = src->y;
+ dst->width = src->width;
+ dst->height = src->height;
+ dst->pitch = src->pitch;
+ dst->zoom_level = 0;
- newDrawPixelInfo->bits = dpi->bits;
- newDrawPixelInfo->x = dpi->x;
- newDrawPixelInfo->y = dpi->y;
- newDrawPixelInfo->width = dpi->width;
- newDrawPixelInfo->height = dpi->height;
- newDrawPixelInfo->pitch = dpi->pitch;
- newDrawPixelInfo->zoom_level = 0;
-
- if (left > newDrawPixelInfo->x) {
- uint16 clippedFromLeft = left - newDrawPixelInfo->x;
- newDrawPixelInfo->width -= clippedFromLeft;
- newDrawPixelInfo->x = left;
- newDrawPixelInfo->pitch += clippedFromLeft;
- newDrawPixelInfo->bits += clippedFromLeft;
+ if (x > dst->x) {
+ uint16 clippedFromLeft = x - dst->x;
+ dst->width -= clippedFromLeft;
+ dst->x = x;
+ dst->pitch += clippedFromLeft;
+ dst->bits += clippedFromLeft;
}
- int stickOutWidth = newDrawPixelInfo->x + newDrawPixelInfo->width - right;
+ int stickOutWidth = dst->x + dst->width - right;
if (stickOutWidth > 0) {
- newDrawPixelInfo->width -= stickOutWidth;
- newDrawPixelInfo->pitch += stickOutWidth;
+ dst->width -= stickOutWidth;
+ dst->pitch += stickOutWidth;
}
- if (top > newDrawPixelInfo->y) {
- uint16 clippedFromTop = top - newDrawPixelInfo->y;
- newDrawPixelInfo->height -= clippedFromTop;
- newDrawPixelInfo->y = top;
- uint32 bitsPlus = (newDrawPixelInfo->pitch + newDrawPixelInfo->width) * clippedFromTop;
- newDrawPixelInfo->bits += bitsPlus;
+ if (y > dst->y) {
+ uint16 clippedFromTop = y - dst->y;
+ dst->height -= clippedFromTop;
+ dst->y = y;
+ uint32 bitsPlus = (dst->pitch + dst->width) * clippedFromTop;
+ dst->bits += bitsPlus;
}
- int bp = newDrawPixelInfo->y + newDrawPixelInfo->height - bottom;
+ int bp = dst->y + dst->height - bottom;
if (bp > 0) {
- newDrawPixelInfo->height -= bp;
+ dst->height -= bp;
}
- if (newDrawPixelInfo->width > 0 && newDrawPixelInfo->height > 0) {
- newDrawPixelInfo->x -= left;
- newDrawPixelInfo->y -= top;
-
- return newDrawPixelInfo;
+ if (dst->width > 0 && dst->height > 0) {
+ dst->x -= x;
+ dst->y -= y;
+ return true;
}
- rct2_free(newDrawPixelInfo);
- return NULL;
+ return false;
}
/***
diff --git a/src/drawing/drawing.h b/src/drawing/drawing.h
index 81bbf2bd8f..85650e33df 100644
--- a/src/drawing/drawing.h
+++ b/src/drawing/drawing.h
@@ -93,7 +93,7 @@ extern rct_g1_element *g1Elements;
extern rct_gx g2;
//
-rct_drawpixelinfo* clip_drawpixelinfo(rct_drawpixelinfo* dpi, int left, int width, int top, int height);
+bool clip_drawpixelinfo(rct_drawpixelinfo *dst, rct_drawpixelinfo *src, int x, int y, int width, int height);
void gfx_set_dirty_blocks(sint16 left, sint16 top, sint16 right, sint16 bottom);
void gfx_draw_all_dirty_blocks();
void gfx_redraw_screen_rect(short left, short top, short right, short bottom);
diff --git a/src/drawing/sprite.c b/src/drawing/sprite.c
index 7fc3f5c585..b7d7a97699 100644
--- a/src/drawing/sprite.c
+++ b/src/drawing/sprite.c
@@ -54,7 +54,7 @@ int gfx_load_g1()
SDL_RWread(file, g1Elements, header.num_entries * sizeof(rct_g1_element), 1);
// Read element data
- _g1Buffer = rct2_malloc(header.total_size);
+ _g1Buffer = malloc(header.total_size);
SDL_RWread(file, _g1Buffer, header.total_size, 1);
SDL_RWclose(file);
diff --git a/src/hook.c b/src/hook.c
index ebed9b189c..24b4b1278c 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -18,11 +18,14 @@
* along with this program. If not, see .
*****************************************************************************/
-#ifdef _WIN32
+#include "common.h"
+
+#ifdef __WINDOWS__
#include
#else
#include
-#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++;
}
diff --git a/src/input.c b/src/input.c
index 34a4fc4e10..deaea3528d 100644
--- a/src/input.c
+++ b/src/input.c
@@ -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;
}
diff --git a/src/interface/keyboard_shortcut.c b/src/interface/keyboard_shortcut.c
index 5462b90311..bc454aef5d 100644
--- a/src/interface/keyboard_shortcut.c
+++ b/src/interface/keyboard_shortcut.c
@@ -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);
diff --git a/src/localisation/localisation.c b/src/localisation/localisation.c
index c6c8566c73..768076a514 100644
--- a/src/localisation/localisation.c
+++ b/src/localisation/localisation.c
@@ -18,12 +18,15 @@
* along with this program. If not, see .
*****************************************************************************/
-#ifdef _WIN32
+#include "../common.h"
+
+#ifdef __WINDOWS__
#include
#else
#include
#include
-#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;
}
diff --git a/src/network/http.cpp b/src/network/http.cpp
index 80fc1672ca..530ab1a3bc 100644
--- a/src/network/http.cpp
+++ b/src/network/http.cpp
@@ -10,11 +10,12 @@ void http_dispose() { }
#else
-#include
#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
#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
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 1754518530..b9558c9f5f 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -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);
diff --git a/src/network/network.h b/src/network/network.h
index 3eefa4f923..2c57c76c83 100644
--- a/src/network/network.h
+++ b/src/network/network.h
@@ -63,7 +63,7 @@ extern "C" {
#ifndef DISABLE_NETWORK
-#ifdef _WIN32
+#ifdef __WINDOWS__
#include
#include
#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)
diff --git a/src/object.c b/src/object.c
index bfd160ccb4..f45c9bb767 100644
--- a/src/object.c
+++ b/src/object.c
@@ -859,8 +859,8 @@ static bool object_type_small_scenery_test(void *objectEntry)
static void object_type_small_scenery_paint(void *objectEntry, rct_drawpixelinfo *dpi, sint32 x, sint32 y)
{
rct_scenery_entry* sceneryEntry = (rct_scenery_entry*)objectEntry;
- dpi = clip_drawpixelinfo(dpi, x - 56, 112, y - 56, 112);
- if (dpi == NULL) {
+ rct_drawpixelinfo clipDPI;
+ if (!clip_drawpixelinfo(&clipDPI, dpi, x - 56, y - 56, 112, 112)) {
return;
}
@@ -880,14 +880,14 @@ static void object_type_small_scenery_paint(void *objectEntry, rct_drawpixelinfo
}
}
- gfx_draw_sprite(dpi, imageId, x, y, 0);
+ gfx_draw_sprite(&clipDPI, imageId, x, y, 0);
if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG10) {
imageId = sceneryEntry->image + 0x44500004;
if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) {
imageId |= 0x92000000;
}
- gfx_draw_sprite(dpi, imageId, x, y, 0);
+ gfx_draw_sprite(&clipDPI, imageId, x, y, 0);
}
if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG8) {
@@ -896,10 +896,8 @@ static void object_type_small_scenery_paint(void *objectEntry, rct_drawpixelinfo
imageId |= 0x92000000;
}
- gfx_draw_sprite(dpi, imageId, x, y, 0);
+ gfx_draw_sprite(&clipDPI, imageId, x, y, 0);
}
-
- rct2_free(dpi);
}
static rct_string_id object_type_small_scenery_desc(void *objectEntry)
@@ -1059,8 +1057,8 @@ static bool object_type_wall_test(void *objectEntry)
static void object_type_wall_paint(void *objectEntry, rct_drawpixelinfo *dpi, sint32 x, sint32 y)
{
rct_scenery_entry* sceneryEntry = (rct_scenery_entry*)objectEntry;
- dpi = clip_drawpixelinfo(dpi, x - 56, 112, y - 56, 112);
- if (dpi == NULL) {
+ rct_drawpixelinfo clipDPI;
+ if (!clip_drawpixelinfo(&clipDPI, dpi, x - 56, y - 56, 112, 112)) {
return;
}
@@ -1072,17 +1070,15 @@ static void object_type_wall_paint(void *objectEntry, rct_drawpixelinfo *dpi, si
x = 70;
y = sceneryEntry->wall.height * 2 + 72;
- gfx_draw_sprite(dpi, imageId, x, y, 0);
+ gfx_draw_sprite(&clipDPI, imageId, x, y, 0);
if (sceneryEntry->wall.flags & WALL_SCENERY_FLAG2){
imageId = sceneryEntry->image + 0x44500006;
- gfx_draw_sprite(dpi, imageId, x, y, 0);
+ gfx_draw_sprite(&clipDPI, imageId, x, y, 0);
} else if (sceneryEntry->wall.flags & WALL_SCENERY_FLAG5){
imageId++;
- gfx_draw_sprite(dpi, imageId, x, y, 0);
+ gfx_draw_sprite(&clipDPI, imageId, x, y, 0);
}
-
- rct2_free(dpi);
}
static rct_string_id object_type_wall_desc(void *objectEntry)
@@ -1428,17 +1424,15 @@ static void object_type_park_entrance_paint(void *objectEntry, rct_drawpixelinfo
{
rct_entrance_type *entranceType = (rct_entrance_type*)objectEntry;
- dpi = clip_drawpixelinfo(dpi, x - 56, 112, y - 56, 112);
- if (dpi == NULL) {
+ rct_drawpixelinfo clipDPI;
+ if (!clip_drawpixelinfo(&clipDPI, dpi, x - 56, y - 56, 112, 112)) {
return;
}
int imageId = entranceType->image_id;
- gfx_draw_sprite(dpi, imageId + 1, 24, 68, 0);
- gfx_draw_sprite(dpi, imageId, 56, 84, 0);
- gfx_draw_sprite(dpi, imageId + 2, 88, 100, 0);
-
- rct2_free(dpi);
+ gfx_draw_sprite(&clipDPI, imageId + 1, 24, 68, 0);
+ gfx_draw_sprite(&clipDPI, imageId, 56, 84, 0);
+ gfx_draw_sprite(&clipDPI, imageId + 2, 88, 100, 0);
}
static rct_string_id object_type_park_entrance_desc(void *objectEntry)
diff --git a/src/openrct2.c b/src/openrct2.c
index a02315f4ad..f519ea9863 100644
--- a/src/openrct2.c
+++ b/src/openrct2.c
@@ -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++)
{
diff --git a/src/platform/linux.c b/src/platform/linux.c
index 98edb78e5e..85eced0d7b 100644
--- a/src/platform/linux.c
+++ b/src/platform/linux.c
@@ -18,13 +18,15 @@
* along with this program. If not, see .
*****************************************************************************/
-#if defined(__linux__)
+#include "../common.h"
+
+#ifdef __LINUX__
-#include "platform.h"
#include
-#include
+#include
+
#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 {
diff --git a/src/platform/platform.h b/src/platform/platform.h
index baadd6a6e1..24717e007b 100644
--- a/src/platform/platform.h
+++ b/src/platform/platform.h
@@ -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
-#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
diff --git a/src/platform/shared.c b/src/platform/shared.c
index 2fb64c3220..e17af7bc71 100644
--- a/src/platform/shared.c
+++ b/src/platform/shared.c
@@ -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);
diff --git a/src/platform/windows.c b/src/platform/windows.c
index a70cc6c9e4..c0ff4ca093 100644
--- a/src/platform/windows.c
+++ b/src/platform/windows.c
@@ -18,7 +18,9 @@
* along with this program. If not, see .
*****************************************************************************/
-#ifdef _WIN32
+#include "../common.h"
+
+#ifdef __WINDOWS__
#include
#include
diff --git a/src/rct2.c b/src/rct2.c
index 358a1806fe..4deeac2fa6 100644
--- a/src/rct2.c
+++ b/src/rct2.c
@@ -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__
}
@@ -587,47 +587,3 @@ void get_local_time()
RCT2_GLOBAL(RCT2_ADDRESS_OS_TIME_HOUR, sint16) = t.hour;
RCT2_GLOBAL(RCT2_ADDRESS_OS_TIME_MINUTE, sint16) = t.minute;
}
-
-/**
- * RCT2 and this DLL can not free each other's allocated memory blocks. Use this to allocate memory if RCT2 is still able to
- * free it.
- * rct2: 0x004068B2
- */
-void *rct2_malloc(size_t numBytes)
-{
- #ifdef _WIN32
- return RCT2_CALLFUNC_1(0x004068B2, void*, size_t, numBytes);
- #else
- //log_warning("call rct's function");
- return malloc(numBytes);
- #endif // _WIN32
-}
-
-/**
- * RCT2 and this DLL can not free each other's allocated memory blocks. Use this to reallocate memory if RCT2 is still able to
- * free it.
- * rct2: 0x004068BD
- */
-void *rct2_realloc(void *block, size_t numBytes)
-{
- #ifdef _WIN32
- return RCT2_CALLFUNC_2(0x004068BD, void*, void*, size_t, block, numBytes);
- #else
- //log_warning("call rct's function");
- return realloc(block, numBytes);
- #endif // _WIN32
-}
-
-/**
- * RCT2 and this DLL can not free each other's allocated memory blocks. Use this to free memory that was allocated by RCT2.
- * rct2: 0x004068CD
- */
-void rct2_free(void *block)
-{
- #ifdef _WIN32
- RCT2_CALLPROC_1(0x004068CD, void*, block);
- #else
- //log_warning("call rct's function");
- free(block);
- #endif // _WIN32
-}
diff --git a/src/rct2.h b/src/rct2.h
index 5b949c3150..da4eff58ea 100644
--- a/src/rct2.h
+++ b/src/rct2.h
@@ -21,6 +21,8 @@
#ifndef _RCT2_H_
#define _RCT2_H_
+#include
+
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
@@ -270,9 +272,6 @@ const char *get_file_path(int pathId);
void get_system_info();
void get_system_time();
void get_local_time();
-void *rct2_malloc(size_t numBytes);
-void *rct2_realloc(void *block, size_t numBytes);
-void rct2_free(void *block);
void rct2_quit();
int rct2_open_file(const char *path);
diff --git a/src/version.h b/src/version.h
index e3a3124ff5..054e208913 100644
--- a/src/version.h
+++ b/src/version.h
@@ -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
diff --git a/src/windows/editor_object_selection.c b/src/windows/editor_object_selection.c
index e5c531c35e..910867533c 100644
--- a/src/windows/editor_object_selection.c
+++ b/src/windows/editor_object_selection.c
@@ -667,7 +667,7 @@ static void setup_in_use_selection_flags(){
static int sub_6AB211(){
uint32 total_objects = gInstalledObjectsCount;
- RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) = rct2_malloc(total_objects);
+ RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) = malloc(total_objects);
if (RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) == NULL){
log_error("Failed to allocate memory for object flag list.");
@@ -717,12 +717,9 @@ static int sub_6AB211(){
*
* rct2: 0x006AB316
*/
-static void editor_object_flags_free(){
- if (RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) == NULL){
- return;
- }
- rct2_free(RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*));
- RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) = NULL;
+static void editor_object_flags_free()
+{
+ SafeFree(RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*));
}
/**
diff --git a/src/windows/game_bottom_toolbar.c b/src/windows/game_bottom_toolbar.c
index 9a9c8970b2..c667d7e059 100644
--- a/src/windows/game_bottom_toolbar.c
+++ b/src/windows/game_bottom_toolbar.c
@@ -537,8 +537,10 @@ static void window_game_bottom_toolbar_draw_news_item(rct_drawpixelinfo *dpi, rc
if (newsItem->flags & 1)
break;
- rct_drawpixelinfo* cliped_dpi = clip_drawpixelinfo(dpi, x + 1, 22, y + 1, 22);
- if (!cliped_dpi) break;
+ rct_drawpixelinfo cliped_dpi;
+ if (!clip_drawpixelinfo(&cliped_dpi, dpi, x + 1, y + 1, 22, 22)) {
+ break;
+ }
rct_peep* peep = GET_PEEP(newsItem->assoc);
int clip_x = 10, clip_y = 19;
@@ -556,28 +558,26 @@ static void window_game_bottom_toolbar_draw_news_item(rct_drawpixelinfo *dpi, rc
uint32 image_id = image_id_base;
image_id |= 0xA0000000 | (peep->tshirt_colour << 19) | (peep->trousers_colour << 24);
- gfx_draw_sprite(cliped_dpi, image_id, clip_x, clip_y, 0);
+ gfx_draw_sprite(&cliped_dpi, image_id, clip_x, clip_y, 0);
if (image_id_base >= 0x2A1D && image_id_base < 0x2A3D){
image_id_base += 32;
image_id_base |= 0x20000000 | (peep->balloon_colour << 19);
- gfx_draw_sprite(cliped_dpi, image_id_base, clip_x, clip_y, 0);
+ gfx_draw_sprite(&cliped_dpi, image_id_base, clip_x, clip_y, 0);
}
else if (image_id_base >= 0x2BBD && image_id_base < 0x2BDD){
image_id_base += 32;
image_id_base |= 0x20000000 | (peep->umbrella_colour << 19);
- gfx_draw_sprite(cliped_dpi, image_id_base, clip_x, clip_y, 0);
+ gfx_draw_sprite(&cliped_dpi, image_id_base, clip_x, clip_y, 0);
}
else if (image_id_base >= 0x29DD && image_id_base < 0x29FD){
image_id_base += 32;
image_id_base |= 0x20000000 | (peep->hat_colour << 19);
- gfx_draw_sprite(cliped_dpi, image_id_base, clip_x, clip_y, 0);
+ gfx_draw_sprite(&cliped_dpi, image_id_base, clip_x, clip_y, 0);
}
-
- rct2_free(cliped_dpi);
break;
case NEWS_ITEM_MONEY:
gfx_draw_sprite(dpi, SPR_FINANCE, x, y, 0);
diff --git a/src/windows/guest.c b/src/windows/guest.c
index 8771fe5c9d..a4ce16054d 100644
--- a/src/windows/guest.c
+++ b/src/windows/guest.c
@@ -819,8 +819,10 @@ void window_guest_overview_tab_paint(rct_window* w, rct_drawpixelinfo* dpi){
int y = widget->top + 1 + w->y;
if (w->page == WINDOW_GUEST_OVERVIEW) height++;
- rct_drawpixelinfo* clip_dpi = clip_drawpixelinfo(dpi, x, width, y, height );
- if (!clip_dpi) return;
+ rct_drawpixelinfo clip_dpi;
+ if (!clip_drawpixelinfo(&clip_dpi, dpi, x, y, width, height)) {
+ return;
+ }
x = 14;
y = 20;
@@ -841,30 +843,28 @@ void window_guest_overview_tab_paint(rct_window* w, rct_drawpixelinfo* dpi){
ebx += eax;
int sprite_id = ebx | (peep->tshirt_colour << 19) | (peep->trousers_colour << 24) | 0xA0000000;
- gfx_draw_sprite( clip_dpi, sprite_id, x, y, 0);
+ gfx_draw_sprite(&clip_dpi, sprite_id, x, y, 0);
// If holding a balloon
if (ebx >= 0x2A1D && ebx < 0x2A3D){
ebx += 32;
ebx |= (peep->balloon_colour << 19) | 0x20000000;
- gfx_draw_sprite( clip_dpi, ebx, x, y, 0);
+ gfx_draw_sprite(&clip_dpi, ebx, x, y, 0);
}
// If holding umbrella
if (ebx >= 0x2BBD && ebx < 0x2BDD){
ebx += 32;
ebx |= (peep->umbrella_colour << 19) | 0x20000000;
- gfx_draw_sprite(clip_dpi, ebx, x, y, 0);
+ gfx_draw_sprite(&clip_dpi, ebx, x, y, 0);
}
// If wearing hat
if (ebx >= 0x29DD && ebx < 0x29FD){
ebx += 32;
ebx |= (peep->hat_colour << 19) | 0x20000000;
- gfx_draw_sprite( clip_dpi, ebx, x, y, 0);
+ gfx_draw_sprite(&clip_dpi, ebx, x, y, 0);
}
-
- rct2_free(clip_dpi);
}
/**
@@ -1016,14 +1016,15 @@ void window_guest_overview_paint(rct_window *w, rct_drawpixelinfo *dpi)
int left = widget->left + 2 + w->x;
int top = widget->top + w->y;
int height = widget->bottom - widget->top;
- rct_drawpixelinfo* dpi_marquee = clip_drawpixelinfo(dpi, left, width, top, height);
+ rct_drawpixelinfo dpi_marquee;
+ if (!clip_drawpixelinfo(&dpi_marquee, dpi, left, top, width, height)) {
+ return;
+ }
- if (!dpi_marquee)return;
int i = 0;
for (; i < PEEP_MAX_THOUGHTS; ++i){
if (peep->thoughts[i].type == PEEP_THOUGHT_TYPE_NONE){
w->list_information_type = 0;
- rct2_free(dpi_marquee);
return;
}
if (peep->thoughts[i].var_2 == 1){ // If a fresh thought
@@ -1032,7 +1033,6 @@ void window_guest_overview_paint(rct_window *w, rct_drawpixelinfo *dpi)
}
if (i == PEEP_MAX_THOUGHTS){
w->list_information_type = 0;
- rct2_free(dpi_marquee);
return;
}
@@ -1043,9 +1043,7 @@ void window_guest_overview_paint(rct_window *w, rct_drawpixelinfo *dpi)
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 8, uint16) = 0;
x = widget->right - widget->left - w->list_information_type;
- gfx_draw_string_left(dpi_marquee, 1193, (void*)RCT2_ADDRESS_COMMON_FORMAT_ARGS, 0, x, 0);
-
- rct2_free(dpi_marquee);
+ gfx_draw_string_left(&dpi_marquee, 1193, (void*)RCT2_ADDRESS_COMMON_FORMAT_ARGS, 0, x, 0);
}
/**
diff --git a/src/windows/news.c b/src/windows/news.c
index 77a0760e01..1ea43167e0 100644
--- a/src/windows/news.c
+++ b/src/windows/news.c
@@ -328,8 +328,10 @@ static void window_news_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int s
case NEWS_ITEM_PEEP:
case NEWS_ITEM_PEEP_ON_RIDE:
{
- rct_drawpixelinfo* cliped_dpi = clip_drawpixelinfo(dpi, x + 1, 22, yy + 1, 22);
- if (!cliped_dpi) break;
+ rct_drawpixelinfo cliped_dpi;
+ if (!clip_drawpixelinfo(&cliped_dpi, dpi, x + 1, yy + 1, 22, 22)) {
+ break;
+ }
rct_peep* peep = GET_PEEP(newsItem->assoc);
int clip_x = 10, clip_y = 19;
@@ -348,9 +350,7 @@ static void window_news_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int s
image_id += 0xA0000001;
image_id |= (peep->tshirt_colour << 19) | (peep->trousers_colour << 24);
- gfx_draw_sprite(cliped_dpi, image_id, clip_x, clip_y, 0);
-
- rct2_free(cliped_dpi);
+ gfx_draw_sprite(&cliped_dpi, image_id, clip_x, clip_y, 0);
break;
}
case NEWS_ITEM_MONEY:
diff --git a/src/windows/options.c b/src/windows/options.c
index 2e6158f6ee..d2e773806a 100644
--- a/src/windows/options.c
+++ b/src/windows/options.c
@@ -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;
diff --git a/src/windows/ride.c b/src/windows/ride.c
index 41e1d0a242..4aee22f1c2 100644
--- a/src/windows/ride.c
+++ b/src/windows/ride.c
@@ -1028,9 +1028,10 @@ static void window_ride_draw_tab_vehicle(rct_drawpixelinfo *dpi, rct_window *w)
x += w->x;
y += w->y;
- dpi = clip_drawpixelinfo(dpi, x, width, y, height);
- if (dpi == NULL)
+ rct_drawpixelinfo clipDPI;
+ if (!clip_drawpixelinfo(&clipDPI, dpi, x, y, width, height)) {
return;
+ }
x = (widget->right - widget->left) / 2;
y = (widget->bottom - widget->top) - 12;
@@ -1042,13 +1043,13 @@ static void window_ride_draw_tab_vehicle(rct_drawpixelinfo *dpi, rct_window *w)
rideEntry = ride_get_entry(ride);
if (rideEntry->flags & RIDE_ENTRY_FLAG_0) {
- dpi->zoom_level = 1;
- dpi->width *= 2;
- dpi->height *= 2;
+ clipDPI.zoom_level = 1;
+ clipDPI.width *= 2;
+ clipDPI.height *= 2;
x *= 2;
y *= 2;
- dpi->x *= 2;
- dpi->y *= 2;
+ clipDPI.x *= 2;
+ clipDPI.y *= 2;
}
rct_ride_type_vehicle* rideVehicleEntry = &rideEntry->vehicles[trainLayout[rideEntry->tab_vehicle]];
@@ -1066,8 +1067,7 @@ static void window_ride_draw_tab_vehicle(rct_drawpixelinfo *dpi, rct_window *w)
spriteIndex |= (vehicleColour.additional_1 << 24) | (vehicleColour.main << 19);
spriteIndex |= 0x80000000;
- gfx_draw_sprite(dpi, spriteIndex, x, y, vehicleColour.additional_2);
- rct2_free(dpi);
+ gfx_draw_sprite(&clipDPI, spriteIndex, x, y, vehicleColour.additional_2);
}
}
@@ -4208,7 +4208,7 @@ static void window_ride_colour_invalidate(rct_window *w)
*/
static void window_ride_colour_paint(rct_window *w, rct_drawpixelinfo *dpi)
{
- rct_drawpixelinfo *clippedDpi;
+ rct_drawpixelinfo clippedDpi;
rct_widget *widget;
rct_ride *ride;
rct_ride_type *rideEntry;
@@ -4265,11 +4265,15 @@ static void window_ride_colour_paint(rct_window *w, rct_drawpixelinfo *dpi)
trackColour = ride_get_track_colour(ride, 0);
widget = &w->widgets[WIDX_ENTRANCE_PREVIEW];
if (widget->type != WWT_EMPTY) {
- clippedDpi = clip_drawpixelinfo(
- dpi, w->x + widget->left + 1, widget->right - widget->left, w->y + widget->top + 1, widget->bottom - widget->top
- );
- if (clippedDpi != NULL) {
- gfx_clear(clippedDpi, 0x0C0C0C0C);
+ if (clip_drawpixelinfo(
+ &clippedDpi,
+ dpi,
+ w->x + widget->left + 1,
+ w->y + widget->top + 1,
+ widget->right - widget->left,
+ widget->bottom - widget->top
+ )) {
+ gfx_clear(&clippedDpi, 0x0C0C0C0C);
if (ride->entrance_style != RIDE_ENTRANCE_STYLE_NONE) {
const rct_ride_entrance_definition *entranceStyle = &RideEntranceDefinitions[ride->entrance_style];
@@ -4284,17 +4288,15 @@ static void window_ride_colour_paint(rct_window *w, rct_drawpixelinfo *dpi)
spriteIndex += RideEntranceDefinitions[ride->entrance_style].sprite_index;
// Back
- gfx_draw_sprite(clippedDpi, spriteIndex, 34, 20, terniaryColour);
+ gfx_draw_sprite(&clippedDpi, spriteIndex, 34, 20, terniaryColour);
// Front
- gfx_draw_sprite(clippedDpi, spriteIndex + 4, 34, 20, terniaryColour);
+ gfx_draw_sprite(&clippedDpi, spriteIndex + 4, 34, 20, terniaryColour);
// ?
if (terniaryColour != 0)
- gfx_draw_sprite(clippedDpi, ((spriteIndex + 20) & 0x7FFFF) + terniaryColour, 34, 20, terniaryColour);
+ gfx_draw_sprite(&clippedDpi, ((spriteIndex + 20) & 0x7FFFF) + terniaryColour, 34, 20, terniaryColour);
}
-
- rct2_free(clippedDpi);
}
}
}
diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c
index 7665d997e0..125052dad0 100644
--- a/src/windows/ride_construction.c
+++ b/src/windows/ride_construction.c
@@ -2094,7 +2094,7 @@ static void window_ride_construction_invalidate(rct_window *w)
*/
static void window_ride_construction_paint(rct_window *w, rct_drawpixelinfo *dpi)
{
- rct_drawpixelinfo *clipdpi;
+ rct_drawpixelinfo clipdpi;
rct_widget *widget;
int x, y, width, height;
@@ -2113,10 +2113,8 @@ static void window_ride_construction_paint(rct_window *w, rct_drawpixelinfo *dpi
y = w->y + widget->top + 1;
width = widget->right - widget->left - 1;
height = widget->bottom - widget->top - 1;
- clipdpi = clip_drawpixelinfo(dpi, x, width, y, height);
- if (clipdpi != NULL) {
- window_ride_construction_draw_track_piece(w, clipdpi, rideIndex, trackType, trackDirection, edxRS16, width, height);
- rct2_free(clipdpi);
+ if (clip_drawpixelinfo(&clipdpi, dpi, x, y, width, height)) {
+ window_ride_construction_draw_track_piece(w, &clipdpi, rideIndex, trackType, trackDirection, edxRS16, width, height);
}
// Draw cost
diff --git a/src/windows/scenery.c b/src/windows/scenery.c
index 87331be5ae..897954d890 100644
--- a/src/windows/scenery.c
+++ b/src/windows/scenery.c
@@ -1091,8 +1091,8 @@ void window_scenery_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrol
gfx_draw_sprite(dpi, imageId, left + 0x21, top, w->colours[1]);
} else if (currentSceneryGlobalId >= 0x200) {
sceneryEntry = g_wallSceneryEntries[currentSceneryGlobalId - 0x200];
- rct_drawpixelinfo* clipdpi = clip_drawpixelinfo(dpi, left + 1, 64, top + 1, 78);
- if (clipdpi != NULL) {
+ rct_drawpixelinfo clipdpi;
+ if (clip_drawpixelinfo(&clipdpi, dpi, left + 1, top + 1, 64, 78)) {
uint32 imageId = sceneryEntry->image;
uint8 tertiaryColour = w->colours[1];
@@ -1102,11 +1102,11 @@ void window_scenery_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrol
if (sceneryEntry->wall.flags & WALL_SCENERY_HAS_SECONDARY_COLOUR) {
imageId |= (window_scenery_secondary_colour << 24) | 0x80000000;
}
- gfx_draw_sprite(clipdpi, imageId, 0x2F, (sceneryEntry->wall.height * 2) + 0x32,
+ gfx_draw_sprite(&clipdpi, imageId, 0x2F, (sceneryEntry->wall.height * 2) + 0x32,
tertiaryColour);
imageId = (sceneryEntry->image + 0x40000006) | ((window_scenery_primary_colour + 0x70) << 19);
- gfx_draw_sprite(clipdpi, imageId, 0x2F, (sceneryEntry->wall.height * 2) + 0x32,
+ gfx_draw_sprite(&clipdpi, imageId, 0x2F, (sceneryEntry->wall.height * 2) + 0x32,
tertiaryColour);
}
else {
@@ -1121,17 +1121,14 @@ void window_scenery_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrol
}
}
- gfx_draw_sprite(clipdpi, imageId, 0x2F, (sceneryEntry->wall.height * 2) + 0x32,
+ gfx_draw_sprite(&clipdpi, imageId, 0x2F, (sceneryEntry->wall.height * 2) + 0x32,
tertiaryColour);
if (sceneryEntry->wall.flags & WALL_SCENERY_FLAG5){
- gfx_draw_sprite(clipdpi, imageId + 1, 0x2F, (sceneryEntry->wall.height * 2) + 0x32,
+ gfx_draw_sprite(&clipdpi, imageId + 1, 0x2F, (sceneryEntry->wall.height * 2) + 0x32,
tertiaryColour);
}
}
-
-
- rct2_free(clipdpi);
}
} else if (currentSceneryGlobalId >= 0x100) {
sceneryEntry = g_pathBitSceneryEntries[currentSceneryGlobalId - 0x100];
@@ -1140,9 +1137,8 @@ void window_scenery_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrol
gfx_draw_sprite(dpi, imageId, left + 0x0B, top + 0x10, w->colours[1]);
} else {
sceneryEntry = g_smallSceneryEntries[currentSceneryGlobalId];
- rct_drawpixelinfo* clipdpi = clip_drawpixelinfo(dpi, left + 1, SCENERY_BUTTON_WIDTH - 2, top + 1, SCENERY_BUTTON_HEIGHT - 2);
- if (clipdpi != NULL) {
-
+ rct_drawpixelinfo clipdpi;
+ if (clip_drawpixelinfo(&clipdpi, dpi, left + 1, top + 1, SCENERY_BUTTON_WIDTH - 2, SCENERY_BUTTON_HEIGHT - 2)) {
uint32 imageId = sceneryEntry->image + window_scenery_rotation;
if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR) {
@@ -1160,21 +1156,19 @@ void window_scenery_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrol
spriteTop -= 0x0C;
}
- gfx_draw_sprite(clipdpi, imageId, 0x20, spriteTop, w->colours[1]);
+ gfx_draw_sprite(&clipdpi, imageId, 0x20, spriteTop, w->colours[1]);
if (sceneryEntry->small_scenery.flags & 0x200) {
imageId = ((sceneryEntry->image + window_scenery_rotation) + 0x40000004) +
((window_scenery_primary_colour + 0x70) << 19);
- gfx_draw_sprite(clipdpi, imageId, 0x20, spriteTop, w->colours[1]);
+ gfx_draw_sprite(&clipdpi, imageId, 0x20, spriteTop, w->colours[1]);
}
if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG8) {
imageId = (sceneryEntry->image + window_scenery_rotation) + 4;
- gfx_draw_sprite(clipdpi, imageId, 0x20, spriteTop, w->colours[1]);
+ gfx_draw_sprite(&clipdpi, imageId, 0x20, spriteTop, w->colours[1]);
}
-
- rct2_free(clipdpi);
}
}
diff --git a/src/windows/staff.c b/src/windows/staff.c
index f20f4c7cb3..e7289bd010 100644
--- a/src/windows/staff.c
+++ b/src/windows/staff.c
@@ -976,8 +976,10 @@ void window_staff_overview_tab_paint(rct_window* w, rct_drawpixelinfo* dpi)
int y = widget->top + 1 + w->y;
if (w->page == WINDOW_STAFF_OVERVIEW) height++;
- rct_drawpixelinfo* clip_dpi = clip_drawpixelinfo(dpi, x, width, y, height);
- if (!clip_dpi) return;
+ rct_drawpixelinfo clip_dpi;
+ if (!clip_drawpixelinfo(&clip_dpi, dpi, x, y, width, height)) {
+ return;
+ }
x = 14;
y = 20;
@@ -998,30 +1000,28 @@ void window_staff_overview_tab_paint(rct_window* w, rct_drawpixelinfo* dpi)
ebx += eax;
int sprite_id = ebx | (peep->tshirt_colour << 19) | (peep->trousers_colour << 24) | 0xA0000000;
- gfx_draw_sprite(clip_dpi, sprite_id, x, y, 0);
+ gfx_draw_sprite(&clip_dpi, sprite_id, x, y, 0);
// If holding a balloon
if (ebx >= 0x2A1D && ebx < 0x2A3D){
ebx += 32;
ebx |= (peep->balloon_colour << 19) | 0x20000000;
- gfx_draw_sprite(clip_dpi, ebx, x, y, 0);
+ gfx_draw_sprite(&clip_dpi, ebx, x, y, 0);
}
// If holding umbrella
if (ebx >= 0x2BBD && ebx < 0x2BDD){
ebx += 32;
ebx |= (peep->umbrella_colour << 19) | 0x20000000;
- gfx_draw_sprite(clip_dpi, ebx, x, y, 0);
+ gfx_draw_sprite(&clip_dpi, ebx, x, y, 0);
}
// If wearing hat
if (ebx >= 0x29DD && ebx < 0x29FD){
ebx += 32;
ebx |= (peep->hat_colour << 19) | 0x20000000;
- gfx_draw_sprite(clip_dpi, ebx, x, y, 0);
+ gfx_draw_sprite(&clip_dpi, ebx, x, y, 0);
}
-
- rct2_free(clip_dpi);
}
/**
diff --git a/src/windows/staff_list.c b/src/windows/staff_list.c
index 0a8d675814..d96e8c0df1 100644
--- a/src/windows/staff_list.c
+++ b/src/windows/staff_list.c
@@ -574,27 +574,19 @@ void window_staff_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
window_staff_list_widgets[WIDX_STAFF_LIST_SECURITY_TAB].bottom - 6 + w->y, 0
);
- rct_drawpixelinfo* sprite_dpi = clip_drawpixelinfo(
+ rct_drawpixelinfo sprite_dpi;
+ if (clip_drawpixelinfo(
+ &sprite_dpi,
dpi,
window_staff_list_widgets[WIDX_STAFF_LIST_ENTERTAINERS_TAB].left + w->x + 1,
- window_staff_list_widgets[WIDX_STAFF_LIST_ENTERTAINERS_TAB].right - window_staff_list_widgets[WIDX_STAFF_LIST_ENTERTAINERS_TAB].left - 1,
window_staff_list_widgets[WIDX_STAFF_LIST_ENTERTAINERS_TAB].top + w->y + 1,
+ window_staff_list_widgets[WIDX_STAFF_LIST_ENTERTAINERS_TAB].right - window_staff_list_widgets[WIDX_STAFF_LIST_ENTERTAINERS_TAB].left - 1,
window_staff_list_widgets[WIDX_STAFF_LIST_ENTERTAINERS_TAB].bottom - window_staff_list_widgets[WIDX_STAFF_LIST_ENTERTAINERS_TAB].top - 1
- );
-
-
-
- if (sprite_dpi != NULL) {
+ )) {
// Entertainers tab image
i = (selectedTab == 3 ? w->list_information_type & 0x0FFFFFFFC : 0);
i += RCT2_ADDRESS(RCT2_GLOBAL(0x00982738, int), int)[0] + 1;
- gfx_draw_sprite(
- sprite_dpi,
- i,
- 0x0F,
- 0x17, 0
- );
- rct2_free(sprite_dpi);
+ gfx_draw_sprite(&sprite_dpi, i, 0x0F, 0x17, 0);
}
if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) {
diff --git a/src/windows/track_place.c b/src/windows/track_place.c
index 4fe5fb149d..8387fbcf9d 100644
--- a/src/windows/track_place.c
+++ b/src/windows/track_place.c
@@ -595,14 +595,13 @@ static void window_track_place_invalidate(rct_window *w)
*/
static void window_track_place_paint(rct_window *w, rct_drawpixelinfo *dpi)
{
- rct_drawpixelinfo *clippedDpi;
+ rct_drawpixelinfo clippedDpi;
rct_g1_element tmpElement, *substituteElement;
window_draw_widgets(w, dpi);
// Draw mini tile preview
- clippedDpi = clip_drawpixelinfo(dpi, w->x + 4, 168, w->y + 18, 78);
- if (clippedDpi != NULL) {
+ if (clip_drawpixelinfo(&clippedDpi, dpi, w->x + 4, 168, w->y + 18, 78)) {
substituteElement = &g1Elements[0];
tmpElement = *substituteElement;
substituteElement->offset = _window_track_place_mini_preview;
@@ -611,10 +610,8 @@ static void window_track_place_paint(rct_window *w, rct_drawpixelinfo *dpi)
substituteElement->x_offset = 0;
substituteElement->y_offset = 0;
substituteElement->flags = 0;
- gfx_draw_sprite(clippedDpi, 0, 0, 0, 0);
+ gfx_draw_sprite(&clippedDpi, 0, 0, 0, 0);
*substituteElement = tmpElement;
-
- rct2_free(clippedDpi);
}
// Price
diff --git a/src/world/map.c b/src/world/map.c
index 268b42ad0e..3bf67de3f0 100644
--- a/src/world/map.c
+++ b/src/world/map.c
@@ -3654,7 +3654,7 @@ void map_reorganise_elements()
{
platform_set_cursor(CURSOR_ZZZ);
- rct_map_element* new_map_elements = rct2_malloc(0x30000 * sizeof(rct_map_element));
+ rct_map_element* new_map_elements = malloc(0x30000 * sizeof(rct_map_element));
rct_map_element* new_elements_pointer = new_map_elements;
if (new_map_elements == NULL || new_map_elements == (rct_map_element*)-1){
@@ -3680,7 +3680,7 @@ void map_reorganise_elements()
memcpy(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element), new_map_elements, num_elements * sizeof(rct_map_element));
memset(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element) + num_elements, 0, (0x30000 - num_elements) * sizeof(rct_map_element));
- rct2_free(new_map_elements);
+ free(new_map_elements);
map_update_tile_pointers();
}