2 |
2 |
3 #ifndef STDAFX_H |
3 #ifndef STDAFX_H |
4 #define STDAFX_H |
4 #define STDAFX_H |
5 |
5 |
6 #if defined(_MSC_VER) |
6 #if defined(_MSC_VER) |
7 #pragma once |
7 # pragma once |
8 |
8 # define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers |
9 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers |
9 # pragma warning(disable: 4018) // 'expression' : signed/unsigned mismatch |
10 #pragma warning(disable: 4018) // 'expression' : signed/unsigned mismatch |
10 # pragma warning(disable: 4100) // 'identifier' : unreferenced formal parameter |
11 #pragma warning(disable: 4100) // 'identifier' : unreferenced formal parameter |
11 # pragma warning(disable: 4127) // conditional expression is constant |
12 #pragma warning(disable: 4127) // conditional expression is constant |
12 # pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union |
13 #pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union |
13 # pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data |
14 #pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data |
14 # pragma warning(disable: 4245) // 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch |
15 #pragma warning(disable: 4245) // 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch |
15 # pragma warning(disable: 4276) // 'fucntion' : no prototype provided; assumed no parameters (MSVC BUG???) |
16 #pragma warning(disable: 4276) // 'fucntion' : no prototype provided; assumed no parameters (MSVC BUG???) |
16 # pragma warning(disable: 4305) // 'identifier' : truncation from 'type1' to 'type2' |
17 #pragma warning(disable: 4305) // 'identifier' : truncation from 'type1' to 'type2' |
17 # pragma warning(disable: 4514) // 'function' : unreferenced inline function has been removed |
18 #pragma warning(disable: 4514) // 'function' : unreferenced inline function has been removed |
18 # pragma warning(disable: 4761) // integral size mismatch in argument : conversion supplied |
19 #pragma warning(disable: 4761) // integral size mismatch in argument : conversion supplied |
19 #endif /* _MSC_VER */ |
20 #endif |
|
21 |
20 |
22 #include <stdio.h> |
21 #include <stdio.h> |
23 #include <string.h> |
22 #include <string.h> |
24 #include <stdlib.h> |
23 #include <stdlib.h> |
25 |
24 |
26 // MacOS X will use an NSAlert to display failed assertaions since they're lost unless running from a terminal |
25 // MacOS X will use an NSAlert to display failed assertaions since they're lost unless running from a terminal |
27 // strgen always runs from terminal and don't need a window for asserts |
26 // strgen always runs from terminal and don't need a window for asserts |
28 #if !defined(__APPLE__) || defined(STRGEN) |
27 #if !defined(__APPLE__) || defined(STRGEN) |
29 #include <assert.h> |
28 # include <assert.h> |
30 #else |
29 #else |
31 #include "os/macosx/macos.h" |
30 # include "os/macosx/macos.h" |
32 #endif |
31 #endif |
33 |
32 |
34 #if defined(UNIX) || defined(__MINGW32__) |
33 #if defined(UNIX) || defined(__MINGW32__) |
35 # include <sys/types.h> |
34 # include <sys/types.h> |
36 #endif |
35 #endif |
37 |
36 |
38 #if defined(__OS2__) |
37 #if defined(__OS2__) |
39 # include <types.h> |
38 # include <types.h> |
40 #endif |
39 #endif |
41 |
40 |
42 #ifdef __BEOS__ |
41 #ifdef __BEOS__ |
43 #include <SupportDefs.h> |
42 # include <SupportDefs.h> |
44 #endif |
43 #endif |
45 |
44 |
46 #ifdef SUNOS |
45 #ifdef SUNOS |
47 #include <alloca.h> |
46 # include <alloca.h> |
48 #endif |
47 #endif |
49 |
48 |
50 #ifdef __MORPHOS__ |
49 #ifdef __MORPHOS__ |
51 // morphos defines certain amiga defines per default, we undefine them |
50 // morphos defines certain amiga defines per default, we undefine them |
52 // here to make the rest of source less messy and more clear what is |
51 // here to make the rest of source less messy and more clear what is |
53 // required for morphos and what for amigaos |
52 // required for morphos and what for amigaos |
54 # ifdef amigaos |
53 # ifdef amigaos |
55 # undef amigaos |
54 # undef amigaos |
56 # endif |
55 # endif |
57 # ifdef __amigaos__ |
56 # ifdef __amigaos__ |
58 # undef __amigaos__ |
57 # undef __amigaos__ |
59 # endif |
58 # endif |
60 # ifdef __AMIGA__ |
59 # ifdef __AMIGA__ |
61 # undef __AMIGA__ |
60 # undef __AMIGA__ |
62 # endif |
61 # endif |
63 # ifdef AMIGA |
62 # ifdef AMIGA |
64 # undef AMIGA |
63 # undef AMIGA |
65 # endif |
64 # endif |
66 # ifdef amiga |
65 # ifdef amiga |
67 # undef amiga |
66 # undef amiga |
68 # endif |
67 # endif |
69 #endif /* __MORPHOS__ */ |
68 #endif /* __MORPHOS__ */ |
70 |
69 |
71 #define BSWAP32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | (((x) << 24) & 0xFF000000)) |
70 #define BSWAP32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | (((x) << 24) & 0xFF000000)) |
72 #define BSWAP16(x) ((x) >> 8 | (x) << 8) |
71 #define BSWAP16(x) ((x) >> 8 | (x) << 8) |
73 |
72 |
84 //#include <malloc.h> |
83 //#include <malloc.h> |
85 # define __int64 long long |
84 # define __int64 long long |
86 # define NOT_REACHED() assert(0) |
85 # define NOT_REACHED() assert(0) |
87 # define GCC_PACK __attribute__((packed)) |
86 # define GCC_PACK __attribute__((packed)) |
88 |
87 |
89 # if (__GNUC__ == 2) |
88 # if (__GNUC__ == 2) |
90 # undef VARARRAY_SIZE |
89 # undef VARARRAY_SIZE |
91 # define VARARRAY_SIZE 0 |
90 # define VARARRAY_SIZE 0 |
92 # endif |
91 # endif |
93 #endif |
92 #endif /* __GNUC__ */ |
94 |
93 |
95 #if defined(__WATCOMC__) |
94 #if defined(__WATCOMC__) |
96 # define NORETURN |
95 # define NORETURN |
97 # define FORCEINLINE inline |
96 # define FORCEINLINE inline |
98 # define CDECL |
97 # define CDECL |
99 # define NOT_REACHED() assert(0) |
98 # define NOT_REACHED() assert(0) |
100 # define GCC_PACK |
99 # define GCC_PACK |
101 # undef TTD_ALIGNMENT_4 |
100 # undef TTD_ALIGNMENT_4 |
102 # undef TTD_ALIGNMENT_2 |
101 # undef TTD_ALIGNMENT_2 |
103 |
102 # include <malloc.h> |
104 # include <malloc.h> |
103 #endif /* __WATCOMC__ */ |
105 #endif |
|
106 |
104 |
107 #if defined(__MINGW32__) || defined(__CYGWIN__) |
105 #if defined(__MINGW32__) || defined(__CYGWIN__) |
108 #include <malloc.h> // alloca() |
106 # include <malloc.h> // alloca() |
109 #endif |
107 #endif |
110 |
108 |
111 // Stuff for MSVC |
109 // Stuff for MSVC |
112 #if defined(_MSC_VER) |
110 #if defined(_MSC_VER) |
113 # include <malloc.h> // alloca() |
111 # include <malloc.h> // alloca() |
114 # define NORETURN __declspec(noreturn) |
112 # define NORETURN __declspec(noreturn) |
115 # define FORCEINLINE __forceinline |
113 # define FORCEINLINE __forceinline |
116 # define inline _inline |
114 # define inline _inline |
117 # define CDECL _cdecl |
115 # define CDECL _cdecl |
118 # if defined(_DEBUG) |
116 # if defined(_DEBUG) |
119 # define NOT_REACHED() assert(0) |
117 # define NOT_REACHED() assert(0) |
120 # else |
118 # else |
121 # define NOT_REACHED() _assume(0) |
119 # define NOT_REACHED() _assume(0) |
122 # endif |
120 # endif /* _DEBUG */ |
123 int CDECL snprintf(char *str, size_t size, const char *format, ...); |
121 int CDECL snprintf(char *str, size_t size, const char *format, ...); |
124 #if _MSC_VER < 1400 |
122 # if _MSC_VER < 1400 |
125 int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap); |
123 int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap); |
126 #endif |
124 # endif |
|
125 |
|
126 # if defined(WIN32) && !defined(_WIN64) && !defined(WIN64) |
|
127 # ifndef _W64 |
|
128 # define _W64 |
|
129 # endif |
|
130 typedef _W64 int INT_PTR, *PINT_PTR; |
|
131 typedef _W64 unsigned int UINT_PTR, *PUINT_PTR; |
|
132 # endif /* WIN32 && !_WIN64 && !WIN64 */ |
|
133 |
|
134 # if _MSC_VER < 1300 // VC6 and lower |
|
135 # ifdef _WIN64 |
|
136 typedef __int64 intptr_t; |
|
137 # else |
|
138 typedef _W64 int intptr_t; |
|
139 # endif |
|
140 # endif /* _MSC_VER < 1300 */ |
|
141 |
127 # undef TTD_ALIGNMENT_4 |
142 # undef TTD_ALIGNMENT_4 |
128 # undef TTD_ALIGNMENT_2 |
143 # undef TTD_ALIGNMENT_2 |
129 # define GCC_PACK |
144 # define GCC_PACK |
130 #endif |
145 #endif /* defined(_MSC_VER) */ |
131 |
146 |
132 // Needed for old PlatformSDK versions (e.g. VC6) |
|
133 #if defined(WIN32) && !defined(_WIN64) && !defined(WIN64) |
|
134 # ifndef _W64 |
|
135 # define _W64 |
|
136 # endif |
|
137 typedef _W64 int INT_PTR, *PINT_PTR; |
|
138 typedef _W64 unsigned int UINT_PTR, *PUINT_PTR; |
|
139 |
|
140 #ifndef _INTPTR_T_DEFINED |
|
141 #ifdef _WIN64 |
|
142 typedef __int64 intptr_t; |
|
143 #else |
|
144 typedef _W64 int intptr_t; |
|
145 #endif |
|
146 #define _INTPTR_T_DEFINED |
|
147 #endif |
|
148 |
|
149 #endif |
|
150 |
147 |
151 // Windows has always LITTLE_ENDIAN |
148 // Windows has always LITTLE_ENDIAN |
152 #if defined(WIN32) || defined(__OS2__) || defined(WIN64) |
149 #if defined(WIN32) || defined(__OS2__) || defined(WIN64) |
153 #define TTD_LITTLE_ENDIAN |
150 # define TTD_LITTLE_ENDIAN |
154 #else |
151 #else |
155 // Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile |
152 // Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile |
156 #if defined(STRGEN) |
153 # if defined(STRGEN) |
157 #include "endian_host.h" |
154 # include "endian_host.h" |
158 #else |
155 # else |
159 #include "endian_target.h" |
156 # include "endian_target.h" |
160 #endif |
157 # endif |
161 #endif |
158 #endif /* WIN32 || __OS2__ || WIN64 */ |
162 |
159 |
163 #if defined(UNIX) |
160 #if defined(UNIX) |
164 #define PATHSEP "/" |
161 # define PATHSEP "/" |
165 #else |
162 #else |
166 #define PATHSEP "\\" |
163 # define PATHSEP "\\" |
167 #endif |
164 #endif |
168 |
|
169 |
165 |
170 typedef unsigned char byte; |
166 typedef unsigned char byte; |
171 #ifndef __BEOS__ // already defined |
167 #ifndef __BEOS__ // already defined |
172 typedef unsigned char uint8; |
168 typedef unsigned char uint8; |
173 typedef unsigned short uint16; |
169 typedef unsigned short uint16; |
174 typedef unsigned int uint32; |
170 typedef unsigned int uint32; |
175 #endif |
171 #endif |
176 |
172 |
177 // This is already defined in unix |
173 // This is already defined in unix |
178 #if !defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) |
174 #if !defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) |
179 typedef unsigned int uint; |
175 typedef unsigned int uint; |
180 #endif |
176 #endif |
181 // Not defined in QNX Neutrino (6.x) |
177 // Not defined in QNX Neutrino (6.x) |
182 #if defined(__QNXNTO__) |
178 #if defined(__QNXNTO__) |
183 typedef unsigned int uint; |
179 typedef unsigned int uint; |
184 #endif |
180 #endif |
185 |
181 |
186 #ifndef __BEOS__ |
182 #ifndef __BEOS__ |
187 typedef signed char int8; |
183 typedef signed char int8; |
188 typedef signed short int16; |
184 typedef signed short int16; |
189 typedef signed int int32; |
185 typedef signed int int32; |
190 #ifndef __cplusplus |
186 # ifndef __cplusplus |
191 typedef unsigned char bool; |
187 typedef unsigned char bool; |
192 #endif |
188 # endif |
193 typedef signed __int64 int64; |
189 typedef signed __int64 int64; |
194 typedef unsigned __int64 uint64; |
190 typedef unsigned __int64 uint64; |
195 #endif |
191 #endif /* __BEOS__ */ |
196 |
192 |
197 // Setup alignment and conversion macros |
193 // Setup alignment and conversion macros |
198 #if defined(TTD_BIG_ENDIAN) |
194 #if defined(TTD_BIG_ENDIAN) |
199 |
|
200 # define TTD_ALIGNMENT_2 |
195 # define TTD_ALIGNMENT_2 |
201 # define TTD_ALIGNMENT_4 |
196 # define TTD_ALIGNMENT_4 |
202 |
197 static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); } |
203 static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); } |
198 static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); } |
204 static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); } |
199 static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); } |
205 static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); } |
200 static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); } |
206 static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); } |
201 # define TO_BE32(x) x |
207 #define TO_BE32(x) x |
202 # define TO_BE16(x) x |
208 #define TO_BE16(x) x |
203 # define FROM_BE32(x) x |
209 #define FROM_BE32(x) x |
204 # define FROM_BE16(x) x |
210 #define FROM_BE16(x) x |
205 # define TO_BE32X(x) x |
211 #define TO_BE32X(x) x |
206 #else |
212 |
207 static inline uint32 TO_BE32(uint32 x) { return BSWAP32(x); } |
213 #else |
208 static inline uint16 TO_BE16(uint16 x) { return BSWAP16(x); } |
214 |
209 static inline uint32 FROM_BE32(uint32 x) { return BSWAP32(x); } |
215 static inline uint32 TO_BE32(uint32 x) { return BSWAP32(x); } |
210 static inline uint16 FROM_BE16(uint16 x) { return BSWAP16(x); } |
216 static inline uint16 TO_BE16(uint16 x) { return BSWAP16(x); } |
211 # define TO_LE32(x) x |
217 static inline uint32 FROM_BE32(uint32 x) { return BSWAP32(x); } |
212 # define TO_LE16(x) x |
218 static inline uint16 FROM_BE16(uint16 x) { return BSWAP16(x); } |
213 # define TO_BE32X(x) BSWAP32(x) |
219 #define TO_LE32(x) x |
214 # define FROM_LE32(x) x |
220 #define TO_LE16(x) x |
215 # define FROM_LE16(x) x |
221 #define TO_BE32X(x) BSWAP32(x) |
216 #endif /* TTD_BIG_ENDIAN */ |
222 #define FROM_LE32(x) x |
|
223 #define FROM_LE16(x) x |
|
224 |
|
225 #endif |
|
226 |
217 |
227 #if !defined(GAME_DATA_DIR) |
218 #if !defined(GAME_DATA_DIR) |
228 #define GAME_DATA_DIR "" |
219 # define GAME_DATA_DIR "" |
229 #endif |
220 #endif |
230 |
221 |
231 #if !defined(PERSONAL_DIR) |
222 #if !defined(PERSONAL_DIR) |
232 #define PERSONAL_DIR "" |
223 # define PERSONAL_DIR "" |
233 #endif |
224 #endif |
234 |
225 |
235 #ifndef __cplusplus |
226 #ifndef __cplusplus |
236 #ifndef __BEOS__ |
227 # ifndef __BEOS__ |
237 enum { |
228 enum { |
238 false = 0, |
229 false = 0, |
239 true = 1, |
230 true = 1, |
240 }; |
231 }; |
241 #endif |
232 # endif |
242 #endif |
233 #endif /* __cplusplus */ |
243 |
234 |
244 // Compile time assertions |
235 // Compile time assertions |
245 #ifdef __OS2__ |
236 #ifdef __OS2__ |
246 # define assert_compile(expr) |
237 # define assert_compile(expr) |
247 #else |
238 #else |
248 # define assert_compile(expr) void __ct_assert__(int a[1 - 2 * !(expr)]) |
239 # define assert_compile(expr) void __ct_assert__(int a[1 - 2 * !(expr)]) |
249 #endif |
240 #endif |
250 |
241 |
251 assert_compile(sizeof(uint32) == 4); |
242 assert_compile(sizeof(uint32) == 4); |
252 assert_compile(sizeof(uint16) == 2); |
243 assert_compile(sizeof(uint16) == 2); |
253 assert_compile(sizeof(uint8) == 1); |
244 assert_compile(sizeof(uint8) == 1); |
254 |
245 |
255 #define lengthof(x) (sizeof(x)/sizeof(x[0])) |
246 #define lengthof(x) (sizeof(x)/sizeof(x[0])) |
256 #define endof(x) (&x[lengthof(x)]) |
247 #define endof(x) (&x[lengthof(x)]) |
257 #define lastof(x) (&x[lengthof(x) - 1]) |
248 #define lastof(x) (&x[lengthof(x) - 1]) |
258 #ifndef offsetof |
249 #ifndef offsetof |
259 #define offsetof(s,m) (size_t)&(((s *)0)->m) |
250 # define offsetof(s,m) (size_t)&(((s *)0)->m) |
260 #endif |
251 #endif |
261 |
252 |
262 |
253 |
263 // take care of some name clashes on macos |
254 // take care of some name clashes on macos |
264 #if defined(__APPLE__) |
255 #if defined(__APPLE__) |
265 #define GetString OTTD_GetString |
256 # define GetString OTTD_GetString |
266 #define DrawString OTTD_DrawString |
257 # define DrawString OTTD_DrawString |
267 #define Random OTTD_Random |
258 # define Random OTTD_Random |
268 #define CloseConnection OTTD_CloseConnection |
259 # define CloseConnection OTTD_CloseConnection |
269 #endif |
260 #endif /* __APPLE */ |
270 |
261 |
271 #ifdef __AMIGA__ |
262 #ifdef __AMIGA__ |
272 // it seems AmigaOS already have a Point declared |
263 // it seems AmigaOS already have a Point declared |
273 #define Point OTTD_AMIGA_POINT |
264 # define Point OTTD_AMIGA_POINT |
274 #endif |
265 #endif |
275 |
266 |
276 #endif /* STDAFX_H */ |
267 #endif /* STDAFX_H */ |