author | tron |
Fri, 03 Dec 2004 07:43:00 +0000 | |
changeset 536 | aef4753985d3 |
parent 500 | ef288590e096 |
child 543 | e3b43338096b |
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) |
|
67 |
# define snprintf _snprintf |
|
289
1e1102dd2a62
(svn r295) -Fix: Rewrite and fix of console stuff, including marking (XXX) of areas that require further investigation (Tron)
darkvater
parents:
275
diff
changeset
|
68 |
# define vsnprintf _vsnprintf |
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 |
|
100 |
||
101 |
#ifndef __BEOS__ |
|
102 |
typedef signed char int8; |
|
103 |
typedef signed short int16; |
|
104 |
typedef signed int int32; |
|
105 |
#ifndef __cplusplus |
|
106 |
typedef unsigned char bool; |
|
107 |
#endif |
|
108 |
typedef signed __int64 int64; |
|
109 |
typedef unsigned __int64 uint64; |
|
110 |
#endif |
|
111 |
||
112 |
// Setup alignment and conversion macros |
|
113 |
#if defined(TTD_BIG_ENDIAN) |
|
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
114 |
|
0 | 115 |
# define TTD_ALIGNMENT_2 |
116 |
# define TTD_ALIGNMENT_4 |
|
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
117 |
|
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
446
diff
changeset
|
118 |
static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); } |
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
446
diff
changeset
|
119 |
static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); } |
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
446
diff
changeset
|
120 |
static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); } |
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
446
diff
changeset
|
121 |
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
|
122 |
#define TO_BE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
123 |
#define TO_BE16(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
124 |
#define FROM_BE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
125 |
#define FROM_BE16(x) x |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
157
diff
changeset
|
126 |
#define TO_BE32X(x) x |
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
127 |
|
0 | 128 |
#else |
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
129 |
|
536 | 130 |
static inline uint32 TO_BE32(uint32 x) { return BSWAP32(x); } |
131 |
static inline uint16 TO_BE16(uint16 x) { return BSWAP16(x); } |
|
132 |
static inline uint32 FROM_BE32(uint32 x) { return BSWAP32(x); } |
|
133 |
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
|
134 |
#define TO_LE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
135 |
#define TO_LE16(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
136 |
#define TO_BE32X(x) BSWAP32(x) |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
137 |
#define FROM_LE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
138 |
#define FROM_LE16(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
139 |
|
0 | 140 |
#endif |
141 |
||
142 |
#if !defined(GAME_DATA_DIR) |
|
143 |
#define GAME_DATA_DIR "" |
|
144 |
#endif |
|
145 |
||
146 |
#if !defined(PERSONAL_DIR) |
|
147 |
#define PERSONAL_DIR "" |
|
148 |
#endif |
|
149 |
||
150 |
#ifndef __cplusplus |
|
151 |
#ifndef __BEOS__ |
|
152 |
enum { |
|
153 |
false = 0, |
|
154 |
true = 1, |
|
155 |
}; |
|
156 |
#endif |
|
157 |
#endif |
|
158 |
||
159 |
// Compile time assertions |
|
536 | 160 |
#define assert_compile(expr) void __ct_assert__(int a[1 - 2 * !(expr)]) |
0 | 161 |
|
162 |
assert_compile(sizeof(uint32) == 4); |
|
163 |
assert_compile(sizeof(uint16) == 2); |
|
164 |
assert_compile(sizeof(uint8) == 1); |
|
165 |
||
166 |
#define lengthof(x) (sizeof(x)/sizeof(x[0])) |
|
167 |
#define endof(x) (&x[lengthof(x)]) |
|
168 |
#ifndef offsetof |
|
169 |
#define offsetof(s,m) (size_t)&(((s *)0)->m) |
|
170 |
#endif |
|
171 |
||
172 |
||
173 |
// take care of some name clashes on macos |
|
174 |
#if defined(__APPLE__) |
|
175 |
#define GetString OTTD_GetString |
|
176 |
#define DrawString OTTD_DrawString |
|
177 |
#define Random OTTD_Random |
|
178 |
#endif |
|
179 |
||
180 |
#endif // !defined(_STDAFX_H) |