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
41 #include "globaldefs.h"
46 #include "q2_threads.h"
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
58 #define MAX_BRUSH_SIDES 128
59 #define CLIP_EPSILON 0.1
61 #define BOGUS_RANGE 8192
63 #define TEXINFO_NODE -1 // side is allready on a node
65 typedef struct plane_s
70 struct plane_s *hash_chain;
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
96 typedef struct brush_s
106 side_t *original_sides;
109 #define PLANENUM_LEAF -1
113 typedef struct face_s
115 struct face_s *next; // on node
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
123 struct portal_s *portal;
126 int contents; // faces in different contents can't merge
130 qboolean badstartvert; // tjunctions cannot be fixed without a midpoint vertex
131 int vertexnums[MAXEDGES];
136 typedef struct bspbrush_s
138 struct bspbrush_s *next;
140 int side, testside; // side of node during construction
141 mapbrush_t *original;
143 side_t sides[6]; // variably sized
148 #define MAX_NODE_BRUSHES 8
149 typedef struct node_s
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
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];
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
173 typedef struct portal_s
176 node_t *onnode; // NULL = outside box
177 node_t *nodes[2]; // [0] = front side of plane
178 struct portal_s *next[2];
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
193 extern int entity_num;
195 extern plane_t mapplanes[MAX_MAP_PLANES];
196 extern int nummapplanes;
198 extern int nummapbrushes;
199 extern mapbrush_t mapbrushes[MAX_MAP_BRUSHES];
201 extern vec3_t map_mins, map_maxs;
203 #define MAX_MAP_SIDES ( MAX_MAP_BRUSHES * 6 )
205 extern int nummapbrushsides;
206 extern side_t brushsides[MAX_MAP_SIDES];
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;
218 extern vec_t microvolume;
220 extern char outbase[32];
222 extern char source[1024];
224 void LoadMapFile( char *filename );
225 int FindFloatPlane( vec3_t normal, vec_t dist );
227 //=============================================================================
240 #define MAX_MAP_TEXTURES 1024
242 extern textureref_t textureref[MAX_MAP_TEXTURES];
244 int FindMiptex( char *name );
246 int TexinfoForBrushTexture( plane_t *plane, brush_texture_t *bt, vec3_t origin );
248 //=============================================================================
250 void FindGCD( int *v );
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 );
259 //=============================================================================
263 extern vec3_t draw_mins, draw_maxs;
264 extern qboolean drawflag;
266 void Draw_ClearWindow( void );
267 void DrawWinding( winding_t *w );
269 void GLS_BeginScene( void );
270 void GLS_Winding( winding_t *w, int code );
271 void GLS_EndScene( void );
273 //=============================================================================
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 );
283 void WriteBrushMap( char *name, bspbrush_t *list );
285 //=============================================================================
289 void WriteBrushList( char *name, bspbrush_t *brush, qboolean onlyvis );
291 bspbrush_t *CopyBrush( bspbrush_t *brush );
293 void SplitBrush( bspbrush_t *brush, int planenum,
294 bspbrush_t **front, bspbrush_t **back );
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 );
303 void BoundBrush( bspbrush_t *brush );
304 void FreeBrushList( bspbrush_t *brushes );
306 tree_t *BrushBSP( bspbrush_t *brushlist, vec3_t mins, vec3_t maxs );
308 //=============================================================================
312 int VisibleContents( int contents );
314 void MakeHeadnodePortals( tree_t *tree );
315 void MakeNodePortal( node_t *node );
316 void SplitNodePortals( node_t *node );
318 qboolean Portal_VisFlood( portal_t *p );
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 );
327 void MakeTreePortals( tree_t *tree );
329 //=============================================================================
333 void OutputWinding( winding_t *w, FILE *glview );
334 void WriteGLView( tree_t *tree, char *source );
336 //=============================================================================
340 //void LeakFile (tree_t *tree);
341 xmlNodePtr LeakFile( tree_t *tree );
343 //=============================================================================
347 void WritePortalFile( tree_t *tree );
349 //=============================================================================
353 void SetModelNumbers( void );
354 void SetLightStyles( void );
356 void BeginBSPFile( void );
357 void WriteBSP( node_t *headnode );
358 void EndBSPFile( void );
359 void BeginModel( void );
360 void EndModel( void );
362 //=============================================================================
366 void MakeFaces( node_t *headnode );
367 void FixTjuncs( node_t *headnode );
368 int GetEdge2( int v1, int v2, face_t *f );
370 face_t *AllocFace( void );
371 void FreeFace( face_t *f );
373 void MergeNodeFaces( node_t *node );
375 //=============================================================================
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 );
386 //=============================================================================
390 extern char *mapname;
391 extern char game[64];