brushbsp.c File Reference

#include "map.h"
#include "bsp.h"
Include dependency graph for brushbsp.c:

Go to the source code of this file.

Defines

#define SNAP_EPSILON   0.01
#define EDGE_LENGTH   0.2

Functions

static void BoundBrush (bspbrush_t *brush)
 Sets the mins/maxs based on the windings.
static void SnapWeldVector (const vec3_t a, const vec3_t b, vec3_t out)
 welds two vec3_t's into a third, taking into account nearest-to-integer instead of averaging
static qboolean FixWinding (winding_t *w)
 removes degenerate edges from a winding
static void CreateBrushWindings (bspbrush_t *brush)
 makes basewindigs for sides and mins/maxs for the brush
static bspbrush_tBrushFromBounds (vec3_t mins, vec3_t maxs)
 Creates a new axial brush.
static vec_t BrushVolume (bspbrush_t *brush)
 Returns the volume of the given brush.
int CountBrushList (bspbrush_t *brushes)
 Returns the amount of brushes in the given brushlist.
static tree_tAllocTree (void)
static node_tAllocNode (void)
bspbrush_tAllocBrush (int numsides)
void FreeBrush (bspbrush_t *brushes)
void FreeBrushList (bspbrush_t *brushes)
bspbrush_tCopyBrush (const bspbrush_t *brush)
 Duplicates the brush, the sides, and the windings.
static int TestBrushToPlanenum (bspbrush_t *brush, int planenum, int *numsplits, qboolean *hintsplit, int *epsilonbrush)
qboolean WindingIsTiny (winding_t *w)
 Returns true if the winding would be crunched out of existance by the vertex snapping.
static qboolean WindingIsHuge (const winding_t *w)
 Returns true if the winding still has one of the points from basewinding for plane.
static void LeafNode (node_t *node, bspbrush_t *brushes)
static void CheckPlaneAgainstParents (int pnum, const node_t *node)
static qboolean CheckPlaneAgainstVolume (int pnum, node_t *node)
static side_tSelectSplitSide (bspbrush_t *brushes, node_t *node)
 Using a heuristic, choses one of the sides out of the brushlist to partition the brushes with.
static int BrushMostlyOnSide (const bspbrush_t *brush, const plane_t *plane)
 Checks on which side a of plane the brush is.
void SplitBrush (const bspbrush_t *brush, int planenum, bspbrush_t **front, bspbrush_t **back)
 Generates two new brushes, leaving the original unchanged.
static void SplitBrushList (bspbrush_t *brushes, node_t *node, bspbrush_t **front, bspbrush_t **back)
static node_tBuildTree_r (node_t *node, bspbrush_t *brushes)
tree_tBrushBSP (bspbrush_t *brushlist, vec3_t mins, vec3_t maxs)
 The incoming list will be freed before exiting.
void WriteBSPBrushMap (const char *name, const bspbrush_t *list)
 writes a map with the split bsp brushes

Variables

int c_nodes
static int c_nonvis
static int c_active_brushes

Detailed Description

Definition in file brushbsp.c.


Define Documentation

#define EDGE_LENGTH   0.2

Definition at line 421 of file brushbsp.c.

Referenced by WindingIsTiny().

#define SNAP_EPSILON   0.01

Definition at line 51 of file brushbsp.c.

Referenced by SnapWeldVector().


Function Documentation

bspbrush_t* AllocBrush ( int  numsides  ) 
See also:
AllocTree
AllocNode

Definition at line 287 of file brushbsp.c.

References c_active_brushes, Mem_Alloc, and threadstate.

Referenced by BrushFromBounds(), CopyBrush(), MakeBspBrushList(), and SplitBrush().

static node_t* AllocNode ( void   )  [static]
See also:
AllocBrush
AllocTree

Definition at line 278 of file brushbsp.c.

References Mem_Alloc.

Referenced by BrushBSP(), and BuildTree_r().

static tree_t* AllocTree ( void   )  [static]
See also:
AllocBrush
AllocNode

Definition at line 265 of file brushbsp.c.

References ClearBounds(), tree_t::maxs, Mem_Alloc, and tree_t::mins.

Referenced by BrushBSP().

static void BoundBrush ( bspbrush_t brush  )  [static]

Sets the mins/maxs based on the windings.

Definition at line 36 of file brushbsp.c.

References AddPointToBounds(), ClearBounds(), i, bspbrush_s::maxs, bspbrush_s::mins, winding_s::numpoints, bspbrush_s::numsides, winding_s::p, bspbrush_s::sides, and side_s::winding.

Referenced by CreateBrushWindings(), and SplitBrush().

tree_t* BrushBSP ( bspbrush_t brushlist,
vec3_t  mins,
vec3_t  maxs 
)
static bspbrush_t* BrushFromBounds ( vec3_t  mins,
vec3_t  maxs 
) [static]

Creates a new axial brush.

Definition at line 183 of file brushbsp.c.

References AllocBrush(), CreateBrushWindings(), FindOrCreateFloatPlane(), i, bspbrush_s::numsides, side_s::planenum, bspbrush_s::sides, and VectorClear.

Referenced by BrushBSP().

static int BrushMostlyOnSide ( const bspbrush_t brush,
const plane_t plane 
) [static]

Checks on which side a of plane the brush is.

Todo:
Or vice versa?

Definition at line 653 of file brushbsp.c.

References plane_s::dist, DotProduct, i, plane_s::normal, winding_s::numpoints, bspbrush_s::numsides, winding_s::p, PSIDE_BACK, PSIDE_FRONT, bspbrush_s::sides, and side_s::winding.

Referenced by SplitBrush().

static vec_t BrushVolume ( bspbrush_t brush  )  [static]

Returns the volume of the given brush.

Definition at line 211 of file brushbsp.c.

References plane_s::dist, DotProduct, i, mapplanes, plane_s::normal, bspbrush_s::numsides, winding_s::p, side_s::planenum, bspbrush_s::sides, VectorCopy, side_s::winding, and WindingArea().

Referenced by BrushBSP(), and SplitBrush().

static node_t* BuildTree_r ( node_t node,
bspbrush_t brushes 
) [static]
static void CheckPlaneAgainstParents ( int  pnum,
const node_t node 
) [static]

Definition at line 491 of file brushbsp.c.

References node_s::parent, node_s::planenum, and Sys_Error().

Referenced by SelectSplitSide().

static qboolean CheckPlaneAgainstVolume ( int  pnum,
node_t node 
) [static]

Definition at line 501 of file brushbsp.c.

References FreeBrush(), SplitBrush(), and node_s::volume.

Referenced by SelectSplitSide().

bspbrush_t* CopyBrush ( const bspbrush_t brush  ) 

Duplicates the brush, the sides, and the windings.

See also:
AllocBrush

Definition at line 328 of file brushbsp.c.

References AllocBrush(), CopyWinding(), i, bspbrush_s::numsides, bspbrush_s::sides, and side_s::winding.

Referenced by SplitBrush(), and SplitBrushList().

int CountBrushList ( bspbrush_t brushes  ) 

Returns the amount of brushes in the given brushlist.

Definition at line 251 of file brushbsp.c.

References bspbrush_s::next.

Referenced by ChopBrushes().

static void CreateBrushWindings ( bspbrush_t brush  )  [static]

makes basewindigs for sides and mins/maxs for the brush

Returns:
false if the brush doesn't enclose a valid volume

Definition at line 146 of file brushbsp.c.

References BaseWindingForPlane(), side_s::bevel, BoundBrush(), ChopWindingInPlace(), plane_s::dist, FixWinding(), i, mapplanes, plane_s::normal, bspbrush_s::numsides, side_s::planenum, bspbrush_s::sides, VERB_EXTRA, Verb_Printf(), and side_s::winding.

Referenced by BrushFromBounds().

static qboolean FixWinding ( winding_t w  )  [static]

removes degenerate edges from a winding

Returns:
qtrue if the winding is valid

Definition at line 95 of file brushbsp.c.

References i, winding_s::numpoints, ON_EPSILON, winding_s::p, qfalse, qtrue, SnapWeldVector(), VectorCopy, VectorLength(), and VectorSubtract.

Referenced by CreateBrushWindings().

void FreeBrush ( bspbrush_t brushes  ) 
void FreeBrushList ( bspbrush_t brushes  ) 
See also:
AllocBrush
CountBrushList

Definition at line 314 of file brushbsp.c.

References FreeBrush(), bspbrush_s::next, and next.

Referenced by BuildTree_r(), ChopBrushes(), FreeTree_r(), and SubtractBrush().

static void LeafNode ( node_t node,
bspbrush_t brushes 
) [static]
static side_t* SelectSplitSide ( bspbrush_t brushes,
node_t node 
) [static]

Using a heuristic, choses one of the sides out of the brushlist to partition the brushes with.

Returns:
NULL if there are no valid planes to split with..

the search order goes: visible-structural, visible-detail, nonvisible-structural, nonvisible-detail. If any valid plane is available in a pass, no further passes will be tried.

Todo:
This will overflow if numsides is bigger than 6
See also:
bspbrush_t

Definition at line 523 of file brushbsp.c.

References AXIAL, side_s::bevel, c_nonvis, CheckPlaneAgainstParents(), CheckPlaneAgainstVolume(), mapbrush_s::contentFlags, CONTENTS_DETAIL, i, mapplanes, bspbrush_s::next, bspbrush_s::numsides, bspbrush_s::original, side_s::planenum, PSIDE_BACK, PSIDE_BOTH, PSIDE_FACING, PSIDE_FRONT, qfalse, qtrue, bspbrush_s::side, bspbrush_s::sides, SURF_HINT, SURF_SKIP, side_s::surfaceFlags, Sys_Error(), TestBrushToPlanenum(), side_s::tested, bspbrush_s::testside, side_s::texinfo, TEXINFO_NODE, threadstate, side_s::visible, and side_s::winding.

Referenced by BuildTree_r().

static void SnapWeldVector ( const vec3_t  a,
const vec3_t  b,
vec3_t  out 
) [static]

welds two vec3_t's into a third, taking into account nearest-to-integer instead of averaging

Definition at line 57 of file brushbsp.c.

References i, and SNAP_EPSILON.

Referenced by FixWinding().

void SplitBrush ( const bspbrush_t brush,
int  planenum,
bspbrush_t **  front,
bspbrush_t **  back 
)

Generates two new brushes, leaving the original unchanged.

Todo:
Print brush and entnum either of the brush that was splitted or the plane that was used as splitplane
Todo:
Print brush and entnum either of the brush that was split or the plane that was used as splitplane
Todo:
Print brush and entnum either of the brush that was splitted or the plane that was used as splitplane
Todo:
Print brush and entnum either of the brush that was splitted or the plane that was used as splitplane

Definition at line 682 of file brushbsp.c.

References AllocBrush(), BaseWindingForPlane(), BoundBrush(), BrushMostlyOnSide(), BrushVolume(), ChopWindingInPlace(), ClipWindingEpsilon(), Com_Printf(), CopyBrush(), CopyWinding(), plane_s::dist, DotProduct, FreeBrush(), i, mapplanes, MAX_WORLD_WIDTH, plane_s::normal, winding_s::numpoints, bspbrush_s::numsides, bspbrush_s::original, winding_s::p, side_s::planenum, PSIDE_BACK, PSIDE_FRONT, qfalse, bspbrush_s::sides, side_s::tested, side_s::texinfo, TEXINFO_NODE, VERB_EXTRA, Verb_Printf(), side_s::visible, side_s::winding, WindingIsHuge(), and WindingIsTiny().

Referenced by BuildTree_r(), CheckPlaneAgainstVolume(), ClipBrushToBox(), SplitBrushList(), and SubtractBrush().

static void SplitBrushList ( bspbrush_t brushes,
node_t node,
bspbrush_t **  front,
bspbrush_t **  back 
) [static]
static int TestBrushToPlanenum ( bspbrush_t brush,
int  planenum,
int *  numsplits,
qboolean hintsplit,
int *  epsilonbrush 
) [static]
static qboolean WindingIsHuge ( const winding_t w  )  [static]

Returns true if the winding still has one of the points from basewinding for plane.

Definition at line 449 of file brushbsp.c.

References i, MAX_WORLD_WIDTH, winding_s::numpoints, winding_s::p, qfalse, and qtrue.

Referenced by SplitBrush().

qboolean WindingIsTiny ( winding_t w  ) 

Returns true if the winding would be crunched out of existance by the vertex snapping.

Definition at line 426 of file brushbsp.c.

References EDGE_LENGTH, i, len, winding_s::numpoints, winding_s::p, qfalse, qtrue, VectorLength(), and VectorSubtract.

Referenced by MakeNodePortal(), SplitBrush(), and SplitNodePortals().

void WriteBSPBrushMap ( const char *  name,
const bspbrush_t list 
)

Variable Documentation

int c_active_brushes [static]

Definition at line 30 of file brushbsp.c.

Referenced by AllocBrush(), and FreeBrush().

int c_nodes

Definition at line 28 of file brushbsp.c.

Referenced by BrushBSP(), BuildTree_r(), and FreeTree_r().

int c_nonvis [static]

Definition at line 29 of file brushbsp.c.

Referenced by BrushBSP(), and SelectSplitSide().


Generated by  doxygen 1.6.2