UFO: Alien Invasion
Loading...
Searching...
No Matches
faces.cpp File Reference
#include "bsp.h"
Include dependency graph for faces.cpp:

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.
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).
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.
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.
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.
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.
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.
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

◆ CONTINUOUS_EPSILON

#define CONTINUOUS_EPSILON   0.001

Definition at line 435 of file faces.cpp.

Referenced by TryMergeWinding().

◆ HASH_SIZE

#define HASH_SIZE   64

Definition at line 49 of file faces.cpp.

Referenced by FindEdgeVerts(), and HashVec().

◆ INTEGRAL_EPSILON

#define INTEGRAL_EPSILON   0.01

Definition at line 30 of file faces.cpp.

Referenced by GetVertexnum().

◆ MAX_SUPERVERTS

#define MAX_SUPERVERTS   512

Definition at line 36 of file faces.cpp.

Referenced by FixFaceEdges(), and TestEdge().

◆ OFF_EPSILON

#define OFF_EPSILON   0.5

Definition at line 32 of file faces.cpp.

Referenced by TestEdge().

◆ POINT_EPSILON

#define POINT_EPSILON   0.0625

Definition at line 31 of file faces.cpp.

Referenced by GetVertexnum().

Function Documentation

◆ AllocFace()

face_t * AllocFace ( void )
static

Definition at line 114 of file faces.cpp.

References c_faces, and Mem_AllocType.

Referenced by FaceFromPortal(), and NewFaceFromFace().

◆ EmitFaceVertexes()

◆ EmitVertexes_r()

void EmitVertexes_r ( node_t * node)
static

◆ FaceFromPortal()

◆ FaceFromSuperverts()

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_t::faces, i, MAXEDGES, NewFaceFromFace(), face_t::next, face_t::numpoints, numsuperverts, superverts, and face_t::vertexnums.

Referenced by EmitFaceVertexes(), and FixFaceEdges().

◆ FindEdgeVerts()

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().

◆ FixEdges_r()

void FixEdges_r ( node_t * node)
static

Definition at line 354 of file faces.cpp.

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

Referenced by FixEdges_r(), and FixTjuncs().

◆ FixFaceEdges()

◆ FixTjuncs()

◆ FreeFace()

void FreeFace ( face_t * f)

Definition at line 133 of file faces.cpp.

References c_faces, f, FreeWinding(), and Mem_Free.

Referenced by FreeTree_r().

◆ GetEdge()

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, curTile, edgefaces, f, firstmodeledge, i, MAX_MAP_EDGES, Sys_Error(), and dBspEdge_t::v.

Referenced by EmitFace().

◆ GetVertexnum()

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, POINT_EPSILON, Q_rint(), Sys_Error(), and vertexchain.

Referenced by EmitFaceVertexes().

◆ HashVec()

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().

◆ MakeFaces()

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().

◆ MakeFaces_r()

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_t::children, config, node_t::contentFlags, CONTENTS_SOLID, portal_t::face, FaceFromPortal(), MakeFaces_r(), MergeNodeFaces(), face_t::next, portal_t::next, portal_t::nodes, portal_t::onnode, node_t::planenum, PLANENUM_LEAF, node_t::portals, and SubdivideNodeFaces().

Referenced by MakeFaces(), and MakeFaces_r().

◆ MergeNodeFaces()

void MergeNodeFaces ( node_t * node)
static

◆ NewFaceFromFace()

face_t * NewFaceFromFace ( const face_t * f)
static

Definition at line 121 of file faces.cpp.

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

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

◆ SubdivideFace()

void SubdivideFace ( node_t * node,
face_t * f )
static

◆ SubdivideNodeFaces()

void SubdivideNodeFaces ( node_t * node)
static

Definition at line 662 of file faces.cpp.

References f, node_t::faces, and SubdivideFace().

Referenced by MakeFaces_r().

◆ TestEdge()

void TestEdge ( vec_t start,
vec_t end,
int p1,
int p2,
int startvert )
static

◆ TryMerge()

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_t::contentFlags, face_t::merged, NewFaceFromFace(), face_t::planenum, face_t::texinfo, TryMergeWinding(), and face_t::w.

Referenced by MergeNodeFaces().

◆ TryMergeWinding()

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_t::numpoints, winding_t::p, VectorCopy, VectorNormalize(), and VectorSubtract.

Referenced by TryMerge().

Variable Documentation

◆ c_badstartverts

int c_badstartverts
static

Definition at line 34 of file faces.cpp.

Referenced by FixFaceEdges(), and FixTjuncs().

◆ c_degenerate

int c_degenerate
static

Definition at line 34 of file faces.cpp.

Referenced by FixTjuncs(), and TestEdge().

◆ c_facecollapse

int c_facecollapse
static

Definition at line 34 of file faces.cpp.

Referenced by FixFaceEdges(), and FixTjuncs().

◆ c_faceoverflows

int c_faceoverflows
static

Definition at line 34 of file faces.cpp.

Referenced by FaceFromSuperverts(), and FixTjuncs().

◆ c_faces

int c_faces
static

Definition at line 34 of file faces.cpp.

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

◆ c_merge

int c_merge
static

Definition at line 34 of file faces.cpp.

Referenced by MakeFaces(), and TryMerge().

◆ c_nodefaces

int c_nodefaces
static

Definition at line 670 of file faces.cpp.

Referenced by MakeFaces(), and MakeFaces_r().

◆ c_subdivide

int c_subdivide
static

Definition at line 34 of file faces.cpp.

Referenced by MakeFaces(), and SubdivideFace().

◆ c_tjunctions

int c_tjunctions
static

Definition at line 34 of file faces.cpp.

Referenced by FixTjuncs(), and TestEdge().

◆ c_totalverts

int c_totalverts
static

Definition at line 34 of file faces.cpp.

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

◆ c_uniqueverts

int c_uniqueverts
static

Definition at line 34 of file faces.cpp.

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

◆ edge_dir

vec3_t edge_dir
static

Definition at line 43 of file faces.cpp.

Referenced by FixFaceEdges(), and TestEdge().

◆ edge_start

vec3_t edge_start
static

Definition at line 44 of file faces.cpp.

Referenced by FixFaceEdges(), and TestEdge().

◆ edge_verts

int edge_verts[MAX_MAP_VERTS]
static

Definition at line 47 of file faces.cpp.

Referenced by FindEdgeVerts(), and TestEdge().

◆ edgefaces

const face_t* edgefaces[MAX_MAP_EDGES][2]
static

Definition at line 40 of file faces.cpp.

Referenced by GetEdge().

◆ firstmodeledge

int firstmodeledge = 1

Definition at line 41 of file faces.cpp.

Referenced by BeginModel(), and GetEdge().

◆ hashverts

int hashverts[HASH_SIZE *HASH_SIZE]
static

Definition at line 52 of file faces.cpp.

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

◆ num_edge_verts

int num_edge_verts
static

Definition at line 46 of file faces.cpp.

Referenced by FindEdgeVerts(), and TestEdge().

◆ numsuperverts

int numsuperverts
static

Definition at line 38 of file faces.cpp.

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

◆ superverts

int superverts[MAX_SUPERVERTS]
static

Definition at line 37 of file faces.cpp.

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

◆ vertexchain

int vertexchain[MAX_MAP_VERTS]
static

Definition at line 51 of file faces.cpp.

Referenced by FindEdgeVerts(), and GetVertexnum().