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