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

bsp model loading More...

#include "common.h"
#include "qfiles.h"
#include "tracing.h"
#include "routing.h"
#include "../shared/parse.h"
Include dependency graph for bsp.cpp:

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.
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.
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.
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.
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.
static void CMod_RerouteMap (mapTiles_t *mapTiles, mapData_t *mapData)
 Recalculate the seams of the tiles after an RMA.
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.
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.
cBspModel_tCM_SetInlineModelOrientation (mapTiles_t *mapTiles, const char *name, const vec3_t origin, const vec3_t angles)
 This function updates a model's orientation.
void CM_GetInlineModelAABB (mapTiles_t *mapTiles, const char *name, AABB &aabb)
 This function calculates a model's aabb in world coordinates.
float CM_GetVisibility (const mapTiles_t *mapTiles, const pos3_t position)
 Checks how well a position is visible.

Variables

static cBspSurface_t nullSurface

Detailed Description

bsp model loading

Definition in file bsp.cpp.

Function Documentation

◆ CM_AddMapTile()

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, mapTiles, MAX_QPATH, MapTile::name, name, NUM_REGULAR_MODELS, MapTile::nummodels, OBJZERO, PATHFINDING_HEIGHT, PATHFINDING_WIDTH, Q_strncpyz(), RT_GetMapSize(), shift, UNIT_HEIGHT, UNIT_SIZE, VectorSet, and dBspHeader_t::version.

Referenced by CM_LoadMap().

◆ CM_GetInlineModelAABB()

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_t::angles, CalculateMinsMaxs(), cBspModel_t::cbmBox, CM_InlineModel(), mapTiles, name, and cBspModel_t::origin.

Referenced by SV_GetInlineModelAABB().

◆ CM_GetVisibility()

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, VectorInside, MapTile::wpMaxs, and MapTile::wpMins.

Referenced by SV_GetVisibility().

◆ CM_InitBoxHull()

◆ CM_InlineModel()

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, MAX_MODELS, name, and NUM_REGULAR_MODELS.

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

◆ CM_LoadBsp()

◆ CM_LoadMap()

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, mapData, mapTiles, MAX_QPATH, MAX_VAR, Mem_FreePool, name, OBJZERO, PATHFINDING_HEIGHT, PATHFINDING_WIDTH, and Q_strncpyz().

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

◆ CM_MakeTracingNodes()

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

◆ CM_SetInlineModelOrientation()

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_t::angles, CM_InlineModel(), mapTiles, name, cBspModel_t::origin, and VectorCopy.

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

◆ CMod_DeCompressRouting()

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

◆ CMod_LoadBrushes()

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 cBspBrush_t::brushContentFlags, dBspBrush_t::brushContentFlags, MapTile::brushes, CMod_ValidateLump(), com_cmodelSysPool, count, lump_t::fileofs, cBspBrush_t::firstbrushside, dBspBrush_t::firstbrushside, i, LittleLong, MAX_MAP_BRUSHES, Mem_PoolAllocTypeN, MapTile::numbrushes, cBspBrush_t::numsides, and dBspBrush_t::numsides.

Referenced by CM_LoadBsp().

◆ CMod_LoadBrushSides()

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_t::plane, dBspBrushSide_t::planenum, MapTile::planes, cBspBrushSide_t::surface, MapTile::surfaces, and dBspBrushSide_t::texinfo.

Referenced by CM_LoadBsp().

◆ CMod_LoadEntityString()

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_t::cbmBox, Com_Error(), Com_Parse(), ERR_DROP, lump_t::filelen, lump_t::fileofs, MapTile::idx, mapData, MAX_MAP_ENTSTRING, AABB::maxs, AABB::mins, MapTile::models, NUM_REGULAR_MODELS, Q_strcat(), Q_streq, Q_strncpyz(), Q_strvalid, shift, v, VectorAdd, and VectorSubtract.

Referenced by CM_AddMapTile().

◆ CMod_LoadLeafBrushes()

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

◆ CMod_LoadLeafs()

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_t::contentFlags, dBspLeaf_t::contentFlags, CONTENTS_SOLID, count, MapTile::emptyleaf, ERR_DROP, lump_t::fileofs, cBspLeaf_t::firstleafbrush, dBspLeaf_t::firstleafbrush, i, MapTile::leafs, LittleLong, LittleShort, MAX_MAP_LEAFS, Mem_PoolAllocTypeN, cBspLeaf_t::numleafbrushes, dBspLeaf_t::numleafbrushes, and MapTile::numleafs.

Referenced by CM_LoadBsp().

◆ CMod_LoadLighting()

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

◆ CMod_LoadNodes()

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 cBspNode_t::children, dBspNode_t::children, CMod_ValidateLump(), com_cmodelSysPool, count, lump_t::fileofs, i, LittleLong, LittleShort, MAX_MAP_NODES, cBspNode_t::maxs, dBspNode_t::maxs, Mem_PoolAllocTypeN, cBspNode_t::mins, dBspNode_t::mins, MapTile::nodes, MapTile::numnodes, cBspNode_t::plane, dBspNode_t::planenum, PLANENUM_LEAF, MapTile::planes, and shift.

Referenced by CM_LoadBsp().

◆ CMod_LoadPlanes()

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_t::dist, dBspPlane_t::dist, lump_t::fileofs, i, LittleFloat, LittleLong, MAX_MAP_PLANES, Mem_PoolAllocTypeN, cBspPlane_t::normal, dBspPlane_t::normal, MapTile::numplanes, MapTile::planes, shift, cBspPlane_t::type, and dBspPlane_t::type.

Referenced by CM_LoadBsp().

◆ CMod_LoadRouting()

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(), DEBUG_ROUTING, ERR_DROP, lump_t::filelen, lump_t::fileofs, i, MapTile::idx, length, LittleLong, mapData, Mem_Alloc, Mem_Free, name, PATHFINDING_HEIGHT, PATHFINDING_WIDTH, ROUTING_NOT_REACHABLE, MapTile::wpMaxs, and MapTile::wpMins.

Referenced by CM_AddMapTile().

◆ CMod_LoadSubmodels()

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_t::cbmBox, CMod_ValidateLump(), com_cmodelSysPool, count, dBspModel_t::dbmBox, AABB::expand(), lump_t::fileofs, cBspModel_t::headnode, dBspModel_t::headnode, i, MapTile::idx, LittleLong, MAX_MAP_MODELS, Mem_PoolAllocTypeN, MapTile::models, MapTile::nummodels, AABB::setFromLittleFloat(), AABB::shift(), cBspModel_t::shift, shift, cBspModel_t::tile, and VectorCopy.

Referenced by CM_LoadBsp().

◆ CMod_LoadSurfaces()

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_t::name, MapTile::numtexinfo, Q_strncpyz(), cBspSurface_t::surfaceFlags, dBspTexinfo_t::surfaceFlags, MapTile::surfaces, and dBspTexinfo_t::texture.

Referenced by CM_LoadBsp().

◆ CMod_RerouteMap()

◆ CMod_ValidateLump()

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

Variable Documentation

◆ nullSurface

cBspSurface_t nullSurface
static
Note
this is a zeroed surface structure

Definition at line 33 of file bsp.cpp.

Referenced by CM_InitBoxHull().