UFO: Alien Invasion
Loading...
Searching...
No Matches
csg.cpp File Reference

Constructive Solids Geometry. More...

#include "bsp.h"
Include dependency graph for csg.cpp:

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.
static bool IsInLevel (const int contents, const int level)
 checks if the level# matches the contentsmask. The level# is mapped to the appropriate levelflags.
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.
static bool BrushGE (bspbrush_t *b1, bspbrush_t *b2)
 Returns true if b1 is allowed to bite b2.
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.
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.

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

◆ AddBrushListToTail()

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

Definition at line 199 of file csg.cpp.

References bspbrush_t::next.

Referenced by ChopBrushes().

◆ BrushesDisjoint()

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_t::brBox, i, AABB::maxs, AABB::mins, bspbrush_t::numsides, side_t::planenum, and bspbrush_t::sides.

Referenced by ChopBrushes().

◆ BrushGE()

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 CONTENTS_DETAIL, CONTENTS_SOLID, and bspbrush_t::original.

Referenced by ChopBrushes().

◆ 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_t::next, SubtractBrush(), VERB_EXTRA, and Verb_Printf().

Referenced by ConstructLevelNodes_r(), and ProcessSubModel().

◆ ClipBrushToBox()

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_t::brBox, FreeBrush(), i, maxplanenums, AABB::maxs, minplanenums, AABB::mins, bspbrush_t::numsides, side_t::planenum, bspbrush_t::sides, SplitBrush(), side_t::texinfo, TEXINFO_NODE, and side_t::visible.

Referenced by MakeBspBrushList().

◆ CullList()

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_t::next.

Referenced by ChopBrushes().

◆ IsInLevel()

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, LEVEL_ACTORCLIP, LEVEL_LIGHTCLIP, LEVEL_WEAPONCLIP, and MASK_CLIP.

Referenced by MakeBspBrushList(), and MapBrushesBounds().

◆ MakeBspBrushList()

◆ 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_t::contentFlags, mapbrush_t::finished, i, IsInLevel(), level, mapbrushes, mapbrush_t::mbBox, and AABB::setNegativeVolume().

Referenced by ConstructLevelNodes_r().

◆ SubtractBrush()

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_t::next, bspbrush_t::numsides, side_t::planenum, bspbrush_t::sides, and SplitBrush().

Referenced by ChopBrushes().

Variable Documentation

◆ maxplanenums

uint16_t maxplanenums[2]
static

Definition at line 107 of file csg.cpp.

Referenced by ClipBrushToBox(), and MakeBspBrushList().

◆ minplanenums

uint16_t minplanenums[2]
static

Definition at line 106 of file csg.cpp.

Referenced by ClipBrushToBox(), and MakeBspBrushList().