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