1 // SONIC ROBO BLAST 2
2 //-----------------------------------------------------------------------------
3 // Copyright (C) 1993-1996 by id Software, Inc.
4 // Copyright (C) 1998-2000 by DooM Legacy Team.
5 // Copyright (C) 1999-2020 by Sonic Team Junior.
6 //
7 // This program is free software distributed under the
8 // terms of the GNU General Public License, version 2.
9 // See the 'LICENSE' file for more details.
10 //-----------------------------------------------------------------------------
11 /// \file  doomtype.h
12 /// \brief SRB2 standard types
13 ///
14 ///        Simple basic typedefs, isolated here to make it easier
15 ///        separating modules.
16 
17 #ifndef __DOOMTYPE__
18 #define __DOOMTYPE__
19 
20 #ifdef _WIN32
21 //#define WIN32_LEAN_AND_MEAN
22 #define RPC_NO_WINDOWS_H
23 #include <windows.h>
24 #endif
25 
26 /* 7.18.1.1  Exact-width integer types */
27 #ifdef _MSC_VER
28 // libopenmpt.h will include stdint.h later;
29 // include it now so that INT8_MAX etc. don't get redefined
30 #ifdef HAVE_OPENMPT
31 #include <stdint.h>
32 #endif
33 
34 #define UINT8 unsigned __int8
35 #define SINT8 signed __int8
36 
37 #define UINT16 unsigned __int16
38 #define INT16 __int16
39 
40 #define INT32 __int32
41 #define UINT32 unsigned __int32
42 
43 #define INT64  __int64
44 #define UINT64 unsigned __int64
45 
46 typedef long ssize_t;
47 
48 /* Older Visual C++ headers don't have the Win64-compatible typedefs... */
49 #if (_MSC_VER <= 1200)
50 	#ifndef DWORD_PTR
51 		#define DWORD_PTR DWORD
52 	#endif
53 	#ifndef PDWORD_PTR
54 		#define PDWORD_PTR PDWORD
55 	#endif
56 #endif
57 #elif defined (__DJGPP__)
58 #define UINT8 unsigned char
59 #define SINT8 signed char
60 
61 #define UINT16 unsigned short int
62 #define INT16 signed short int
63 
64 #define INT32 signed long
65 #define UINT32 unsigned long
66 #define INT64  signed long long
67 #define UINT64 unsigned long long
68 #else
69 #define __STDC_LIMIT_MACROS
70 #include <stdint.h>
71 
72 #define UINT8 uint8_t
73 #define SINT8 int8_t
74 
75 #define UINT16 uint16_t
76 #define INT16 int16_t
77 
78 #define INT32 int32_t
79 #define UINT32 uint32_t
80 #define INT64  int64_t
81 #define UINT64 uint64_t
82 #endif
83 
84 #ifdef __APPLE_CC__
85 #define DIRECTFULLSCREEN 1
86 #define DEBUG_LOG
87 #define NOIPX
88 #endif
89 
90 /* Strings and some misc platform specific stuff */
91 
92 #ifdef _MSC_VER
93 	// Microsoft VisualC++
94 #if (_MSC_VER <= 1800) // MSVC 2013 and back
95 	#define snprintf                _snprintf
96 #if (_MSC_VER <= 1200) // MSVC 6.0 and back
97 	#define vsnprintf               _vsnprintf
98 #endif
99 #endif
100 	#define strncasecmp             strnicmp
101 	#define strcasecmp              stricmp
102 	#define inline                  __inline
103 #elif defined (__WATCOMC__)
104 	#include <dos.h>
105 	#include <sys\types.h>
106 	#include <direct.h>
107 	#include <malloc.h>
108 	#define strncasecmp             strnicmp
109 	#define strcasecmp              strcmpi
110 #endif
111 #if (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON)
112 	#undef stricmp
113 	#define stricmp(x,y) strcasecmp(x,y)
114 	#undef strnicmp
115 	#define strnicmp(x,y,n) strncasecmp(x,y,n)
116 #endif
117 
118 char *strcasestr(const char *in, const char *what);
119 #define stristr strcasestr
120 
121 #if defined (macintosh) //|| defined (__APPLE__) //skip all boolean/Boolean crap
122 	#define true 1
123 	#define false 0
124 	#define min(x,y) (((x)<(y)) ? (x) : (y))
125 	#define max(x,y) (((x)>(y)) ? (x) : (y))
126 
127 #ifdef macintosh
128 	#define stricmp strcmp
129 	#define strnicmp strncmp
130 #endif
131 
132 	#define boolean INT32
133 
134 	#ifndef O_BINARY
135 	#define O_BINARY 0
136 	#endif
137 #endif //macintosh
138 
139 #if defined (PC_DOS) || defined (_WIN32) || defined (__HAIKU__)
140 #define HAVE_DOSSTR_FUNCS
141 #endif
142 
143 #ifndef HAVE_DOSSTR_FUNCS
144 int strupr(char *n); // from dosstr.c
145 int strlwr(char *n); // from dosstr.c
146 #endif
147 
148 #include <stddef.h> // for size_t
149 
150 #ifndef __APPLE__
151 size_t strlcat(char *dst, const char *src, size_t siz);
152 size_t strlcpy(char *dst, const char *src, size_t siz);
153 #endif
154 
155 // Macro for use with char foo[FOOSIZE+1] type buffers.
156 // Never use this with a buffer that is a "char *" or passed
157 // into the function as an argument.
158 //
159 // In those cases sizeof will return the size of the pointer,
160 // not the number of bytes in the buffer.
161 #define STRBUFCPY(dst,src) strlcpy(dst, src, sizeof dst)
162 
163 /* Boolean type definition */
164 
165 // \note __BYTEBOOL__ used to be set above if "macintosh" was defined,
166 // if macintosh's version of boolean type isn't needed anymore, then isn't this macro pointless now?
167 #ifndef __BYTEBOOL__
168 	#define __BYTEBOOL__
169 
170 	//faB: clean that up !!
171 	#if defined( _MSC_VER)  && (_MSC_VER >= 1800) // MSVC 2013 and forward
172 		#include "stdbool.h"
173 	#elif defined (_WIN32)
174 		#define false   FALSE           // use windows types
175 		#define true    TRUE
176 		#define boolean BOOL
177 	#else
178 		typedef enum {false, true} boolean;
179 	#endif
180 #endif // __BYTEBOOL__
181 
182 /* 7.18.2.1  Limits of exact-width integer types */
183 
184 #ifndef INT8_MIN
185 #define INT8_MIN (-128)
186 #endif
187 #ifndef INT16_MIN
188 #define INT16_MIN (-32768)
189 #endif
190 #ifndef INT32_MIN
191 #define INT32_MIN (-2147483647 - 1)
192 #endif
193 #ifndef INT64_MIN
194 #define INT64_MIN  (-9223372036854775807LL - 1)
195 #endif
196 
197 #ifndef INT8_MAX
198 #define INT8_MAX 127
199 #endif
200 #ifndef INT16_MAX
201 #define INT16_MAX 32767
202 #endif
203 #ifndef INT32_MAX
204 #define INT32_MAX 2147483647
205 #endif
206 #ifndef INT64_MAX
207 #define INT64_MAX 9223372036854775807LL
208 #endif
209 
210 #ifndef UINT8_MAX
211 #define UINT8_MAX 0xff /* 255U */
212 #endif
213 #ifndef UINT16_MAX
214 #define UINT16_MAX 0xffff /* 65535U */
215 #endif
216 #ifndef UINT32_MAX
217 #define UINT32_MAX 0xffffffff  /* 4294967295U */
218 #endif
219 #ifndef UINT64_MAX
220 #define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
221 #endif
222 
223 /* Compiler-specific attributes and other macros */
224 
225 #ifdef __GNUC__ // __attribute__ ((X))
226 	#define FUNCNORETURN __attribute__ ((noreturn))
227 
228 	#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && defined (__MINGW32__) // MinGW, >= GCC 4.1
229 		#include "inttypes.h"
230 		#if 0 //defined  (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO > 0
231 			#define FUNCPRINTF __attribute__ ((format(gnu_printf, 1, 2)))
232 			#define FUNCDEBUG  __attribute__ ((format(gnu_printf, 2, 3)))
233 			#define FUNCIERROR __attribute__ ((format(gnu_printf, 1, 2),noreturn))
234 		#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) // >= GCC 4.4
235 			#define FUNCPRINTF __attribute__ ((format(ms_printf, 1, 2)))
236 			#define FUNCDEBUG  __attribute__ ((format(ms_printf, 2, 3)))
237 			#define FUNCIERROR __attribute__ ((format(ms_printf, 1, 2),noreturn))
238 		#else
239 			#define FUNCPRINTF __attribute__ ((format(printf, 1, 2)))
240 			#define FUNCDEBUG  __attribute__ ((format(printf, 2, 3)))
241 			#define FUNCIERROR __attribute__ ((format(printf, 1, 2),noreturn))
242 		#endif
243 	#else
244 		#define FUNCPRINTF __attribute__ ((format(printf, 1, 2)))
245 		#define FUNCDEBUG  __attribute__ ((format(printf, 2, 3)))
246 		#define FUNCIERROR __attribute__ ((format(printf, 1, 2),noreturn))
247 	#endif
248 
249 	#ifndef FUNCIERROR
250 		#define FUNCIERROR __attribute__ ((noreturn))
251 	#endif
252 
253 	#define FUNCMATH __attribute__((const))
254 
255 	#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) // >= GCC 3.1
256 		#define FUNCDEAD __attribute__ ((deprecated))
257 		#define FUNCINLINE __attribute__((always_inline))
258 		#define FUNCNONNULL __attribute__((nonnull))
259 	#endif
260 
261 	#define FUNCNOINLINE __attribute__((noinline))
262 
263 	#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) // >= GCC 4.4
264 		#ifdef __i386__ // i386 only
265 			#define FUNCTARGET(X)  __attribute__ ((__target__ (X)))
266 		#endif
267 	#endif
268 
269 	#if defined (__MINGW32__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) // MinGW, >= GCC 3.4
270 		#define ATTRPACK __attribute__((packed, gcc_struct))
271 	#else
272 		#define ATTRPACK __attribute__((packed))
273 	#endif
274 
275 	#define ATTRUNUSED __attribute__((unused))
276 #elif defined (_MSC_VER)
277 	#define ATTRNORETURN __declspec(noreturn)
278 	#define ATTRINLINE __forceinline
279 	#if _MSC_VER > 1200 // >= MSVC 6.0
280 		#define ATTRNOINLINE __declspec(noinline)
281 	#endif
282 #endif
283 
284 #ifndef FUNCPRINTF
285 #define FUNCPRINTF
286 #endif
287 #ifndef FUNCDEBUG
288 #define FUNCDEBUG
289 #endif
290 #ifndef FUNCNORETURN
291 #define FUNCNORETURN
292 #endif
293 #ifndef FUNCIERROR
294 #define FUNCIERROR
295 #endif
296 #ifndef FUNCMATH
297 #define FUNCMATH
298 #endif
299 #ifndef FUNCDEAD
300 #define FUNCDEAD
301 #endif
302 #ifndef FUNCINLINE
303 #define FUNCINLINE
304 #endif
305 #ifndef FUNCNONNULL
306 #define FUNCNONNULL
307 #endif
308 #ifndef FUNCNOINLINE
309 #define FUNCNOINLINE
310 #endif
311 #ifndef FUNCTARGET
312 #define FUNCTARGET(x)
313 #endif
314 #ifndef ATTRPACK
315 #define ATTRPACK
316 #endif
317 #ifndef ATTRUNUSED
318 #define ATTRUNUSED
319 #endif
320 #ifndef ATTRNORETURN
321 #define ATTRNORETURN
322 #endif
323 #ifndef ATTRINLINE
324 #define ATTRINLINE inline
325 #endif
326 #ifndef ATTRNOINLINE
327 #define ATTRNOINLINE
328 #endif
329 
330 /* Miscellaneous types that don't fit anywhere else (Can this be changed?) */
331 
332 typedef struct
333 {
334 	UINT8 red;
335 	UINT8 green;
336 	UINT8 blue;
337 	UINT8 alpha;
338 } byteColor_t;
339 
340 union FColorRGBA
341 {
342 	UINT32 rgba;
343 	byteColor_t s;
344 } ATTRPACK;
345 typedef union FColorRGBA RGBA_t;
346 
347 typedef enum
348 {
349 	postimg_none,
350 	postimg_water,
351 	postimg_motion,
352 	postimg_flip,
353 	postimg_heat
354 } postimg_t;
355 
356 typedef UINT32 lumpnum_t; // 16 : 16 unsigned long (wad num: lump num)
357 #define LUMPERROR UINT32_MAX
358 
359 typedef UINT32 tic_t;
360 #define INFTICS UINT32_MAX
361 
362 #include "endian.h" // This is needed to make sure the below macro acts correctly in big endian builds
363 
364 #ifdef SRB2_BIG_ENDIAN
365 #define UINT2RGBA(a) a
366 #else
367 #define UINT2RGBA(a) (UINT32)((a&0xff)<<24)|((a&0xff00)<<8)|((a&0xff0000)>>8)|(((UINT32)a&0xff000000)>>24)
368 #endif
369 
370 /* preprocessor dumb and needs second macro to expand input */
371 #define WSTRING2(s) L ## s
372 #define WSTRING(s) WSTRING2 (s)
373 
374 /*
375 A hack by Monster Iestyn: Return a pointer to a field of
376 a struct from a pointer to another field in the struct.
377 Needed for some lua shenanigans.
378 */
379 #define FIELDFROM( type, field, have, want ) \
380 	(void *)((intptr_t)(field) - offsetof (type, have) + offsetof (type, want))
381 
382 typedef UINT8 bitarray_t;
383 
384 #define BIT_ARRAY_SIZE(n) (((n) + 7) >> 3)
385 
386 static inline int
in_bit_array(const bitarray_t * const array,const int value)387 in_bit_array (const bitarray_t * const array, const int value)
388 {
389 	return (array[value >> 3] & (1<<(value & 7)));
390 }
391 
392 static inline void
set_bit_array(bitarray_t * const array,const int value)393 set_bit_array (bitarray_t * const array, const int value)
394 {
395 	array[value >> 3] |= (1<<(value & 7));
396 }
397 
398 static inline void
unset_bit_array(bitarray_t * const array,const int value)399 unset_bit_array (bitarray_t * const array, const int value)
400 {
401 	array[value >> 3] &= ~(1<<(value & 7));
402 }
403 
404 #ifdef HAVE_SDL
405 typedef UINT64 precise_t;
406 #endif
407 
408 #endif //__DOOMTYPE__
409