]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake2/extra/qe4/bspfile.h
Merge remote-tracking branch 'ttimo/master'
[xonotic/netradiant.git] / tools / quake2 / extra / qe4 / bspfile.h
1 /*
2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
4
5 This file is part of Quake 2 Tools source code.
6
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 ===========================================================================
21 */
22
23 // upper design bounds
24 // leaffaces, leafbrushes, planes, and verts are still bounded by
25 // 16 bit short limits
26 #define MAX_MAP_MODELS          1024
27 #define MAX_MAP_BRUSHES         8192
28 #define MAX_MAP_ENTITIES        2048
29 #define MAX_MAP_PATHS           2048
30 #define MAX_MAP_ENTSTRING       0x20000
31 #define MAX_MAP_TEXTURES        1024
32 #define MAX_MAP_TEXINFO         8192
33
34 #define MAX_MAP_PLANES          65536
35 #define MAX_MAP_NODES           65536
36 #define MAX_MAP_BRUSHSIDES      65536
37 #define MAX_MAP_LEAFS           65536
38 #define MAX_MAP_VERTS           65536
39 #define MAX_MAP_FACES           65536
40 #define MAX_MAP_LEAFFACES       65536
41 #define MAX_MAP_LEAFBRUSHES 65536
42 #define MAX_MAP_PORTALS         65536
43 #define MAX_MAP_EDGES           128000
44 #define MAX_MAP_SURFEDGES       256000
45 #define MAX_MAP_MIPTEX          0x200000
46 #define MAX_MAP_LIGHTING        0x200000
47 #define MAX_MAP_VISIBILITY      0x100000
48
49 // key / value pair sizes
50
51 #define MAX_KEY         32
52 #define MAX_VALUE       1024
53
54 //=============================================================================
55
56 #define BSPVERSION      34
57
58 typedef struct
59 {
60         int             fileofs, filelen;
61 } lump_t;
62
63 #define LUMP_ENTITIES           0
64 #define LUMP_PLANES                     1
65 #define LUMP_TEXTURES           2
66 #define LUMP_VERTEXES           3
67 #define LUMP_VISIBILITY         4
68 #define LUMP_NODES                      5
69 #define LUMP_TEXINFO            6
70 #define LUMP_FACES                      7
71 #define LUMP_LIGHTING           8
72 #define LUMP_LEAFS                      9
73 #define LUMP_LEAFFACES          10
74 #define LUMP_LEAFBRUSHES        11
75 #define LUMP_EDGES                      12
76 #define LUMP_SURFEDGES          13
77 #define LUMP_MODELS                     14
78 #define LUMP_PATHS                      15
79 #define LUMP_BRUSHES            16
80 #define LUMP_BRUSHSIDES         17
81 #define LUMP_POP                        18
82
83 #define HEADER_LUMPS    18
84
85 typedef struct
86 {
87         int                     version;
88         lump_t          lumps[HEADER_LUMPS];
89 } dheader_t;
90
91 typedef struct
92 {
93         float           mins[3], maxs[3];
94         float           origin[3];              // for sounds or lights
95         int                     headnode;
96         int                     visleafs;               // not including the solid leaf 0
97         int                     firstface, numfaces;
98 } dmodel_t;
99
100 typedef struct
101 {
102         int                     nummiptex;
103         int                     dataofs[4];             // [nummiptex]
104 } dmiptexlump_t;
105
106 #define MIPLEVELS       4
107 typedef struct miptex_s
108 {
109         char            name[16];
110         unsigned        width, height;
111         unsigned        offsets[MIPLEVELS];             // four mip maps stored
112         int                     flags;
113         int                     value;
114 } miptex_t;
115
116
117 typedef struct
118 {
119         float   point[3];
120 } dvertex_t;
121
122
123 // 0-2 are axial planes
124 #define PLANE_X                 0
125 #define PLANE_Y                 1
126 #define PLANE_Z                 2
127
128 // 3-5 are non-axial planes snapped to the nearest
129 #define PLANE_ANYX              3
130 #define PLANE_ANYY              4
131 #define PLANE_ANYZ              5
132
133 // planes (x&~1) and (x&~1)+1 are allways opposites
134
135 typedef struct
136 {
137         float   normal[3];
138         float   dist;
139         int             type;           // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
140 } dplane_t;
141
142
143 // contents flags are seperate bits
144 // a given brush can contribute multiple content bits
145 // multiple brushes can be in a single leaf
146
147 // lower bits are stronger, and will eat weaker brushes completely
148 #define CONTENTS_SOLID                  1               // an eye is never valid in a solid
149 #define CONTENTS_WINDOW                 2               // translucent, but not watery
150 #define CONTENTS_LAVA                   8
151 #define CONTENTS_SLIME                  16
152 #define CONTENTS_WATER                  32
153 #define CONTENTS_THINWATER              64              // translucent faces
154
155 #define LAST_VISIBLE_CONTENTS   64
156
157 // remaining contents are non-visible, and don't eat brushes
158 #define CONTENTS_MONSTER                128
159 #define CONTENTS_PLAYERCLIP             256
160 #define CONTENTS_MONSTERCLIP    512
161
162
163 // currents can be added to any other contents, and may be mixed
164 #define CONTENTS_CURRENT_0              1024
165 #define CONTENTS_CURRENT_90             2048
166 #define CONTENTS_CURRENT_180    4096
167 #define CONTENTS_CURRENT_270    8192
168 #define CONTENTS_CURRENT_UP             16384
169 #define CONTENTS_CURRENT_DOWN   32768
170
171 #define CONTENTS_ORIGIN                 65536           // removed before processing
172
173
174
175 // !!! if this is changed, it must be changed in asm_i386.h too !!!
176 typedef struct
177 {
178         int                     planenum;
179         int                     children[2];    // negative numbers are -(leafs+1), not nodes
180         short           mins[3];                // for frustom culling
181         short           maxs[3];
182         unsigned short  firstface;
183         unsigned short  numfaces;       // counting both sides
184 } dnode_t;
185
186 typedef struct texinfo_s
187 {
188         float           vecs[2][4];             // [s/t][xyz offset]
189         int                     miptex;
190         int                     flags;                  // miptex flags + overrides
191         int                     value;                  // light emition, etc
192 } texinfo_t;
193
194 #define TEX_SPECIAL             1               // sky or slime, no lightmap or 256 subdivision
195 #define SURF_LIGHT              2
196
197 #define SURF_WATER              4
198 #define SURF_SLIME              8
199 #define SURF_LAVA               16
200 #define SURF_WINDOW             32
201
202 #define SURF_SKY                64
203 #define SURF_MIRROR             128
204
205 #define SURF_SLIPPERY   256
206
207 // note that edge 0 is never used, because negative edge nums are used for
208 // counterclockwise use of the edge in a face
209 typedef struct
210 {
211         unsigned short  v[2];           // vertex numbers
212 } dedge_t;
213
214 #define MAXLIGHTMAPS    4
215 typedef struct
216 {
217         unsigned short  planenum;
218         short           side;
219
220         int                     firstedge;              // we must support > 64k edges
221         short           numedges;
222         short           texinfo;
223
224 // lighting info
225         byte            styles[MAXLIGHTMAPS];
226         int                     lightofs;               // start of [numstyles*surfsize] samples
227 } dface_t;
228
229 typedef struct
230 {
231         int                     contents;                       // OR of all brushes
232         int                     visofs;                         // -1 = no visibility info
233
234         short           mins[3];                        // for frustum culling
235         short           maxs[3];
236
237         unsigned short          firstleafface;
238         unsigned short          numleaffaces;
239
240         unsigned short          firstleafbrush;
241         unsigned short          numleafbrushes;
242 } dleaf_t;
243
244
245 typedef struct
246 {
247         unsigned short  planenum;               // facing out of the leaf
248         short   texinfo;
249 } dbrushside_t;
250
251 typedef struct
252 {
253         int                     firstside;
254         int                     numsides;
255         int                     contents;
256 } dbrush_t;
257
258 typedef struct
259 {
260         float           origin[3];
261         float           angles[3];
262         int                     next, prev;
263         int                     flags;
264         float           speed;
265 } dpath_t;
266
267 //============================================================================
268
269 #ifndef QUAKE_GAME
270
271 #define ANGLE_UP        -1
272 #define ANGLE_DOWN      -2
273
274
275 // the utilities get to be lazy and just use large static arrays
276
277 extern  int                     nummodels;
278 extern  dmodel_t        dmodels[MAX_MAP_MODELS];
279
280 extern  int                     visdatasize;
281 extern  byte            dvisdata[MAX_MAP_VISIBILITY];
282
283 extern  int                     lightdatasize;
284 extern  byte            dlightdata[MAX_MAP_LIGHTING];
285
286 extern  int                     texdatasize;
287 extern  byte            dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t)
288
289 extern  int                     entdatasize;
290 extern  char            dentdata[MAX_MAP_ENTSTRING];
291
292 extern  int                     numleafs;
293 extern  dleaf_t         dleafs[MAX_MAP_LEAFS];
294
295 extern  int                     numplanes;
296 extern  dplane_t        dplanes[MAX_MAP_PLANES];
297
298 extern  int                     numvertexes;
299 extern  dvertex_t       dvertexes[MAX_MAP_VERTS];
300
301 extern  int                     numnodes;
302 extern  dnode_t         dnodes[MAX_MAP_NODES];
303
304 extern  int                     numtexinfo;
305 extern  texinfo_t       texinfo[MAX_MAP_TEXINFO];
306
307 extern  int                     numfaces;
308 extern  dface_t         dfaces[MAX_MAP_FACES];
309
310 extern  int                     numedges;
311 extern  dedge_t         dedges[MAX_MAP_EDGES];
312
313 extern  int                     numleaffaces;
314 extern  unsigned short  dleaffaces[MAX_MAP_LEAFFACES];
315
316 extern  int                     numleafbrushes;
317 extern  unsigned short  dleafbrushes[MAX_MAP_LEAFBRUSHES];
318
319 extern  int                     numsurfedges;
320 extern  int                     dsurfedges[MAX_MAP_SURFEDGES];
321
322 extern  int                     numpaths;
323 extern  dpath_t         dpaths[MAX_MAP_PATHS];
324
325 extern  int                     numbrushes;
326 extern  dbrush_t        dbrushes[MAX_MAP_BRUSHES];
327
328 extern  int                     numbrushsides;
329 extern  dbrushside_t    dbrushsides[MAX_MAP_BRUSHSIDES];
330
331
332 void DecompressVis (byte *in, byte *decompressed);
333 int CompressVis (byte *vis, byte *dest);
334
335 void    LoadBSPFile (char *filename);
336 void    WriteBSPFile (char *filename);
337 void    PrintBSPFileSizes (void);
338
339 //===============
340
341
342 typedef struct epair_s
343 {
344         struct epair_s  *next;
345         char    *key;
346         char    *value;
347 } epair_t;
348
349 typedef struct
350 {
351         vec3_t          origin;
352         int                     firstbrush;
353         int                     numbrushes;
354         epair_t         *epairs;
355 } entity_t;
356
357 extern  int                     num_entities;
358 extern  entity_t        entities[MAX_MAP_ENTITIES];
359
360 void    ParseEntities (void);
361 void    UnparseEntities (void);
362
363 void    SetKeyValue (entity_t *ent, char *key, char *value);
364 char    *ValueForKey (entity_t *ent, char *key);
365 // will return "" if not present
366
367 vec_t   FloatForKey (entity_t *ent, char *key);
368 void    GetVectorForKey (entity_t *ent, char *key, vec3_t vec);
369
370 epair_t *ParseEpair (void);
371
372 void PrintEntity (entity_t *ent);
373
374 extern  int             r_leaftovis[MAX_MAP_LEAFS];
375 extern  int             r_vistoleaf[MAX_MAP_LEAFS];
376 extern  int             r_numvisleafs;
377
378 #endif