Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

qbsp.h

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 
00023 #include "cmdlib.h"
00024 #include "mathlib.h"
00025 #include "scriplib.h"
00026 #include "polylib.h"
00027 #include "imagelib.h"
00028 #include "threads.h"
00029 #include "bspfile.h"
00030 #include "shaders.h"
00031 #include "mesh.h"
00032 
00033 
00034 #define MAX_PATCH_SIZE  32
00035 
00036 #define CLIP_EPSILON        0.1
00037 #define PLANENUM_LEAF       -1
00038 
00039 #define HINT_PRIORITY       1000
00040 
00041 typedef struct parseMesh_s {
00042     struct parseMesh_s  *next;
00043     mesh_t          mesh;
00044     shaderInfo_t    *shaderInfo;
00045 
00046     qboolean    grouped;            // used during shared edge grouping
00047     struct parseMesh_s *groupChain;
00048 } parseMesh_t;
00049 
00050 typedef struct bspface_s {
00051     struct bspface_s    *next;
00052     int                 planenum;
00053     int                 priority;   // added to value calculation
00054     qboolean            checked;
00055     qboolean            hint;
00056     winding_t           *w;
00057 } bspface_t;
00058 
00059 typedef struct plane_s {
00060     vec3_t  normal;
00061     vec_t   dist;
00062     int     type;
00063     struct plane_s  *hash_chain;
00064 } plane_t;
00065 
00066 typedef struct side_s {
00067     int         planenum;
00068 
00069     float       texMat[2][3];   // brush primitive texture matrix
00070     // for old brush coordinates mode
00071     float       vecs[2][4];     // texture coordinate mapping
00072 
00073     winding_t   *winding;
00074     winding_t   *visibleHull;   // convex hull of all visible fragments
00075 
00076     struct shaderInfo_s *shaderInfo;
00077 
00078     int         contents;       // from shaderInfo
00079     int         surfaceFlags;   // from shaderInfo
00080     int         value;          // from shaderInfo
00081 
00082     qboolean    visible;        // choose visble planes first
00083     qboolean    bevel;          // don't ever use for bsp splitting, and don't bother
00084                                 // making windings for it
00085     qboolean    backSide;       // generated side for a q3map_backShader
00086 } side_t;
00087 
00088 
00089 #define MAX_BRUSH_SIDES     1024
00090 
00091 typedef struct bspbrush_s {
00092     struct bspbrush_s   *next;
00093 
00094     int         entitynum;          // editor numbering
00095     int         brushnum;           // editor numbering
00096 
00097     struct shaderInfo_s *contentShader;
00098 
00099     int         contents;
00100     qboolean    detail;
00101     qboolean    opaque;
00102     int         outputNumber;       // set when the brush is written to the file list
00103 
00104     int         portalareas[2];
00105 
00106     struct bspbrush_s   *original;  // chopped up brushes will reference the originals
00107 
00108     vec3_t      mins, maxs;
00109     int         numsides;
00110     side_t      sides[6];           // variably sized
00111 } bspbrush_t;
00112 
00113 
00114 
00115 typedef struct drawsurf_s {
00116     shaderInfo_t    *shaderInfo;
00117 
00118     bspbrush_t  *mapBrush;          // not valid for patches
00119     side_t      *side;              // not valid for patches
00120 
00121     struct drawsurf_s   *nextOnShader;  // when sorting by shader for lightmaps
00122 
00123     int         fogNum;             // set by FogDrawSurfs
00124 
00125     int         lightmapNum;        // -1 = no lightmap
00126     int         lightmapX, lightmapY;
00127     int         lightmapWidth, lightmapHeight;
00128 
00129     int         numVerts;
00130     drawVert_t  *verts;
00131 
00132     int         numIndexes;
00133     int         *indexes;
00134 
00135     // for faces only
00136     int         planeNum;
00137 
00138     vec3_t      lightmapOrigin;     // also used for flares
00139     vec3_t      lightmapVecs[3];    // also used for flares
00140 
00141     // for patches only
00142     qboolean    patch;
00143     int         patchWidth;
00144     int         patchHeight;
00145 
00146     // for misc_models only
00147     qboolean    miscModel;
00148 
00149     qboolean    flareSurface;
00150 } mapDrawSurface_t;
00151 
00152 typedef struct drawSurfRef_s {
00153     struct drawSurfRef_s    *nextRef;
00154     int                     outputNumber;
00155 } drawSurfRef_t;
00156 
00157 typedef struct node_s {
00158     // both leafs and nodes
00159     int             planenum;   // -1 = leaf node
00160     struct node_s   *parent;
00161     vec3_t          mins, maxs; // valid after portalization
00162     bspbrush_t      *volume;    // one for each leaf/node
00163 
00164     // nodes only
00165     side_t          *side;      // the side that created the node
00166     struct node_s   *children[2];
00167     qboolean        hint;
00168     int             tinyportals;
00169     vec3_t          referencepoint;
00170 
00171     // leafs only
00172     qboolean        opaque;     // view can never be inside
00173     qboolean        areaportal;
00174     int             cluster;    // for portalfile writing
00175     int             area;       // for areaportals
00176     bspbrush_t      *brushlist; // fragments of all brushes in this leaf
00177     drawSurfRef_t   *drawSurfReferences;    // references to patches pushed down
00178 
00179     int             occupied;   // 1 or greater can reach entity
00180     entity_t        *occupant;  // for leak file testing
00181 
00182     struct portal_s *portals;   // also on nodes during construction
00183 } node_t;
00184 
00185 typedef struct portal_s {
00186     plane_t     plane;
00187     node_t      *onnode;        // NULL = outside box
00188     node_t      *nodes[2];      // [0] = front side of plane
00189     struct portal_s *next[2];
00190     winding_t   *winding;
00191 
00192     qboolean    sidefound;      // false if ->side hasn't been checked
00193     qboolean    hint;
00194     side_t      *side;          // NULL = non-visible
00195 } portal_t;
00196 
00197 typedef struct {
00198     node_t      *headnode;
00199     node_t      outside_node;
00200     vec3_t      mins, maxs;
00201 } tree_t;
00202 
00203 extern  int         entity_num;
00204 
00205 
00206 extern  qboolean    noprune;
00207 extern  qboolean    nodetail;
00208 extern  qboolean    fulldetail;
00209 extern  qboolean    nowater;
00210 extern  qboolean    noCurveBrushes;
00211 extern  qboolean    fakemap;
00212 extern  qboolean    coplanar;
00213 extern  qboolean    nofog;
00214 extern  qboolean    testExpand;
00215 extern  qboolean    showseams;
00216 
00217 extern  vec_t       microvolume;
00218 
00219 extern  char        outbase[32];
00220 extern  char        source[1024];
00221 
00222 extern int      samplesize;         //sample size in units
00223 extern int      novertexlighting;
00224 extern int      nogridlighting;
00225 
00226 //=============================================================================
00227 
00228 // brush.c
00229 
00230 int CountBrushList (bspbrush_t *brushes);
00231 bspbrush_t *AllocBrush (int numsides);
00232 void FreeBrush (bspbrush_t *brushes);
00233 void FreeBrushList (bspbrush_t *brushes);
00234 bspbrush_t *CopyBrush (bspbrush_t *brush);
00235 void DrawBrushList (bspbrush_t *brush);
00236 void WriteBrushList (char *name, bspbrush_t *brush, qboolean onlyvis);
00237 void PrintBrush (bspbrush_t *brush);
00238 qboolean BoundBrush (bspbrush_t *brush);
00239 qboolean CreateBrushWindings (bspbrush_t *brush);
00240 bspbrush_t  *BrushFromBounds (vec3_t mins, vec3_t maxs);
00241 vec_t BrushVolume (bspbrush_t *brush);
00242 void WriteBspBrushMap (char *name, bspbrush_t *list);
00243 
00244 void FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree );
00245 void FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree );
00246 
00247 //=============================================================================
00248 
00249 // map.c
00250 
00251 extern  int         entitySourceBrushes;
00252 
00253 // mapplanes[ num^1 ] will always be the mirror or mapplanes[ num ]
00254 // nummapplanes will always be even
00255 extern  plane_t     mapplanes[MAX_MAP_PLANES];
00256 extern  int         nummapplanes;
00257 
00258 extern  vec3_t      map_mins, map_maxs;
00259 
00260 extern  char        mapIndexedShaders[MAX_MAP_BRUSHSIDES][MAX_QPATH];
00261 extern  int         numMapIndexedShaders;
00262 
00263 extern  entity_t    *mapent;
00264 
00265 #define     MAX_BUILD_SIDES     300
00266 extern  bspbrush_t  *buildBrush;
00267 
00268 
00269 void        LoadMapFile (char *filename);
00270 int         FindFloatPlane (vec3_t normal, vec_t dist);
00271 int         PlaneTypeForNormal (vec3_t normal);
00272 bspbrush_t  *FinishBrush( void );
00273 mapDrawSurface_t    *AllocDrawSurf( void );
00274 mapDrawSurface_t    *DrawSurfaceForSide( bspbrush_t *b, side_t *s, winding_t *w );
00275 
00276 //=============================================================================
00277 
00278 //=============================================================================
00279 
00280 // draw.c
00281 
00282 extern  vec3_t      draw_mins, draw_maxs;
00283 extern  qboolean    drawflag;
00284 
00285 void Draw_ClearWindow (void);
00286 void DrawWinding (winding_t *w);
00287 
00288 void GLS_BeginScene (void);
00289 void GLS_Winding (winding_t *w, int code);
00290 void GLS_EndScene (void);
00291 
00292 //=============================================================================
00293 
00294 // csg
00295 
00296 bspbrush_t *MakeBspBrushList ( bspbrush_t *brushes, vec3_t clipmins, vec3_t clipmaxs);
00297 
00298 //=============================================================================
00299 
00300 // brushbsp
00301 
00302 #define PSIDE_FRONT         1
00303 #define PSIDE_BACK          2
00304 #define PSIDE_BOTH          (PSIDE_FRONT|PSIDE_BACK)
00305 #define PSIDE_FACING        4
00306 
00307 int BoxOnPlaneSide (vec3_t mins, vec3_t maxs, plane_t *plane);
00308 qboolean WindingIsTiny (winding_t *w);
00309 
00310 void SplitBrush (bspbrush_t *brush, int planenum,
00311     bspbrush_t **front, bspbrush_t **back);
00312 
00313 tree_t *AllocTree (void);
00314 node_t *AllocNode (void);
00315 
00316 tree_t *BrushBSP (bspbrush_t *brushlist, vec3_t mins, vec3_t maxs);
00317 
00318 //=============================================================================
00319 
00320 // portals.c
00321 
00322 void MakeHeadnodePortals (tree_t *tree);
00323 void MakeNodePortal (node_t *node);
00324 void SplitNodePortals (node_t *node);
00325 
00326 qboolean    Portal_Passable(portal_t *p);
00327 
00328 qboolean FloodEntities (tree_t *tree);
00329 void FillOutside (node_t *headnode);
00330 void FloodAreas (tree_t *tree);
00331 bspface_t *VisibleFaces(entity_t *e, tree_t *tree);
00332 void FreePortal (portal_t *p);
00333 
00334 void MakeTreePortals (tree_t *tree);
00335 
00336 //=============================================================================
00337 
00338 // glfile.c
00339 
00340 void OutputWinding( winding_t *w, FILE *glview );
00341 void WriteGLView( tree_t *tree, char *source );
00342 
00343 //=============================================================================
00344 
00345 // leakfile.c
00346 
00347 void LeakFile( tree_t *tree );
00348 
00349 //=============================================================================
00350 
00351 // prtfile.c
00352 
00353 void NumberClusters( tree_t *tree );
00354 void WritePortalFile( tree_t *tree );
00355 
00356 //=============================================================================
00357 
00358 // writebsp.c
00359 
00360 void SetModelNumbers (void);
00361 void SetLightStyles (void);
00362 
00363 int EmitShader( const char *shader );
00364 
00365 void BeginBSPFile (void);
00366 void EndBSPFile (void);
00367 
00368 void BeginModel (void);
00369 void EndModel( node_t *headnode );
00370 
00371 
00372 //=============================================================================
00373 
00374 // tree.c
00375 
00376 void FreeTree (tree_t *tree);
00377 void FreeTree_r (node_t *node);
00378 void PrintTree_r (node_t *node, int depth);
00379 void FreeTreePortals_r (node_t *node);
00380 
00381 //=============================================================================
00382 
00383 // patch.c
00384 
00385 extern  int         numMapPatches;
00386 
00387 mapDrawSurface_t    *DrawSurfaceForMesh( mesh_t *m );
00388 void ParsePatch( void );
00389 mesh_t *SubdivideMesh( mesh_t in, float maxError, float minLength );
00390 void PatchMapDrawSurfs( entity_t *e );
00391 
00392 //=============================================================================
00393 
00394 // lightmap.c
00395 
00396 void AllocateLightmaps( entity_t *e );
00397 
00398 //=============================================================================
00399 
00400 // tjunction.c
00401 
00402 void FixTJunctions( entity_t *e );
00403 
00404 
00405 //=============================================================================
00406 
00407 // fog.c
00408 
00409 void FogDrawSurfs( void );
00410 winding_t   *WindingFromDrawSurf( mapDrawSurface_t *ds );
00411 
00412 //=============================================================================
00413 
00414 // facebsp.c
00415 
00416 bspface_t   *BspFaceForPortal( portal_t *p );
00417 bspface_t   *MakeStructuralBspFaceList( bspbrush_t *list );
00418 bspface_t   *MakeVisibleBspFaceList( bspbrush_t *list );
00419 tree_t *FaceBSP( bspface_t *list );
00420 
00421 //=============================================================================
00422 
00423 // misc_model.c
00424 
00425 extern  int     c_triangleModels;
00426 extern  int     c_triangleSurfaces;
00427 extern  int     c_triangleVertexes;
00428 extern  int     c_triangleIndexes;
00429 
00430 void AddTriangleModels( tree_t *tree );
00431 
00432 //=============================================================================
00433 
00434 // surface.c
00435 
00436 extern  mapDrawSurface_t    mapDrawSurfs[MAX_MAP_DRAW_SURFS];
00437 extern  int         numMapDrawSurfs;
00438 
00439 mapDrawSurface_t    *AllocDrawSurf( void );
00440 void    MergeSides( entity_t *e, tree_t *tree );
00441 void    SubdivideDrawSurfs( entity_t *e, tree_t *tree );
00442 void    MakeDrawSurfaces( bspbrush_t *b );
00443 void    ClipSidesIntoTree( entity_t *e, tree_t *tree );
00444 void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree );
00445 
00446 //==============================================================================
00447 
00448 // brush_primit.c
00449 
00450 #define BPRIMIT_UNDEFINED 0
00451 #define BPRIMIT_OLDBRUSHES 1
00452 #define BPRIMIT_NEWBRUSHES 2
00453 extern  int g_bBrushPrimit;
00454 
00455 void ComputeAxisBase( vec3_t normal, vec3_t texX, vec3_t texY);

Generated on Thu Aug 25 12:37:19 2005 for Quake III Arena by  doxygen 1.3.9.1