bsp.h File Reference

#include <assert.h>
#include "map.h"
#include "common/shared.h"
#include "common/scriplib.h"
#include "common/polylib.h"
#include "common/bspfile.h"
#include "../../common/tracing.h"
Include dependency graph for bsp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  bspbrush_s
struct  node_s
struct  tree_t
struct  textureref_t

Typedefs

typedef struct bspbrush_s bspbrush_t
typedef struct node_s node_t

Functions

byte GetLevelFlagsFromBrush (const mapbrush_t *brush)
 Extract the level flags (1-8) from the content flags of the given brush.
void LoadMapFile (const char *filename)
void WriteMapFile (const char *filename)
int FindOrCreateFloatPlane (vec3_t normal, vec_t dist)
int FindMiptex (const char *name)
int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, const vec3_t origin, qboolean isTerrain)
int MapBrushesBounds (const int startbrush, const int endbrush, const int level, const vec3_t clipmins, const vec3_t clipmaxs, vec3_t mins, vec3_t maxs)
 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, vec3_t clipmins, vec3_t clipmaxs)
bspbrush_tChopBrushes (bspbrush_t *head)
 Carves any intersecting solid brushes into the minimum number of non-intersecting brushes.
bspbrush_tCopyBrush (const bspbrush_t *brush)
 Duplicates the brush, the sides, and the windings.
void SplitBrush (const bspbrush_t *brush, int planenum, bspbrush_t **front, bspbrush_t **back)
 Generates two new brushes, leaving the original unchanged.
bspbrush_tAllocBrush (int numsides)
int CountBrushList (bspbrush_t *brushes)
 Returns the amount of brushes in the given brushlist.
void FreeBrush (bspbrush_t *brushes)
void FreeBrushList (bspbrush_t *brushes)
qboolean WindingIsTiny (winding_t *w)
 Returns true if the winding would be crunched out of existance by the vertex snapping.
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
int VisibleContents (int contents)
 Returns the single content bit of the strongest visible content present.
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.
void SetModelNumbers (void)
 Set the model numbers for SOLID_BSP entities like func_door or func_breakable.
void BeginBSPFile (void)
 Starts a new bsp file.
int WriteBSP (node_t *headnode)
 copies working data for a bsp tree into the structures used to create the bsp file.
void EndBSPFile (const char *filename)
 Finishes a new bsp and writes to disk.
void BeginModel (int entityNum)
 Sets up a new brush model.
void EndModel (void)
 Finish a model's processing.
void EmitBrushes (void)
 Writes the brush list to the bsp.
void EmitPlanes (void)
 Emits planes to the bsp file.
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)
void FreeTree (tree_t *tree)
void MakeTracingNodes (int levels)
 Use the bsp node structure to reconstruct efficient tracing structures that are used for fast visibility and pathfinding checks.
void CloseTracingNodes (void)
void PushInfo (void)
void PopInfo (void)
void ProcessLevel (unsigned int levelnum)
 process brushes with that level mask
void PruneNodes (node_t *node)
void DoRouting (void)
 Calculates the routing of a map.
void ProcessModels (const char *filename)

Variables

dMapTile_tcurTile
mapTiles_t mapTiles
int entity_num
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
textureref_t textureref [MAX_MAP_TEXTURES]
const vec3_t v_epsilon
vec3_t worldMins
vec3_t worldMaxs

Detailed Description

Definition in file bsp.h.


Typedef Documentation

typedef struct bspbrush_s bspbrush_t
typedef struct node_s node_t

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

void BeginBSPFile ( void   ) 
void BeginModel ( int  entityNum  ) 
tree_t* BrushBSP ( bspbrush_t brushlist,
vec3_t  mins,
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 391 of file csg.c.

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

Referenced by ConstructLevelNodes_r(), and ProcessSubModel().

void CloseTracingNodes ( void   ) 
See also:
MakeTnodes

Definition at line 73 of file trace.c.

References curTile, Mem_Free, and dMapTile_t::tnodes.

Referenced by LightWorld(), and MakeTracingNodes().

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

void DoRouting ( void   ) 
void EmitBrushes ( void   ) 
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.c.

References curTile, plane_s::dist, dBspPlane_t::dist, i, mapplanes, dBspPlane_t::normal, plane_s::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 342 of file writebsp.c.

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 400 of file writebsp.c.

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

Referenced by ProcessSubModel().

int FindMiptex ( const char *  name  ) 
Returns:
-1 means that the texture was not found
See also:
TexinfoForBrushTexture
ParseBrush

Definition at line 37 of file textures.c.

References i, MAX_MAP_TEXTURES, nummiptex, Q_strncpyz(), and Sys_Error().

Referenced by ParseBrush().

int FindOrCreateFloatPlane ( vec3_t  normal,
vec_t  dist 
)
void FixTjuncs ( node_t headnode  ) 
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().

void FreeFace ( face_t f  ) 

Definition at line 134 of file faces.c.

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

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

Referenced by FreeTreePortals_r().

void FreeTree ( tree_t tree  ) 

Definition at line 79 of file tree.c.

References FreeTree_r(), FreeTreePortals_r(), tree_t::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 412 of file faces.c.

References config, face_s::contentFlags, curTile, dMapTile_t::edges, 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:
brush The brush to extract the level flags from
Returns:
The level flags (content flags) of the given brush

Definition at line 276 of file map.c.

References byte, and mapbrush_s::contentFlags.

void LoadMapFile ( const char *  filename  ) 
bspbrush_t* MakeBspBrushList ( int  startbrush,
int  endbrush,
int  level,
vec3_t  clipmins,
vec3_t  clipmaxs 
)
void MakeFaces ( node_t headnode  ) 

Definition at line 777 of file faces.c.

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

References CloseTracingNodes(), curTile, dBspModel_t::headnode, i, LEVEL_ACTORCLIP, LEVEL_LIGHTCLIP, LEVEL_MAX, Mem_Alloc, 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 396 of file portals.c.

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

Referenced by ConstructLevelNodes_r(), and ProcessSubModel().

int MapBrushesBounds ( const int  startbrush,
const int  endbrush,
const int  level,
const vec3_t  clipmins,
const vec3_t  clipmaxs,
vec3_t  mins,
vec3_t  maxs 
)

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] startbrush the index of the first brush to check.
[in] endbrush the index after the last brush to check.
[in] level the level that we are searching for brushes in. -1 for skipping the levelflag check.
[in] clipmins the absolute lowest boundary to allow for brushes.
[in] clipmaxs the absolute highest boundary to allow for brushes.
[out] mins the lowest boundary for all accepted brushes within the clipped bounds.
[out] maxs the highest boundary for all accepted brushes within the clipped bounds.
See also:
ProcessSubModel
IsInLevel

Definition at line 266 of file csg.c.

References AddPointToBounds(), ClearBounds(), mapbrush_s::contentFlags, mapbrush_s::finished, i, IsInLevel(), mapbrushes, mapbrush_s::maxs, and mapbrush_s::mins.

Referenced by ConstructLevelNodes_r().

void MarkVisibleSides ( tree_t tree,
int  start,
int  end 
)
void PopInfo ( void   ) 
void ProcessLevel ( unsigned int  levelnum  ) 

process brushes with that level mask

Parameters:
[in] levelnum is the level mask
Note:
levelnum 256: weaponclip-level 257: actorclip-level 258: stepon-level 259: tracing structure
See also:
ProcessWorldModel
ConstructLevelNodes_r

Note:
Should be reentrant as each thread has a unique levelnum at any given time
Todo:
Check what happens if two threads do the memcpy

Definition at line 233 of file levels.c.

References config, ConstructLevelNodes_r(), curTile, dBspModel_t::firstface, dBspModel_t::headnode, mapbrushes, MAX_WORLD_WIDTH, dMapTile_t::models, dBspModel_t::numfaces, dMapTile_t::numfaces, nummapbrushes, dMapTile_t::nummodels, VERB_EXTRA, and Verb_Printf().

Referenced by ProcessWorldModel().

void ProcessModels ( const char *  filename  ) 
void PruneNodes ( node_t node  ) 
See also:
PruneNodes_r

Definition at line 135 of file tree.c.

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

Referenced by ConstructLevelNodes_r().

void PushInfo ( void   ) 
void RemovePortalFromNode ( portal_t portal,
node_t l 
)

Removes references to the given portal from the given node.

Parameters:
[in,out] portal The portal to remove from the node
[in,out] l The node to remove the portal from
See also:
AddPortalToNodes

Definition at line 102 of file portals.c.

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 entities like func_door or func_breakable.

Definition at line 223 of file writebsp.c.

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

Referenced by main().

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

int TexinfoForBrushTexture ( plane_t plane,
brush_texture_t bt,
const vec3_t  origin,
qboolean  isTerrain 
)
int VisibleContents ( int  contents  ) 

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

Definition at line 64 of file portals.c.

References i, and LAST_VISIBLE_CONTENTS.

Referenced by FaceFromPortal(), and FindPortalSide().

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

int WriteBSP ( node_t headnode  ) 

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

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

Definition at line 201 of file writebsp.c.

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

Referenced by ConstructLevelNodes_r(), and ProcessSubModel().

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

Variable Documentation

int brush_end

Definition at line 29 of file levels.c.

Referenced by ConstructLevelNodes_r(), and ProcessWorldModel().

Definition at line 29 of file levels.c.

Referenced by ConstructLevelNodes_r(), and ProcessWorldModel().

side_t brushsides[MAX_MAP_SIDES]

Definition at line 28 of file bsp.c.

Referenced by ConstructLevelNodes_r(), and ProcessModels().

mapbrush_t mapbrushes[MAX_MAP_BRUSHES]
plane_t mapplanes[MAX_MAP_PLANES]

Definition at line 34 of file bsp.c.

Definition at line 36 of file map.c.

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

Definition at line 42 of file map.c.

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

textureref_t textureref[MAX_MAP_TEXTURES]

Definition at line 29 of file textures.c.

Referenced by GenerateFootstepList(), and GenerateMaterialFile().

Definition at line 28 of file levels.c.

Referenced by ConstructLevelNodes_r().

Definition at line 31 of file levels.c.

Referenced by BuildNodeChildren(), and ProcessWorldModel().

Definition at line 31 of file levels.c.

Referenced by BuildNodeChildren(), and ProcessWorldModel().


Generated by  doxygen 1.6.2