home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / sharewar / quake106 / utils / qbsp / bsp5.h < prev    next >
C/C++ Source or Header  |  1996-09-12  |  7KB  |  298 lines

  1.  
  2. // bsp5.h
  3.  
  4. #include "cmdlib.h"
  5. #include "mathlib.h"
  6. #include "bspfile.h"
  7.  
  8. typedef struct
  9. {
  10.     vec3_t    normal;
  11.     vec_t    dist;
  12.     int        type;
  13. } plane_t;
  14.  
  15.  
  16. #include "map.h"
  17.  
  18. #define    MAX_THREADS    4
  19.  
  20. #define    ON_EPSILON    0.05
  21. #define    BOGUS_RANGE    18000
  22.  
  23. // the exact bounding box of the brushes is expanded some for the headnode
  24. // volume.  is this still needed?
  25. #define    SIDESPACE    24
  26.  
  27. //============================================================================
  28.  
  29.  
  30. typedef struct
  31. {
  32.     int        numpoints;
  33.     vec3_t    points[8];            // variable sized
  34. } winding_t;
  35.  
  36. #define MAX_POINTS_ON_WINDING    64
  37.  
  38. winding_t *BaseWindingForPlane (plane_t *p);
  39. void CheckWinding (winding_t *w);
  40. winding_t    *NewWinding (int points);
  41. void        FreeWinding (winding_t *w);
  42. winding_t    *CopyWinding (winding_t *w);
  43. winding_t    *ClipWinding (winding_t *in, plane_t *split, qboolean keepon);
  44. void    DivideWinding (winding_t *in, plane_t *split, winding_t **front, winding_t **back);
  45.  
  46. //============================================================================
  47.  
  48. #define    MAXEDGES            32
  49. #define    MAXPOINTS            28        // don't let a base face get past this
  50.                                     // because it can be split more later
  51.  
  52. typedef struct visfacet_s
  53. {
  54.     struct visfacet_s    *next;
  55.     
  56.     int                planenum;
  57.     int                planeside;    // which side is the front of the face
  58.     int                texturenum;
  59.     int                contents[2];    // 0 = front side
  60.  
  61.     struct visfacet_s    *original;        // face on node
  62.     int                outputnumber;        // only valid for original faces after
  63.                                         // write surfaces
  64.     int                numpoints;
  65.     vec3_t            pts[MAXEDGES];        // FIXME: change to use winding_t
  66.     int                edges[MAXEDGES];
  67. } face_t;
  68.  
  69.  
  70. typedef struct surface_s
  71. {
  72.     struct surface_s    *next;
  73.     struct surface_s    *original;    // before BSP cuts it up
  74.     int            planenum;
  75.     int            outputplanenum;        // only valid after WriteSurfacePlanes
  76.     vec3_t        mins, maxs;
  77.     qboolean        onnode;                // true if surface has already been used
  78.                                     // as a splitting node
  79.     face_t        *faces;    // links to all the faces on either side of the surf
  80. } surface_t;
  81.  
  82.  
  83. //
  84. // there is a node_t structure for every node and leaf in the bsp tree
  85. //
  86. #define    PLANENUM_LEAF        -1
  87.  
  88. typedef struct node_s
  89. {
  90.     vec3_t            mins,maxs;        // bounding volume, not just points inside
  91.  
  92. // information for decision nodes    
  93.     int                planenum;        // -1 = leaf node    
  94.     int                outputplanenum;    // only valid after WriteNodePlanes
  95.     int                firstface;        // decision node only
  96.     int                numfaces;        // decision node only
  97.     struct node_s    *children[2];    // only valid for decision nodes
  98.     face_t            *faces;            // decision nodes only, list for both sides
  99.     
  100. // information for leafs
  101.     int                contents;        // leaf nodes (0 for decision nodes)
  102.     face_t            **markfaces;    // leaf nodes only, point to node faces
  103.     struct portal_s    *portals;
  104.     int                visleafnum;        // -1 = solid
  105.     int                valid;            // for flood filling
  106.     int                occupied;        // light number in leaf for outside filling
  107. } node_t;
  108.  
  109. //=============================================================================
  110.  
  111. // brush.c
  112.  
  113. #define    NUM_HULLS        2                // normal and +16
  114.  
  115. #define    NUM_CONTENTS    2                // solid and water
  116.  
  117. typedef struct brush_s
  118. {
  119.     struct brush_s    *next;
  120.     vec3_t            mins, maxs;
  121.     face_t            *faces;
  122.     int                contents;
  123. } brush_t;
  124.  
  125. typedef struct
  126. {
  127.     vec3_t        mins, maxs;
  128.     brush_t        *brushes;        // NULL terminated list
  129. } brushset_t;
  130.  
  131. extern    int            numbrushplanes;
  132. extern    plane_t        planes[MAX_MAP_PLANES];
  133.  
  134. brushset_t *Brush_LoadEntity (entity_t *ent, int hullnum);
  135. int    PlaneTypeForNormal (vec3_t normal);
  136. int    FindPlane (plane_t *dplane, int *side);
  137.  
  138. //=============================================================================
  139.  
  140. // csg4.c
  141.  
  142. // build surfaces is also used by GatherNodeFaces
  143. extern    face_t    *validfaces[MAX_MAP_PLANES];
  144. surface_t *BuildSurfaces (void);
  145.  
  146. face_t *NewFaceFromFace (face_t *in);
  147. surface_t *CSGFaces (brushset_t *bs);
  148. void SplitFace (face_t *in, plane_t *split, face_t **front, face_t **back);
  149.  
  150. //=============================================================================
  151.  
  152. // solidbsp.c
  153.  
  154. void DivideFacet (face_t *in, plane_t *split, face_t **front, face_t **back);
  155. void CalcSurfaceInfo (surface_t *surf);
  156. void SubdivideFace (face_t *f, face_t **prevptr);
  157. node_t *SolidBSP (surface_t *surfhead, qboolean midsplit);
  158.  
  159. //=============================================================================
  160.  
  161. // merge.c
  162.  
  163. void MergePlaneFaces (surface_t *plane);
  164. face_t *MergeFaceToList (face_t *face, face_t *list);
  165. face_t *FreeMergeListScraps (face_t *merged);
  166. void MergeAll (surface_t *surfhead);
  167.  
  168. //=============================================================================
  169.  
  170. // surfaces.c
  171.  
  172. extern    int        c_cornerverts;
  173. extern    int        c_tryedges;
  174. extern    face_t        *edgefaces[MAX_MAP_EDGES][2];
  175.  
  176. extern    int        firstmodeledge;
  177. extern    int        firstmodelface;
  178.  
  179. void SubdivideFaces (surface_t *surfhead);
  180.  
  181. surface_t *GatherNodeFaces (node_t *headnode);
  182.  
  183. void MakeFaceEdges (node_t *headnode);
  184.  
  185. //=============================================================================
  186.  
  187. // portals.c
  188.  
  189. typedef struct portal_s
  190. {
  191.     int            planenum;
  192.     node_t        *nodes[2];        // [0] = front side of planenum
  193.     struct portal_s    *next[2];    
  194.     winding_t    *winding;
  195. } portal_t;
  196.  
  197. extern    node_t    outside_node;        // portals outside the world face this
  198.  
  199. void PortalizeWorld (node_t *headnode);
  200. void WritePortalfile (node_t *headnode);
  201. void FreeAllPortals (node_t *node);
  202.  
  203. //=============================================================================
  204.  
  205. // region.c
  206.  
  207. void GrowNodeRegions (node_t *headnode);
  208.  
  209. //=============================================================================
  210.  
  211. // tjunc.c
  212.  
  213. void tjunc (node_t *headnode);
  214.  
  215. //=============================================================================
  216.  
  217. // writebsp.c
  218.  
  219. void WriteNodePlanes (node_t *headnode);
  220. void WriteClipNodes (node_t *headnode);
  221. void WriteDrawNodes (node_t *headnode);
  222.  
  223. void BumpModel (int hullnum);
  224. int FindFinalPlane (dplane_t *p);
  225.  
  226. void BeginBSPFile (void);
  227. void FinishBSPFile (void);
  228.  
  229. //=============================================================================
  230.  
  231. // draw.c
  232.  
  233. void Draw_ClearBounds (void);
  234. void Draw_AddToBounds (vec3_t v);
  235. void Draw_DrawFace (face_t *f);
  236. void Draw_ClearWindow (void);
  237. void Draw_SetRed (void);
  238. void Draw_SetGrey (void);
  239. void Draw_SetBlack (void);
  240. void DrawPoint (vec3_t v);
  241.  
  242. void Draw_SetColor (int c);
  243. void SetColor (int c);
  244. void DrawPortal (portal_t *p);
  245. void DrawLeaf (node_t *l, int color);
  246. void DrawBrush (brush_t *b);
  247.  
  248. void DrawWinding (winding_t *w);
  249. void DrawTri (vec3_t p1, vec3_t p2, vec3_t p3);
  250.  
  251. //=============================================================================
  252.  
  253. // outside.c
  254.  
  255. qboolean FillOutside (node_t *node);
  256.  
  257. //=============================================================================
  258.  
  259. extern    qboolean    drawflag;
  260. extern    qboolean nofill;
  261. extern    qboolean notjunc;
  262. extern    qboolean noclip;
  263. extern    qboolean    verbose;
  264.  
  265. extern    int        subdivide_size;
  266.  
  267. extern    int        hullnum;
  268.  
  269. extern    brushset_t    *brushset;
  270.  
  271. void qprintf (char *fmt, ...);    // only prints if verbose
  272.  
  273. extern    int        valid;
  274.  
  275. extern    char    portfilename[1024];
  276. extern    char    bspfilename[1024];
  277. extern    char    pointfilename[1024];
  278.  
  279. extern    qboolean    worldmodel;
  280.  
  281.  
  282. // misc functions
  283.  
  284. face_t *AllocFace (void);
  285. void FreeFace (face_t *f);
  286.  
  287. struct portal_s *AllocPortal (void);
  288. void FreePortal (struct portal_s *p);
  289.  
  290. surface_t *AllocSurface (void);
  291. void FreeSurface (surface_t *s);
  292.  
  293. node_t *AllocNode (void);
  294. struct brush_s *AllocBrush (void);
  295.  
  296. //=============================================================================
  297.  
  298.