| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "cmdlib.h" |
| 24 |
#include "mathlib.h" |
| 25 |
#include "scriplib.h" |
| 26 |
#include "polylib.h" |
| 27 |
#include "threads.h" |
| 28 |
#include "bspfile.h" |
| 29 |
|
| 30 |
#define MAX_BRUSH_SIDES 128 |
| 31 |
#define CLIP_EPSILON 0.1 |
| 32 |
|
| 33 |
#define BOGUS_RANGE 8192 |
| 34 |
|
| 35 |
#define TEXINFO_NODE -1 // side is allready on a node |
| 36 |
|
| 37 |
typedef struct plane_s |
| 38 |
{ |
| 39 |
vec3_t normal; |
| 40 |
vec_t dist; |
| 41 |
int type; |
| 42 |
struct plane_s *hash_chain; |
| 43 |
} plane_t; |
| 44 |
|
| 45 |
typedef struct |
| 46 |
{ |
| 47 |
vec_t shift[2]; |
| 48 |
vec_t rotate; |
| 49 |
vec_t scale[2]; |
| 50 |
char name[32]; |
| 51 |
int flags; |
| 52 |
int value; |
| 53 |
} brush_texture_t; |
| 54 |
|
| 55 |
typedef struct side_s |
| 56 |
{ |
| 57 |
int planenum; |
| 58 |
int texinfo; |
| 59 |
winding_t *winding; |
| 60 |
struct side_s *original; |
| 61 |
int contents; |
| 62 |
int surf; |
| 63 |
qboolean visible; |
| 64 |
qboolean tested; |
| 65 |
qboolean bevel; |
| 66 |
} side_t; |
| 67 |
|
| 68 |
typedef struct brush_s |
| 69 |
{ |
| 70 |
int entitynum; |
| 71 |
int brushnum; |
| 72 |
|
| 73 |
int contents; |
| 74 |
|
| 75 |
vec3_t mins, maxs; |
| 76 |
|
| 77 |
int numsides; |
| 78 |
side_t *original_sides; |
| 79 |
} mapbrush_t; |
| 80 |
|
| 81 |
#define PLANENUM_LEAF -1 |
| 82 |
|
| 83 |
#define MAXEDGES 20 |
| 84 |
|
| 85 |
typedef struct face_s |
| 86 |
{ |
| 87 |
struct face_s *next; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
struct face_s *merged; |
| 93 |
struct face_s *split[2]; |
| 94 |
|
| 95 |
struct portal_s *portal; |
| 96 |
int texinfo; |
| 97 |
int planenum; |
| 98 |
int contents; |
| 99 |
int outputnumber; |
| 100 |
winding_t *w; |
| 101 |
int numpoints; |
| 102 |
qboolean badstartvert; |
| 103 |
int vertexnums[MAXEDGES]; |
| 104 |
} face_t; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
typedef struct bspbrush_s |
| 109 |
{ |
| 110 |
struct bspbrush_s *next; |
| 111 |
vec3_t mins, maxs; |
| 112 |
int side, testside; |
| 113 |
mapbrush_t *original; |
| 114 |
int numsides; |
| 115 |
side_t sides[6]; |
| 116 |
} bspbrush_t; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
#define MAX_NODE_BRUSHES 8 |
| 121 |
typedef struct node_s |
| 122 |
{ |
| 123 |
|
| 124 |
int planenum; |
| 125 |
struct node_s *parent; |
| 126 |
vec3_t mins, maxs; |
| 127 |
bspbrush_t *volume; |
| 128 |
|
| 129 |
|
| 130 |
qboolean detail_seperator; |
| 131 |
side_t *side; |
| 132 |
struct node_s *children[2]; |
| 133 |
face_t *faces; |
| 134 |
|
| 135 |
|
| 136 |
bspbrush_t *brushlist; |
| 137 |
int contents; |
| 138 |
int occupied; |
| 139 |
entity_t *occupant; |
| 140 |
int cluster; |
| 141 |
int area; |
| 142 |
struct portal_s *portals; |
| 143 |
} node_t; |
| 144 |
|
| 145 |
typedef struct portal_s |
| 146 |
{ |
| 147 |
plane_t plane; |
| 148 |
node_t *onnode; |
| 149 |
node_t *nodes[2]; |
| 150 |
struct portal_s *next[2]; |
| 151 |
winding_t *winding; |
| 152 |
|
| 153 |
qboolean sidefound; |
| 154 |
side_t *side; |
| 155 |
face_t *face[2]; |
| 156 |
} portal_t; |
| 157 |
|
| 158 |
typedef struct |
| 159 |
{ |
| 160 |
node_t *headnode; |
| 161 |
node_t outside_node; |
| 162 |
vec3_t mins, maxs; |
| 163 |
} tree_t; |
| 164 |
|
| 165 |
extern int entity_num; |
| 166 |
|
| 167 |
extern plane_t mapplanes[MAX_MAP_PLANES]; |
| 168 |
extern int nummapplanes; |
| 169 |
|
| 170 |
extern int nummapbrushes; |
| 171 |
extern mapbrush_t mapbrushes[MAX_MAP_BRUSHES]; |
| 172 |
|
| 173 |
extern vec3_t map_mins, map_maxs; |
| 174 |
|
| 175 |
#define MAX_MAP_SIDES (MAX_MAP_BRUSHES*6) |
| 176 |
|
| 177 |
extern int nummapbrushsides; |
| 178 |
extern side_t brushsides[MAX_MAP_SIDES]; |
| 179 |
|
| 180 |
extern qboolean noprune; |
| 181 |
extern qboolean nodetail; |
| 182 |
extern qboolean fulldetail; |
| 183 |
extern qboolean nomerge; |
| 184 |
extern qboolean nosubdiv; |
| 185 |
extern qboolean nowater; |
| 186 |
extern qboolean noweld; |
| 187 |
extern qboolean noshare; |
| 188 |
extern qboolean notjunc; |
| 189 |
|
| 190 |
extern vec_t microvolume; |
| 191 |
|
| 192 |
extern char outbase[32]; |
| 193 |
|
| 194 |
extern char source[1024]; |
| 195 |
|
| 196 |
void LoadMapFile (char *filename); |
| 197 |
int FindFloatPlane (vec3_t normal, vec_t dist); |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
typedef struct |
| 204 |
{ |
| 205 |
char name[64]; |
| 206 |
int flags; |
| 207 |
int value; |
| 208 |
int contents; |
| 209 |
char animname[64]; |
| 210 |
} textureref_t; |
| 211 |
|
| 212 |
#define MAX_MAP_TEXTURES 1024 |
| 213 |
|
| 214 |
extern textureref_t textureref[MAX_MAP_TEXTURES]; |
| 215 |
|
| 216 |
int FindMiptex (char *name); |
| 217 |
|
| 218 |
int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin); |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
void FindGCD (int *v); |
| 223 |
|
| 224 |
mapbrush_t *Brush_LoadEntity (entity_t *ent); |
| 225 |
int PlaneTypeForNormal (vec3_t normal); |
| 226 |
qboolean MakeBrushPlanes (mapbrush_t *b); |
| 227 |
int FindIntPlane (int *inormal, int *iorigin); |
| 228 |
void CreateBrush (int brushnum); |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
extern vec3_t draw_mins, draw_maxs; |
| 236 |
extern qboolean drawflag; |
| 237 |
|
| 238 |
void Draw_ClearWindow (void); |
| 239 |
void DrawWinding (winding_t *w); |
| 240 |
|
| 241 |
void GLS_BeginScene (void); |
| 242 |
void GLS_Winding (winding_t *w, int code); |
| 243 |
void GLS_EndScene (void); |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
bspbrush_t *MakeBspBrushList (int startbrush, int endbrush, |
| 250 |
vec3_t clipmins, vec3_t clipmaxs); |
| 251 |
bspbrush_t *ChopBrushes (bspbrush_t *head); |
| 252 |
bspbrush_t *InitialBrushList (bspbrush_t *list); |
| 253 |
bspbrush_t *OptimizedBrushList (bspbrush_t *list); |
| 254 |
|
| 255 |
void WriteBrushMap (char *name, bspbrush_t *list); |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
void WriteBrushList (char *name, bspbrush_t *brush, qboolean onlyvis); |
| 262 |
|
| 263 |
bspbrush_t *CopyBrush (bspbrush_t *brush); |
| 264 |
|
| 265 |
void SplitBrush (bspbrush_t *brush, int planenum, |
| 266 |
bspbrush_t **front, bspbrush_t **back); |
| 267 |
|
| 268 |
tree_t *AllocTree (void); |
| 269 |
node_t *AllocNode (void); |
| 270 |
bspbrush_t *AllocBrush (int numsides); |
| 271 |
int CountBrushList (bspbrush_t *brushes); |
| 272 |
void FreeBrush (bspbrush_t *brushes); |
| 273 |
vec_t BrushVolume (bspbrush_t *brush); |
| 274 |
|
| 275 |
void BoundBrush (bspbrush_t *brush); |
| 276 |
void FreeBrushList (bspbrush_t *brushes); |
| 277 |
|
| 278 |
tree_t *BrushBSP (bspbrush_t *brushlist, vec3_t mins, vec3_t maxs); |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
int VisibleContents (int contents); |
| 285 |
|
| 286 |
void MakeHeadnodePortals (tree_t *tree); |
| 287 |
void MakeNodePortal (node_t *node); |
| 288 |
void SplitNodePortals (node_t *node); |
| 289 |
|
| 290 |
qboolean Portal_VisFlood (portal_t *p); |
| 291 |
|
| 292 |
qboolean FloodEntities (tree_t *tree); |
| 293 |
void FillOutside (node_t *headnode); |
| 294 |
void FloodAreas (tree_t *tree); |
| 295 |
void MarkVisibleSides (tree_t *tree, int start, int end); |
| 296 |
void FreePortal (portal_t *p); |
| 297 |
void EmitAreaPortals (node_t *headnode); |
| 298 |
|
| 299 |
void MakeTreePortals (tree_t *tree); |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
void OutputWinding (winding_t *w, FILE *glview); |
| 306 |
void WriteGLView (tree_t *tree, char *source); |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
void LeakFile (tree_t *tree); |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
void WritePortalFile (tree_t *tree); |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
void SetModelNumbers (void); |
| 325 |
void SetLightStyles (void); |
| 326 |
|
| 327 |
void BeginBSPFile (void); |
| 328 |
void WriteBSP (node_t *headnode); |
| 329 |
void EndBSPFile (void); |
| 330 |
void BeginModel (void); |
| 331 |
void EndModel (void); |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
void MakeFaces (node_t *headnode); |
| 338 |
void FixTjuncs (node_t *headnode); |
| 339 |
int GetEdge2 (int v1, int v2, face_t *f); |
| 340 |
|
| 341 |
face_t *AllocFace (void); |
| 342 |
void FreeFace (face_t *f); |
| 343 |
|
| 344 |
void MergeNodeFaces (node_t *node); |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
void FreeTree (tree_t *tree); |
| 351 |
void FreeTree_r (node_t *node); |
| 352 |
void PrintTree_r (node_t *node, int depth); |
| 353 |
void FreeTreePortals_r (node_t *node); |
| 354 |
void PruneNodes_r (node_t *node); |
| 355 |
void PruneNodes (node_t *node); |