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