2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
45 #include "q2_threads.h"
50 #ifdef NDEBUG // Don't show in a Release build
51 #pragma warning(disable : 4305) // truncate from double to float
52 #pragma warning(disable : 4244) // conversion from double to float
53 #pragma warning(disable : 4018) // signed/unsigned mismatch
57 #define MAX_BRUSH_SIDES 128
58 #define CLIP_EPSILON 0.1
60 #define BOGUS_RANGE 8192
62 #define TEXINFO_NODE -1 // side is allready on a node
64 typedef struct plane_s
69 struct plane_s *hash_chain;
87 struct side_s *original; // bspbrush_t sides will reference the mapbrush_t sides
88 int contents; // from miptex
89 int surf; // from miptex
90 qboolean visible; // choose visble planes first
91 qboolean tested; // this plane allready checked as a split
92 qboolean bevel; // don't ever use for bsp splitting
95 typedef struct brush_s
105 side_t *original_sides;
108 #define PLANENUM_LEAF -1
112 typedef struct face_s
114 struct face_s *next; // on node
116 // the chain of faces off of a node can be merged or split,
117 // but each face_t along the way will remain in the chain
118 // until the entire tree is freed
119 struct face_s *merged; // if set, this face isn't valid anymore
120 struct face_s *split[2]; // if set, this face isn't valid anymore
122 struct portal_s *portal;
125 int contents; // faces in different contents can't merge
129 qboolean badstartvert; // tjunctions cannot be fixed without a midpoint vertex
130 int vertexnums[MAXEDGES];
135 typedef struct bspbrush_s
137 struct bspbrush_s *next;
139 int side, testside; // side of node during construction
140 mapbrush_t *original;
142 side_t sides[6]; // variably sized
147 #define MAX_NODE_BRUSHES 8
148 typedef struct node_s
150 // both leafs and nodes
151 int planenum; // -1 = leaf node
152 struct node_s *parent;
153 vec3_t mins, maxs; // valid after portalization
154 bspbrush_t *volume; // one for each leaf/node
157 qboolean detail_seperator; // a detail brush caused the split
158 side_t *side; // the side that created the node
159 struct node_s *children[2];
163 bspbrush_t *brushlist; // fragments of all brushes in this leaf
164 int contents; // OR of all brush contents
165 int occupied; // 1 or greater can reach entity
166 entity_t *occupant; // for leak file testing
167 int cluster; // for portalfile writing
168 int area; // for areaportals
169 struct portal_s *portals; // also on nodes during construction
172 typedef struct portal_s
175 node_t *onnode; // NULL = outside box
176 node_t *nodes[2]; // [0] = front side of plane
177 struct portal_s *next[2];
180 qboolean sidefound; // false if ->side hasn't been checked
181 side_t *side; // NULL = non-visible
182 face_t *face[2]; // output face in bsp file
192 extern int entity_num;
194 extern plane_t mapplanes[MAX_MAP_PLANES];
195 extern int nummapplanes;
197 extern int nummapbrushes;
198 extern mapbrush_t mapbrushes[MAX_MAP_BRUSHES];
200 extern vec3_t map_mins, map_maxs;
202 #define MAX_MAP_SIDES (MAX_MAP_BRUSHES*6)
204 extern int nummapbrushsides;
205 extern side_t brushsides[MAX_MAP_SIDES];
207 extern qboolean noprune;
208 extern qboolean nodetail;
209 extern qboolean fulldetail;
210 extern qboolean nomerge;
211 extern qboolean nosubdiv;
212 extern qboolean nowater;
213 extern qboolean noweld;
214 extern qboolean noshare;
215 extern qboolean notjunc;
217 extern vec_t microvolume;
219 extern char outbase[32];
221 extern char source[1024];
223 void LoadMapFile (char *filename);
224 int FindFloatPlane (vec3_t normal, vec_t dist);
226 //=============================================================================
239 #define MAX_MAP_TEXTURES 1024
241 extern textureref_t textureref[MAX_MAP_TEXTURES];
243 int FindMiptex (char *name);
245 int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin);
247 //=============================================================================
249 void FindGCD (int *v);
251 mapbrush_t *Brush_LoadEntity (entity_t *ent);
252 int PlaneTypeForNormal (vec3_t normal);
253 qboolean MakeBrushPlanes (mapbrush_t *b);
254 int FindIntPlane (int *inormal, int *iorigin);
255 void CreateBrush (int brushnum);
258 //=============================================================================
262 extern vec3_t draw_mins, draw_maxs;
263 extern qboolean drawflag;
265 void Draw_ClearWindow (void);
266 void DrawWinding (winding_t *w);
268 void GLS_BeginScene (void);
269 void GLS_Winding (winding_t *w, int code);
270 void GLS_EndScene (void);
272 //=============================================================================
276 bspbrush_t *MakeBspBrushList (int startbrush, int endbrush,
277 vec3_t clipmins, vec3_t clipmaxs);
278 bspbrush_t *ChopBrushes (bspbrush_t *head);
279 bspbrush_t *InitialBrushList (bspbrush_t *list);
280 bspbrush_t *OptimizedBrushList (bspbrush_t *list);
282 void WriteBrushMap (char *name, bspbrush_t *list);
284 //=============================================================================
288 void WriteBrushList (char *name, bspbrush_t *brush, qboolean onlyvis);
290 bspbrush_t *CopyBrush (bspbrush_t *brush);
292 void SplitBrush (bspbrush_t *brush, int planenum,
293 bspbrush_t **front, bspbrush_t **back);
295 tree_t *AllocTree (void);
296 node_t *AllocNode (void);
297 bspbrush_t *AllocBrush (int numsides);
298 int CountBrushList (bspbrush_t *brushes);
299 void FreeBrush (bspbrush_t *brushes);
300 vec_t BrushVolume (bspbrush_t *brush);
302 void BoundBrush (bspbrush_t *brush);
303 void FreeBrushList (bspbrush_t *brushes);
305 tree_t *BrushBSP (bspbrush_t *brushlist, vec3_t mins, vec3_t maxs);
307 //=============================================================================
311 int VisibleContents (int contents);
313 void MakeHeadnodePortals (tree_t *tree);
314 void MakeNodePortal (node_t *node);
315 void SplitNodePortals (node_t *node);
317 qboolean Portal_VisFlood (portal_t *p);
319 qboolean FloodEntities (tree_t *tree);
320 void FillOutside (node_t *headnode);
321 void FloodAreas (tree_t *tree);
322 void MarkVisibleSides (tree_t *tree, int start, int end);
323 void FreePortal (portal_t *p);
324 void EmitAreaPortals (node_t *headnode);
326 void MakeTreePortals (tree_t *tree);
328 //=============================================================================
332 void OutputWinding (winding_t *w, FILE *glview);
333 void WriteGLView (tree_t *tree, char *source);
335 //=============================================================================
339 //void LeakFile (tree_t *tree);
340 xmlNodePtr LeakFile (tree_t *tree);
342 //=============================================================================
346 void WritePortalFile (tree_t *tree);
348 //=============================================================================
352 void SetModelNumbers (void);
353 void SetLightStyles (void);
355 void BeginBSPFile (void);
356 void WriteBSP (node_t *headnode);
357 void EndBSPFile (void);
358 void BeginModel (void);
359 void EndModel (void);
361 //=============================================================================
365 void MakeFaces (node_t *headnode);
366 void FixTjuncs (node_t *headnode);
367 int GetEdge2 (int v1, int v2, face_t *f);
369 face_t *AllocFace (void);
370 void FreeFace (face_t *f);
372 void MergeNodeFaces (node_t *node);
374 //=============================================================================
378 void FreeTree (tree_t *tree);
379 void FreeTree_r (node_t *node);
380 void PrintTree_r (node_t *node, int depth);
381 void FreeTreePortals_r (node_t *node);
382 void PruneNodes_r (node_t *node);
383 void PruneNodes (node_t *node);
385 //=============================================================================
389 extern char *mapname;
390 extern char game[64];