UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
faces.cpp File Reference
#include "bsp.h"

Go to the source code of this file.

Macros

#define INTEGRAL_EPSILON   0.01
 
#define POINT_EPSILON   0.0625
 
#define OFF_EPSILON   0.5
 
#define MAX_SUPERVERTS   512
 
#define HASH_SIZE   64
 
#define CONTINUOUS_EPSILON   0.001
 

Functions

static unsigned HashVec (const vec3_t vec)
 
static int GetVertexnum (const vec3_t in)
 Returns the number of an existing vertex or allocates a new one. More...
 
static face_tAllocFace (void)
 
static face_tNewFaceFromFace (const face_t *f)
 
void FreeFace (face_t *f)
 
static void FaceFromSuperverts (node_t *node, face_t *f, int base)
 The faces vertexes have been added to the superverts[] array, and there may be more there than can be held in a face (MAXEDGES). More...
 
static void EmitFaceVertexes (node_t *node, face_t *f)
 
static void EmitVertexes_r (node_t *node)
 
static void FindEdgeVerts (const vec3_t v1, const vec3_t v2)
 Uses the hash tables to cut down to a small number. More...
 
static void TestEdge (vec_t start, vec_t end, int p1, int p2, int startvert)
 
static void FixFaceEdges (node_t *node, face_t *f)
 
static void FixEdges_r (node_t *node)
 
void FixTjuncs (node_t *headnode)
 
int GetEdge (int v1, int v2, const face_t *f)
 
static winding_tTryMergeWinding (winding_t *f1, winding_t *f2, const vec3_t planenormal)
 If two polygons share a common edge and the edges that meet at the common points are both inside the other polygons, merge them. More...
 
static face_tTryMerge (face_t *f1, face_t *f2, const vec3_t planenormal)
 If two polygons share a common edge and the edges that meet at the common points are both inside the other polygons, merge them. More...
 
static void MergeNodeFaces (node_t *node)
 
static void SubdivideFace (node_t *node, face_t *f)
 Chop up faces that are larger than we want in the surface cache. More...
 
static void SubdivideNodeFaces (node_t *node)
 
static face_tFaceFromPortal (portal_t *p, bool pside)
 
static void MakeFaces_r (node_t *node)
 If a portal will make a visible face, mark the side that originally created it. More...
 
void MakeFaces (node_t *node)
 

Variables

static int c_merge
 
static int c_subdivide
 
static int c_totalverts
 
static int c_uniqueverts
 
static int c_degenerate
 
static int c_tjunctions
 
static int c_faceoverflows
 
static int c_facecollapse
 
static int c_badstartverts
 
static int c_faces
 
static int superverts [MAX_SUPERVERTS]
 
static int numsuperverts
 
static const face_tedgefaces [MAX_MAP_EDGES][2]
 
int firstmodeledge = 1
 
static vec3_t edge_dir
 
static vec3_t edge_start
 
static int num_edge_verts
 
static int edge_verts [MAX_MAP_VERTS]
 
static int vertexchain [MAX_MAP_VERTS]
 
static int hashverts [HASH_SIZE *HASH_SIZE]
 
static int c_nodefaces
 

Detailed Description

Note
some faces will be removed before saving, but still form nodes: meeting planes of different water current volumes

Definition in file faces.cpp.

Macro Definition Documentation

#define CONTINUOUS_EPSILON   0.001

Definition at line 435 of file faces.cpp.

Referenced by TryMergeWinding().

#define HASH_SIZE   64

Definition at line 49 of file faces.cpp.

Referenced by FindEdgeVerts(), and HashVec().

#define INTEGRAL_EPSILON   0.01

Definition at line 30 of file faces.cpp.

Referenced by GetVertexnum().

#define MAX_SUPERVERTS   512

Definition at line 36 of file faces.cpp.

Referenced by FixFaceEdges(), and TestEdge().

#define OFF_EPSILON   0.5

Definition at line 32 of file faces.cpp.

Referenced by TestEdge().

#define POINT_EPSILON   0.0625

Definition at line 31 of file faces.cpp.

Referenced by GetVertexnum().

Function Documentation

static face_t* AllocFace ( void  )
static

Definition at line 114 of file faces.cpp.

References c_faces, and Mem_AllocType.

Referenced by FaceFromPortal(), and NewFaceFromFace().

static void EmitVertexes_r ( node_t node)
static

Definition at line 210 of file faces.cpp.

References node_s::children, EmitFaceVertexes(), f, node_s::faces, i, node_s::planenum, and PLANENUM_LEAF.

Referenced by FixTjuncs().

static void FaceFromSuperverts ( node_t node,
face_t f,
int  base 
)
static

The faces vertexes have been added to the superverts[] array, and there may be more there than can be held in a face (MAXEDGES).

If less, the faces vertexnums[] will be filled in, otherwise face will reference a tree of split[] faces until all of the vertexnums can be added.

Note
superverts[base] will become face->vertexnums[0], and the others will be circularly filled in.

Definition at line 152 of file faces.cpp.

References c_faceoverflows, f, node_s::faces, i, MAXEDGES, NewFaceFromFace(), face_s::next, face_s::numpoints, numsuperverts, face_s::split, superverts, and face_s::vertexnums.

Referenced by EmitFaceVertexes(), and FixFaceEdges().

static void FindEdgeVerts ( const vec3_t  v1,
const vec3_t  v2 
)
static

Uses the hash tables to cut down to a small number.

Definition at line 226 of file faces.cpp.

References edge_verts, HASH_SIZE, hashverts, int(), MAX_WORLD_WIDTH, num_edge_verts, and vertexchain.

Referenced by FixFaceEdges().

static void FixEdges_r ( node_t node)
static

Definition at line 354 of file faces.cpp.

References node_s::children, f, node_s::faces, FixFaceEdges(), i, node_s::planenum, and PLANENUM_LEAF.

Referenced by FixTjuncs().

void FreeFace ( face_t f)

Definition at line 133 of file faces.cpp.

References c_faces, FreeWinding(), Mem_Free, and face_s::w.

Referenced by FreeTree_r().

int GetEdge ( int  v1,
int  v2,
const face_t f 
)
See also
EmitFace.
Note
Don't allow four way edges

Definition at line 399 of file faces.cpp.

References config, face_s::contentFlags, curTile, dMapTile_t::edges, f, firstmodeledge, i, MAX_MAP_EDGES, dMapTile_t::numedges, Sys_Error(), and dBspEdge_t::v.

Referenced by EmitFace().

static int GetVertexnum ( const vec3_t  in)
static

Returns the number of an existing vertex or allocates a new one.

Note
Uses hashing

Definition at line 72 of file faces.cpp.

References c_totalverts, c_uniqueverts, curTile, HashVec(), hashverts, i, INTEGRAL_EPSILON, MAX_MAP_VERTS, dMapTile_t::numnormals, dMapTile_t::numvertexes, dBspVertex_t::point, POINT_EPSILON, Q_rint(), Sys_Error(), vertexchain, and dMapTile_t::vertexes.

Referenced by EmitFaceVertexes().

static unsigned HashVec ( const vec3_t  vec)
static
Todo:
Fix this to support the full bsp level bounds

Definition at line 57 of file faces.cpp.

References HASH_SIZE, int(), and Sys_Error().

Referenced by GetVertexnum().

void MakeFaces ( node_t node)

Definition at line 764 of file faces.cpp.

References c_merge, c_nodefaces, c_subdivide, MakeFaces_r(), VERB_EXTRA, and Verb_Printf().

Referenced by ConstructLevelNodes_r(), and ProcessSubModel().

static void MakeFaces_r ( node_t node)
static

If a portal will make a visible face, mark the side that originally created it.

  • solid / empty : solid
  • solid / water : solid
  • water / empty : water
  • water / water : none

Definition at line 728 of file faces.cpp.

References c_nodefaces, node_s::children, config, node_s::contentFlags, CONTENTS_SOLID, portal_s::face, FaceFromPortal(), node_s::faces, MergeNodeFaces(), face_s::next, portal_s::next, portal_s::nodes, portal_s::onnode, node_s::planenum, PLANENUM_LEAF, node_s::portals, and SubdivideNodeFaces().

Referenced by MakeFaces().

static void MergeNodeFaces ( node_t node)
static
static face_t* NewFaceFromFace ( const face_t f)
static

Definition at line 121 of file faces.cpp.

References AllocFace(), f, face_s::merged, face_s::split, and face_s::w.

Referenced by FaceFromSuperverts(), SubdivideFace(), and TryMerge().

static void SubdivideNodeFaces ( node_t node)
static

Definition at line 662 of file faces.cpp.

References f, node_s::faces, face_s::next, and SubdivideFace().

Referenced by MakeFaces_r().

static void TestEdge ( vec_t  start,
vec_t  end,
int  p1,
int  p2,
int  startvert 
)
static
static face_t* TryMerge ( face_t f1,
face_t f2,
const vec3_t  planenormal 
)
static

If two polygons share a common edge and the edges that meet at the common points are both inside the other polygons, merge them.

Returns
nullptr if the faces couldn't be merged, or the new face.
Note
The originals will NOT be freed.

Definition at line 537 of file faces.cpp.

References c_merge, face_s::contentFlags, face_s::merged, NewFaceFromFace(), face_s::planenum, face_s::texinfo, TryMergeWinding(), and face_s::w.

Referenced by MergeNodeFaces().

static winding_t* TryMergeWinding ( winding_t f1,
winding_t f2,
const vec3_t  planenormal 
)
static

If two polygons share a common edge and the edges that meet at the common points are both inside the other polygons, merge them.

Returns
nullptr if the faces couldn't be merged, or the new winding.
Note
The originals will NOT be freed.

Definition at line 443 of file faces.cpp.

References AllocWinding(), CONTINUOUS_EPSILON, CrossProduct(), DotProduct, EQUAL_EPSILON, i, winding_s::numpoints, winding_s::p, VectorCopy, VectorNormalize(), and VectorSubtract.

Referenced by TryMerge().

Variable Documentation

int c_badstartverts
static

Definition at line 34 of file faces.cpp.

Referenced by FixFaceEdges(), and FixTjuncs().

int c_degenerate
static

Definition at line 34 of file faces.cpp.

Referenced by FixTjuncs(), and TestEdge().

int c_facecollapse
static

Definition at line 34 of file faces.cpp.

Referenced by FixFaceEdges(), and FixTjuncs().

int c_faceoverflows
static

Definition at line 34 of file faces.cpp.

Referenced by FaceFromSuperverts(), and FixTjuncs().

int c_faces
static

Definition at line 34 of file faces.cpp.

Referenced by AllocFace(), BrushlistCalcStats(), and FreeFace().

int c_merge
static

Definition at line 34 of file faces.cpp.

Referenced by MakeFaces(), and TryMerge().

int c_nodefaces
static

Definition at line 670 of file faces.cpp.

Referenced by MakeFaces(), and MakeFaces_r().

int c_subdivide
static

Definition at line 34 of file faces.cpp.

Referenced by MakeFaces(), and SubdivideFace().

int c_tjunctions
static

Definition at line 34 of file faces.cpp.

Referenced by FixTjuncs(), and TestEdge().

int c_totalverts
static

Definition at line 34 of file faces.cpp.

Referenced by EmitFaceVertexes(), FixTjuncs(), and GetVertexnum().

int c_uniqueverts
static

Definition at line 34 of file faces.cpp.

Referenced by EmitFaceVertexes(), FixTjuncs(), and GetVertexnum().

vec3_t edge_dir
static

Definition at line 43 of file faces.cpp.

Referenced by FixFaceEdges(), and TestEdge().

vec3_t edge_start
static

Definition at line 44 of file faces.cpp.

Referenced by FixFaceEdges(), and TestEdge().

int edge_verts[MAX_MAP_VERTS]
static

Definition at line 47 of file faces.cpp.

Referenced by FindEdgeVerts(), and TestEdge().

const face_t* edgefaces[MAX_MAP_EDGES][2]
static

Definition at line 40 of file faces.cpp.

int firstmodeledge = 1

Definition at line 41 of file faces.cpp.

Referenced by BeginModel(), and GetEdge().

int hashverts[HASH_SIZE *HASH_SIZE]
static

Definition at line 52 of file faces.cpp.

Referenced by FindEdgeVerts(), FixTjuncs(), and GetVertexnum().

int num_edge_verts
static

Definition at line 46 of file faces.cpp.

Referenced by FindEdgeVerts(), and TestEdge().

int numsuperverts
static

Definition at line 38 of file faces.cpp.

Referenced by EmitFaceVertexes(), FaceFromSuperverts(), FixFaceEdges(), and TestEdge().

int superverts[MAX_SUPERVERTS]
static

Definition at line 37 of file faces.cpp.

Referenced by EmitFaceVertexes(), FaceFromSuperverts(), and TestEdge().

int vertexchain[MAX_MAP_VERTS]
static

Definition at line 51 of file faces.cpp.

Referenced by FindEdgeVerts(), and GetVertexnum().