Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

qbsp.h (11846B)


      1 /*
      2 ===========================================================================
      3 Copyright (C) 1999-2005 Id Software, Inc.
      4 
      5 This file is part of Quake III Arena source code.
      6 
      7 Quake III Arena 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 III Arena 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 Foobar; 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 "imagelib.h"
     28 #include "threads.h"
     29 #include "bspfile.h"
     30 #include "shaders.h"
     31 #include "mesh.h"
     32 
     33 
     34 #define	MAX_PATCH_SIZE	32
     35 
     36 #define	CLIP_EPSILON		0.1
     37 #define	PLANENUM_LEAF		-1
     38 
     39 #define	HINT_PRIORITY		1000
     40 
     41 typedef struct parseMesh_s {
     42 	struct parseMesh_s	*next;
     43 	mesh_t			mesh;
     44 	shaderInfo_t	*shaderInfo;
     45 
     46 	qboolean	grouped;			// used during shared edge grouping
     47 	struct parseMesh_s *groupChain;
     48 } parseMesh_t;
     49 
     50 typedef struct bspface_s {
     51 	struct bspface_s	*next;
     52 	int					planenum;
     53 	int					priority;	// added to value calculation
     54 	qboolean			checked;
     55 	qboolean			hint;
     56 	winding_t			*w;
     57 } bspface_t;
     58 
     59 typedef struct plane_s {
     60 	vec3_t	normal;
     61 	vec_t	dist;
     62 	int		type;
     63 	struct plane_s	*hash_chain;
     64 } plane_t;
     65 
     66 typedef struct side_s {
     67 	int			planenum;
     68 
     69 	float		texMat[2][3];	// brush primitive texture matrix
     70 	// for old brush coordinates mode
     71 	float		vecs[2][4];		// texture coordinate mapping
     72 
     73 	winding_t	*winding;
     74 	winding_t	*visibleHull;	// convex hull of all visible fragments
     75 
     76 	struct shaderInfo_s	*shaderInfo;
     77 
     78 	int			contents;		// from shaderInfo
     79 	int			surfaceFlags;	// from shaderInfo
     80 	int			value;			// from shaderInfo
     81 
     82 	qboolean	visible;		// choose visble planes first
     83 	qboolean	bevel;			// don't ever use for bsp splitting, and don't bother
     84 								// making windings for it
     85 	qboolean	backSide;		// generated side for a q3map_backShader
     86 } side_t;
     87 
     88 
     89 #define	MAX_BRUSH_SIDES		1024
     90 
     91 typedef struct bspbrush_s {
     92 	struct bspbrush_s	*next;
     93 
     94 	int			entitynum;			// editor numbering
     95 	int			brushnum;			// editor numbering
     96 
     97 	struct shaderInfo_s	*contentShader;
     98 
     99 	int			contents;
    100 	qboolean	detail;
    101 	qboolean	opaque;
    102 	int			outputNumber;		// set when the brush is written to the file list
    103 
    104 	int			portalareas[2];
    105 
    106 	struct bspbrush_s	*original;	// chopped up brushes will reference the originals
    107 
    108 	vec3_t		mins, maxs;
    109 	int			numsides;
    110 	side_t		sides[6];			// variably sized
    111 } bspbrush_t;
    112 
    113 
    114 
    115 typedef struct drawsurf_s {
    116 	shaderInfo_t	*shaderInfo;
    117 
    118 	bspbrush_t	*mapBrush;			// not valid for patches
    119 	side_t		*side;				// not valid for patches
    120 
    121 	struct drawsurf_s	*nextOnShader;	// when sorting by shader for lightmaps
    122 
    123 	int			fogNum;				// set by FogDrawSurfs
    124 
    125 	int			lightmapNum;		// -1 = no lightmap
    126 	int			lightmapX, lightmapY;
    127 	int			lightmapWidth, lightmapHeight;
    128 
    129 	int			numVerts;
    130 	drawVert_t	*verts;
    131 
    132 	int			numIndexes;
    133 	int			*indexes;
    134 
    135 	// for faces only
    136 	int			planeNum;
    137 
    138 	vec3_t		lightmapOrigin;		// also used for flares
    139 	vec3_t		lightmapVecs[3];	// also used for flares
    140 
    141 	// for patches only
    142 	qboolean	patch;
    143 	int			patchWidth;
    144 	int			patchHeight;
    145 
    146 	// for misc_models only
    147 	qboolean	miscModel;
    148 
    149 	qboolean	flareSurface;
    150 } mapDrawSurface_t;
    151 
    152 typedef struct drawSurfRef_s {
    153 	struct drawSurfRef_s	*nextRef;
    154 	int						outputNumber;
    155 } drawSurfRef_t;
    156 
    157 typedef struct node_s {
    158 	// both leafs and nodes
    159 	int				planenum;	// -1 = leaf node
    160 	struct node_s	*parent;
    161 	vec3_t			mins, maxs;	// valid after portalization
    162 	bspbrush_t		*volume;	// one for each leaf/node
    163 
    164 	// nodes only
    165 	side_t			*side;		// the side that created the node
    166 	struct node_s	*children[2];
    167 	qboolean		hint;
    168 	int				tinyportals;
    169 	vec3_t			referencepoint;
    170 
    171 	// leafs only
    172 	qboolean		opaque;		// view can never be inside
    173 	qboolean		areaportal;
    174 	int				cluster;	// for portalfile writing
    175 	int				area;		// for areaportals
    176 	bspbrush_t		*brushlist;	// fragments of all brushes in this leaf
    177 	drawSurfRef_t	*drawSurfReferences;	// references to patches pushed down
    178 
    179 	int				occupied;	// 1 or greater can reach entity
    180 	entity_t		*occupant;	// for leak file testing
    181 
    182 	struct portal_s	*portals;	// also on nodes during construction
    183 } node_t;
    184 
    185 typedef struct portal_s {
    186 	plane_t		plane;
    187 	node_t		*onnode;		// NULL = outside box
    188 	node_t		*nodes[2];		// [0] = front side of plane
    189 	struct portal_s	*next[2];
    190 	winding_t	*winding;
    191 
    192 	qboolean	sidefound;		// false if ->side hasn't been checked
    193 	qboolean	hint;
    194 	side_t		*side;			// NULL = non-visible
    195 } portal_t;
    196 
    197 typedef struct {
    198 	node_t		*headnode;
    199 	node_t		outside_node;
    200 	vec3_t		mins, maxs;
    201 } tree_t;
    202 
    203 extern	int			entity_num;
    204 
    205 
    206 extern	qboolean	noprune;
    207 extern	qboolean	nodetail;
    208 extern	qboolean	fulldetail;
    209 extern	qboolean	nowater;
    210 extern	qboolean	noCurveBrushes;
    211 extern	qboolean	fakemap;
    212 extern	qboolean	coplanar;
    213 extern	qboolean	nofog;
    214 extern	qboolean	testExpand;
    215 extern	qboolean	showseams;
    216 
    217 extern	vec_t		microvolume;
    218 
    219 extern	char		outbase[32];
    220 extern	char		source[1024];
    221 
    222 extern int		samplesize;			//sample size in units
    223 extern int		novertexlighting;
    224 extern int		nogridlighting;
    225 
    226 //=============================================================================
    227 
    228 // brush.c
    229 
    230 int	CountBrushList (bspbrush_t *brushes);
    231 bspbrush_t *AllocBrush (int numsides);
    232 void FreeBrush (bspbrush_t *brushes);
    233 void FreeBrushList (bspbrush_t *brushes);
    234 bspbrush_t *CopyBrush (bspbrush_t *brush);
    235 void DrawBrushList (bspbrush_t *brush);
    236 void WriteBrushList (char *name, bspbrush_t *brush, qboolean onlyvis);
    237 void PrintBrush (bspbrush_t *brush);
    238 qboolean BoundBrush (bspbrush_t *brush);
    239 qboolean CreateBrushWindings (bspbrush_t *brush);
    240 bspbrush_t	*BrushFromBounds (vec3_t mins, vec3_t maxs);
    241 vec_t BrushVolume (bspbrush_t *brush);
    242 void WriteBspBrushMap (char *name, bspbrush_t *list);
    243 
    244 void FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree );
    245 void FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree );
    246 
    247 //=============================================================================
    248 
    249 // map.c
    250 
    251 extern	int			entitySourceBrushes;
    252 
    253 // mapplanes[ num^1 ] will always be the mirror or mapplanes[ num ]
    254 // nummapplanes will always be even
    255 extern	plane_t		mapplanes[MAX_MAP_PLANES];
    256 extern	int			nummapplanes;
    257 
    258 extern	vec3_t		map_mins, map_maxs;
    259 
    260 extern	char		mapIndexedShaders[MAX_MAP_BRUSHSIDES][MAX_QPATH];
    261 extern	int			numMapIndexedShaders;
    262 
    263 extern	entity_t	*mapent;
    264 
    265 #define		MAX_BUILD_SIDES		300
    266 extern	bspbrush_t	*buildBrush;
    267 
    268 
    269 void 		LoadMapFile (char *filename);
    270 int			FindFloatPlane (vec3_t normal, vec_t dist);
    271 int			PlaneTypeForNormal (vec3_t normal);
    272 bspbrush_t	*FinishBrush( void );
    273 mapDrawSurface_t	*AllocDrawSurf( void );
    274 mapDrawSurface_t	*DrawSurfaceForSide( bspbrush_t *b, side_t *s, winding_t *w );
    275 
    276 //=============================================================================
    277 
    278 //=============================================================================
    279 
    280 // draw.c
    281 
    282 extern	vec3_t		draw_mins, draw_maxs;
    283 extern	qboolean	drawflag;
    284 
    285 void Draw_ClearWindow (void);
    286 void DrawWinding (winding_t *w);
    287 
    288 void GLS_BeginScene (void);
    289 void GLS_Winding (winding_t *w, int code);
    290 void GLS_EndScene (void);
    291 
    292 //=============================================================================
    293 
    294 // csg
    295 
    296 bspbrush_t *MakeBspBrushList ( bspbrush_t *brushes,	vec3_t clipmins, vec3_t clipmaxs);
    297 
    298 //=============================================================================
    299 
    300 // brushbsp
    301 
    302 #define	PSIDE_FRONT			1
    303 #define	PSIDE_BACK			2
    304 #define	PSIDE_BOTH			(PSIDE_FRONT|PSIDE_BACK)
    305 #define	PSIDE_FACING		4
    306 
    307 int BoxOnPlaneSide (vec3_t mins, vec3_t maxs, plane_t *plane);
    308 qboolean WindingIsTiny (winding_t *w);
    309 
    310 void SplitBrush (bspbrush_t *brush, int planenum,
    311 	bspbrush_t **front, bspbrush_t **back);
    312 
    313 tree_t *AllocTree (void);
    314 node_t *AllocNode (void);
    315 
    316 tree_t *BrushBSP (bspbrush_t *brushlist, vec3_t mins, vec3_t maxs);
    317 
    318 //=============================================================================
    319 
    320 // portals.c
    321 
    322 void MakeHeadnodePortals (tree_t *tree);
    323 void MakeNodePortal (node_t *node);
    324 void SplitNodePortals (node_t *node);
    325 
    326 qboolean	Portal_Passable(portal_t *p);
    327 
    328 qboolean FloodEntities (tree_t *tree);
    329 void FillOutside (node_t *headnode);
    330 void FloodAreas (tree_t *tree);
    331 bspface_t *VisibleFaces(entity_t *e, tree_t *tree);
    332 void FreePortal (portal_t *p);
    333 
    334 void MakeTreePortals (tree_t *tree);
    335 
    336 //=============================================================================
    337 
    338 // glfile.c
    339 
    340 void OutputWinding( winding_t *w, FILE *glview );
    341 void WriteGLView( tree_t *tree, char *source );
    342 
    343 //=============================================================================
    344 
    345 // leakfile.c
    346 
    347 void LeakFile( tree_t *tree );
    348 
    349 //=============================================================================
    350 
    351 // prtfile.c
    352 
    353 void NumberClusters( tree_t *tree );
    354 void WritePortalFile( tree_t *tree );
    355 
    356 //=============================================================================
    357 
    358 // writebsp.c
    359 
    360 void SetModelNumbers (void);
    361 void SetLightStyles (void);
    362 
    363 int	EmitShader( const char *shader );
    364 
    365 void BeginBSPFile (void);
    366 void EndBSPFile (void);
    367 
    368 void BeginModel (void);
    369 void EndModel( node_t *headnode );
    370 
    371 
    372 //=============================================================================
    373 
    374 // tree.c
    375 
    376 void FreeTree (tree_t *tree);
    377 void FreeTree_r (node_t *node);
    378 void PrintTree_r (node_t *node, int depth);
    379 void FreeTreePortals_r (node_t *node);
    380 
    381 //=============================================================================
    382 
    383 // patch.c
    384 
    385 extern	int			numMapPatches;
    386 
    387 mapDrawSurface_t	*DrawSurfaceForMesh( mesh_t *m );
    388 void ParsePatch( void );
    389 mesh_t *SubdivideMesh( mesh_t in, float maxError, float minLength );
    390 void PatchMapDrawSurfs( entity_t *e );
    391 
    392 //=============================================================================
    393 
    394 // lightmap.c
    395 
    396 void AllocateLightmaps( entity_t *e );
    397 
    398 //=============================================================================
    399 
    400 // tjunction.c
    401 
    402 void FixTJunctions( entity_t *e );
    403 
    404 
    405 //=============================================================================
    406 
    407 // fog.c
    408 
    409 void FogDrawSurfs( void );
    410 winding_t	*WindingFromDrawSurf( mapDrawSurface_t *ds );
    411 
    412 //=============================================================================
    413 
    414 // facebsp.c
    415 
    416 bspface_t	*BspFaceForPortal( portal_t *p );
    417 bspface_t	*MakeStructuralBspFaceList( bspbrush_t *list );
    418 bspface_t	*MakeVisibleBspFaceList( bspbrush_t *list );
    419 tree_t *FaceBSP( bspface_t *list );
    420 
    421 //=============================================================================
    422 
    423 // misc_model.c
    424 
    425 extern	int		c_triangleModels;
    426 extern	int		c_triangleSurfaces;
    427 extern	int		c_triangleVertexes;
    428 extern	int		c_triangleIndexes;
    429 
    430 void AddTriangleModels( tree_t *tree );
    431 
    432 //=============================================================================
    433 
    434 // surface.c
    435 
    436 extern	mapDrawSurface_t	mapDrawSurfs[MAX_MAP_DRAW_SURFS];
    437 extern	int			numMapDrawSurfs;
    438 
    439 mapDrawSurface_t	*AllocDrawSurf( void );
    440 void	MergeSides( entity_t *e, tree_t *tree );
    441 void	SubdivideDrawSurfs( entity_t *e, tree_t *tree );
    442 void	MakeDrawSurfaces( bspbrush_t *b );
    443 void	ClipSidesIntoTree( entity_t *e, tree_t *tree );
    444 void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree );
    445 
    446 //==============================================================================
    447 
    448 // brush_primit.c
    449 
    450 #define BPRIMIT_UNDEFINED 0
    451 #define BPRIMIT_OLDBRUSHES 1
    452 #define BPRIMIT_NEWBRUSHES 2
    453 extern	int	g_bBrushPrimit;
    454 
    455 void ComputeAxisBase( vec3_t normal, vec3_t texX, vec3_t texY);