]> git.xonotic.org Git - xonotic/darkplaces.git/blob - qdefs.h
cvar: Remove unused ignore_callback variable
[xonotic/darkplaces.git] / qdefs.h
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 #else
13 #define DP_FUNC_PRINTF(n)
14 #define DP_FUNC_PURE
15 #define DP_FUNC_NORETURN
16 #endif
17
18 #ifdef DP_GCC_COMPATIBLE
19 #define Q_typeof(var) typeof(var)
20 #elif defined (MSVC)
21 #define Q_typeof(var) decltype(var)
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 ///< maximum length of console commandline, QuakeC strings, and many other text processing buffers
95 #define CON_TEXTSIZE                    1048576 ///< max scrollback buffer characters in console
96 #define CON_MAXLINES                    16384 ///< max scrollback buffer lines in console
97 #define HIST_TEXTSIZE                   262144 ///< max command history buffer characters in console
98 #define HIST_MAXLINES                   4096 ///< max command history buffer lines in console
99 #define MAX_ALIAS_NAME                  32
100 #define CMDBUFSIZE                              655360 ///< maximum script size that can be loaded by the exec command (8192 in Quake)
101 #define MAX_ARGS                                80 ///< maximum number of parameters to a console command or alias
102
103 #define NET_MAXMESSAGE                  65536 ///< max reliable packet size (sent as multiple fragments of MAX_PACKETFRAGMENT)
104 #define MAX_PACKETFRAGMENT              1024 ///< max length of packet fragment
105 #define MAX_EDICTS                              32768 ///< max number of objects in game world at once (32768 protocol limit)
106 #define MAX_MODELS                              8192 ///< max number of models loaded at once (including during level transitions)
107 #define MAX_SOUNDS                              4096 ///< max number of sounds loaded at once
108 #define MAX_LIGHTSTYLES                 256 ///< max flickering light styles in level (note: affects savegame format)
109 #define MAX_STYLESTRING                 64 ///< max length of flicker pattern for light style
110 #define MAX_SCOREBOARD                  255 ///< max number of players in game at once (255 protocol limit)
111 #define MAX_SCOREBOARDNAME              128 ///< max length of player name in game
112 #define MAX_USERINFO_STRING             1280 ///< max length of infostring for PROTOCOL_QUAKEWORLD (196 in QuakeWorld)
113 #define MAX_SERVERINFO_STRING   1280 ///< max length of server infostring for PROTOCOL_QUAKEWORLD (512 in QuakeWorld)
114 #define MAX_LOCALINFO_STRING    32768 ///< max length of server-local infostring for PROTOCOL_QUAKEWORLD (32768 in QuakeWorld)
115 #define CL_MAX_USERCMDS                 128 ///< max number of predicted input packets in queue
116 #define CVAR_HASHSIZE                   65536 ///< number of hash buckets for accelerating cvar name lookups
117 #define M_MAX_EDICTS                    32768 ///< max objects in menu vm
118 #define MAX_DEMOS                               8 ///< max demos provided to demos command
119 #define MAX_DEMONAME                    16 ///< max demo name length for demos command
120 #define MAX_SAVEGAMES                   12 ///< max savegames listed in savegame menu
121 #define SAVEGAME_COMMENT_LENGTH 39 ///< max comment length of savegame in menu
122 #define MAX_CLIENTNETWORKEYES   16 ///< max number of locations that can be added to pvs when culling network entities (must be at least 2 for prediction)
123 #define MAX_LEVELNETWORKEYES    512 ///< max number of locations that can be added to pvs when culling network entities (must be at least 2 for prediction)
124 #define MAX_OCCLUSION_QUERIES   4096 ///< max number of query objects that can be used in one frame
125
126 #define CRYPTO_HOSTKEY_HASHSIZE 8192 ///< number of hash buckets for accelerating host key lookups
127 #define MAX_NETWM_ICON 352822 // 16x16, 22x22, 24x24, 32x32, 48x48, 64x64, 128x128, 256x256, 512x512
128
129 #define MAX_WATERPLANES                 16 ///< max number of water planes visible (each one causes additional view renders)
130 #define MAX_CUBEMAPS                    1024 ///< max number of cubemap textures loaded for light filters
131 #define MAX_EXPLOSIONS                  64 ///< max number of explosion shell effects active at once (not particle related)
132 #define MAX_DLIGHTS                             256 ///< max number of dynamic lights (rocket flashes, etc) in scene at once
133 #define MAX_CACHED_PICS                 2048 ///< max number of 2D pics loaded at once
134 #define CACHEPICHASHSIZE                256 ///< number of hash buckets for accelerating 2D pic name lookups
135 #define MAX_PARTICLEEFFECTNAME  4096 ///< maximum number of unique names of particle effects (for particleeffectnum)
136 #define MAX_PARTICLEEFFECTINFO  8192 ///< maximum number of unique particle effects (each name may associate with several of these)
137 #define MAX_PARTICLETEXTURES    256 ///< maximum number of unique particle textures in the particle font
138 #define MAXCLVIDEOS                             65 ///< maximum number of video streams being played back at once (1 is reserved for the playvideo command)
139 #define MAX_DYNAMIC_TEXTURE_COUNT       64 ///< maximum number of dynamic textures (web browsers, playvideo, etc)
140 #define MAX_MAP_LEAFS                   65536 ///< maximum number of BSP leafs in world (8192 in Quake)
141
142 #define MAXTRACKS                               256 ///< max CD track index
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 ///< initial allocation for cl.particles
154 #define MAX_PARTICLES                   1048576 ///< upper limit on cl.particles size
155 #define MAX_ENTITIES_INITIAL            256 ///< initial size of cl.entities
156 #define MAX_STATICENTITIES              4096 ///< limit on size of cl.static_entities
157 #define MAX_EFFECTS                             256 ///< limit on size of cl.effects
158 #define MAX_BEAMS                               256 ///< limit on size of cl.beams
159 #define MAX_TEMPENTITIES                4096 ///< max number of temporary models visible per frame (certain sprite effects, certain types of CSQC entities also use this)
160 #define SERVERLIST_TOTALSIZE            2048 ///< max servers in the server list
161 #define SERVERLIST_ANDMASKCOUNT         16 ///< max items in server list AND mask
162 #define SERVERLIST_ORMASKCOUNT          16 ///< max items in server list OR mask
163 #endif
164
165
166 #define CMD_TOKENIZELENGTH (MAX_INPUTLINE + MAX_ARGS) ///< maximum tokenizable commandline length (counting trailing 0)
167
168
169 #define MAX_QPATH               128                     ///< max length of a quake game pathname
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            ///< max length of a filesystem pathname
176 #endif
177
178 #define ON_EPSILON              0.1                     ///< point on plane side epsilon
179
180 #define NET_MINRATE             1000 ///< limits "rate" and "sv_maxrate" cvars
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 #ifdef PRVM_64
190 #define FLOAT_IS_TRUE_FOR_INT(x) ((x) & 0x7FFFFFFFFFFFFFFF) // also match "negative zero" doubles of value 0x8000000000000000
191 #define FLOAT_LOSSLESS_FORMAT "%.17g"
192 #define VECTOR_LOSSLESS_FORMAT "%.17g %.17g %.17g"
193 #else
194 #define FLOAT_IS_TRUE_FOR_INT(x) ((x) & 0x7FFFFFFF) // also match "negative zero" floats of value 0x80000000
195 #define FLOAT_LOSSLESS_FORMAT "%.9g"
196 #define VECTOR_LOSSLESS_FORMAT "%.9g %.9g %.9g"
197 #endif
198
199 // originally this was _MSC_VER
200 // but here we want to test the system libc, which on win32 is borked, and NOT the compiler
201 #ifdef WIN32
202 #define INT_LOSSLESS_FORMAT_SIZE "I64"
203 #define INT_LOSSLESS_FORMAT_CONVERT_S(x) ((__int64)(x))
204 #define INT_LOSSLESS_FORMAT_CONVERT_U(x) ((unsigned __int64)(x))
205 #else
206 #define INT_LOSSLESS_FORMAT_SIZE "j"
207 #define INT_LOSSLESS_FORMAT_CONVERT_S(x) ((intmax_t)(x))
208 #define INT_LOSSLESS_FORMAT_CONVERT_U(x) ((uintmax_t)(x))
209 #endif
210
211 // simple safe library to handle integer overflows when doing buffer size calculations
212 // Usage:
213 //   - calculate data size using INTOVERFLOW_??? macros
214 //   - compare: calculated-size <= INTOVERFLOW_NORMALIZE(buffersize)
215 // Functionality:
216 //   - all overflows (values > INTOVERFLOW_MAX) and errors are mapped to INTOVERFLOW_MAX
217 //   - if any input of an operation is INTOVERFLOW_MAX, INTOVERFLOW_MAX will be returned
218 //   - otherwise, regular arithmetics apply
219
220 #define INTOVERFLOW_MAX 2147483647
221
222 #define INTOVERFLOW_ADD(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX - (b)) ? ((a) + (b)) : INTOVERFLOW_MAX)
223 #define INTOVERFLOW_SUB(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) <= (a))                  ? ((a) - (b)) : INTOVERFLOW_MAX)
224 #define INTOVERFLOW_MUL(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (a) < INTOVERFLOW_MAX / (b)) ? ((a) * (b)) : INTOVERFLOW_MAX)
225 #define INTOVERFLOW_DIV(a,b) (((a) < INTOVERFLOW_MAX && (b) < INTOVERFLOW_MAX && (b) > 0)                     ? ((a) / (b)) : INTOVERFLOW_MAX)
226
227 #define INTOVERFLOW_NORMALIZE(a) (((a) < INTOVERFLOW_MAX) ? (a) : (INTOVERFLOW_MAX - 1))
228
229 #endif