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

bsp model loading More...

#include "common.h"
#include "qfiles.h"
#include "tracing.h"
#include "routing.h"
#include "../shared/parse.h"

Go to the source code of this file.

Functions

static int CMod_ValidateLump (const lump_t *lump, const char *functionName, size_t elementSize, const char *elementName, int elementMaxCount)
 
static void CMod_LoadSubmodels (MapTile &tile, const byte *base, const lump_t *lump, const vec3_t shift)
 Loads brush entities like func_door and func_breakable. More...
 
static void CMod_LoadSurfaces (MapTile &tile, const byte *base, const lump_t *lump)
 
static void CMod_LoadNodes (MapTile &tile, const byte *base, const lump_t *lump, const vec3_t shift)
 
static void CMod_LoadBrushes (MapTile &tile, const byte *base, const lump_t *lump)
 
static void CMod_LoadLeafs (MapTile &tile, const byte *base, const lump_t *lump)
 
static void CMod_LoadPlanes (MapTile &tile, const byte *base, const lump_t *lump, const vec3_t shift)
 
static void CMod_LoadLeafBrushes (MapTile &tile, const byte *base, const lump_t *lump)
 
static void CMod_LoadBrushSides (MapTile &tile, const byte *base, const lump_t *lump)
 
static int CMod_DeCompressRouting (const byte **source, byte *dataStart)
 
static void CM_MakeTracingNodes (MapTile &tile)
 Use the bsp node structure to reconstruct efficient tracing structures that are used for fast visibility and pathfinding checks. More...
 
static void CMod_LoadRouting (MapTile &tile, mapData_t *mapData, const byte *base, const char *name, const lump_t *lump, const int sX, const int sY, const int sZ)
 
static void CMod_LoadEntityString (MapTile &tile, const char *entityString, mapData_t *mapData, const byte *base, const lump_t *l, const vec3_t shift)
 
static void CMod_LoadLighting (MapTile &tile, const byte *base, const lump_t *lump)
 Loads the lightmap for server side visibility lookup. More...
 
static void CM_InitBoxHull (MapTile &tile)
 Set up the planes and nodes so that the six floats of a bounding box can just be stored out and get a proper clipping hull structure. More...
 
void CM_LoadBsp (MapTile &tile, const dBspHeader_t &header, const vec3_t shift, const byte *base)
 
static void CM_AddMapTile (const char *name, const char *entityString, const bool day, const int sX, const int sY, const byte sZ, mapData_t *mapData, mapTiles_t *mapTiles)
 Adds in a single map tile. More...
 
static void CMod_RerouteMap (mapTiles_t *mapTiles, mapData_t *mapData)
 Recalculate the seams of the tiles after an RMA. More...
 
void CM_LoadMap (const char *tiles, bool day, const char *pos, const char *entityString, mapData_t *mapData, mapTiles_t *mapTiles)
 Loads in the map and all submodels. More...
 
cBspModel_tCM_InlineModel (const mapTiles_t *mapTiles, const char *name)
 Searches all inline models and return the cBspModel_t pointer for the given modelnumber or -name. More...
 
cBspModel_tCM_SetInlineModelOrientation (mapTiles_t *mapTiles, const char *name, const vec3_t origin, const vec3_t angles)
 This function updates a model's orientation. More...
 
void CM_GetInlineModelAABB (mapTiles_t *mapTiles, const char *name, AABB &aabb)
 This function calculates a model's aabb in world coordinates. More...
 
float CM_GetVisibility (const mapTiles_t *mapTiles, const pos3_t position)
 Checks how well a position is visible. More...
 

Variables

static cBspSurface_t nullSurface
 

Detailed Description

bsp model loading

Definition in file bsp.cpp.

Function Documentation

static void CM_AddMapTile ( const char *  name,
const char *  entityString,
const bool  day,
const int  sX,
const int  sY,
const byte  sZ,
mapData_t mapData,
mapTiles_t mapTiles 
)
static

Adds in a single map tile.

Parameters
[in]nameThe (file-)name of the tile to add.
[in]entityStringIf not empty, this is added to mapEntityString by CMod_LoadEntityString
[in]daywhether the lighting for day or night should be loaded.
[in]sXThe x position on the world plane (grid position) - values from -(PATHFINDING_WIDTH / 2) up to PATHFINDING_WIDTH / 2 are allowed
[in]sYThe y position on the world plane (grid position) - values from -(PATHFINDING_WIDTH / 2) up to PATHFINDING_WIDTH / 2 are allowed
[in]sZThe height level on the world plane (grid position) - values from 0 up to PATHFINDING_HEIGHT are allowed
[in]mapDataThe loaded data is stored here.
[in]mapTilesList of tiles the current (RMA-)map is composed of
Note
The sX and sY values are grid positions - max. grid size is PATHFINDING_WIDTH - unit size is UNIT_SIZE => ends up at 2*MAX_WORLD_WIDTH (the worldplace size - or [-MAX_WORLD_WIDTH, MAX_WORLD_WIDTH])
Returns
The checksum of the maptile
0 on error
See also
CM_LoadMap
R_ModAddMapTile

Definition at line 674 of file bsp.cpp.

References BSP_SwapHeader, BSPVERSION, CM_InitBoxHull(), CM_LoadBsp(), CM_MakeTracingNodes(), CMod_LoadEntityString(), CMod_LoadLighting(), CMod_LoadRouting(), Com_BlockChecksum(), Com_DPrintf(), Com_Error(), Com_sprintf(), DEBUG_ENGINE, ERR_DROP, ERR_FATAL, FS_FreeFile(), FS_LoadFile(), MapTile::idx, length, LittleLong, LUMP_ENTITIES, LUMP_LIGHTING_DAY, LUMP_LIGHTING_NIGHT, LUMP_ROUTING, dBspHeader_t::lumps, mapData_s::mapBox, mapData_s::mapChecksum, mapTiles_s::mapTiles, MAX_QPATH, MapTile::name, NUM_REGULAR_MODELS, mapData_s::numInline, MapTile::nummodels, mapTiles_s::numTiles, OBJZERO, PATHFINDING_HEIGHT, PATHFINDING_WIDTH, Q_strncpyz(), RT_GetMapSize(), shift, UNIT_HEIGHT, UNIT_SIZE, VectorSet, and dBspHeader_t::version.

Referenced by CM_LoadMap().

void CM_GetInlineModelAABB ( mapTiles_t mapTiles,
const char *  name,
AABB aabb 
)

This function calculates a model's aabb in world coordinates.

Parameters
[in]mapTilesList of tiles the current (RMA-)map is composed of
[in]nameThe name of the model, must include the '*'
[out]aabbThe aabb to be filled

Definition at line 979 of file bsp.cpp.

References cBspModel_s::angles, CalculateMinsMaxs(), cBspModel_s::cbmBox, CM_InlineModel(), and cBspModel_s::origin.

Referenced by SV_GetInlineModelAABB().

float CM_GetVisibility ( const mapTiles_t mapTiles,
const pos3_t  position 
)

Checks how well a position is visible.

Returns
a visibility factor. 1.0 means fully visible, 0.0 means hardly visible because the given position is in the darkness
Todo:
implement me

Definition at line 991 of file bsp.cpp.

References Com_Printf(), i, MapTile::lightdata, mapTiles_s::mapTiles, mapTiles_s::numTiles, VectorInside, MapTile::wpMaxs, and MapTile::wpMins.

Referenced by SV_GetVisibility().

cBspModel_t* CM_InlineModel ( const mapTiles_t mapTiles,
const char *  name 
)

Searches all inline models and return the cBspModel_t pointer for the given modelnumber or -name.

Parameters
[in]mapTilesList of tiles the current (RMA-)map is composed of
[in]nameThe modelnumber (e.g. "*2") for inline brush models [bmodels]
Note
Inline bmodels are e.g. the brushes that are assoziated with a func_breakable or func_door

Definition at line 929 of file bsp.cpp.

References Com_Error(), ERR_DROP, i, mapTiles_s::mapTiles, MAX_MODELS, NUM_REGULAR_MODELS, and mapTiles_s::numTiles.

Referenced by CL_GridRecalcRouting(), CL_ParseConfigString(), CL_ViewLoadMedia(), CM_EntCompleteBoxTrace(), CM_EntTestLine(), CM_EntTestLineDM(), CM_GetInlineModelAABB(), CM_SetInlineModelOrientation(), Grid_RecalcRouting(), LET_SlideDoor(), SV_Map(), and SV_SetModel().

void CM_LoadMap ( const char *  tiles,
bool  day,
const char *  pos,
const char *  entityString,
mapData_t mapData,
mapTiles_t mapTiles 
)

Loads in the map and all submodels.

Note
This function loads the collision data from the bsp file. For rendering R_ModBeginLoading is used.
Parameters
[in]tilesMap name(s) relative to base/maps or random map assembly string
[in]dayUse the day (true) or the night (false) version of the map
[in]posIn case you gave more than one tile (Random map assembly [rma]) you also have to provide the positions where those tiles should be placed at.
[out]mapDataThe loaded data is stored here.
[in]mapTilesList of tiles the current (RMA-)map is composed of
[in]entityStringAn entity string that is used for all map tiles. Might be nullptr.
See also
CM_AddMapTile
R_ModBeginLoading

Definition at line 860 of file bsp.cpp.

References CM_AddMapTile(), CMod_RerouteMap(), com_cmodelSysPool, Com_DPrintf(), Com_Error(), Com_Parse(), Com_sprintf(), DEBUG_ENGINE, ERR_DROP, i, MAX_QPATH, MAX_VAR, Mem_FreePool, name, OBJZERO, PATHFINDING_HEIGHT, PATHFINDING_WIDTH, and Q_strncpyz().

Referenced by CL_CanMultiplayerStart(), SV_Map(), and TEST_F().

static void CM_MakeTracingNodes ( MapTile tile)
static

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

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

Definition at line 345 of file bsp.cpp.

References com_cmodelSysPool, cBspModel_s::headnode, i, LEAFNODE, LEVEL_MAX, Mem_PoolAllocTypeN, MapTile::models, NUM_REGULAR_MODELS, MapTile::numcheads, MapTile::nummodels, MapTile::numnodes, MapTile::numtheads, MapTile::thead, MapTile::theadlevel, MapTile::tnodes, and TR_BuildTracingNode_r().

Referenced by CM_AddMapTile().

cBspModel_t* CM_SetInlineModelOrientation ( mapTiles_t mapTiles,
const char *  name,
const vec3_t  origin,
const vec3_t  angles 
)

This function updates a model's orientation.

Parameters
[in]mapTilesList of tiles the current (RMA-)map is composed of
[in]nameThe name of the model, must include the '*'
[in]originThe new origin for the model
[in]anglesThe new facing angles for the model
Note
This is used whenever a model's orientation changes, e.g. for func_doors and func_rotating models
See also
LE_DoorAction
G_ClientUseEdict

Definition at line 963 of file bsp.cpp.

References cBspModel_s::angles, CM_InlineModel(), cBspModel_s::origin, and VectorCopy.

Referenced by CL_AddBrushModel(), LET_RotateDoor(), SV_SetInlineModelOrientation(), and SV_SetModel().

static int CMod_DeCompressRouting ( const byte **  source,
byte dataStart 
)
static
Parameters
[in]sourceSource will be set to the end of the compressed data block!
[in]dataStartwhere to place the uncompressed data
See also
CompressRouting (ufo2map)
CMod_LoadRouting

Definition at line 304 of file bsp.cpp.

References i.

Referenced by CMod_LoadRouting().

static void CMod_LoadBrushes ( MapTile tile,
const byte base,
const lump_t lump 
)
static
Parameters
[in]tileStores the data of the map tile
[in]baseThe start of the data loaded from the file.
[in]lumpdescriptor of the data block we are working on
See also
CM_AddMapTile

Definition at line 160 of file bsp.cpp.

References dBspBrush_t::brushContentFlags, MapTile::brushes, CMod_ValidateLump(), com_cmodelSysPool, count, lump_t::fileofs, cBspBrush_s::firstbrushside, dBspBrush_t::firstbrushside, i, LittleLong, MAX_MAP_BRUSHES, Mem_PoolAllocTypeN, MapTile::numbrushes, and dBspBrush_t::numsides.

Referenced by CM_LoadBsp().

static void CMod_LoadBrushSides ( MapTile tile,
const byte base,
const lump_t lump 
)
static
Parameters
[in]tileStores the data of the map tile
[in]baseThe start of the data loaded from the file.
[in]lumpdescriptor of the data block we are working on
See also
CM_AddMapTile

Definition at line 276 of file bsp.cpp.

References MapTile::brushsides, CMod_ValidateLump(), com_cmodelSysPool, Com_Error(), count, ERR_DROP, lump_t::fileofs, i, LittleShort, MAX_MAP_BRUSHSIDES, Mem_PoolAllocTypeN, MapTile::numbrushsides, MapTile::numtexinfo, cBspBrushSide_s::plane, MapTile::planes, cBspBrushSide_s::surface, and MapTile::surfaces.

Referenced by CM_LoadBsp().

static void CMod_LoadEntityString ( MapTile tile,
const char *  entityString,
mapData_t mapData,
const byte base,
const lump_t l,
const vec3_t  shift 
)
static
Note
Transforms coordinates and stuff for assembled maps
Parameters
[in]mapDataThe loaded data is stored here.
[in]tileStores the data of the map tile
[in]entityStringIf not empty, this is added to mapEntityString
[in]baseThe start of the data loaded from the file.
[in]ldescriptor of the data block we are working on
[in]shiftThe shifting vector in case this is a map assemble loaded map tiles.
See also
CM_AddMapTile

Definition at line 488 of file bsp.cpp.

References cBspModel_s::cbmBox, Com_Error(), Com_Parse(), ERR_DROP, lump_t::filelen, lump_t::fileofs, MapTile::idx, mapData_s::mapEntityString, MAX_MAP_ENTSTRING, AABB::maxs, AABB::mins, MapTile::models, NUM_REGULAR_MODELS, mapData_s::numInline, Q_strcat(), Q_streq, Q_strncpyz(), Q_strvalid, v, VectorAdd, and VectorSubtract.

Referenced by CM_AddMapTile().

static void CMod_LoadLeafBrushes ( MapTile tile,
const byte base,
const lump_t lump 
)
static
Parameters
[in]tileStores the data of the map tile
[in]baseThe start of the data loaded from the file.
[in]lumpdescriptor of the data block we are working on
See also
CM_AddMapTile

Definition at line 254 of file bsp.cpp.

References CMod_ValidateLump(), com_cmodelSysPool, count, lump_t::fileofs, i, MapTile::leafbrushes, LittleShort, MAX_MAP_LEAFBRUSHES, Mem_PoolAllocTypeN, and MapTile::numleafbrushes.

Referenced by CM_LoadBsp().

static void CMod_LoadLeafs ( MapTile tile,
const byte base,
const lump_t lump 
)
static
Parameters
[in]tileStores the data of the map tile
[in]baseThe start of the data loaded from the file.
[in]lumpdescriptor of the data block we are working on
See also
CM_AddMapTile

Definition at line 185 of file bsp.cpp.

References CMod_ValidateLump(), com_cmodelSysPool, Com_Error(), cBspLeaf_s::contentFlags, CONTENTS_SOLID, count, MapTile::emptyleaf, ERR_DROP, lump_t::fileofs, cBspLeaf_s::firstleafbrush, i, MapTile::leafs, LittleLong, LittleShort, MAX_MAP_LEAFS, Mem_PoolAllocTypeN, cBspLeaf_s::numleafbrushes, and MapTile::numleafs.

Referenced by CM_LoadBsp().

static void CMod_LoadLighting ( MapTile tile,
const byte base,
const lump_t lump 
)
static

Loads the lightmap for server side visibility lookup.

Todo:
Implement this

Definition at line 576 of file bsp.cpp.

References com_cmodelSysPool, lump_t::filelen, lump_t::fileofs, MapTile::lightdata, and Mem_PoolAllocTypeN.

Referenced by CM_AddMapTile().

static void CMod_LoadNodes ( MapTile tile,
const byte base,
const lump_t lump,
const vec3_t  shift 
)
static
Parameters
[in]tileStores the data of the map tile
[in]baseThe start of the data loaded from the file.
[in]lumpdescriptor of the data block we are working on
[in]shiftThe shifting vector in case this is a map assemble
See also
CM_AddMapTile
TR_BuildTracingNode_r

Definition at line 123 of file bsp.cpp.

References dBspNode_t::children, CMod_ValidateLump(), com_cmodelSysPool, count, lump_t::fileofs, i, LittleLong, LittleShort, MAX_MAP_NODES, dBspNode_t::maxs, Mem_PoolAllocTypeN, dBspNode_t::mins, MapTile::nodes, MapTile::numnodes, cBspNode_s::plane, dBspNode_t::planenum, PLANENUM_LEAF, and MapTile::planes.

Referenced by CM_LoadBsp().

static void CMod_LoadPlanes ( MapTile tile,
const byte base,
const lump_t lump,
const vec3_t  shift 
)
static
Parameters
[in]tileStores the data of the map tile
[in]baseThe start of the data loaded from the file.
[in]lumpdescriptor of the data block we are working on
[in]shiftThe shifting vector in case this is a map assemble
See also
CM_AddMapTile
R_ModLoadPlanes

Definition at line 224 of file bsp.cpp.

References CMod_ValidateLump(), com_cmodelSysPool, count, cBspPlane_s::dist, lump_t::fileofs, i, LittleFloat, LittleLong, MAX_MAP_PLANES, Mem_PoolAllocTypeN, cBspPlane_s::normal, MapTile::numplanes, MapTile::planes, and cBspPlane_s::type.

Referenced by CM_LoadBsp().

static void CMod_LoadRouting ( MapTile tile,
mapData_t mapData,
const byte base,
const char *  name,
const lump_t lump,
const int  sX,
const int  sY,
const int  sZ 
)
static
Parameters
[in]tileStores the data of the map tile
[in]baseThe start of the data loaded from the file.
[in]mapDataThe loaded data is stored here.
[in]nameThe name of the maptile
[in]lumpRouting lump ... (routing data lump from bsp file)
[in]sXThe x position on the world plane (grid position) - values from -(PATHFINDING_WIDTH/2) up to PATHFINDING_WIDTH/2 are allowed
[in]sYThe y position on the world plane (grid position) - values from -(PATHFINDING_WIDTH/2) up to PATHFINDING_WIDTH/2 are allowed
[in]sZThe height level on the world plane (grid position) - values from 0 - PATHFINDING_HEIGHT are allowed
See also
CM_AddMapTile
Todo:
TEST z-level routing
Todo:
this eats a lot of memory - load directory into mapData->map

Definition at line 380 of file bsp.cpp.

References ACTOR_MAX_SIZE, CMod_DeCompressRouting(), Com_DPrintf(), Com_Error(), Routing::copyPosData(), DEBUG_ROUTING, ERR_DROP, lump_t::filelen, lump_t::fileofs, i, MapTile::idx, length, LittleLong, Mem_Alloc, Mem_Free, PATHFINDING_HEIGHT, PATHFINDING_WIDTH, mapData_s::reroute, mapData_s::routing, ROUTING_NOT_REACHABLE, MapTile::wpMaxs, and MapTile::wpMins.

Referenced by CM_AddMapTile().

static void CMod_LoadSubmodels ( MapTile tile,
const byte base,
const lump_t lump,
const vec3_t  shift 
)
static

Loads brush entities like func_door and func_breakable.

Parameters
[in]tileStores the data of the map tile
[in]baseThe start of the data loaded from the file.
[in]lumpThe lump to load the data from
[in]shiftThe shifting vector in case this is a map assemble
See also
CM_AddMapTile
R_ModLoadSubmodels
CM_InlineModel

Definition at line 68 of file bsp.cpp.

References cBspModel_s::cbmBox, CMod_ValidateLump(), com_cmodelSysPool, count, AABB::expand(), lump_t::fileofs, cBspModel_s::headnode, i, MapTile::idx, LittleLong, MAX_MAP_MODELS, Mem_PoolAllocTypeN, MapTile::models, MapTile::nummodels, AABB::setFromLittleFloat(), cBspModel_s::shift, AABB::shift(), cBspModel_s::tile, and VectorCopy.

Referenced by CM_LoadBsp().

static void CMod_LoadSurfaces ( MapTile tile,
const byte base,
const lump_t lump 
)
static
Parameters
[in]tileStores the data of the map tile
[in]baseThe start of the data loaded from the file.
[in]lumpdescriptor of the data block we are working on
See also
CM_AddMapTile

Definition at line 97 of file bsp.cpp.

References CMod_ValidateLump(), com_cmodelSysPool, count, lump_t::fileofs, i, LittleLong, MAX_MAP_TEXINFO, Mem_PoolAllocTypeN, cBspSurface_s::name, MapTile::numtexinfo, Q_strncpyz(), cBspSurface_s::surfaceFlags, and MapTile::surfaces.

Referenced by CM_LoadBsp().

static int CMod_ValidateLump ( const lump_t lump,
const char *  functionName,
size_t  elementSize,
const char *  elementName,
int  elementMaxCount 
)
static

Variable Documentation

cBspSurface_t nullSurface
static
Note
this is a zeroed surface structure

Definition at line 33 of file bsp.cpp.

Referenced by CM_InitBoxHull().