0
|
1 |
#if !defined(_STDAFX_H)
|
|
2 |
#define _STDAFX_H
|
|
3 |
|
|
4 |
#if defined(_MSC_VER)
|
|
5 |
#pragma once
|
|
6 |
|
|
7 |
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
|
8 |
#pragma warning(disable: 4100) // parameter not used
|
|
9 |
#pragma warning(disable: 4244) // conversion
|
|
10 |
#pragma warning(disable: 4245) // conversion
|
|
11 |
#pragma warning(disable: 4201) // nameless union
|
|
12 |
#pragma warning(disable: 4514) // removed unref inline
|
|
13 |
#pragma warning(disable: 4127) // constant conditional expression
|
|
14 |
#pragma warning(disable: 4276) // MSVC BUG??? Complains about function body not declared when using function pointers
|
|
15 |
#pragma warning(disable: 4761) // warning C4761: integral size mismatch in argument; conversion supplied
|
|
16 |
#endif
|
|
17 |
|
|
18 |
#include <stdio.h>
|
|
19 |
#include <assert.h>
|
|
20 |
#include <string.h>
|
|
21 |
#include <stdlib.h>
|
|
22 |
|
|
23 |
#if defined(UNIX)
|
|
24 |
# include <sys/types.h>
|
|
25 |
#endif
|
|
26 |
|
|
27 |
#ifdef __BEOS__
|
|
28 |
#include <SupportDefs.h>
|
|
29 |
#endif
|
|
30 |
|
|
31 |
#define BSWAP32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | (((x) << 24) & 0xFF000000))
|
|
32 |
#define BSWAP16(x) ((x) >> 8 | (x) << 8)
|
|
33 |
|
|
34 |
// by default we use [] var arrays
|
|
35 |
#define VARARRAY_SIZE
|
|
36 |
|
|
37 |
|
|
38 |
// Stuff for GCC
|
|
39 |
#if defined(__GNUC__)
|
|
40 |
# define NORETURN
|
|
41 |
# define FORCEINLINE inline
|
|
42 |
# define INLINE inline
|
|
43 |
# define CDECL
|
|
44 |
//#include <alloca.h>
|
|
45 |
//#include <malloc.h>
|
|
46 |
# define __int64 long long
|
|
47 |
# define NOT_REACHED()
|
|
48 |
# define GCC_PACK __attribute__((packed))
|
|
49 |
|
|
50 |
# if (__GNUC__ == 2)
|
|
51 |
# undef VARARRAY_SIZE
|
|
52 |
# define VARARRAY_SIZE 0
|
|
53 |
# endif
|
|
54 |
#endif
|
|
55 |
|
|
56 |
// Stuff for MSVC
|
|
57 |
#if defined(_MSC_VER)
|
|
58 |
# include <malloc.h> // alloca()
|
|
59 |
# define NORETURN __declspec(noreturn)
|
|
60 |
# define FORCEINLINE __forceinline
|
|
61 |
# define INLINE _inline
|
|
62 |
# define CDECL _cdecl
|
|
63 |
# define NOT_REACHED() _assume(0)
|
|
64 |
# define snprintf _snprintf
|
|
65 |
# undef TTD_ALIGNMENT_4
|
|
66 |
# undef TTD_ALIGNMENT_2
|
|
67 |
# define GCC_PACK
|
|
68 |
#endif
|
|
69 |
|
|
70 |
#if defined(WIN32)
|
|
71 |
# define TTD_LITTLE_ENDIAN
|
|
72 |
#endif
|
|
73 |
|
|
74 |
#if defined(i386)
|
|
75 |
# define TTD_LITTLE_ENDIAN
|
|
76 |
#endif
|
|
77 |
|
|
78 |
#if defined(__MORPHOS__)
|
|
79 |
# define TTD_BIG_ENDIAN
|
|
80 |
#endif
|
|
81 |
|
|
82 |
// Check endianness
|
|
83 |
#if !defined(TTD_LITTLE_ENDIAN) && !defined(TTD_BIG_ENDIAN)
|
|
84 |
# if defined(_BIG_ENDIAN)
|
|
85 |
# define TTD_BIG_ENDIAN
|
|
86 |
# elif defined(_LITTLE_ENDIAN)
|
|
87 |
# define TTD_LITTLE_ENDIAN
|
|
88 |
# else
|
|
89 |
# error No endianness defined, use either TTD_LITTLE_ENDIAN or TTD_BIG_ENDIAN
|
|
90 |
#endif
|
|
91 |
#endif
|
|
92 |
|
|
93 |
#if defined(UNIX)
|
|
94 |
#define PATHSEP "/"
|
|
95 |
#else
|
|
96 |
#define PATHSEP "\\"
|
|
97 |
#endif
|
|
98 |
|
|
99 |
|
|
100 |
typedef unsigned char byte;
|
|
101 |
#ifndef __BEOS__ // already defined
|
|
102 |
typedef unsigned char uint8;
|
|
103 |
typedef unsigned short uint16;
|
|
104 |
typedef unsigned int uint32;
|
|
105 |
#endif
|
|
106 |
|
|
107 |
// This is already defined in unix
|
|
108 |
#if !defined(UNIX) && !defined(__CYGWIN__)
|
|
109 |
typedef unsigned int uint;
|
|
110 |
#endif
|
|
111 |
|
|
112 |
#if defined(_MSC_VER)
|
|
113 |
#define memcpy_overlapping memcpy
|
|
114 |
#else
|
|
115 |
#define memcpy_overlapping memmove
|
|
116 |
#endif
|
|
117 |
|
|
118 |
#ifndef __BEOS__
|
|
119 |
typedef signed char int8;
|
|
120 |
typedef signed short int16;
|
|
121 |
typedef signed int int32;
|
|
122 |
#ifndef __cplusplus
|
|
123 |
typedef unsigned char bool;
|
|
124 |
#endif
|
|
125 |
typedef signed __int64 int64;
|
|
126 |
typedef unsigned __int64 uint64;
|
|
127 |
#endif
|
|
128 |
|
|
129 |
// Setup alignment and conversion macros
|
|
130 |
#if defined(TTD_BIG_ENDIAN)
|
|
131 |
# define TTD_ALIGNMENT_2
|
|
132 |
# define TTD_ALIGNMENT_4
|
|
133 |
static uint32 INLINE TO_LE32(uint32 x) { return BSWAP32(x); }
|
|
134 |
static uint16 INLINE TO_LE16(uint16 x) { return BSWAP16(x); }
|
|
135 |
# define TO_BE32(x) x
|
|
136 |
# define TO_BE16(x) x
|
|
137 |
#define TO_BE32X(x) x
|
|
138 |
#else
|
|
139 |
# define TO_LE32(x) x
|
|
140 |
# define TO_LE16(x) x
|
|
141 |
#define TO_BE32X(x) BSWAP32(x)
|
|
142 |
static uint32 FORCEINLINE TO_BE32(uint32 x) { return BSWAP32(x); }
|
|
143 |
static uint16 FORCEINLINE TO_BE16(uint16 x) { return BSWAP16(x); }
|
|
144 |
#endif
|
|
145 |
|
|
146 |
#if !defined(GAME_DATA_DIR)
|
|
147 |
#define GAME_DATA_DIR ""
|
|
148 |
#endif
|
|
149 |
|
|
150 |
#if !defined(PERSONAL_DIR)
|
|
151 |
#define PERSONAL_DIR ""
|
|
152 |
#endif
|
|
153 |
|
|
154 |
#ifndef __cplusplus
|
|
155 |
#ifndef __BEOS__
|
|
156 |
enum {
|
|
157 |
false = 0,
|
|
158 |
true = 1,
|
|
159 |
};
|
|
160 |
#endif
|
|
161 |
#endif
|
|
162 |
|
|
163 |
// Compile time assertions
|
|
164 |
#define assert_compile(expr) void __ct_assert__(int a[1 - 2 * !(expr)]);
|
|
165 |
|
|
166 |
assert_compile(sizeof(uint32) == 4);
|
|
167 |
assert_compile(sizeof(uint16) == 2);
|
|
168 |
assert_compile(sizeof(uint8) == 1);
|
|
169 |
|
|
170 |
#define lengthof(x) (sizeof(x)/sizeof(x[0]))
|
|
171 |
#define endof(x) (&x[lengthof(x)])
|
|
172 |
#ifndef offsetof
|
|
173 |
#define offsetof(s,m) (size_t)&(((s *)0)->m)
|
|
174 |
#endif
|
|
175 |
|
|
176 |
|
|
177 |
// take care of some name clashes on macos
|
|
178 |
#if defined(__APPLE__)
|
|
179 |
#define GetString OTTD_GetString
|
|
180 |
#define DrawString OTTD_DrawString
|
|
181 |
#define Random OTTD_Random
|
|
182 |
#endif
|
|
183 |
|
|
184 |
#endif // !defined(_STDAFX_H)
|