]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake2/q2map/qbsp.h
d803354c8e9865f5cee54f662b1a0037d664427f
[xonotic/netradiant.git] / tools / quake2 / q2map / qbsp.h
1 /*
2    Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    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 GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 /* Files:
23
24    brushbsp.c
25    csg.c
26    faces.c
27    gldraw.c
28    glfile.c
29    leakfile.c
30    map.c
31    nodraw.c
32    portals.c
33    prtfile.c
34    qbsp3.c
35    textures.c
36    tree.c
37    writebsp.c
38
39  */
40
41 #include "globaldefs.h"
42 #include "cmdlib.h"
43 #include "mathlib.h"
44 #include "scriplib.h"
45 #include "polylib.h"
46 #include "q2_threads.h"
47 #include "bspfile.h"
48 #include "inout.h"
49
50 #if GDEF_COMPILER_MSVC
51         #ifdef NDEBUG                           // Don't show in a Release build
52                 #pragma warning(disable : 4305)     // truncate from double to float
53                 #pragma warning(disable : 4244)     // conversion from double to float
54                 #pragma warning(disable : 4018)     // signed/unsigned mismatch
55         #endif
56 #endif
57
58 #define MAX_BRUSH_SIDES 128
59 #define CLIP_EPSILON    0.1
60
61 #define BOGUS_RANGE 8192
62
63 #define TEXINFO_NODE        -1      // side is allready on a node
64
65 typedef struct plane_s
66 {
67         vec3_t normal;
68         vec_t dist;
69         int type;
70         struct plane_s  *hash_chain;
71 } plane_t;
72
73 typedef struct
74 {
75         vec_t shift[2];
76         vec_t rotate;
77         vec_t scale[2];
78         char name[32];
79         int flags;
80         int value;
81 } brush_texture_t;
82
83 typedef struct side_s
84 {
85         int planenum;
86         int texinfo;
87         winding_t   *winding;
88         struct side_s   *original;  // bspbrush_t sides will reference the mapbrush_t sides
89         int contents;               // from miptex
90         int surf;                   // from miptex
91         qboolean visible;           // choose visble planes first
92         qboolean tested;            // this plane allready checked as a split
93         qboolean bevel;             // don't ever use for bsp splitting
94 } side_t;
95
96 typedef struct brush_s
97 {
98         int entitynum;
99         int brushnum;
100
101         int contents;
102
103         vec3_t mins, maxs;
104
105         int numsides;
106         side_t  *original_sides;
107 } mapbrush_t;
108
109 #define PLANENUM_LEAF           -1
110
111 #define MAXEDGES        20
112
113 typedef struct face_s
114 {
115         struct face_s   *next;      // on node
116
117         // the chain of faces off of a node can be merged or split,
118         // but each face_t along the way will remain in the chain
119         // until the entire tree is freed
120         struct face_s   *merged;    // if set, this face isn't valid anymore
121         struct face_s   *split[2];  // if set, this face isn't valid anymore
122
123         struct portal_s *portal;
124         int texinfo;
125         int planenum;
126         int contents;               // faces in different contents can't merge
127         int outputnumber;
128         winding_t       *w;
129         int numpoints;
130         qboolean badstartvert;          // tjunctions cannot be fixed without a midpoint vertex
131         int vertexnums[MAXEDGES];
132 } face_t;
133
134
135
136 typedef struct bspbrush_s
137 {
138         struct bspbrush_s   *next;
139         vec3_t mins, maxs;
140         int side, testside;         // side of node during construction
141         mapbrush_t  *original;
142         int numsides;
143         side_t sides[6];            // variably sized
144 } bspbrush_t;
145
146
147
148 #define MAX_NODE_BRUSHES    8
149 typedef struct node_s
150 {
151         // both leafs and nodes
152         int planenum;               // -1 = leaf node
153         struct node_s   *parent;
154         vec3_t mins, maxs;          // valid after portalization
155         bspbrush_t      *volume;    // one for each leaf/node
156
157         // nodes only
158         qboolean detail_seperator;          // a detail brush caused the split
159         side_t          *side;      // the side that created the node
160         struct node_s   *children[2];
161         face_t          *faces;
162
163         // leafs only
164         bspbrush_t      *brushlist; // fragments of all brushes in this leaf
165         int contents;               // OR of all brush contents
166         int occupied;               // 1 or greater can reach entity
167         entity_t        *occupant;  // for leak file testing
168         int cluster;                // for portalfile writing
169         int area;                   // for areaportals
170         struct portal_s *portals;   // also on nodes during construction
171 } node_t;
172
173 typedef struct portal_s
174 {
175         plane_t plane;
176         node_t      *onnode;        // NULL = outside box
177         node_t      *nodes[2];      // [0] = front side of plane
178         struct portal_s *next[2];
179         winding_t   *winding;
180
181         qboolean sidefound;         // false if ->side hasn't been checked
182         side_t      *side;          // NULL = non-visible
183         face_t      *face[2];       // output face in bsp file
184 } portal_t;
185
186 typedef struct
187 {
188         node_t      *headnode;
189         node_t outside_node;
190         vec3_t mins, maxs;
191 } tree_t;
192
193 extern int entity_num;
194
195 extern plane_t mapplanes[MAX_MAP_PLANES];
196 extern int nummapplanes;
197
198 extern int nummapbrushes;
199 extern mapbrush_t mapbrushes[MAX_MAP_BRUSHES];
200
201 extern vec3_t map_mins, map_maxs;
202
203 #define MAX_MAP_SIDES       ( MAX_MAP_BRUSHES * 6 )
204
205 extern int nummapbrushsides;
206 extern side_t brushsides[MAX_MAP_SIDES];
207
208 extern qboolean noprune;
209 extern qboolean nodetail;
210 extern qboolean fulldetail;
211 extern qboolean nomerge;
212 extern qboolean nosubdiv;
213 extern qboolean nowater;
214 extern qboolean noweld;
215 extern qboolean noshare;
216 extern qboolean notjunc;
217
218 extern vec_t microvolume;
219
220 extern char outbase[32];
221
222 extern char source[1024];
223
224 void    LoadMapFile( char *filename );
225 int     FindFloatPlane( vec3_t normal, vec_t dist );
226
227 //=============================================================================
228
229 // textures.c
230
231 typedef struct
232 {
233         char name[64];
234         int flags;
235         int value;
236         int contents;
237         char animname[64];
238 } textureref_t;
239
240 #define MAX_MAP_TEXTURES    1024
241
242 extern textureref_t textureref[MAX_MAP_TEXTURES];
243
244 int FindMiptex( char *name );
245
246 int TexinfoForBrushTexture( plane_t *plane, brush_texture_t *bt, vec3_t origin );
247
248 //=============================================================================
249
250 void FindGCD( int *v );
251
252 mapbrush_t *Brush_LoadEntity( entity_t *ent );
253 int PlaneTypeForNormal( vec3_t normal );
254 qboolean MakeBrushPlanes( mapbrush_t *b );
255 int     FindIntPlane( int *inormal, int *iorigin );
256 void    CreateBrush( int brushnum );
257
258
259 //=============================================================================
260
261 // draw.c
262
263 extern vec3_t draw_mins, draw_maxs;
264 extern qboolean drawflag;
265
266 void Draw_ClearWindow( void );
267 void DrawWinding( winding_t *w );
268
269 void GLS_BeginScene( void );
270 void GLS_Winding( winding_t *w, int code );
271 void GLS_EndScene( void );
272
273 //=============================================================================
274
275 // csg
276
277 bspbrush_t *MakeBspBrushList( int startbrush, int endbrush,
278                                                           vec3_t clipmins, vec3_t clipmaxs );
279 bspbrush_t *ChopBrushes( bspbrush_t *head );
280 bspbrush_t *InitialBrushList( bspbrush_t *list );
281 bspbrush_t *OptimizedBrushList( bspbrush_t *list );
282
283 void WriteBrushMap( char *name, bspbrush_t *list );
284
285 //=============================================================================
286
287 // brushbsp
288
289 void WriteBrushList( char *name, bspbrush_t *brush, qboolean onlyvis );
290
291 bspbrush_t *CopyBrush( bspbrush_t *brush );
292
293 void SplitBrush( bspbrush_t *brush, int planenum,
294                                  bspbrush_t **front, bspbrush_t **back );
295
296 tree_t *AllocTree( void );
297 node_t *AllocNode( void );
298 bspbrush_t *AllocBrush( int numsides );
299 int CountBrushList( bspbrush_t *brushes );
300 void FreeBrush( bspbrush_t *brushes );
301 vec_t BrushVolume( bspbrush_t *brush );
302
303 void BoundBrush( bspbrush_t *brush );
304 void FreeBrushList( bspbrush_t *brushes );
305
306 tree_t *BrushBSP( bspbrush_t *brushlist, vec3_t mins, vec3_t maxs );
307
308 //=============================================================================
309
310 // portals.c
311
312 int VisibleContents( int contents );
313
314 void MakeHeadnodePortals( tree_t *tree );
315 void MakeNodePortal( node_t *node );
316 void SplitNodePortals( node_t *node );
317
318 qboolean    Portal_VisFlood( portal_t *p );
319
320 qboolean FloodEntities( tree_t *tree );
321 void FillOutside( node_t *headnode );
322 void FloodAreas( tree_t *tree );
323 void MarkVisibleSides( tree_t *tree, int start, int end );
324 void FreePortal( portal_t *p );
325 void EmitAreaPortals( node_t *headnode );
326
327 void MakeTreePortals( tree_t *tree );
328
329 //=============================================================================
330
331 // glfile.c
332
333 void OutputWinding( winding_t *w, FILE *glview );
334 void WriteGLView( tree_t *tree, char *source );
335
336 //=============================================================================
337
338 // leakfile.c
339
340 //void LeakFile (tree_t *tree);
341 xmlNodePtr LeakFile( tree_t *tree );
342
343 //=============================================================================
344
345 // prtfile.c
346
347 void WritePortalFile( tree_t *tree );
348
349 //=============================================================================
350
351 // writebsp.c
352
353 void SetModelNumbers( void );
354 void SetLightStyles( void );
355
356 void BeginBSPFile( void );
357 void WriteBSP( node_t *headnode );
358 void EndBSPFile( void );
359 void BeginModel( void );
360 void EndModel( void );
361
362 //=============================================================================
363
364 // faces.c
365
366 void MakeFaces( node_t *headnode );
367 void FixTjuncs( node_t *headnode );
368 int GetEdge2( int v1, int v2,  face_t *f );
369
370 face_t  *AllocFace( void );
371 void FreeFace( face_t *f );
372
373 void MergeNodeFaces( node_t *node );
374
375 //=============================================================================
376
377 // tree.c
378
379 void FreeTree( tree_t *tree );
380 void FreeTree_r( node_t *node );
381 void PrintTree_r( node_t *node, int depth );
382 void FreeTreePortals_r( node_t *node );
383 void PruneNodes_r( node_t *node );
384 void PruneNodes( node_t *node );
385
386 //=============================================================================
387
388 // externs
389
390 extern char *mapname;
391 extern char game[64];