UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
bsp.h File Reference
#include <assert.h>
#include "map.h"
#include "bspbrush.h"
#include "common/shared.h"
#include "common/scriplib.h"
#include "common/polylib.h"
#include "common/bspfile.h"
#include "../../common/tracing.h"

Go to the source code of this file.

Data Structures

struct  node_s
 
struct  tree_s
 

Typedefs

typedef struct node_s node_t
 
typedef struct tree_s tree_t
 

Functions

byte GetLevelFlagsFromBrush (const mapbrush_t *brush)
 Extract the level flags (1-8) from the content flags of the given brush. More...
 
void LoadMapFile (const char *filename)
 
void WriteMapFile (const char *filename)
 
uint16_t FindOrCreateFloatPlane (vec3_t normal, vec_t dist)
 
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...
 
uint32_t VisibleContents (uint32_t contents)
 Returns the single content bit of the strongest visible content present. More...
 
void MarkVisibleSides (tree_t *tree, int start, int end)
 
void FreePortal (portal_t *p)
 
void MakeTreePortals (tree_t *tree)
 
void RemovePortalFromNode (portal_t *portal, node_t *l)
 Removes references to the given portal from the given node. More...
 
void SetModelNumbers (void)
 Set the model numbers for SOLID_BSP or SOLID_TRIGGER entities like func_door or func_breakable. More...
 
void BeginBSPFile (void)
 Starts a new bsp file. More...
 
int WriteBSP (node_t *headnode)
 copies working data for a bsp tree into the structures used to create the bsp file. More...
 
void EndBSPFile (const char *filename)
 Finishes a new bsp and writes to disk. More...
 
void BeginModel (int entityNum)
 Sets up a new brush model. More...
 
void EndModel (void)
 Finish a model's processing. More...
 
void EmitBrushes (void)
 Writes the brush list to the bsp. More...
 
void EmitPlanes (void)
 Emits planes to the bsp file. More...
 
void MakeFaces (node_t *headnode)
 
void FixTjuncs (node_t *headnode)
 
int GetEdge (int v1, int v2, const face_t *f)
 
void FreeFace (face_t *f)
 
node_tAllocNode (void)
 
tree_tAllocTree (void)
 Allocates a tree and initializes it. More...
 
tree_tBuildTree (bspbrush_t *brushlist, const vec3_t mins, const vec3_t maxs)
 The incoming list will be freed before exiting. More...
 
void FreeTree (tree_t *tree)
 
void PruneNodes (node_t *node)
 
void MakeTracingNodes (int levels)
 Use the bsp node structure to reconstruct efficient tracing structures that are used for fast visibility and pathfinding checks. More...
 
void CloseTracingNodes (void)
 
void DoRouting (void)
 Calculates the routing of a map. More...
 
void ProcessModels (const char *filename)
 

Variables

dMapTile_tcurTile
 
mapTiles_t mapTiles
 
plane_t mapplanes [MAX_MAP_PLANES]
 
int nummapplanes
 
int nummapbrushes
 
mapbrush_t mapbrushes [MAX_MAP_BRUSHES]
 
int nummapbrushsides
 
side_t brushsides [MAX_MAP_SIDES]
 
brush_texture_t side_brushtextures [MAX_MAP_SIDES]
 
int brush_start
 
int brush_end
 

Typedef Documentation

typedef struct node_s node_t
typedef struct tree_s tree_t

Function Documentation

node_t* AllocNode ( void  )
See also
AllocBrush
AllocTree

Definition at line 34 of file tree.cpp.

References Mem_AllocType.

Referenced by BuildTree(), and BuildTree_r().

tree_t* AllocTree ( void  )

Allocates a tree and initializes it.

Definition at line 92 of file tree.cpp.

References tree_s::aabb, Mem_AllocType, and AABB::setNegativeVolume().

Referenced by BuildTree().

tree_t* BuildTree ( bspbrush_t brushlist,
const vec3_t  mins,
const vec3_t  maxs 
)
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().

void CloseTracingNodes ( void  )
See also
MakeTnodes

Definition at line 65 of file trace.cpp.

References curTile, Mem_Free, and dMapTile_t::tnodes.

Referenced by LightWorld(), and MakeTracingNodes().

void EmitPlanes ( void  )

Emits planes to the bsp file.

Note
There is no oportunity to discard planes, because all of the original brushes will be saved in the map.

Definition at line 41 of file writebsp.cpp.

References curTile, plane_s::dist, dBspPlane_t::dist, i, mapplanes, plane_s::normal, dBspPlane_t::normal, nummapplanes, dMapTile_t::numplanes, dMapTile_t::planes, plane_s::type, dBspPlane_t::type, and VectorCopy.

Referenced by DoRouting(), and EndBSPFile().

void EndBSPFile ( const char *  filename)

Finishes a new bsp and writes to disk.

See also
BeginBSPFile

Definition at line 336 of file writebsp.cpp.

References EmitBrushes(), EmitPlanes(), UnparseEntities(), VERB_LESS, Verb_Printf(), and WriteBSPFile().

Referenced by ProcessModels().

void EndModel ( void  )

Finish a model's processing.

See also
BeginModel

Definition at line 387 of file writebsp.cpp.

References curTile, dBspModel_t::firstface, dMapTile_t::models, dBspModel_t::numfaces, dMapTile_t::numfaces, and dMapTile_t::nummodels.

Referenced by ProcessSubModel().

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

void FreePortal ( portal_t p)
See also
AllocPortal

Definition at line 52 of file portals.cpp.

References c_active_portals, FreeWinding(), Mem_Free, threadstate, and portal_s::winding.

Referenced by FreeTreePortals_r().

void FreeTree ( tree_t tree)

Definition at line 102 of file tree.cpp.

References FreeTree_r(), FreeTreePortals_r(), tree_s::headnode, and Mem_Free.

Referenced by ConstructLevelNodes_r(), and ProcessSubModel().

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

byte GetLevelFlagsFromBrush ( const mapbrush_t brush)

Extract the level flags (1-8) from the content flags of the given brush.

Parameters
brushThe brush to extract the level flags from
Returns
The level flags (content flags) of the given brush

Definition at line 277 of file map.cpp.

References mapbrush_s::contentFlags.

void MakeFaces ( node_t headnode)

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

void MakeTracingNodes ( int  levels)

Use the bsp node structure to reconstruct efficient tracing structures that are used for fast visibility and pathfinding checks.

Note
curTile->tnodes is expected to have enough memory malloc'ed for the function to work.
See also
BuildTracingNode_r

Definition at line 38 of file trace.cpp.

References CloseTracingNodes(), curTile, dBspModel_t::headnode, i, LEVEL_ACTORCLIP, LEVEL_LIGHTCLIP, LEVEL_MAX, Mem_AllocTypeN, dMapTile_t::models, dBspModel_t::numfaces, dMapTile_t::numnodes, dMapTile_t::numtheads, dMapTile_t::thead, dMapTile_t::theadlevel, dMapTile_t::tnodes, and TR_BuildTracingNode_r().

Referenced by DoRouting(), and LightWorld().

void MakeTreePortals ( tree_t tree)

Definition at line 391 of file portals.cpp.

References tree_s::headnode, MakeHeadnodePortals(), and MakeTreePortals_r().

Referenced by ConstructLevelNodes_r(), and ProcessSubModel().

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

void MarkVisibleSides ( tree_t tree,
int  start,
int  end 
)
void ProcessModels ( const char *  filename)
void PruneNodes ( node_t node)
See also
PruneNodes_r

Definition at line 261 of file tree.cpp.

References c_pruned, PruneNodes_r(), VERB_EXTRA, and Verb_Printf().

Referenced by ConstructLevelNodes_r().

void RemovePortalFromNode ( portal_t portal,
node_t l 
)

Removes references to the given portal from the given node.

Parameters
[in,out]portalThe portal to remove from the node
[in,out]lThe node to remove the portal from
See also
AddPortalToNodes

Definition at line 102 of file portals.cpp.

References portal_s::next, portal_s::nodes, node_s::portals, and Sys_Error().

Referenced by FreeTreePortals_r(), and SplitNodePortals().

void SetModelNumbers ( void  )

Set the model numbers for SOLID_BSP or SOLID_TRIGGER entities like func_door or func_breakable.

Definition at line 217 of file writebsp.cpp.

References Com_sprintf(), entities, i, num_entities, and SetKeyValue().

Referenced by main().

uint32_t VisibleContents ( uint32_t  contents)

Returns the single content bit of the strongest visible content present.

Definition at line 64 of file portals.cpp.

References i, and LAST_VISIBLE_CONTENTS.

Referenced by FaceFromPortal(), and FindPortalSide().

int WriteBSP ( node_t headnode)

copies working data for a bsp tree into the structures used to create the bsp file.

Parameters
[in]headnodethe top-most node in this bsp tree
Returns
the index to the head node created.

Definition at line 195 of file writebsp.cpp.

References c_facenodes, c_nofaces, curTile, EmitDrawNode_r(), dMapTile_t::numfaces, oldfaces, VERB_EXTRA, and Verb_Printf().

Referenced by ConstructLevelNodes_r(), and ProcessSubModel().

Variable Documentation

int brush_end

Definition at line 29 of file levels.cpp.

Referenced by ConstructLevelNodes_r(), and ProcessWorldModel().

int brush_start

Definition at line 29 of file levels.cpp.

Referenced by ConstructLevelNodes_r(), and ProcessWorldModel().

mapTiles_t mapTiles

Definition at line 33 of file bsp.cpp.

int nummapbrushsides

Definition at line 38 of file map.cpp.

Referenced by AddBrushBevels(), Check_Stats(), LoadMapFile(), and ParseBrush().

int nummapplanes

Definition at line 44 of file map.cpp.

Referenced by Check_Stats(), CreateNewFloatPlane(), EmitPlanes(), and LoadMapFile().