00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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;
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;
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];
00070
00071 float vecs[2][4];
00072
00073 winding_t *winding;
00074 winding_t *visibleHull;
00075
00076 struct shaderInfo_s *shaderInfo;
00077
00078 int contents;
00079 int surfaceFlags;
00080 int value;
00081
00082 qboolean visible;
00083 qboolean bevel;
00084
00085 qboolean backSide;
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;
00095 int brushnum;
00096
00097 struct shaderInfo_s *contentShader;
00098
00099 int contents;
00100 qboolean detail;
00101 qboolean opaque;
00102 int outputNumber;
00103
00104 int portalareas[2];
00105
00106 struct bspbrush_s *original;
00107
00108 vec3_t mins, maxs;
00109 int numsides;
00110 side_t sides[6];
00111 } bspbrush_t;
00112
00113
00114
00115 typedef struct drawsurf_s {
00116 shaderInfo_t *shaderInfo;
00117
00118 bspbrush_t *mapBrush;
00119 side_t *side;
00120
00121 struct drawsurf_s *nextOnShader;
00122
00123 int fogNum;
00124
00125 int lightmapNum;
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
00136 int planeNum;
00137
00138 vec3_t lightmapOrigin;
00139 vec3_t lightmapVecs[3];
00140
00141
00142 qboolean patch;
00143 int patchWidth;
00144 int patchHeight;
00145
00146
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
00159 int planenum;
00160 struct node_s *parent;
00161 vec3_t mins, maxs;
00162 bspbrush_t *volume;
00163
00164
00165 side_t *side;
00166 struct node_s *children[2];
00167 qboolean hint;
00168 int tinyportals;
00169 vec3_t referencepoint;
00170
00171
00172 qboolean opaque;
00173 qboolean areaportal;
00174 int cluster;
00175 int area;
00176 bspbrush_t *brushlist;
00177 drawSurfRef_t *drawSurfReferences;
00178
00179 int occupied;
00180 entity_t *occupant;
00181
00182 struct portal_s *portals;
00183 } node_t;
00184
00185 typedef struct portal_s {
00186 plane_t plane;
00187 node_t *onnode;
00188 node_t *nodes[2];
00189 struct portal_s *next[2];
00190 winding_t *winding;
00191
00192 qboolean sidefound;
00193 qboolean hint;
00194 side_t *side;
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;
00223 extern int novertexlighting;
00224 extern int nogridlighting;
00225
00226
00227
00228
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
00250
00251 extern int entitySourceBrushes;
00252
00253
00254
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
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
00295
00296 bspbrush_t *MakeBspBrushList ( bspbrush_t *brushes, vec3_t clipmins, vec3_t clipmaxs);
00297
00298
00299
00300
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
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
00339
00340 void OutputWinding( winding_t *w, FILE *glview );
00341 void WriteGLView( tree_t *tree, char *source );
00342
00343
00344
00345
00346
00347 void LeakFile( tree_t *tree );
00348
00349
00350
00351
00352
00353 void NumberClusters( tree_t *tree );
00354 void WritePortalFile( tree_t *tree );
00355
00356
00357
00358
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
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
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
00395
00396 void AllocateLightmaps( entity_t *e );
00397
00398
00399
00400
00401
00402 void FixTJunctions( entity_t *e );
00403
00404
00405
00406
00407
00408
00409 void FogDrawSurfs( void );
00410 winding_t *WindingFromDrawSurf( mapDrawSurface_t *ds );
00411
00412
00413
00414
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
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
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
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);