1 // Emacs style mode select -*- C++ -*- 2 //----------------------------------------------------------------------------- 3 // 4 // $Id: doomtype.h 1544 2020-08-22 02:40:35Z wesleyjohnson $ 5 // 6 // Copyright (C) 1993-1996 by id Software, Inc. 7 // Copyright (C) 1998-2016 by DooM Legacy Team. 8 // 9 // This program is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU General Public License 11 // as published by the Free Software Foundation; either version 2 12 // of the License, or (at your option) any later version. 13 // 14 // This program is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // 20 // $Log: doomtype.h,v $ 21 // Revision 1.8 2001/05/16 22:33:34 bock 22 // Initial FreeBSD support. 23 // 24 // Revision 1.7 2001/04/17 22:26:07 calumr 25 // Initial Mac add 26 // 27 // Revision 1.6 2001/02/24 13:35:19 bpereira 28 // Revision 1.5 2000/11/02 19:49:35 bpereira 29 // Revision 1.4 2000/10/21 08:43:28 bpereira 30 // 31 // Revision 1.3 2000/08/10 14:53:57 ydario 32 // OS/2 port 33 // 34 // Revision 1.2 2000/02/27 00:42:10 hurdler 35 // Revision 1.1.1.1 2000/02/22 20:32:32 hurdler 36 // Initial import into CVS (v1.29 pr3) 37 // 38 // 39 // DESCRIPTION: 40 // doom games standard types 41 // Simple basic typedefs, isolated here to make it easier 42 // separating modules. 43 // Dependent upon system and compile flags, but not dependent upon 44 // doomdef.h. 45 // 46 //----------------------------------------------------------------------------- 47 48 #ifndef DOOMTYPE_H 49 #define DOOMTYPE_H 50 // General type defines, not dependent upon doomdef.h 51 52 #include <stdint.h> 53 54 #if defined( __WATCOMC__) && defined( _M_I386) 55 // _M_I386 means 32bit Intel 56 #ifndef WIN32 57 # define WIN32 58 #endif 59 #ifndef __WIN32__ 60 # define __WIN32__ 61 #endif 62 #endif 63 64 #ifdef WIN32 65 #define WINVER 0x0500 // require windows 2k or later 66 #include <windows.h> 67 #else 68 // WIN32 standard headers already define these! 69 // TODO this is just a temporary measure, all USHORT / ULONG / INT64 instances 70 // in the code should be changed to stdint.h types or basic types 71 typedef uint32_t ULONG; 72 typedef uint16_t USHORT; 73 typedef int64_t INT64; 74 #endif 75 76 // boolean type 77 #if defined( __APPLE_CC__ ) && ! defined( __GNUC__ ) 78 # define boolean int 79 # define false 0 80 # define true 1 81 #elif defined(WIN32) 82 # define false FALSE // use windows types 83 # define true TRUE 84 # define boolean BOOL 85 #else 86 typedef enum {false, true} boolean; 87 #endif 88 89 90 typedef uint8_t byte; 91 typedef uint32_t tic_t; 92 93 // Return values 94 // Positive are positive indicators 95 // 0 is NULL result 96 // Negative are failure indicators 97 typedef enum { 98 FAIL = -1, // general fail 99 FAIL_end = -2, // end of valid input 100 FAIL_invalid_input = -3, // invalid input to the function 101 FAIL_create = -100, 102 FAIL_memory = -101, 103 FAIL_select = -102, 104 } status_return_e; 105 106 typedef enum { 107 FS_NOTFOUND, 108 FS_FOUND, 109 FS_REQUESTED, 110 FS_DOWNLOADING, 111 FS_OPEN, // is opened and used in w_wad 112 FS_MD5SUMBAD, 113 FS_SECURITY, // rejected for security reasons 114 FS_FILEERR, // access error 115 FS_INVALID, // invalid for the operation 116 FS_NOTWAD, 117 FS_ZIP, 118 } filestatus_e; 119 120 #ifdef __APPLE_CC__ 121 // Apple GNAT, GNU C 4.5, __APPLE_CC__ == 1 122 // Apple C 4.2, __APPLE_CC__ == 5666 123 // They define __MACH__, __GNUC__, and conditionally __BIG_ENDIAN__ 124 // Do not use __LITTLE_ENDIAN__, it is not defined on WIN, LINUX 125 # ifdef SMIF_SDL 126 // Mac on SDL, is like Linux 127 // Can also test for __APPLE_CC__ or __MACH__ 128 # define MAC_SDL 129 # else 130 // Hardware direct interface using macos directory (NOT SDL) 131 # define MACOS_DI 132 # define DEBUG_LOG 133 # ifndef HWRENDER 134 # define HWRENDER 135 # endif 136 # endif 137 #endif 138 139 #ifdef __GNUC__ 140 // Mingw32 ignores this. 141 #define PACKED_ATTR __attribute__((packed)) 142 #else 143 #define PACKED_ATTR 144 #endif 145 146 #ifdef WIN32 147 # define ASMCALL __cdecl 148 #else 149 # define ASMCALL 150 #endif 151 152 // [WDJ] This program uses strcasecmp, strncasecmp. 153 #if defined( __MSC__) || defined( __OS2__) 154 // Microsoft VisualC++ 155 #define strncasecmp strnicmp 156 #define strcasecmp stricmp 157 #define inline __inline 158 #else 159 #ifdef __WATCOMC__ 160 #include <dos.h> 161 #include <sys\types.h> 162 #include <direct.h> 163 #include <malloc.h> 164 #define strncasecmp strnicmp 165 #define strcasecmp strcmpi 166 #endif 167 #endif 168 169 170 #if !defined(WIN32) && !defined(__WINDOWS__) 171 #define min(x,y) ( ((x)<(y)) ? (x) : (y) ) 172 #define max(x,y) ( ((x)>(y)) ? (x) : (y) ) 173 174 int strupr(char *n); 175 int strlwr(char *n); 176 #endif 177 178 #ifndef O_BINARY 179 #define O_BINARY 0 // stupid windows text files 180 #endif 181 182 183 // [WDJ] This is needs to be fixed throughout all the files. 184 // But, not until it is determined which systems support which names. 185 // Predefined with some OS. 186 #ifdef __WIN32__ 187 #include <limits.h> 188 #elif defined( MACOS_DI ) || defined( __MACH__ ) || defined( FREEBSD ) || defined( NETBSD ) 189 #include <limits.h> 190 #else 191 // Linux GNU, which also includes limits.h 192 // obsolete header file 193 //#include <values.h> 194 #include <limits.h> 195 #endif 196 197 #if ! defined(MAXINT) && defined( INT_MAX ) 198 // [WDJ] Define the values.h symbols using defines from limits.h. 199 // This is what values.h does now. 200 #define MAXINT INT_MAX 201 #define MININT INT_MIN 202 #endif 203 #if ! defined(MAXCHAR) && defined( CHAR_MAX ) 204 #define MAXCHAR CHAR_MAX 205 #define MINCHAR CHAR_MIN 206 #endif 207 #if ! defined(MAXSHORT) && defined( SHRT_MAX ) 208 #define MAXSHORT SHRT_MAX 209 #define MINSHORT SHRT_MIN 210 #endif 211 212 #if 0 213 // [WDJ] This is very dangerous considering 32 bit and 64 bit systems, 214 // should use stdint.h values instead. 215 // These are obsolete defines from values.h. 216 #ifndef MAXCHAR 217 // unused 218 #define MAXCHAR ((char)0x7f) 219 #endif 220 221 #ifndef MAXSHORT 222 // defined in values.h 223 // used in r_segs.c 224 #define MAXSHORT ((short)0x7fff) 225 #endif 226 227 #ifndef MAXINT 228 // defined in values.h 229 // used in many places 230 #define MAXINT ((int)0x7fffffff) 231 #endif 232 233 #ifndef MINCHAR 234 // unused 235 #define MINCHAR ((char)0x80) 236 #endif 237 238 #ifndef MINSHORT 239 // defined in values.h 240 // unused 241 #define MINSHORT ((short)0x8000) 242 #endif 243 244 #ifndef MININT 245 // defined in values.h 246 // used in many places 247 #define MININT ((int)0x80000000) 248 #endif 249 #endif 250 251 // Sound effect id type. 252 typedef uint16_t sfxid_t; 253 254 // This is compatible with SDL_color (R,G,B,-). 255 typedef union { 256 uint32_t rgba; 257 struct { // component memory order ( R, G, B, A ) 258 byte red; // LITTLE_ENDIAN LSB 259 byte green; 260 byte blue; 261 byte alpha; 262 } s; 263 } RGBA_t; 264 265 // [WDJ] Note that RGBA cannot be trusted to be the order of the components. 266 // SDL uses the term RGBA, SDL opengl uses it extensively. 267 // The literal RGBA() is the same order as RGBA_t, which works for SDL calls, 268 // The order of RGBA in memory is (A,B,G,R). 269 // BIG_ENDIAN that is (A,B,G,R), and LITTLE_ENDIAN is (R,G,B,A). 270 // UINT2RGBA reverses the byte order for LITTLE_ENDIAN, which is often not 271 // what you want. Mostly, it is just confusing, so avoid it. 272 // SDL_PixelFormat identifies the actual component order and fields. 273 // The component order for 32bit pixels in video buffers is (A,R,G,B), 274 // which is different. 275 276 #ifdef __BIG_ENDIAN__ 277 // __BIG_ENDIAN__ is defined on MAC compilers, not on WIN, nor LINUX 278 #define UINT2RGBA(a) a 279 #define RGBA( r, g, b, a ) (((r)<<24)|((g)<<16)|((b)<<8)|(a)) 280 #else 281 #define UINT2RGBA(a) (((a)&0xff)<<24)|(((a)&0xff00)<<8)|(((a)&0xff0000)>>8)|((((uint32_t)(a))&0xff000000)>>24) 282 #define RGBA( r, g, b, a ) ((r)|((g)<<8)|((b)<<16)|((a)<<24)) 283 #endif 284 285 // Lights values 0..255, but signed to detect underflow. 286 typedef int16_t lightlev_t; 287 288 typedef uint16_t statenum_t; 289 290 // [WDJ] I would prefer this was uint32_t, but it is being kept signed so that 291 // tests for -1 can be preserved. This reduces the chance of logical errors 292 // due to older fail tests that have not been discovered yet (2018). 293 // The number of wads is limited to 32, and signed allows over 8000 wads. 294 typedef int32_t lumpnum_t; 295 296 #endif //__DOOMTYPE__ 297