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 
00024 #if defined(WIN32) || defined(_WIN32)
00025 #include <io.h>
00026 #endif
00027 #include <malloc.h>
00028 #include "l_cmd.h"
00029 #include "l_math.h"
00030 #include "l_poly.h"
00031 #include "l_threads.h"
00032 #include "../botlib/l_script.h"
00033 #include "l_bsp_ent.h"
00034 #include "q2files.h"
00035 #include "l_mem.h"
00036 #include "l_utils.h"
00037 #include "l_log.h"
00038 #include "l_qfiles.h"
00039 
00040 #define BSPC_VERSION        "2.1h"
00041 
00042 #define ME
00043 #define DEBUG
00044 #define NODELIST
00045 #define SIN
00046 
00047 #define MAX_BRUSH_SIDES     128     //maximum number of sides per brush
00048 #define CLIP_EPSILON        0.1
00049 #define MAX_MAP_BOUNDS      65535
00050 #define BOGUS_RANGE         (MAX_MAP_BOUNDS+128)    //somewhere outside the map
00051 #define TEXINFO_NODE        -1      //side is allready on a node
00052 #define PLANENUM_LEAF       -1      //used for leaf nodes
00053 #define MAXEDGES            20      //maximum number of face edges
00054 #define MAX_NODE_BRUSHES    8       //maximum brushes in a node
00055 //side flags
00056 #define SFL_TESTED          1
00057 #define SFL_VISIBLE         2
00058 #define SFL_BEVEL           4
00059 #define SFL_TEXTURED        8
00060 #define SFL_CURVE           16
00061 
00062 //map plane
00063 typedef struct plane_s
00064 {
00065     vec3_t normal;
00066     vec_t dist;
00067     int type;
00068     int signbits;
00069     struct plane_s  *hash_chain;
00070 } plane_t;
00071 //brush texture
00072 typedef struct
00073 {
00074     vec_t   shift[2];
00075     vec_t   rotate;
00076     vec_t   scale[2];
00077     char    name[32];
00078     int     flags;
00079     int     value;
00080 } brush_texture_t;
00081 //brush side
00082 typedef struct side_s
00083 {
00084     int             planenum;   // map plane this side is in
00085     int             texinfo;        // texture reference
00086     winding_t       *winding;   // winding of this side
00087     struct side_s   *original;  // bspbrush_t sides will reference the mapbrush_t sides
00088    int              lightinfo;  // for SIN only
00089     int             contents;   // from miptex
00090     int             surf;           // from miptex
00091     unsigned short flags;       // side flags
00092 } side_t;       //sizeof(side_t) = 36
00093 //map brush
00094 typedef struct mapbrush_s
00095 {
00096     int     entitynum;
00097     int     brushnum;
00098 
00099     int     contents;
00100 #ifdef ME
00101     int     expansionbbox;          //bbox used for expansion of the brush
00102     int     leafnum;
00103     int     modelnum;
00104 #endif
00105 
00106     vec3_t  mins, maxs;
00107 
00108     int     numsides;
00109     side_t  *original_sides;
00110 } mapbrush_t;
00111 //bsp face
00112 typedef struct face_s
00113 {
00114     struct face_s       *next;      // on node
00115 
00116     // the chain of faces off of a node can be merged or split,
00117     // but each face_t along the way will remain in the chain
00118     // until the entire tree is freed
00119     struct face_s       *merged;    // if set, this face isn't valid anymore
00120     struct face_s       *split[2];  // if set, this face isn't valid anymore
00121 
00122     struct portal_s *portal;
00123     int                 texinfo;
00124 #ifdef SIN
00125    int                  lightinfo;
00126 #endif
00127     int                 planenum;
00128     int                 contents;   // faces in different contents can't merge
00129     int                 outputnumber;
00130     winding_t           *w;
00131     int                 numpoints;
00132     qboolean                badstartvert;   // tjunctions cannot be fixed without a midpoint vertex
00133     int                 vertexnums[MAXEDGES];
00134 } face_t;
00135 //bsp brush
00136 typedef struct bspbrush_s
00137 {
00138     struct      bspbrush_s  *next;
00139     vec3_t      mins, maxs;
00140     int         side, testside;     // side of node during construction
00141     mapbrush_t  *original;
00142     int         numsides;
00143     side_t      sides[6];           // variably sized
00144 } bspbrush_t;   //sizeof(bspbrush_t) = 44 + numsides * sizeof(side_t)
00145 //bsp node
00146 typedef struct node_s
00147 {
00148     //both leafs and nodes
00149     int             planenum;   // -1 = leaf node
00150     struct node_s   *parent;
00151     vec3_t          mins, maxs; // valid after portalization
00152     bspbrush_t      *volume;        // one for each leaf/node
00153 
00154     // nodes only
00155     qboolean            detail_seperator;   // a detail brush caused the split
00156     side_t          *side;      // the side that created the node
00157     struct node_s   *children[2];
00158     face_t          *faces;
00159 
00160     // leafs only
00161     bspbrush_t      *brushlist; // fragments of all brushes in this leaf
00162     int             contents;   // OR of all brush contents
00163     int             occupied;   // 1 or greater can reach entity
00164     entity_t            *occupant;  // for leak file testing
00165     int             cluster;        // for portalfile writing
00166     int             area;           // for areaportals
00167     struct portal_s *portals;   // also on nodes during construction
00168 #ifdef NODELIST
00169     struct node_s *next;            //next node in the nodelist
00170 #endif
00171 #ifdef ME
00172     int expansionbboxes;            //OR of all bboxes used for expansion of the brushes
00173     int modelnum;
00174 #endif
00175 } node_t;       //sizeof(node_t) = 80 bytes
00176 //bsp portal
00177 typedef struct portal_s
00178 {
00179     plane_t plane;
00180     node_t *onnode;                 // NULL = outside box
00181     node_t *nodes[2];               // [0] = front side of plane
00182     struct portal_s *next[2];
00183     winding_t *winding;
00184 
00185     qboolean    sidefound;          // false if ->side hasn't been checked
00186     side_t *side;                   // NULL = non-visible
00187     face_t *face[2];                // output face in bsp file
00188 #ifdef ME
00189     struct tmp_face_s *tmpface;     //pointer to the tmpface created for this portal
00190     int planenum;                   //number of the map plane used by the portal
00191 #endif
00192 } portal_t;
00193 //bsp tree
00194 typedef struct
00195 {
00196     node_t      *headnode;
00197     node_t      outside_node;
00198     vec3_t      mins, maxs;
00199 } tree_t;
00200 
00201 //=============================================================================
00202 // bspc.c
00203 //=============================================================================
00204 
00205 extern  qboolean noprune;
00206 extern  qboolean nodetail;
00207 extern  qboolean fulldetail;
00208 extern  qboolean nomerge;
00209 extern  qboolean nosubdiv;
00210 extern  qboolean nowater;
00211 extern  qboolean noweld;
00212 extern  qboolean noshare;
00213 extern  qboolean notjunc;
00214 extern  qboolean onlyents;
00215 #ifdef ME
00216 extern  qboolean nocsg;
00217 extern  qboolean create_aas;
00218 extern  qboolean freetree;
00219 extern  qboolean lessbrushes;
00220 extern  qboolean nobrushmerge;
00221 extern  qboolean cancelconversion;
00222 extern  qboolean noliquids;
00223 extern  qboolean capsule_collision;
00224 #endif //ME
00225 
00226 extern  float subdivide_size;
00227 extern  vec_t microvolume;
00228 
00229 extern  char outbase[32];
00230 extern  char source[1024];
00231 
00232 //=============================================================================
00233 // map.c
00234 //=============================================================================
00235 
00236 #define MAX_MAPFILE_PLANES          256000
00237 #define MAX_MAPFILE_BRUSHES         65535
00238 #define MAX_MAPFILE_BRUSHSIDES      (MAX_MAPFILE_BRUSHES*8)
00239 #define MAX_MAPFILE_TEXINFO         8192
00240 
00241 extern  int         entity_num;
00242 
00243 extern  plane_t     mapplanes[MAX_MAPFILE_PLANES];
00244 extern  int         nummapplanes;
00245 extern  int         mapplaneusers[MAX_MAPFILE_PLANES];
00246 
00247 extern  int         nummapbrushes;
00248 extern  mapbrush_t  mapbrushes[MAX_MAPFILE_BRUSHES];
00249 
00250 extern  vec3_t      map_mins, map_maxs;
00251 
00252 extern  int         nummapbrushsides;
00253 extern  side_t      brushsides[MAX_MAPFILE_BRUSHSIDES];
00254 extern  brush_texture_t side_brushtextures[MAX_MAPFILE_BRUSHSIDES];
00255 
00256 #ifdef ME
00257 
00258 typedef struct
00259 {
00260     float   vecs[2][4];     // [s/t][xyz offset]
00261     int     flags;          // miptex flags + overrides
00262     int     value;
00263     char    texture[64];    // texture name (textures/*.wal)
00264     int     nexttexinfo;    // for animations, -1 = end of chain
00265 } map_texinfo_t;
00266 
00267 extern  map_texinfo_t       map_texinfo[MAX_MAPFILE_TEXINFO];
00268 extern  int                 map_numtexinfo;
00269 #define NODESTACKSIZE       1024
00270 
00271 #define MAPTYPE_QUAKE1      1
00272 #define MAPTYPE_QUAKE2      2
00273 #define MAPTYPE_QUAKE3      3
00274 #define MAPTYPE_HALFLIFE    4
00275 #define MAPTYPE_SIN         5
00276 
00277 extern  int nodestack[NODESTACKSIZE];
00278 extern  int *nodestackptr;
00279 extern  int nodestacksize;
00280 extern  int brushmodelnumbers[MAX_MAPFILE_BRUSHES];
00281 extern  int dbrushleafnums[MAX_MAPFILE_BRUSHES];
00282 extern  int dplanes2mapplanes[MAX_MAPFILE_PLANES];
00283 
00284 extern  int loadedmaptype;
00285 #endif //ME
00286 
00287 extern  int c_boxbevels;
00288 extern  int c_edgebevels;
00289 extern  int c_areaportals;
00290 extern  int c_clipbrushes;
00291 extern  int c_squattbrushes;
00292 
00293 //finds a float plane for the given normal and distance
00294 int FindFloatPlane(vec3_t normal, vec_t dist);
00295 //returns the plane type for the given normal
00296 int PlaneTypeForNormal(vec3_t normal);
00297 //returns the plane defined by the three given points
00298 int PlaneFromPoints(int *p0, int *p1, int *p2);
00299 //add bevels to the map brush
00300 void AddBrushBevels(mapbrush_t *b);
00301 //makes brush side windings for the brush
00302 qboolean MakeBrushWindings(mapbrush_t *ob);
00303 //marks brush bevels of the brush as bevel
00304 void MarkBrushBevels(mapbrush_t *brush);
00305 //returns true if the map brush already exists
00306 int BrushExists(mapbrush_t *brush);
00307 //loads a map from a bsp file
00308 int LoadMapFromBSP(struct quakefile_s *qf);
00309 //resets map loading
00310 void ResetMapLoading(void);
00311 //print some map info
00312 void PrintMapInfo(void);
00313 //writes a map file (type depending on loaded map type)
00314 void WriteMapFile(char *filename);
00315 
00316 //=============================================================================
00317 // map_q2.c
00318 //=============================================================================
00319 
00320 void Q2_ResetMapLoading(void);
00321 //loads a Quake2 map file
00322 void Q2_LoadMapFile(char *filename);
00323 //loads a map from a Quake2 bsp file
00324 void Q2_LoadMapFromBSP(char *filename, int offset, int length);
00325 
00326 //=============================================================================
00327 // map_q1.c
00328 //=============================================================================
00329 
00330 void Q1_ResetMapLoading(void);
00331 //loads a Quake2 map file
00332 void Q1_LoadMapFile(char *filename);
00333 //loads a map from a Quake1 bsp file
00334 void Q1_LoadMapFromBSP(char *filename, int offset, int length);
00335 
00336 //=============================================================================
00337 // map_q3.c
00338 //=============================================================================
00339 void Q3_ResetMapLoading(void);
00340 //loads a map from a Quake3 bsp file
00341 void Q3_LoadMapFromBSP(struct quakefile_s *qf);
00342 
00343 //=============================================================================
00344 // map_sin.c
00345 //=============================================================================
00346 
00347 void Sin_ResetMapLoading(void);
00348 //loads a Sin map file
00349 void Sin_LoadMapFile(char *filename);
00350 //loads a map from a Sin bsp file
00351 void Sin_LoadMapFromBSP(char *filename, int offset, int length);
00352 
00353 //=============================================================================
00354 // map_hl.c
00355 //=============================================================================
00356 
00357 void HL_ResetMapLoading(void);
00358 //loads a Half-Life map file
00359 void HL_LoadMapFile(char *filename);
00360 //loads a map from a Half-Life bsp file
00361 void HL_LoadMapFromBSP(char *filename, int offset, int length);
00362 
00363 //=============================================================================
00364 // textures.c
00365 //=============================================================================
00366 
00367 typedef struct
00368 {
00369     char    name[64];
00370     int     flags;
00371     int     value;
00372     int     contents;
00373     char    animname[64];
00374 } textureref_t;
00375 
00376 #define MAX_MAP_TEXTURES    1024
00377 
00378 extern  textureref_t    textureref[MAX_MAP_TEXTURES];
00379 
00380 int FindMiptex(char *name);
00381 int TexinfoForBrushTexture(plane_t *plane, brush_texture_t *bt, vec3_t origin);
00382 void TextureAxisFromPlane(plane_t *pln, vec3_t xv, vec3_t yv);
00383 
00384 //=============================================================================
00385 // csg
00386 //=============================================================================
00387 
00388 bspbrush_t *MakeBspBrushList(int startbrush, int endbrush, vec3_t clipmins, vec3_t clipmaxs);
00389 bspbrush_t *ChopBrushes(bspbrush_t *head);
00390 bspbrush_t *InitialBrushList(bspbrush_t *list);
00391 bspbrush_t *OptimizedBrushList(bspbrush_t *list);
00392 void WriteBrushMap(char *name, bspbrush_t *list);
00393 void CheckBSPBrush(bspbrush_t *brush);
00394 void BSPBrushWindings(bspbrush_t *brush);
00395 bspbrush_t *TryMergeBrushes(bspbrush_t *brush1, bspbrush_t *brush2);
00396 tree_t *ProcessWorldBrushes(int brush_start, int brush_end);
00397 
00398 //=============================================================================
00399 // brushbsp
00400 //=============================================================================
00401 
00402 #define PSIDE_FRONT         1
00403 #define PSIDE_BACK          2
00404 #define PSIDE_BOTH          (PSIDE_FRONT|PSIDE_BACK)
00405 #define PSIDE_FACING        4
00406 
00407 void WriteBrushList(char *name, bspbrush_t *brush, qboolean onlyvis);
00408 bspbrush_t *CopyBrush(bspbrush_t *brush);
00409 void SplitBrush(bspbrush_t *brush, int planenum, bspbrush_t **front, bspbrush_t **back);
00410 node_t *AllocNode(void);
00411 bspbrush_t *AllocBrush(int numsides);
00412 int CountBrushList(bspbrush_t *brushes);
00413 void FreeBrush(bspbrush_t *brushes);
00414 vec_t BrushVolume(bspbrush_t *brush);
00415 void BoundBrush(bspbrush_t *brush);
00416 void FreeBrushList(bspbrush_t *brushes);
00417 tree_t *BrushBSP(bspbrush_t *brushlist, vec3_t mins, vec3_t maxs);
00418 bspbrush_t *BrushFromBounds(vec3_t mins, vec3_t maxs);
00419 int BrushMostlyOnSide(bspbrush_t *brush, plane_t *plane);
00420 qboolean WindingIsHuge(winding_t *w);
00421 qboolean WindingIsTiny(winding_t *w);
00422 void ResetBrushBSP(void);
00423 
00424 //=============================================================================
00425 // portals.c
00426 //=============================================================================
00427 
00428 int VisibleContents (int contents);
00429 void MakeHeadnodePortals (tree_t *tree);
00430 void MakeNodePortal (node_t *node);
00431 void SplitNodePortals (node_t *node);
00432 qboolean Portal_VisFlood (portal_t *p);
00433 qboolean FloodEntities (tree_t *tree);
00434 void FillOutside (node_t *headnode);
00435 void FloodAreas (tree_t *tree);
00436 void MarkVisibleSides (tree_t *tree, int start, int end);
00437 void FreePortal (portal_t *p);
00438 void EmitAreaPortals (node_t *headnode);
00439 void MakeTreePortals (tree_t *tree);
00440 
00441 //=============================================================================
00442 // glfile.c
00443 //=============================================================================
00444 
00445 void OutputWinding(winding_t *w, FILE *glview);
00446 void WriteGLView(tree_t *tree, char *source);
00447 
00448 //=============================================================================
00449 // gldraw.c
00450 //=============================================================================
00451 
00452 extern vec3_t draw_mins, draw_maxs;
00453 extern qboolean drawflag;
00454 
00455 void Draw_ClearWindow (void);
00456 void DrawWinding (winding_t *w);
00457 void GLS_BeginScene (void);
00458 void GLS_Winding (winding_t *w, int code);
00459 void GLS_EndScene (void);
00460 
00461 //=============================================================================
00462 // leakfile.c
00463 //=============================================================================
00464 
00465 void LeakFile (tree_t *tree);
00466 
00467 //=============================================================================
00468 // tree.c
00469 //=============================================================================
00470 
00471 tree_t *Tree_Alloc(void);
00472 void Tree_Free(tree_t *tree);
00473 void Tree_Free_r(node_t *node);
00474 void Tree_Print_r(node_t *node, int depth);
00475 void Tree_FreePortals_r(node_t *node);
00476 void Tree_PruneNodes_r(node_t *node);
00477 void Tree_PruneNodes(node_t *node);

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