DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
qdefs.h
Go to the documentation of this file.
1#ifndef QDEFS_H
2#define QDEFS_H
3
4#if defined (__GNUC__) || defined (__clang__) || defined (__TINYC__)
5#define DP_GCC_COMPATIBLE
6#endif
7
8#if (__GNUC__ > 2) || defined (__clang__) || (__TINYC__)
9#define DP_FUNC_PRINTF(n) __attribute__ ((format (printf, n, n+1)))
10#define DP_FUNC_PURE __attribute__ ((pure))
11#define DP_FUNC_NORETURN __attribute__ ((noreturn))
12#define DP_FUNC_ALWAYS_INLINE inline __attribute__((always_inline))
13#else
14#define DP_FUNC_PRINTF(n)
15#define DP_FUNC_PURE
16#define DP_FUNC_NORETURN
17# if defined (_MSC_VER)
18# define DP_FUNC_ALWAYS_INLINE __forceinline
19# else
20# define DP_FUNC_ALWAYS_INLINE inline
21# endif
22#endif
23
24#define MAX_NUM_ARGVS 50
25
26#ifdef DP_SMALLMEMORY
27#define MAX_INPUTLINE 1024
28#define CON_TEXTSIZE 16384
29#define CON_MAXLINES 256
30#define HIST_TEXTSIZE 2048
31#define HIST_MAXLINES 16
32#define MAX_ALIAS_NAME 32
33#define CMDBUFSIZE 131072
34#define MAX_ARGS 80
35
36#define NET_MAXMESSAGE 65536
37#define MAX_PACKETFRAGMENT 1024
38#define MAX_EDICTS 4096
39#define MAX_MODELS 1024
40#define MAX_SOUNDS 1024
41#define MAX_LIGHTSTYLES 64
42#define MAX_STYLESTRING 16
43#define MAX_SCOREBOARD 32
44#define MAX_SCOREBOARDNAME 128
45#define MAX_USERINFO_STRING 196
46#define MAX_SERVERINFO_STRING 512
47#define MAX_LOCALINFO_STRING 1 // not actually used by DP servers
48#define CL_MAX_USERCMDS 32
49#define CVAR_HASHSIZE 1024
50#define M_MAX_EDICTS 4096
51#define MAX_DEMOS 8
52#define MAX_DEMONAME 16
53#define MAX_SAVEGAMES 12
54#define SAVEGAME_COMMENT_LENGTH 39
55#define MAX_CLIENTNETWORKEYES 2
56#define MAX_LEVELNETWORKEYES 0 // no portal support
57#define MAX_OCCLUSION_QUERIES 256
58
59#define CRYPTO_HOSTKEY_HASHSIZE 256
60#define MAX_NETWM_ICON 1026 // one 32x32
61
62#define MAX_WATERPLANES 2
63#define MAX_CUBEMAPS 1024
64#define MAX_EXPLOSIONS 8
65#define MAX_DLIGHTS 16
66#define MAX_CACHED_PICS 2048 // this is 144 bytes each (or 152 on 64bit)
67#define CACHEPICHASHSIZE 256
68#define MAX_PARTICLEEFFECTNAME 256
69#define MAX_PARTICLEEFFECTINFO 1024
70#define MAX_PARTICLETEXTURES 256
71#define MAXCLVIDEOS 1
72#define MAX_DYNAMIC_TEXTURE_COUNT 2
73//#define MAX_MAP_LEAFS 8192
74
75#define MAXTRACKS 256
76#define MAX_DYNAMIC_CHANNELS 64
77#define MAX_CHANNELS 260
78#define MODLIST_TOTALSIZE 32
79#define MAX_FAVORITESERVERS 32
80#define MAX_DECALSYSTEM_QUEUE 64
81#define PAINTBUFFER_SIZE 512
82#define MAX_BINDMAPS 8
83#define MAX_PARTICLES_INITIAL 8192
84#define MAX_PARTICLES 8192
85#define MAX_ENTITIES_INITIAL 256
86#define MAX_STATICENTITIES 256
87#define MAX_EFFECTS 16
88#define MAX_BEAMS 16
89#define MAX_TEMPENTITIES 256
90#define SERVERLIST_TOTALSIZE 1024
91#define SERVERLIST_ANDMASKCOUNT 5
92#define SERVERLIST_ORMASKCOUNT 5
93#else
94#define MAX_INPUTLINE 16384
95#define CON_TEXTSIZE 1048576
96#define CON_MAXLINES 16384
97#define HIST_TEXTSIZE 262144
98#define HIST_MAXLINES 4096
99#define MAX_ALIAS_NAME 32
100#define CMDBUFSIZE 655360
101#define MAX_ARGS 80
102
103#define NET_MAXMESSAGE 65536
104#define MAX_PACKETFRAGMENT 1024
105#define MAX_EDICTS 32768
106#define MAX_MODELS 8192
107#define MAX_SOUNDS 4096
108#define MAX_LIGHTSTYLES 256
109#define MAX_STYLESTRING 64
110#define MAX_SCOREBOARD 255
111#define MAX_SCOREBOARDNAME 128
112#define MAX_USERINFO_STRING 1280
113#define MAX_SERVERINFO_STRING 1280
114#define MAX_LOCALINFO_STRING 32768
115#define CL_MAX_USERCMDS 128
116#define CVAR_HASHSIZE 65536
117#define M_MAX_EDICTS 32768
118#define MAX_DEMOS 8
119#define MAX_DEMONAME 32
120#define MAX_SAVEGAMES 12
121#define SAVEGAME_COMMENT_LENGTH 39
122#define MAX_CLIENTNETWORKEYES 16
123#define MAX_LEVELNETWORKEYES 512
124#define MAX_OCCLUSION_QUERIES 4096
125
126#define CRYPTO_HOSTKEY_HASHSIZE 8192
127#define MAX_NETWM_ICON 352822 // 16x16, 22x22, 24x24, 32x32, 48x48, 64x64, 128x128, 256x256, 512x512
128
129#define MAX_WATERPLANES 16
130#define MAX_CUBEMAPS 1024
131#define MAX_EXPLOSIONS 64
132#define MAX_DLIGHTS 256
133#define MAX_CACHED_PICS 2048
134#define CACHEPICHASHSIZE 256
135#define MAX_PARTICLEEFFECTNAME 4096
136#define MAX_PARTICLEEFFECTINFO 8192
137#define MAX_PARTICLETEXTURES 256
138#define MAXCLVIDEOS 65
139#define MAX_DYNAMIC_TEXTURE_COUNT 64
140//#define MAX_MAP_LEAFS 65536 ///< maximum number of BSP leafs in world (8192 in Quake), now dynamically allocated
141
142#define MAXTRACKS 256
143// 0 to NUM_AMBIENTS - 1 = water, etc
144// NUM_AMBIENTS to NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS - 1 = normal entity sounds
145// NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS to total_channels = static sounds
146#define MAX_DYNAMIC_CHANNELS 512
147#define MAX_CHANNELS (8192 + 4)
148#define MODLIST_TOTALSIZE 256
149#define MAX_FAVORITESERVERS 256
150#define MAX_DECALSYSTEM_QUEUE 1024
151#define PAINTBUFFER_SIZE 2048
152#define MAX_BINDMAPS 8
153#define MAX_PARTICLES_INITIAL 8192
154#define MAX_PARTICLES 1048576
155#define MAX_ENTITIES_INITIAL 256
156#define MAX_STATICENTITIES 4096
157#define MAX_EFFECTS 256
158#define MAX_BEAMS 256
159#define MAX_TEMPENTITIES 4096
160#define SERVERLIST_TOTALSIZE 2048
161#define SERVERLIST_ANDMASKCOUNT 16
162#define SERVERLIST_ORMASKCOUNT 16
163#endif
164
165
166#define CMD_TOKENIZELENGTH (MAX_INPUTLINE + MAX_ARGS)
167
168
169#define MAX_QPATH 128
170#ifdef PATH_MAX
171#define MAX_OSPATH PATH_MAX
172#elif MAX_PATH
173#define MAX_OSPATH MAX_PATH
174#else
175#define MAX_OSPATH 1024
176#endif
177
178#define ON_EPSILON 0.1
179
180#define NET_MINRATE 1000
181
182// In Quake, any char in 0..32 counts as whitespace
183//#define ISWHITESPACE(ch) ((unsigned char) ch <= (unsigned char) ' ')
184#define ISWHITESPACE(ch) (!(ch) || (ch) == ' ' || (ch) == '\t' || (ch) == '\r' || (ch) == '\n')
185#define ISCOMMENT(ch, pos) ch[pos] == '/' && ch[pos + 1] == '/' && (pos == 0 || ISWHITESPACE(ch[pos - 1]))
186// This also includes extended characters, and ALL control chars
187#define ISWHITESPACEORCONTROL(ch) ((signed char) (ch) <= (signed char) ' ')
188
189#define DOUBLE_IS_TRUE_FOR_INT(x) ((x) & 0x7FFFFFFFFFFFFFFF) // also match "negative zero" doubles of value 0x8000000000000000
190#define DOUBLE_LOSSLESS_FORMAT "%.17g"
191#define DOUBLE_VECTOR_LOSSLESS_FORMAT "%.17g %.17g %.17g"
192
193#define FLOAT_IS_TRUE_FOR_INT(x) ((x) & 0x7FFFFFFF) // also match "negative zero" floats of value 0x80000000
194#define FLOAT_LOSSLESS_FORMAT "%.9g"
195#define FLOAT_VECTOR_LOSSLESS_FORMAT "%.9g %.9g %.9g"
196
197// originally this was _MSC_VER
198// but here we want to test the system libc, which on win32 is borked, and NOT the compiler
199#ifdef WIN32
200#define INT_LOSSLESS_FORMAT_SIZE "I64"
201#define INT_LOSSLESS_FORMAT_CONVERT_S(x) ((__int64)(x))
202#define INT_LOSSLESS_FORMAT_CONVERT_U(x) ((unsigned __int64)(x))
203#else
204#define INT_LOSSLESS_FORMAT_SIZE "j"
205#define INT_LOSSLESS_FORMAT_CONVERT_S(x) ((intmax_t)(x))
206#define INT_LOSSLESS_FORMAT_CONVERT_U(x) ((uintmax_t)(x))
207#endif
208
209// simple safe library to handle integer overflows when doing buffer size calculations
210// Usage:
211// - calculate data size using INTOVERFLOW_??? macros
212// - compare: calculated-size <= INTOVERFLOW_NORMALIZE(buffersize)
213// Functionality:
214// - all overflows (values > INTOVERFLOW_MAX) and errors are mapped to INTOVERFLOW_MAX
215// - if any input of an operation is INTOVERFLOW_MAX, INTOVERFLOW_MAX will be returned
216// - otherwise, regular arithmetics apply
217
218#define INTOVERFLOW_MAX 2147483647
219
220#define INTOVERFLOW_ADD(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX - (b)) ? ((a) + (b)) : INTOVERFLOW_MAX)
221#define INTOVERFLOW_SUB(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) <= (a)) ? ((a) - (b)) : INTOVERFLOW_MAX)
222#define INTOVERFLOW_MUL(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX / (b)) ? ((a) * (b)) : INTOVERFLOW_MAX)
223#define INTOVERFLOW_DIV(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) > 0) ? ((a) / (b)) : INTOVERFLOW_MAX)
224
225#define INTOVERFLOW_NORMALIZE(a) (((a) < INTOVERFLOW_MAX) ? (a) : (INTOVERFLOW_MAX - 1))
226
227#endif