author | bjarni |
Wed, 08 Dec 2004 16:27:54 +0000 | |
changeset 569 | 2e86ae517874 |
parent 543 | e3b43338096b |
child 770 | 89dab23f04ca |
permissions | -rw-r--r-- |
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 |
||
446
20304ea8e94e
(svn r655) Add the necessary bits to make building on SunOS/Solaris work
tron
parents:
425
diff
changeset
|
31 |
#ifdef SUNOS |
20304ea8e94e
(svn r655) Add the necessary bits to make building on SunOS/Solaris work
tron
parents:
425
diff
changeset
|
32 |
#include <alloca.h> |
20304ea8e94e
(svn r655) Add the necessary bits to make building on SunOS/Solaris work
tron
parents:
425
diff
changeset
|
33 |
#endif |
20304ea8e94e
(svn r655) Add the necessary bits to make building on SunOS/Solaris work
tron
parents:
425
diff
changeset
|
34 |
|
0 | 35 |
#define BSWAP32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | (((x) << 24) & 0xFF000000)) |
36 |
#define BSWAP16(x) ((x) >> 8 | (x) << 8) |
|
37 |
||
38 |
// by default we use [] var arrays |
|
39 |
#define VARARRAY_SIZE |
|
40 |
||
41 |
||
42 |
// Stuff for GCC |
|
43 |
#if defined(__GNUC__) |
|
44 |
# define NORETURN |
|
45 |
# define FORCEINLINE inline |
|
46 |
# define CDECL |
|
47 |
//#include <alloca.h> |
|
48 |
//#include <malloc.h> |
|
49 |
# define __int64 long long |
|
50 |
# define NOT_REACHED() |
|
51 |
# define GCC_PACK __attribute__((packed)) |
|
52 |
||
53 |
# if (__GNUC__ == 2) |
|
54 |
# undef VARARRAY_SIZE |
|
55 |
# define VARARRAY_SIZE 0 |
|
56 |
# endif |
|
57 |
#endif |
|
58 |
||
59 |
// Stuff for MSVC |
|
60 |
#if defined(_MSC_VER) |
|
61 |
# include <malloc.h> // alloca() |
|
62 |
# define NORETURN __declspec(noreturn) |
|
63 |
# define FORCEINLINE __forceinline |
|
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
446
diff
changeset
|
64 |
# define inline _inline |
0 | 65 |
# define CDECL _cdecl |
66 |
# define NOT_REACHED() _assume(0) |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
536
diff
changeset
|
67 |
int snprintf(char *str, size_t size, const char *format, ...); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
536
diff
changeset
|
68 |
int vsnprintf(char *str, size_t size, const char *format, va_list ap); |
0 | 69 |
# undef TTD_ALIGNMENT_4 |
70 |
# undef TTD_ALIGNMENT_2 |
|
71 |
# define GCC_PACK |
|
72 |
#endif |
|
73 |
||
157
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
0
diff
changeset
|
74 |
// Windows has always LITTLE_ENDIAN |
0 | 75 |
#if defined(WIN32) |
157
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
0
diff
changeset
|
76 |
#define TTD_LITTLE_ENDIAN |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
0
diff
changeset
|
77 |
#else |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
0
diff
changeset
|
78 |
// Else include endian.h, which has the endian-type, autodetected by the Makefile |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
0
diff
changeset
|
79 |
#include "endian.h" |
0 | 80 |
#endif |
81 |
||
82 |
#if defined(UNIX) |
|
83 |
#define PATHSEP "/" |
|
84 |
#else |
|
85 |
#define PATHSEP "\\" |
|
86 |
#endif |
|
87 |
||
88 |
||
89 |
typedef unsigned char byte; |
|
90 |
#ifndef __BEOS__ // already defined |
|
91 |
typedef unsigned char uint8; |
|
92 |
typedef unsigned short uint16; |
|
93 |
typedef unsigned int uint32; |
|
94 |
#endif |
|
95 |
||
96 |
// This is already defined in unix |
|
97 |
#if !defined(UNIX) && !defined(__CYGWIN__) |
|
98 |
typedef unsigned int uint; |
|
99 |
#endif |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
536
diff
changeset
|
100 |
// Not defined in QNX Neutrino (6.x) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
536
diff
changeset
|
101 |
#if defined(__QNXNTO__) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
536
diff
changeset
|
102 |
typedef unsigned int uint; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
536
diff
changeset
|
103 |
#endif |
0 | 104 |
|
105 |
#ifndef __BEOS__ |
|
106 |
typedef signed char int8; |
|
107 |
typedef signed short int16; |
|
108 |
typedef signed int int32; |
|
109 |
#ifndef __cplusplus |
|
110 |
typedef unsigned char bool; |
|
111 |
#endif |
|
112 |
typedef signed __int64 int64; |
|
113 |
typedef unsigned __int64 uint64; |
|
114 |
#endif |
|
115 |
||
116 |
// Setup alignment and conversion macros |
|
117 |
#if defined(TTD_BIG_ENDIAN) |
|
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
118 |
|
0 | 119 |
# define TTD_ALIGNMENT_2 |
120 |
# define TTD_ALIGNMENT_4 |
|
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
121 |
|
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
446
diff
changeset
|
122 |
static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); } |
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
446
diff
changeset
|
123 |
static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); } |
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
446
diff
changeset
|
124 |
static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); } |
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
446
diff
changeset
|
125 |
static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); } |
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
126 |
#define TO_BE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
127 |
#define TO_BE16(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
128 |
#define FROM_BE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
129 |
#define FROM_BE16(x) x |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
157
diff
changeset
|
130 |
#define TO_BE32X(x) x |
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
131 |
|
0 | 132 |
#else |
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
133 |
|
536 | 134 |
static inline uint32 TO_BE32(uint32 x) { return BSWAP32(x); } |
135 |
static inline uint16 TO_BE16(uint16 x) { return BSWAP16(x); } |
|
136 |
static inline uint32 FROM_BE32(uint32 x) { return BSWAP32(x); } |
|
137 |
static inline uint16 FROM_BE16(uint16 x) { return BSWAP16(x); } |
|
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
138 |
#define TO_LE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
139 |
#define TO_LE16(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
140 |
#define TO_BE32X(x) BSWAP32(x) |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
141 |
#define FROM_LE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
142 |
#define FROM_LE16(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
143 |
|
0 | 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 |
|
536 | 164 |
#define assert_compile(expr) void __ct_assert__(int a[1 - 2 * !(expr)]) |
0 | 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 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
536
diff
changeset
|
182 |
#define CloseConnection OTTD_CloseConnection |
0 | 183 |
#endif |
184 |
||
569
2e86ae517874
(svn r980) Fixed issues where MorphOS would get problems if AmigaOS would get a port, since MorphOS also have the flag __AMIGA__ defined (Tokai)
bjarni
parents:
543
diff
changeset
|
185 |
#if !(defined(__AMIGA__) && !defined(__MORPHOS__)) |
2e86ae517874
(svn r980) Fixed issues where MorphOS would get problems if AmigaOS would get a port, since MorphOS also have the flag __AMIGA__ defined (Tokai)
bjarni
parents:
543
diff
changeset
|
186 |
// it seems AmigaOS already have a Point declared |
2e86ae517874
(svn r980) Fixed issues where MorphOS would get problems if AmigaOS would get a port, since MorphOS also have the flag __AMIGA__ defined (Tokai)
bjarni
parents:
543
diff
changeset
|
187 |
#define Point OTTD_AMIGA_POINT |
2e86ae517874
(svn r980) Fixed issues where MorphOS would get problems if AmigaOS would get a port, since MorphOS also have the flag __AMIGA__ defined (Tokai)
bjarni
parents:
543
diff
changeset
|
188 |
#endif |
2e86ae517874
(svn r980) Fixed issues where MorphOS would get problems if AmigaOS would get a port, since MorphOS also have the flag __AMIGA__ defined (Tokai)
bjarni
parents:
543
diff
changeset
|
189 |
|
0 | 190 |
#endif // !defined(_STDAFX_H) |