home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / qbsp.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  11.1 KB  |  435 lines

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