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

World query functions. More...

#include "../shared/moveclip.h"
#include "server.h"
#include "../common/qfiles.h"

Go to the source code of this file.

Data Structures

struct  areaParms_t
 
class  MoveClipSV
 Server side moveclip - see cmodel.c. More...
 

Macros

#define AREA_DEPTH   4
 

Functions

static worldSector_tSV_CreateWorldSector (int depth, const AABB &sBox)
 Builds a uniformly subdivided tree for the given world size. More...
 
void SV_ClearWorld (void)
 Clear physics interaction links. More...
 
static sv_edict_tSV_GetServerDataForEdict (const edict_t *ent)
 
void SV_UnlinkEdict (edict_t *ent)
 call before removing an entity, and before trying to move one, so it doesn't clip against itself More...
 
void SV_LinkEdict (edict_t *ent)
 Needs to be called any time an entity changes origin, mins, maxs, or solid. Automatically unlinks if needed. Sets ent->absmin and ent->absBox.maxs. More...
 
static bool SV_BoundingBoxesIntersect (const AABB &aabb, const edict_t *ent)
 Checks whether the bounding box of the given edict will intersect with the given bbox. More...
 
static void SV_AreaEdicts_r (worldSector_t *node, areaParms_t *ap)
 fills in a table of edict pointers with edicts that have bounding boxes that intersect the given area. It is possible for a non-axial bmodel to be returned that doesn't actually intersect the area on an exact test. More...
 
static int SV_AreaEdicts (const AABB &abox, edict_t **list, int maxCount)
 
static int SV_HullForEntity (const edict_t *ent, int *tile, vec3_t rmaShift)
 Returns a headnode that can be used for testing or clipping an object of mins/maxs size. Offset is filled in to contain the adjustment that must be added to the testing object's origin to get a point to use with the returned hull. More...
 
static void SV_ClipMoveToEntities (MoveClipSV *clip)
 
int SV_PointContents (const vec3_t p)
 Returns the content flags for a given point. More...
 
trace_t SV_Trace (const Line &traceLine, const AABB &box, const edict_t *passedict, int contentmask)
 Moves the given mins/maxs volume through the world from start to end. More...
 
const char * SV_GetFootstepSound (const char *texture)
 Query the footstep sound for the given surface texture. More...
 
float SV_GetBounceFraction (const char *texture)
 Different terrain types might have different bounce fraction. More...
 
static void SV_ModLoadAliasMD2Model (sv_model_t *mod, const byte *buffer)
 Loads the mins/maxs for a md2 mesh model. More...
 
static void SV_ModLoadAliasMD3Model (sv_model_t *mod, const byte *buffer)
 Loads the mins/maxs for a md3 mesh model. More...
 
static void SV_ModLoadObjModel (sv_model_t *mod, const byte *buffer, int bufferLength)
 Loads the mins/maxs for a obj mesh model. More...
 
bool SV_LoadModelAABB (const char *model, int frame, AABB &aabb)
 Load the bounding box for the model on the serverside for pathfinding and clipping. More...
 

Variables

static char const *const mod_extensions []
 all supported model formats More...
 

Detailed Description

World query functions.

Definition in file sv_world.cpp.

Macro Definition Documentation

#define AREA_DEPTH   4

Definition at line 33 of file sv_world.cpp.

Referenced by SV_CreateWorldSector().

Function Documentation

static int SV_AreaEdicts ( const AABB abox,
edict_t **  list,
int  maxCount 
)
static
See also
SV_AreaEdicts_r
Parameters
[in]aboxThe bounding box
[out]listThe edict list that this trace is hitting
[in]maxCountThe size of the given list
Returns
the number of pointers filled in

Definition at line 256 of file sv_world.cpp.

References areaParms_t::areaBox, areaParms_t::areaEdictList, areaParms_t::areaEdictListCount, areaParms_t::areaEdictListMaxCount, AABB::set(), sv, SV_AreaEdicts_r(), and serverInstanceGame_s::worldSectors.

Referenced by SV_ClipMoveToEntities().

static void SV_AreaEdicts_r ( worldSector_t node,
areaParms_t ap 
)
static

fills in a table of edict pointers with edicts that have bounding boxes that intersect the given area. It is possible for a non-axial bmodel to be returned that doesn't actually intersect the area on an exact test.

See also
SV_AreaEdicts

Definition at line 213 of file sv_world.cpp.

References areaParms_t::areaBox, areaParms_t::areaEdictList, areaParms_t::areaEdictListCount, areaParms_t::areaEdictListMaxCount, worldSector_s::axis, worldSector_s::children, Com_Printf(), worldSector_s::dist, sv_edict_s::ent, worldSector_s::entities, SrvEdict::inuse, LEAFNODE, AABB::maxs, AABB::mins, sv_edict_s::nextEntityInWorldSector, SrvEdict::solid, SOLID_NOT, and SV_BoundingBoxesIntersect().

Referenced by SV_AreaEdicts().

static bool SV_BoundingBoxesIntersect ( const AABB aabb,
const edict_t ent 
)
static

Checks whether the bounding box of the given edict will intersect with the given bbox.

Parameters
[in]aabbthe bounding box
[in]entThe edict to check the intersection for
Returns
true if intersect, false otherwise

Definition at line 196 of file sv_world.cpp.

References SrvEdict::absBox, and AABB::doesIntersect().

Referenced by SV_AreaEdicts_r().

void SV_ClearWorld ( void  )

Clear physics interaction links.

Note
Called after the world model has been loaded, before linking any entities
See also
SV_SpawnServer
SV_CreateAreaNode

Definition at line 81 of file sv_world.cpp.

References mapData_s::mapBox, serverInstanceGame_s::mapData, sv, and SV_CreateWorldSector().

Referenced by SV_Map(), and TEST_F().

static worldSector_t* SV_CreateWorldSector ( int  depth,
const AABB sBox 
)
static
float SV_GetBounceFraction ( const char *  texture)

Different terrain types might have different bounce fraction.

See also
Com_GetTerrainType
GenerateFootstepList

Definition at line 462 of file sv_world.cpp.

References terrainType_s::bounceFraction, and Com_GetTerrainType().

Referenced by SV_InitGameProgs().

const char* SV_GetFootstepSound ( const char *  texture)

Query the footstep sound for the given surface texture.

See also
Com_GetTerrainType
GenerateFootstepList
Returns
either nullptr or the footstep sound filename if there is one assigned in the scripts

Definition at line 451 of file sv_world.cpp.

References Com_GetTerrainType(), and terrainType_s::footstepSound.

Referenced by SV_InitGameProgs(), and TEST_F().

static sv_edict_t* SV_GetServerDataForEdict ( const edict_t ent)
inlinestatic

Definition at line 86 of file sv_world.cpp.

References Com_Error(), serverInstanceGame_s::edicts, ERR_DROP, lengthof, SrvEdict::number, and sv.

Referenced by SV_LinkEdict(), and SV_UnlinkEdict().

static int SV_HullForEntity ( const edict_t ent,
int tile,
vec3_t  rmaShift 
)
static

Returns a headnode that can be used for testing or clipping an object of mins/maxs size. Offset is filled in to contain the adjustment that must be added to the testing object's origin to get a point to use with the returned hull.

Parameters
[in]entThe edict to get the bmodel from (at least in case of SOLID_BSP)
[out]tileThe maptile the bmodel belongs, too (at least in case of SOLID_BSP)
[out]rmaShiftthe shift vector in case of an RMA (needed for doors)
Returns
The headnode for the edict
See also
CL_HullForEntity

Definition at line 290 of file sv_world.cpp.

References CM_HeadnodeForBox(), Com_Error(), SrvEdict::entBox, ERR_FATAL, cBspModel_s::headnode, mapTiles_s::mapTiles, serverInstanceGame_s::mapTiles, MAX_MAP_NODES, MAX_MODELS, SrvEdict::modelindex, serverInstanceGame_s::models, cBspModel_s::shift, SrvEdict::solid, SOLID_BSP, SOLID_NOT, SOLID_TRIGGER, sv, cBspModel_s::tile, vec3_origin, and VectorCopy.

Referenced by SV_ClipMoveToEntities().

bool SV_LoadModelAABB ( const char *  model,
int  frame,
AABB aabb 
)

Load the bounding box for the model on the serverside for pathfinding and clipping.

Parameters
[in]modelThe relative model path to load the bounding box for
[in]frameThe frame to load the bounding box for
[out]aabbThe bounding box of the model - this is absolute to the worldorigin (0,0,0)

Definition at line 543 of file sv_world.cpp.

References sv_model_s::aabb, Com_Error(), com_genericPool, Com_GetExtension(), Com_sprintf(), ERR_DROP, sv_model_s::frame, FS_FreeFile(), FS_LoadFile(), i, IDALIASHEADER, IDMD3HEADER, LittleLong, MAX_MOD_KNOWN, MAX_QPATH, Mem_PoolStrDup, mod_extensions, sv_model_s::name, serverInstanceGame_s::numSVModels, OBJZERO, Q_strcasecmp, Q_streq, AABB::reset(), AABB::set(), AABB::setNegativeVolume(), sv, SV_ModLoadAliasMD2Model(), SV_ModLoadAliasMD3Model(), SV_ModLoadObjModel(), and serverInstanceGame_s::svModels.

Referenced by SV_InitGameProgs().

static void SV_ModLoadAliasMD2Model ( sv_model_t mod,
const byte buffer 
)
static

Loads the mins/maxs for a md2 mesh model.

Parameters
[in,out]modThe server side model struct to store the results in
[in]bufferThe mesh model buffer

Definition at line 473 of file sv_world.cpp.

References sv_model_s::aabb, AABB::add(), sv_model_s::frame, dMD2Model_t::framesize, LittleFloat, LittleLong, dMD2Model_t::num_frames, dMD2Model_t::ofs_frames, dAliasFrame_s::scale, scale, dAliasFrame_s::translate, and VectorMA().

Referenced by SV_LoadModelAABB().

static void SV_ModLoadAliasMD3Model ( sv_model_t mod,
const byte buffer 
)
static

Loads the mins/maxs for a md3 mesh model.

Parameters
[in,out]modThe server side model struct to store the results in
[in]bufferThe mesh model buffer

Definition at line 499 of file sv_world.cpp.

References sv_model_s::aabb, AABB::add(), sv_model_s::frame, LittleFloat, LittleLong, dmd3frame_t::maxs, dmd3frame_t::mins, dmd3_t::num_frames, and dmd3_t::ofs_frames.

Referenced by SV_LoadModelAABB().

static void SV_ModLoadObjModel ( sv_model_t mod,
const byte buffer,
int  bufferLength 
)
static

Loads the mins/maxs for a obj mesh model.

Parameters
[in,out]modThe server side model struct to store the results in
[in]bufferThe mesh model buffer
[in]bufferLengthThe mesh model buffer length
Todo:
implement me

Definition at line 524 of file sv_world.cpp.

Referenced by SV_LoadModelAABB().

int SV_PointContents ( const vec3_t  p)

Returns the content flags for a given point.

Note
Useful to determine whether an actor is e.g. inside of a water brush
See also
CM_TestInLeaf
CM_TestBoxInBrush
CM_CompleteBoxTrace

Definition at line 395 of file sv_world.cpp.

References CM_CompleteBoxTrace(), trace_s::contentFlags, AABB::EMPTY, trace_s::fraction, serverInstanceGame_s::mapTiles, MASK_ALL, sv, and TRACE_ALL_LEVELS.

Referenced by SV_InitGameProgs().

trace_t SV_Trace ( const Line traceLine,
const AABB box,
const edict_t passedict,
int  contentmask 
)

Moves the given mins/maxs volume through the world from start to end.

Note
Passedict and edicts owned by passedict are explicitly not checked.
See also
SV_TraceBounds
CL_Trace
Parameters
[in]traceLineThe from/to position in the world for this trace
[in]boxThe bounding box that is moved through the world
[in]passedictis explicitly excluded from clipping checks (normally nullptr) if the entire move stays in a solid volume, trace.allsolid will be set, trace.startsolid will be set, and trace.fraction will be 0 if the starting point is in a solid, it will be allowed to move out to an open area
[in]contentmaskbrushes the trace should stop at (see MASK_*)
Todo:
There is more than one world in case of a map assembly - use clip.trace.mapTile to get the correct one

Definition at line 417 of file sv_world.cpp.

References MoveClip::calcBounds(), CM_CompleteBoxTrace(), MoveClip::contentmask, trace_s::entNum, trace_s::fraction, serverInstanceGame_s::mapTiles, MoveClip::moveLine, MoveClip::objBox, OBJZERO, MoveClipSV::passedict, Line::set(), AABB::set(), sv, SV_ClipMoveToEntities(), MoveClipSV::trace, and TRACE_ALL_LEVELS.

Referenced by SV_InitGameProgs(), and TEST_F().

void SV_UnlinkEdict ( edict_t ent)

call before removing an entity, and before trying to move one, so it doesn't clip against itself

Definition at line 97 of file sv_world.cpp.

References Com_Printf(), worldSector_s::entities, sv_edict_s::linked, sv_edict_s::nextEntityInWorldSector, SV_GetServerDataForEdict(), and sv_edict_s::worldSector.

Referenced by SV_InitGameProgs(), and SV_LinkEdict().

Variable Documentation

char const* const mod_extensions[]
static
Initial value:
= {
"md2", "md3", "obj", nullptr
}

all supported model formats

See also
modtype_t

Definition at line 533 of file sv_world.cpp.

Referenced by SV_LoadModelAABB().