2002-09-19 18:51:19 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
See file, 'COPYING', for details.
|
2002-09-23 16:27:17 +00:00
|
|
|
|
|
|
|
$Id$
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// bsp5.h
|
|
|
|
|
|
|
|
#include "QF/mathlib.h"
|
|
|
|
#include "QF/bspfile.h"
|
|
|
|
|
2004-01-11 08:48:58 +00:00
|
|
|
typedef struct {
|
2002-09-19 16:58:48 +00:00
|
|
|
vec3_t normal;
|
|
|
|
vec_t dist;
|
|
|
|
int type;
|
|
|
|
} plane_t;
|
|
|
|
|
|
|
|
#include "map.h"
|
|
|
|
|
|
|
|
#define MAX_THREADS 4
|
|
|
|
|
|
|
|
#define ON_EPSILON 0.05
|
|
|
|
#define BOGUS_RANGE 18000
|
|
|
|
|
|
|
|
// the exact bounding box of the brushes is expanded some for the headnode
|
|
|
|
// volume. is this still needed?
|
|
|
|
#define SIDESPACE 24
|
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
#define TEX_SKIP -1
|
|
|
|
#define TEX_HINT -2
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2004-01-11 08:48:58 +00:00
|
|
|
typedef struct {
|
2002-09-19 16:58:48 +00:00
|
|
|
int numpoints;
|
|
|
|
vec3_t points[8]; // variable sized
|
|
|
|
} winding_t;
|
|
|
|
|
|
|
|
winding_t *BaseWindingForPlane (plane_t *p);
|
|
|
|
winding_t *NewWinding (int points);
|
|
|
|
void FreeWinding (winding_t *w);
|
|
|
|
winding_t *CopyWinding (winding_t *w);
|
2003-09-08 03:00:53 +00:00
|
|
|
winding_t *CopyWindingReverse (winding_t *w);
|
2002-09-19 16:58:48 +00:00
|
|
|
winding_t *ClipWinding (winding_t *in, plane_t *split, qboolean keepon);
|
|
|
|
void DivideWinding (winding_t *in, plane_t *split, winding_t **front, winding_t **back);
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2004-01-11 08:48:58 +00:00
|
|
|
typedef struct visfacet_s {
|
2002-09-19 16:58:48 +00:00
|
|
|
struct visfacet_s *next;
|
|
|
|
|
|
|
|
int planenum;
|
|
|
|
int planeside; // which side is the front of the face
|
|
|
|
int texturenum;
|
|
|
|
int contents[2]; // 0 = front side
|
|
|
|
|
|
|
|
struct visfacet_s *original; // face on node
|
|
|
|
int outputnumber; // only valid for original faces after
|
|
|
|
// write surfaces
|
2003-02-04 23:26:26 +00:00
|
|
|
qboolean detail; // is a detail face
|
|
|
|
|
2003-09-08 03:00:53 +00:00
|
|
|
winding_t *points;
|
|
|
|
int *edges;
|
2002-09-19 16:58:48 +00:00
|
|
|
} face_t;
|
|
|
|
|
2004-01-11 08:48:58 +00:00
|
|
|
typedef struct surface_s {
|
2002-09-19 16:58:48 +00:00
|
|
|
struct surface_s *next;
|
|
|
|
struct surface_s *original; // before BSP cuts it up
|
|
|
|
int planenum;
|
|
|
|
int outputplanenum; // only valid after WriteSurfacePlanes
|
|
|
|
vec3_t mins, maxs;
|
2002-09-19 18:51:19 +00:00
|
|
|
qboolean onnode; // true if surface has already been used
|
2002-09-19 16:58:48 +00:00
|
|
|
// as a splitting node
|
2003-02-04 23:26:26 +00:00
|
|
|
qboolean has_detail; // true if the surface has detail brushes
|
|
|
|
qboolean has_struct; // true if the surface has non-detail brushes
|
2002-09-19 16:58:48 +00:00
|
|
|
face_t *faces; // links to all the faces on either side of the surf
|
|
|
|
} surface_t;
|
|
|
|
|
|
|
|
// there is a node_t structure for every node and leaf in the bsp tree
|
|
|
|
#define PLANENUM_LEAF -1
|
|
|
|
|
2004-01-11 08:48:58 +00:00
|
|
|
typedef struct node_s {
|
2002-09-19 16:58:48 +00:00
|
|
|
vec3_t mins,maxs; // bounding volume, not just points inside
|
|
|
|
|
|
|
|
// information for decision nodes
|
|
|
|
int planenum; // -1 = leaf node
|
|
|
|
int outputplanenum; // only valid after WriteNodePlanes
|
|
|
|
int firstface; // decision node only
|
|
|
|
int numfaces; // decision node only
|
|
|
|
struct node_s *children[2]; // only valid for decision nodes
|
|
|
|
face_t *faces; // decision nodes only, list for both sides
|
|
|
|
|
|
|
|
// information for leafs
|
|
|
|
int contents; // leaf nodes (0 for decision nodes)
|
|
|
|
face_t **markfaces; // leaf nodes only, point to node faces
|
|
|
|
struct portal_s *portals;
|
|
|
|
int visleafnum; // -1 = solid
|
|
|
|
int valid; // for flood filling
|
|
|
|
int occupied; // light number in leaf for outside filling
|
2003-02-04 23:26:26 +00:00
|
|
|
int o_dist; // distance to nearest entity
|
|
|
|
int detail; // 1 if created by detail split
|
2002-09-19 16:58:48 +00:00
|
|
|
} node_t;
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// brush.c ====================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
#define NUM_HULLS 2 // normal and +16
|
|
|
|
|
|
|
|
#define NUM_CONTENTS 2 // solid and water
|
|
|
|
|
2004-01-11 08:48:58 +00:00
|
|
|
typedef struct brush_s {
|
2002-09-19 16:58:48 +00:00
|
|
|
struct brush_s *next;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
face_t *faces;
|
|
|
|
int contents;
|
|
|
|
} brush_t;
|
|
|
|
|
2004-01-11 08:48:58 +00:00
|
|
|
typedef struct {
|
2002-09-19 16:58:48 +00:00
|
|
|
vec3_t mins, maxs;
|
|
|
|
brush_t *brushes; // NULL terminated list
|
|
|
|
} brushset_t;
|
|
|
|
|
|
|
|
extern int numbrushplanes;
|
|
|
|
extern plane_t planes[MAX_MAP_PLANES];
|
|
|
|
|
|
|
|
brushset_t *Brush_LoadEntity (entity_t *ent, int hullnum);
|
|
|
|
int PlaneTypeForNormal (vec3_t normal);
|
|
|
|
int FindPlane (plane_t *dplane, int *side);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// csg4.c =====================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
// build surfaces is also used by GatherNodeFaces
|
|
|
|
extern face_t *validfaces[MAX_MAP_PLANES];
|
|
|
|
surface_t *BuildSurfaces (void);
|
|
|
|
|
|
|
|
face_t *NewFaceFromFace (face_t *in);
|
|
|
|
surface_t *CSGFaces (brushset_t *bs);
|
|
|
|
void SplitFace (face_t *in, plane_t *split, face_t **front, face_t **back);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// solidbsp.c =================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
void DivideFacet (face_t *in, plane_t *split, face_t **front, face_t **back);
|
|
|
|
void CalcSurfaceInfo (surface_t *surf);
|
|
|
|
node_t *SolidBSP (surface_t *surfhead, qboolean midsplit);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// merge.c ====================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
void MergePlaneFaces (surface_t *plane);
|
|
|
|
face_t *MergeFaceToList (face_t *face, face_t *list);
|
|
|
|
face_t *FreeMergeListScraps (face_t *merged);
|
|
|
|
void MergeAll (surface_t *surfhead);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// surfaces.c =================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
extern int c_cornerverts;
|
|
|
|
extern int c_tryedges;
|
|
|
|
extern face_t *edgefaces[MAX_MAP_EDGES][2];
|
|
|
|
|
|
|
|
extern int firstmodeledge;
|
|
|
|
extern int firstmodelface;
|
|
|
|
|
2007-10-08 09:50:02 +00:00
|
|
|
void SubdivideFace (face_t *f, face_t **prevptr);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
surface_t *GatherNodeFaces (node_t *headnode);
|
|
|
|
|
|
|
|
void MakeFaceEdges (node_t *headnode);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// portals.c ==================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2004-01-11 08:48:58 +00:00
|
|
|
typedef struct portal_s {
|
2002-09-19 16:58:48 +00:00
|
|
|
int planenum;
|
|
|
|
node_t *nodes[2]; // [0] = front side of planenum
|
|
|
|
struct portal_s *next[2];
|
|
|
|
winding_t *winding;
|
|
|
|
} portal_t;
|
|
|
|
|
|
|
|
extern node_t outside_node; // portals outside the world face this
|
|
|
|
|
|
|
|
void PortalizeWorld (node_t *headnode);
|
2003-02-04 23:26:26 +00:00
|
|
|
void PortalizeWorldDetail (node_t *headnode); // stop at detail nodes
|
2002-09-19 16:58:48 +00:00
|
|
|
void WritePortalfile (node_t *headnode);
|
|
|
|
void FreeAllPortals (node_t *node);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// region.c ===================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
void GrowNodeRegions (node_t *headnode);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// tjunc.c ====================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
void tjunc (node_t *headnode);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// writebsp.c =================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
void WriteNodePlanes (node_t *headnode);
|
|
|
|
void WriteClipNodes (node_t *headnode);
|
|
|
|
void WriteDrawNodes (node_t *headnode);
|
|
|
|
|
|
|
|
void BumpModel (int hullnum);
|
|
|
|
int FindFinalPlane (dplane_t *p);
|
|
|
|
|
|
|
|
void BeginBSPFile (void);
|
|
|
|
void FinishBSPFile (void);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// draw.c =====================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
void Draw_ClearBounds (void);
|
|
|
|
void Draw_AddToBounds (vec3_t v);
|
|
|
|
void Draw_DrawFace (face_t *f);
|
|
|
|
void Draw_ClearWindow (void);
|
|
|
|
void Draw_SetRed (void);
|
|
|
|
void Draw_SetGrey (void);
|
|
|
|
void Draw_SetBlack (void);
|
|
|
|
void DrawPoint (vec3_t v);
|
|
|
|
|
|
|
|
void Draw_SetColor (int c);
|
|
|
|
void SetColor (int c);
|
|
|
|
void DrawPortal (portal_t *p);
|
|
|
|
void DrawLeaf (node_t *l, int color);
|
|
|
|
void DrawBrush (brush_t *b);
|
|
|
|
|
|
|
|
void DrawWinding (winding_t *w);
|
|
|
|
void DrawTri (vec3_t p1, vec3_t p2, vec3_t p3);
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// outside.c ==================================================================
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
qboolean FillOutside (node_t *node);
|
|
|
|
|
2004-01-11 08:48:58 +00:00
|
|
|
// readbsp.c ==================================================================
|
|
|
|
|
|
|
|
void LoadBSP (void);
|
2004-01-13 03:02:25 +00:00
|
|
|
void bsp2prt (void);
|
2004-01-15 07:16:44 +00:00
|
|
|
void extract_textures (void);
|
2004-04-30 21:51:00 +00:00
|
|
|
void extract_entities (void);
|
2009-03-18 03:28:34 +00:00
|
|
|
void extract_hull (void);
|
2004-01-11 08:48:58 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
extern brushset_t *brushset;
|
|
|
|
|
2003-01-27 23:14:07 +00:00
|
|
|
void qprintf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); // only prints if verbose
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
extern int valid;
|
|
|
|
|
|
|
|
extern qboolean worldmodel;
|
|
|
|
|
|
|
|
// misc functions
|
|
|
|
|
|
|
|
face_t *AllocFace (void);
|
|
|
|
void FreeFace (face_t *f);
|
|
|
|
|
|
|
|
struct portal_s *AllocPortal (void);
|
|
|
|
void FreePortal (struct portal_s *p);
|
|
|
|
|
|
|
|
surface_t *AllocSurface (void);
|
|
|
|
void FreeSurface (surface_t *s);
|
|
|
|
|
|
|
|
node_t *AllocNode (void);
|
|
|
|
struct brush_s *AllocBrush (void);
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
extern bsp_t *bsp;
|