quake-hipnotic-sdk/utils/qbsp/bsp5.h
1997-03-11 00:00:00 +00:00

297 lines
7.2 KiB
C

// bsp5.h
#include "cmdlib.h"
#include "mathlib.h"
#include "bspfile.h"
typedef struct
{
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
//============================================================================
typedef struct
{
int numpoints;
vec3_t points[8]; // variable sized
} winding_t;
#define max_points_on_winding 64
winding_t *basewindingforplane (plane_t *p);
void checkwinding (winding_t *w);
winding_t *newwinding (int points);
void freewinding (winding_t *w);
winding_t *copywinding (winding_t *w);
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);
//============================================================================
#define maxedges 32
#define maxpoints 28 // don't let a base face get past this
// because it can be split more later
typedef struct visfacet_s
{
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
int numpoints;
vec3_t pts[maxedges]; // fixme: change to use winding_t
int edges[maxedges];
} face_t;
typedef struct surface_s
{
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;
qboolean onnode; // true if surface has already been used
// as a splitting node
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
typedef struct node_s
{
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
} node_t;
//=============================================================================
// brush.c
#define num_hulls 2 // normal and +16
#define num_contents 2 // solid and water
typedef struct brush_s
{
struct brush_s *next;
vec3_t mins, maxs;
face_t *faces;
int contents;
} brush_t;
typedef struct
{
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);
//=============================================================================
// csg4.c
// 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);
//=============================================================================
// solidbsp.c
void dividefacet (face_t *in, plane_t *split, face_t **front, face_t **back);
void calcsurfaceinfo (surface_t *surf);
void subdivideface (face_t *f, face_t **prevptr);
node_t *solidbsp (surface_t *surfhead, qboolean midsplit);
//=============================================================================
// merge.c
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);
//=============================================================================
// surfaces.c
extern int c_cornerverts;
extern int c_tryedges;
extern face_t *edgefaces[max_map_edges][2];
extern int firstmodeledge;
extern int firstmodelface;
void subdividefaces (surface_t *surfhead);
surface_t *gathernodefaces (node_t *headnode);
void makefaceedges (node_t *headnode);
//=============================================================================
// portals.c
typedef struct portal_s
{
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);
void writeportalfile (node_t *headnode);
void freeallportals (node_t *node);
//=============================================================================
// region.c
void grownoderegions (node_t *headnode);
//=============================================================================
// tjunc.c
void tjunc (node_t *headnode);
//=============================================================================
// writebsp.c
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);
//=============================================================================
// draw.c
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);
//=============================================================================
// outside.c
qboolean filloutside (node_t *node);
//=============================================================================
extern qboolean drawflag;
extern qboolean nofill;
extern qboolean notjunc;
extern qboolean noclip;
extern qboolean verbose;
extern int subdivide_size;
extern int hullnum;
extern brushset_t *brushset;
void qprintf (char *fmt, ...); // only prints if verbose
extern int valid;
extern char portfilename[1024];
extern char bspfilename[1024];
extern char pointfilename[1024];
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);
//=============================================================================