author | darkvater |
Sun, 19 Sep 2004 15:24:45 +0000 | |
changeset 289 | 1e1102dd2a62 |
parent 275 | 31a5354de6f4 |
child 425 | a8a07a6fbe1c |
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 |
||
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 |
|
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
|
65 |
# define vsnprintf _vsnprintf |
0 | 66 |
# undef TTD_ALIGNMENT_4 |
67 |
# undef TTD_ALIGNMENT_2 |
|
68 |
# define GCC_PACK |
|
69 |
#endif |
|
70 |
||
157
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
0
diff
changeset
|
71 |
// Windows has always LITTLE_ENDIAN |
0 | 72 |
#if defined(WIN32) |
157
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
0
diff
changeset
|
73 |
#define TTD_LITTLE_ENDIAN |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
0
diff
changeset
|
74 |
#else |
dd017fa3bad8
(svn r158) -Fix: make endianess check 100% accurate (hopefully ;))
truelight
parents:
0
diff
changeset
|
75 |
// 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
|
76 |
#include "endian.h" |
0 | 77 |
#endif |
78 |
||
79 |
#if defined(UNIX) |
|
80 |
#define PATHSEP "/" |
|
81 |
#else |
|
82 |
#define PATHSEP "\\" |
|
83 |
#endif |
|
84 |
||
85 |
||
86 |
typedef unsigned char byte; |
|
87 |
#ifndef __BEOS__ // already defined |
|
88 |
typedef unsigned char uint8; |
|
89 |
typedef unsigned short uint16; |
|
90 |
typedef unsigned int uint32; |
|
91 |
#endif |
|
92 |
||
93 |
// This is already defined in unix |
|
94 |
#if !defined(UNIX) && !defined(__CYGWIN__) |
|
95 |
typedef unsigned int uint; |
|
96 |
#endif |
|
97 |
||
98 |
#if defined(_MSC_VER) |
|
99 |
#define memcpy_overlapping memcpy |
|
100 |
#else |
|
101 |
#define memcpy_overlapping memmove |
|
102 |
#endif |
|
103 |
||
104 |
#ifndef __BEOS__ |
|
105 |
typedef signed char int8; |
|
106 |
typedef signed short int16; |
|
107 |
typedef signed int int32; |
|
108 |
#ifndef __cplusplus |
|
109 |
typedef unsigned char bool; |
|
110 |
#endif |
|
111 |
typedef signed __int64 int64; |
|
112 |
typedef unsigned __int64 uint64; |
|
113 |
#endif |
|
114 |
||
115 |
// Setup alignment and conversion macros |
|
116 |
#if defined(TTD_BIG_ENDIAN) |
|
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
117 |
|
0 | 118 |
# define TTD_ALIGNMENT_2 |
119 |
# define TTD_ALIGNMENT_4 |
|
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
120 |
|
0 | 121 |
static uint32 INLINE TO_LE32(uint32 x) { return BSWAP32(x); } |
122 |
static uint16 INLINE TO_LE16(uint16 x) { return BSWAP16(x); } |
|
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
123 |
static uint32 INLINE FROM_LE32(uint32 x) { return BSWAP32(x); } |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
124 |
static uint16 INLINE FROM_LE16(uint16 x) { return BSWAP16(x); } |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
125 |
#define TO_BE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
126 |
#define TO_BE16(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
127 |
#define FROM_BE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
128 |
#define FROM_BE16(x) x |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
157
diff
changeset
|
129 |
#define TO_BE32X(x) x |
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
130 |
|
0 | 131 |
#else |
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
132 |
|
0 | 133 |
static uint32 FORCEINLINE TO_BE32(uint32 x) { return BSWAP32(x); } |
134 |
static uint16 FORCEINLINE TO_BE16(uint16 x) { return BSWAP16(x); } |
|
275
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
135 |
static uint32 FORCEINLINE FROM_BE32(uint32 x) { return BSWAP32(x); } |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
136 |
static uint16 FORCEINLINE FROM_BE16(uint16 x) { return BSWAP16(x); } |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
137 |
#define TO_LE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
138 |
#define TO_LE16(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
139 |
#define TO_BE32X(x) BSWAP32(x) |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
140 |
#define FROM_LE32(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
141 |
#define FROM_LE16(x) x |
31a5354de6f4
(svn r281) -Fix: some endian issues fixed in network code
signde
parents:
193
diff
changeset
|
142 |
|
0 | 143 |
#endif |
144 |
||
145 |
#if !defined(GAME_DATA_DIR) |
|
146 |
#define GAME_DATA_DIR "" |
|
147 |
#endif |
|
148 |
||
149 |
#if !defined(PERSONAL_DIR) |
|
150 |
#define PERSONAL_DIR "" |
|
151 |
#endif |
|
152 |
||
153 |
#ifndef __cplusplus |
|
154 |
#ifndef __BEOS__ |
|
155 |
enum { |
|
156 |
false = 0, |
|
157 |
true = 1, |
|
158 |
}; |
|
159 |
#endif |
|
160 |
#endif |
|
161 |
||
162 |
// Compile time assertions |
|
163 |
#define assert_compile(expr) void __ct_assert__(int a[1 - 2 * !(expr)]); |
|
164 |
||
165 |
assert_compile(sizeof(uint32) == 4); |
|
166 |
assert_compile(sizeof(uint16) == 2); |
|
167 |
assert_compile(sizeof(uint8) == 1); |
|
168 |
||
169 |
#define lengthof(x) (sizeof(x)/sizeof(x[0])) |
|
170 |
#define endof(x) (&x[lengthof(x)]) |
|
171 |
#ifndef offsetof |
|
172 |
#define offsetof(s,m) (size_t)&(((s *)0)->m) |
|
173 |
#endif |
|
174 |
||
175 |
||
176 |
// take care of some name clashes on macos |
|
177 |
#if defined(__APPLE__) |
|
178 |
#define GetString OTTD_GetString |
|
179 |
#define DrawString OTTD_DrawString |
|
180 |
#define Random OTTD_Random |
|
181 |
#endif |
|
182 |
||
183 |
#endif // !defined(_STDAFX_H) |