2016-05-04 19:24:41 +02:00
|
|
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
2014-10-06 18:36:58 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
2015-09-22 22:45:03 +02:00
|
|
|
*
|
2016-05-04 19:24:41 +02:00
|
|
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
|
|
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
2015-09-22 22:45:03 +02:00
|
|
|
*
|
2014-10-06 18:36:58 +02:00
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
|
|
|
* A full copy of the GNU General Public License can be found in licence.txt
|
2014-10-06 18:36:58 +02:00
|
|
|
*****************************************************************************/
|
2016-05-04 19:24:41 +02:00
|
|
|
#pragma endregion
|
2015-09-22 22:45:03 +02:00
|
|
|
|
2014-10-06 18:36:58 +02:00
|
|
|
#ifndef _COMMON_H_
|
|
|
|
#define _COMMON_H_
|
|
|
|
|
2016-11-30 12:07:10 +01:00
|
|
|
#include <SDL_platform.h>
|
|
|
|
|
|
|
|
#ifndef _USE_MATH_DEFINES
|
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
#endif
|
|
|
|
#undef M_PI
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
typedef int8_t sint8;
|
|
|
|
typedef int16_t sint16;
|
|
|
|
typedef int32_t sint32;
|
|
|
|
typedef int64_t sint64;
|
|
|
|
typedef uint8_t uint8;
|
|
|
|
typedef uint16_t uint16;
|
|
|
|
typedef uint32_t uint32;
|
|
|
|
typedef uint64_t uint64;
|
|
|
|
|
2017-01-04 22:27:25 +01:00
|
|
|
#include "diagnostic.h"
|
|
|
|
|
2016-11-30 12:07:10 +01:00
|
|
|
typedef char utf8;
|
|
|
|
typedef utf8* utf8string;
|
|
|
|
typedef const utf8* const_utf8string;
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
typedef wchar_t utf16;
|
|
|
|
typedef utf16* utf16string;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef uint32 codepoint_t;
|
|
|
|
typedef uint8 colour_t;
|
|
|
|
|
|
|
|
#define rol8(x, shift) (((uint8)(x) << (shift)) | ((uint8)(x) >> (8 - (shift))))
|
|
|
|
#define ror8(x, shift) (((uint8)(x) >> (shift)) | ((uint8)(x) << (8 - (shift))))
|
|
|
|
#define rol16(x, shift) (((uint16)(x) << (shift)) | ((uint16)(x) >> (16 - (shift))))
|
|
|
|
#define ror16(x, shift) (((uint16)(x) >> (shift)) | ((uint16)(x) << (16 - (shift))))
|
|
|
|
#define rol32(x, shift) (((uint32)(x) << (shift)) | ((uint32)(x) >> (32 - (shift))))
|
|
|
|
#define ror32(x, shift) (((uint32)(x) >> (shift)) | ((uint32)(x) << (32 - (shift))))
|
|
|
|
#define rol64(x, shift) (((uint64)(x) << (shift)) | ((uint32)(x) >> (64 - (shift))))
|
|
|
|
#define ror64(x, shift) (((uint64)(x) >> (shift)) | ((uint32)(x) << (64 - (shift))))
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
// in C++ you should be using Math::Min and Math::Max
|
|
|
|
#ifndef min
|
|
|
|
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
#ifndef max
|
|
|
|
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define sgn(x) ((x > 0) ? 1 : ((x < 0) ? -1 : 0))
|
|
|
|
#define clamp(l, x, h) (min(h, max(l, x)))
|
|
|
|
|
2016-12-16 02:19:41 +01:00
|
|
|
#endif // __cplusplus
|
|
|
|
|
2016-11-30 12:07:10 +01:00
|
|
|
// Rounds an integer down to the given power of 2. y must be a power of 2.
|
|
|
|
#define floor2(x, y) ((x) & (~((y) - 1)))
|
|
|
|
|
|
|
|
// Rounds an integer up to the given power of 2. y must be a power of 2.
|
|
|
|
#define ceil2(x, y) (((x) + (y) - 1) & (~((y) - 1)))
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
// in C++ you should be using Util::CountOf
|
|
|
|
#ifdef __GNUC__
|
|
|
|
/**
|
|
|
|
* Force a compilation error if condition is true, but also produce a
|
|
|
|
* result (of value 0 and type size_t), so the expression can be used
|
|
|
|
* e.g. in a structure initializer (or where-ever else comma expressions
|
|
|
|
* aren't permitted).
|
|
|
|
*/
|
2017-01-04 22:17:08 +01:00
|
|
|
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { sint32:-!!(e); }))
|
2016-11-30 12:07:10 +01:00
|
|
|
|
|
|
|
/* &a[0] degrades to a pointer: a different type from an array */
|
|
|
|
#define __must_be_array(a) \
|
|
|
|
BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
|
|
|
|
|
|
|
|
// based on http://lxr.free-electrons.com/source/include/linux/kernel.h#L54
|
|
|
|
#define countof(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
|
|
|
|
#elif defined (_MSC_VER)
|
|
|
|
#define countof(arr) _countof(arr)
|
|
|
|
#else
|
|
|
|
#define countof(arr) (sizeof(arr) / sizeof((arr)[0]))
|
|
|
|
#endif // __GNUC__
|
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
|
#include <unistd.h>
|
|
|
|
#define STUB() log_warning("Function %s at %s:%d is a stub.\n", __PRETTY_FUNCTION__, __FILE__, __LINE__)
|
|
|
|
#define _strcmpi _stricmp
|
|
|
|
#define _stricmp(x, y) strcasecmp((x), (y))
|
|
|
|
#define _strnicmp(x, y, n) strncasecmp((x), (y), (n))
|
|
|
|
#define _strdup(x) strdup((x))
|
|
|
|
|
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
|
|
#define RCT2_ENDIANESS __ORDER_LITTLE_ENDIAN__
|
|
|
|
#define LOBYTE(w) ((uint8)(w))
|
|
|
|
#define HIBYTE(w) ((uint8)(((uint16)(w)>>8)&0xFF))
|
|
|
|
#endif // __BYTE_ORDER__
|
|
|
|
|
|
|
|
#ifndef RCT2_ENDIANESS
|
|
|
|
#error Unknown endianess!
|
|
|
|
#endif // RCT2_ENDIANESS
|
|
|
|
|
|
|
|
#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
|
|
|
|
|
#if !((defined (_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700))
|
|
|
|
char *strndup(const char *src, size_t size);
|
|
|
|
#endif // !(POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
|
|
|
|
|
|
|
|
// BSD and macOS have MAP_ANON instead of MAP_ANONYMOUS
|
|
|
|
#ifndef MAP_ANONYMOUS
|
|
|
|
#define MAP_ANONYMOUS MAP_ANON
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
#define OPENRCT2_MASTER_SERVER_URL "https://servers.openrct2.website"
|
|
|
|
|
|
|
|
// Time (represented as number of 100-nanosecond intervals since 0001-01-01T00:00:00Z)
|
|
|
|
typedef uint64 datetime64;
|
|
|
|
|
|
|
|
#define DATETIME64_MIN ((datetime64)0)
|
|
|
|
|
|
|
|
// Represent fixed point numbers. dp = decimal point
|
|
|
|
typedef uint8 fixed8_1dp;
|
|
|
|
typedef uint8 fixed8_2dp;
|
|
|
|
typedef sint16 fixed16_1dp;
|
|
|
|
typedef sint16 fixed16_2dp;
|
|
|
|
typedef sint32 fixed32_1dp;
|
|
|
|
typedef sint32 fixed32_2dp;
|
|
|
|
|
|
|
|
// Money is stored as a multiple of 0.10.
|
|
|
|
typedef fixed8_1dp money8;
|
|
|
|
typedef fixed16_1dp money16;
|
|
|
|
typedef fixed32_1dp money32;
|
|
|
|
|
|
|
|
// Construct a fixed point number. For example, to create the value 3.65 you
|
|
|
|
// would write FIXED_2DP(3,65)
|
|
|
|
#define FIXED_XDP(x, whole, fraction) ((whole) * (10 * x) + (fraction))
|
|
|
|
#define FIXED_1DP(whole, fraction) FIXED_XDP(1, whole, fraction)
|
|
|
|
#define FIXED_2DP(whole, fraction) FIXED_XDP(10, whole, fraction)
|
|
|
|
|
|
|
|
// Construct a money value in the format MONEY(10,70) to represent 10.70. Fractional part must be two digits.
|
|
|
|
#define MONEY(whole, fraction) ((whole) * 10 + ((fraction) / 10))
|
|
|
|
|
|
|
|
#define MONEY_FREE MONEY(0,00)
|
|
|
|
#define MONEY32_UNDEFINED ((money32)0x80000000)
|
|
|
|
|
|
|
|
typedef void (EMPTY_ARGS_VOID_POINTER)();
|
2017-01-04 22:17:08 +01:00
|
|
|
typedef uint16 rct_string_id;
|
2014-10-06 18:36:58 +02:00
|
|
|
|
2015-09-22 22:45:03 +02:00
|
|
|
#define SafeFree(x) do { free(x); (x) = NULL; } while (0)
|
2015-02-16 23:47:11 +01:00
|
|
|
|
2015-09-22 22:45:03 +02:00
|
|
|
#define SafeDelete(x) do { delete (x); (x) = nullptr; } while (0)
|
|
|
|
#define SafeDeleteArray(x) do { delete[] (x); (x) = nullptr; } while (0)
|
2015-09-05 00:27:47 +02:00
|
|
|
|
2015-09-12 19:17:25 +02:00
|
|
|
#ifndef interface
|
|
|
|
#define interface struct
|
|
|
|
#endif
|
2015-09-05 00:27:47 +02:00
|
|
|
#define abstract = 0
|
2015-08-29 03:05:21 +02:00
|
|
|
|
2016-04-22 08:59:50 +02:00
|
|
|
#if defined(__i386__) || defined(_M_IX86)
|
2016-04-21 22:18:59 +02:00
|
|
|
#define PLATFORM_X86
|
2016-05-01 19:11:41 +02:00
|
|
|
#else
|
|
|
|
#define NO_RCT2 1
|
2016-04-21 22:18:59 +02:00
|
|
|
#endif
|
|
|
|
|
2016-06-03 00:18:20 +02:00
|
|
|
#if defined(__LP64__) || defined(_WIN64)
|
|
|
|
#define PLATFORM_64BIT
|
|
|
|
#else
|
|
|
|
#define PLATFORM_32BIT
|
|
|
|
#endif
|
|
|
|
|
2016-06-01 16:40:31 +02:00
|
|
|
// C99's restrict keywords guarantees the pointer in question, for the whole of its lifetime,
|
|
|
|
// will be the only way to access a given memory region. In other words: there is no other pointer
|
|
|
|
// aliasing the same memory area. Using it lets compiler generate better code. If your compiler
|
|
|
|
// does not support it, feel free to drop it, at some performance hit.
|
|
|
|
#ifdef __cplusplus
|
2016-07-09 10:05:12 +02:00
|
|
|
#ifdef _MSC_VER
|
2016-06-01 18:44:06 +02:00
|
|
|
#define RESTRICT __restrict
|
|
|
|
#else
|
2016-06-01 16:40:31 +02:00
|
|
|
#define RESTRICT __restrict__
|
|
|
|
#endif
|
|
|
|
#else
|
2016-07-09 10:05:12 +02:00
|
|
|
#ifdef _MSC_VER
|
2016-06-01 18:44:06 +02:00
|
|
|
#define RESTRICT __restrict
|
|
|
|
#else
|
2016-06-01 16:40:31 +02:00
|
|
|
#define RESTRICT restrict
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifndef RESTRICT
|
|
|
|
#define RESTRICT
|
|
|
|
#endif
|
|
|
|
|
2016-06-02 20:40:29 +02:00
|
|
|
#ifdef __cplusplus
|
2016-06-03 10:54:44 +02:00
|
|
|
#define assert_struct_size(x, y) static_assert(sizeof(x) == (y), "Improper struct size")
|
2016-06-02 20:40:29 +02:00
|
|
|
#else
|
|
|
|
// Visual Studio does not know _Static_assert
|
|
|
|
#if !defined(_MSC_VER)
|
2016-06-03 10:54:44 +02:00
|
|
|
#define assert_struct_size(x, y) _Static_assert(sizeof(x) == (y), "Improper struct size")
|
2016-06-02 20:40:29 +02:00
|
|
|
#else
|
2016-06-03 10:54:44 +02:00
|
|
|
#define assert_struct_size(x, y)
|
2016-06-02 20:40:29 +02:00
|
|
|
#endif // !defined(_MSC_VER)
|
|
|
|
#endif
|
|
|
|
|
2016-04-21 22:18:59 +02:00
|
|
|
#ifdef PLATFORM_X86
|
2016-05-28 22:37:54 +02:00
|
|
|
#ifndef FASTCALL
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define FASTCALL __attribute__((fastcall))
|
2016-07-09 10:24:26 +02:00
|
|
|
#elif defined(_MSC_VER)
|
2016-05-28 22:37:54 +02:00
|
|
|
#define FASTCALL __fastcall
|
|
|
|
#else
|
|
|
|
#pragma message "Not using fastcall calling convention, please check your compiler support"
|
|
|
|
#define FASTCALL
|
|
|
|
#endif
|
|
|
|
#endif // FASTCALL
|
2016-04-21 22:18:59 +02:00
|
|
|
#else // PLATFORM_X86
|
2016-05-28 22:37:54 +02:00
|
|
|
#define FASTCALL
|
2016-04-21 22:18:59 +02:00
|
|
|
#endif // PLATFORM_X86
|
2016-02-20 11:12:00 +01:00
|
|
|
|
2016-09-18 00:12:25 +02:00
|
|
|
/**
|
|
|
|
* x86 register structure, only used for easy interop to RCT2 code.
|
|
|
|
*/
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
typedef struct registers {
|
|
|
|
union {
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 eax;
|
|
|
|
sint16 ax;
|
2016-09-18 00:12:25 +02:00
|
|
|
struct {
|
|
|
|
char al;
|
|
|
|
char ah;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
union {
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 ebx;
|
|
|
|
sint16 bx;
|
2016-09-18 00:12:25 +02:00
|
|
|
struct {
|
|
|
|
char bl;
|
|
|
|
char bh;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
union {
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 ecx;
|
|
|
|
sint16 cx;
|
2016-09-18 00:12:25 +02:00
|
|
|
struct {
|
|
|
|
char cl;
|
|
|
|
char ch;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
union {
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 edx;
|
|
|
|
sint16 dx;
|
2016-09-18 00:12:25 +02:00
|
|
|
struct {
|
|
|
|
char dl;
|
|
|
|
char dh;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
union {
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 esi;
|
|
|
|
sint16 si;
|
2016-09-18 00:12:25 +02:00
|
|
|
};
|
|
|
|
union {
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 edi;
|
|
|
|
sint16 di;
|
2016-09-18 00:12:25 +02:00
|
|
|
};
|
|
|
|
union {
|
2017-01-04 22:17:08 +01:00
|
|
|
sint32 ebp;
|
|
|
|
sint16 bp;
|
2016-09-18 00:12:25 +02:00
|
|
|
};
|
|
|
|
} registers;
|
|
|
|
assert_struct_size(registers, 7 * 4);
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2016-10-03 23:03:09 +02:00
|
|
|
#define UNUSED(x) ((void)(x))
|
|
|
|
|
2015-09-22 22:45:03 +02:00
|
|
|
#endif
|