2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\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
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
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
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
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
57 #define MAX_BRUSH_SIDES 128
\r
58 #define CLIP_EPSILON 0.1
\r
60 #define BOGUS_RANGE 8192
\r
62 #define TEXINFO_NODE -1 // side is allready on a node
\r
64 typedef struct plane_s
\r
69 struct plane_s *hash_chain;
\r
82 typedef struct side_s
\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
95 typedef struct brush_s
\r
105 side_t *original_sides;
\r
108 #define PLANENUM_LEAF -1
\r
110 #define MAXEDGES 20
\r
112 typedef struct face_s
\r
114 struct face_s *next; // on node
\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
122 struct portal_s *portal;
\r
125 int contents; // faces in different contents can't merge
\r
129 qboolean badstartvert; // tjunctions cannot be fixed without a midpoint vertex
\r
130 int vertexnums[MAXEDGES];
\r
135 typedef struct bspbrush_s
\r
137 struct bspbrush_s *next;
\r
139 int side, testside; // side of node during construction
\r
140 mapbrush_t *original;
\r
142 side_t sides[6]; // variably sized
\r
147 #define MAX_NODE_BRUSHES 8
\r
148 typedef struct node_s
\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
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
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
172 typedef struct portal_s
\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
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
188 node_t outside_node;
\r
192 extern int entity_num;
\r
194 extern plane_t mapplanes[MAX_MAP_PLANES];
\r
195 extern int nummapplanes;
\r
197 extern int nummapbrushes;
\r
198 extern mapbrush_t mapbrushes[MAX_MAP_BRUSHES];
\r
200 extern vec3_t map_mins, map_maxs;
\r
202 #define MAX_MAP_SIDES (MAX_MAP_BRUSHES*6)
\r
204 extern int nummapbrushsides;
\r
205 extern side_t brushsides[MAX_MAP_SIDES];
\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
217 extern vec_t microvolume;
\r
219 extern char outbase[32];
\r
221 extern char source[1024];
\r
223 void LoadMapFile (char *filename);
\r
224 int FindFloatPlane (vec3_t normal, vec_t dist);
\r
226 //=============================================================================
\r
239 #define MAX_MAP_TEXTURES 1024
\r
241 extern textureref_t textureref[MAX_MAP_TEXTURES];
\r
243 int FindMiptex (char *name);
\r
245 int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin);
\r
247 //=============================================================================
\r
249 void FindGCD (int *v);
\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
258 //=============================================================================
\r
262 extern vec3_t draw_mins, draw_maxs;
\r
263 extern qboolean drawflag;
\r
265 void Draw_ClearWindow (void);
\r
266 void DrawWinding (winding_t *w);
\r
268 void GLS_BeginScene (void);
\r
269 void GLS_Winding (winding_t *w, int code);
\r
270 void GLS_EndScene (void);
\r
272 //=============================================================================
\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
282 void WriteBrushMap (char *name, bspbrush_t *list);
\r
284 //=============================================================================
\r
288 void WriteBrushList (char *name, bspbrush_t *brush, qboolean onlyvis);
\r
290 bspbrush_t *CopyBrush (bspbrush_t *brush);
\r
292 void SplitBrush (bspbrush_t *brush, int planenum,
\r
293 bspbrush_t **front, bspbrush_t **back);
\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
302 void BoundBrush (bspbrush_t *brush);
\r
303 void FreeBrushList (bspbrush_t *brushes);
\r
305 tree_t *BrushBSP (bspbrush_t *brushlist, vec3_t mins, vec3_t maxs);
\r
307 //=============================================================================
\r
311 int VisibleContents (int contents);
\r
313 void MakeHeadnodePortals (tree_t *tree);
\r
314 void MakeNodePortal (node_t *node);
\r
315 void SplitNodePortals (node_t *node);
\r
317 qboolean Portal_VisFlood (portal_t *p);
\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
326 void MakeTreePortals (tree_t *tree);
\r
328 //=============================================================================
\r
332 void OutputWinding (winding_t *w, FILE *glview);
\r
333 void WriteGLView (tree_t *tree, char *source);
\r
335 //=============================================================================
\r
339 //void LeakFile (tree_t *tree);
\r
340 xmlNodePtr LeakFile (tree_t *tree);
\r
342 //=============================================================================
\r
346 void WritePortalFile (tree_t *tree);
\r
348 //=============================================================================
\r
352 void SetModelNumbers (void);
\r
353 void SetLightStyles (void);
\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
361 //=============================================================================
\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
369 face_t *AllocFace (void);
\r
370 void FreeFace (face_t *f);
\r
372 void MergeNodeFaces (node_t *node);
\r
374 //=============================================================================
\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
385 //=============================================================================
\r
389 extern char *mapname;
\r
390 extern char game[64];
\r