UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
csg.cpp File Reference

Constructive Solids Geometry. More...

#include "bsp.h"

Go to the source code of this file.

Functions

static bspbrush_tSubtractBrush (bspbrush_t *a, const bspbrush_t *b)
 
static bool BrushesDisjoint (bspbrush_t *a, bspbrush_t *b)
 
static bspbrush_tClipBrushToBox (bspbrush_t *brush, const AABB &clipBox)
 Any planes shared with the box edge will be set to no texinfo. More...
 
static bool IsInLevel (const int contents, const int level)
 checks if the level# matches the contentsmask. The level# is mapped to the appropriate levelflags. More...
 
static bspbrush_tAddBrushListToTail (bspbrush_t *list, bspbrush_t *tail)
 
static bspbrush_tCullList (bspbrush_t *list, bspbrush_t *skip)
 Builds a new list that doesn't hold the given brush. More...
 
static bool BrushGE (bspbrush_t *b1, bspbrush_t *b2)
 Returns true if b1 is allowed to bite b2. More...
 
int MapBrushesBounds (const int startbrush, const int endbrush, const int level, const AABB &clipBox, AABB &bBox)
 sets mins and maxs to the smallest sizes that can contain all brushes from startbrush to endbrush that are in a given level. More...
 
bspbrush_tMakeBspBrushList (int startbrush, int endbrush, int level, const AABB &clip)
 
bspbrush_tChopBrushes (bspbrush_t *head)
 Carves any intersecting solid brushes into the minimum number of non-intersecting brushes. More...
 

Variables

static uint16_t minplanenums [2]
 
static uint16_t maxplanenums [2]
 

Detailed Description

Constructive Solids Geometry.

Note
tag all brushes with original contents brushes may contain multiple contents there will be no brush overlap after csg phase

each side has a count of the other sides it splits

the best split will be the one that minimizes the total split counts of all remaining sides

precalc side on plane table

evaluate split side

{
cost = 0
for all sides
for all sides
get
if side splits side and splitside is on same child
cost++;
}

Definition in file csg.cpp.

Function Documentation

static bspbrush_t* AddBrushListToTail ( bspbrush_t list,
bspbrush_t tail 
)
static

Definition at line 199 of file csg.cpp.

References bspbrush_s::next.

Referenced by ChopBrushes().

static bool BrushesDisjoint ( bspbrush_t a,
bspbrush_t b 
)
static
Returns
true if the two brushes definately do not intersect.
Note
There will be false negatives for some non-axial combinations.

Definition at line 86 of file csg.cpp.

References bspbrush_s::brBox, i, AABB::maxs, AABB::mins, bspbrush_s::numsides, side_s::planenum, and bspbrush_s::sides.

Referenced by ChopBrushes().

static bool BrushGE ( bspbrush_t b1,
bspbrush_t b2 
)
inlinestatic

Returns true if b1 is allowed to bite b2.

Definition at line 242 of file csg.cpp.

References mapbrush_s::contentFlags, CONTENTS_DETAIL, CONTENTS_SOLID, and bspbrush_s::original.

Referenced by ChopBrushes().

bspbrush_t* ChopBrushes ( bspbrush_t head)

Carves any intersecting solid brushes into the minimum number of non-intersecting brushes.

Definition at line 376 of file csg.cpp.

References AddBrushListToTail(), BrushesDisjoint(), BrushGE(), CountBrushList(), CullList(), FreeBrushList(), bspbrush_s::next, SubtractBrush(), VERB_EXTRA, and Verb_Printf().

Referenced by ConstructLevelNodes_r(), and ProcessSubModel().

static bspbrush_t* ClipBrushToBox ( bspbrush_t brush,
const AABB clipBox 
)
static

Any planes shared with the box edge will be set to no texinfo.

Note
not thread safe

Definition at line 113 of file csg.cpp.

References bspbrush_s::brBox, FreeBrush(), i, maxplanenums, AABB::maxs, minplanenums, AABB::mins, bspbrush_s::numsides, side_s::planenum, bspbrush_s::sides, SplitBrush(), side_s::texinfo, TEXINFO_NODE, and side_s::visible.

Referenced by MakeBspBrushList().

static bspbrush_t* CullList ( bspbrush_t list,
bspbrush_t skip 
)
static

Builds a new list that doesn't hold the given brush.

Parameters
[in]listThe brush list to copy
[in]skipThe brush to skip
Returns
a bspbrush_t that is the old list without the skip entry

Definition at line 220 of file csg.cpp.

References FreeBrush(), and bspbrush_s::next.

Referenced by ChopBrushes().

static bool IsInLevel ( const int  contents,
const int  level 
)
static

checks if the level# matches the contentsmask. The level# is mapped to the appropriate levelflags.

Parameters
[in]contentsThe contentsmask (of the brush, surface, etc.) to check
[in]level-1 for skipping the levelflag check
Returns
boolean value

Definition at line 158 of file csg.cpp.

References CONTENTS_ACTORCLIP, CONTENTS_LIGHTCLIP, CONTENTS_WEAPONCLIP, LEVEL_ACTORCLIP, LEVEL_LIGHTCLIP, LEVEL_WEAPONCLIP, and MASK_CLIP.

Referenced by MakeBspBrushList(), and MapBrushesBounds().

int MapBrushesBounds ( const int  startbrush,
const int  endbrush,
const int  level,
const AABB clipBox,
AABB bBox 
)

sets mins and maxs to the smallest sizes that can contain all brushes from startbrush to endbrush that are in a given level.

Parameters
[in]startbrushthe index of the first brush to check.
[in]endbrushthe index after the last brush to check.
[in]levelthe level that we are searching for brushes in. -1 for skipping the levelflag check.
[in]clipBoxthe absolute lowest and highest boundaries to allow for brushes.
[out]bBoxthe max boundaries for all accepted brushes within the clipped bounds.
See also
ProcessSubModel
IsInLevel

Definition at line 264 of file csg.cpp.

References AABB::add(), AABB::contains(), mapbrush_s::contentFlags, mapbrush_s::finished, i, IsInLevel(), mapbrushes, mapbrush_s::mbBox, and AABB::setNegativeVolume().

Referenced by ConstructLevelNodes_r().

static bspbrush_t* SubtractBrush ( bspbrush_t a,
const bspbrush_t b 
)
static
Returns
a list of brushes that remain after B is subtracted from A.
Note
Return may by empty if A is contained inside B.
The originals are undisturbed.

Definition at line 55 of file csg.cpp.

References FreeBrush(), FreeBrushList(), i, bspbrush_s::next, bspbrush_s::numsides, side_s::planenum, bspbrush_s::sides, and SplitBrush().

Referenced by ChopBrushes().

Variable Documentation

uint16_t maxplanenums[2]
static

Definition at line 107 of file csg.cpp.

Referenced by ClipBrushToBox(), and MakeBspBrushList().

uint16_t minplanenums[2]
static

Definition at line 106 of file csg.cpp.

Referenced by ClipBrushToBox(), and MakeBspBrushList().