UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
map.cpp File Reference
#include "map.h"
#include "bsp.h"
#include "textures.h"
#include "check/check.h"
#include "check/checkentities.h"
#include "common/aselib.h"
#include "../../shared/parse.h"

Go to the source code of this file.

Macros

#define PLANE_HASHES   1024
 

Functions

static int GetPlaneHashValueForDistance (const vec_t distance)
 Planes are stored by their distance (resp. the calculated hash) in the plane hash table. More...
 
static int PlaneTypeForNormal (const vec3_t normal)
 Set the type of the plane according to it's normal vector. More...
 
static bool PlaneEqual (const plane_t *p, const vec3_t normal, const vec_t dist)
 Checks whether the given normal and distance vectors match the given plane by some epsilon value. More...
 
static void AddPlaneToHash (plane_t *p)
 
static uint16_t CreateNewFloatPlane (vec3_t normal, vec_t dist)
 
static bool SnapVector (vec3_t normal)
 Round the vector to int values. More...
 
static void SnapPlane (vec3_t normal, vec_t *dist)
 Snaps normal to axis-aligned if it is within an epsilon of axial. More...
 
uint16_t FindOrCreateFloatPlane (vec3_t normal, vec_t dist)
 
static int16_t PlaneFromPoints (const mapbrush_t *b, const vec3_t p0, const vec3_t p1, const vec3_t p2)
 Builds a plane normal and distance from three points on the plane. If the normal is nearly axial, it will be snapped to be axial. Looks up the plane in the unique planes. More...
 
static int BrushContents (mapbrush_t *b)
 Get the content flags for a given brush. More...
 
byte GetLevelFlagsFromBrush (const mapbrush_t *brush)
 Extract the level flags (1-8) from the content flags of the given brush. More...
 
static void AddBrushBevels (mapbrush_t *b)
 Adds any additional planes necessary to allow the brush to be expanded against axial bounding boxes. More...
 
static bool MakeBrushWindings (mapbrush_t *brush)
 makes basewindings for sides and mins / maxs for the brush More...
 
static void CheckFlags (side_t *side, const mapbrush_t *b)
 Checks whether the surface and content flags are correct. More...
 
static void GenerateMaterialFile (const char *filename, int mipTexIndex, side_t *s)
 Generates material files in case the settings can be guessed from map file. More...
 
static void GenerateFootstepList (const char *filename, int mipTexIndex)
 Generate a list of textures that should have footsteps when walking on them. More...
 
static void ParseBrush (entity_t *mapent, const char *filename)
 Parses a brush from the map file. More...
 
static void MoveBrushesToWorld (entity_t *mapent)
 Takes all of the brushes from the current entity and adds them to the world's brush list. More...
 
static void AdjustBrushesForOrigin (const entity_t *ent)
 If there was an origin brush, offset all of the planes and texinfo. More...
 
static bool IsInlineModelEntity (const char *entName)
 Checks whether this entity is an inline model that should have brushes. More...
 
entity_tFindTargetEntity (const char *target)
 Searches the entities array for an entity with the parameter targetname that matches the searched target parameter. More...
 
static bool ParseMapEntity (const char *filename, const char *entityString)
 Parsed map entites and brushes. More...
 
static void WriteMapEntities (qFILE *f, const epair_t *e)
 Recurse down the epair list. More...
 
static void WriteMapBrush (const mapbrush_t *brush, const int j, qFILE *f)
 write a brush to the .map file More...
 
void WriteMapFile (const char *filename)
 
static void ParseUMP (const char *name, char *entityString, bool inherit)
 Parses an ump file that contains the random map definition. More...
 
static const char * GetUMPName (const char *mapFilename)
 The contract is that the directory name is equal to the base of the ump filename. More...
 
void LoadMapFile (const char *filename)
 

Variables

mapbrush_t mapbrushes [MAX_MAP_BRUSHES]
 
int nummapbrushes
 
side_t brushsides [MAX_MAP_SIDES]
 
int nummapbrushsides
 
brush_texture_t side_brushtextures [MAX_MAP_SIDES]
 
plane_t mapplanes [MAX_MAP_PLANES]
 
int nummapplanes
 
static plane_tplanehash [PLANE_HASHES]
 
static int c_boxbevels = 0
 
static int c_edgebevels = 0
 
static int materialsCnt = 0
 How many materials were created for this map. More...
 
static int footstepsCnt = 0
 Amount of footstep surfaces found in this map. More...
 

Macro Definition Documentation

#define PLANE_HASHES   1024

Definition at line 46 of file map.cpp.

Referenced by FindOrCreateFloatPlane(), and GetPlaneHashValueForDistance().

Function Documentation

static void AddPlaneToHash ( plane_t p)
inlinestatic

Definition at line 112 of file map.cpp.

References plane_s::dist, GetPlaneHashValueForDistance(), hash, and plane_s::hash_chain.

Referenced by CreateNewFloatPlane().

static void AdjustBrushesForOrigin ( const entity_t ent)
static
static int BrushContents ( mapbrush_t b)
static

Get the content flags for a given brush.

Parameters
bThe mapbrush to get the content flags for
Returns
The calculated content flags

Definition at line 254 of file map.cpp.

References mapbrush_s::brushnum, side_s::contentFlags, mapbrush_s::entitynum, i, mapbrush_s::numsides, mapbrush_s::original_sides, VERB_EXTRA, and Verb_Printf().

Referenced by ParseBrush().

static void CheckFlags ( side_t side,
const mapbrush_t b 
)
inlinestatic

Checks whether the surface and content flags are correct.

See also
ParseBrush
SetImpliedFlags

Definition at line 484 of file map.cpp.

References mapbrush_s::brushnum, side_s::contentFlags, CONTENTS_ACTORCLIP, CONTENTS_LIGHTCLIP, CONTENTS_PASSABLE, CONTENTS_SOLID, CONTENTS_WEAPONCLIP, mapbrush_s::entitynum, and Sys_Error().

Referenced by ParseBrush().

static uint16_t CreateNewFloatPlane ( vec3_t  normal,
vec_t  dist 
)
static
entity_t* FindTargetEntity ( const char *  target)

Searches the entities array for an entity with the parameter targetname that matches the searched target parameter.

Parameters
[in]targetThe targetname value that the entity should have that we are looking for

Definition at line 911 of file map.cpp.

References entities, i, num_entities, Q_streq, and ValueForKey().

Referenced by BuildLights().

static void GenerateFootstepList ( const char *  filename,
int  mipTexIndex 
)
static

Generate a list of textures that should have footsteps when walking on them.

Parameters
[in]filenameAdd this texture to the list of textures where we should have footstep sounds for
[in]mipTexIndexThe index in the textures array
See also
SV_GetFootstepSound
Com_GetTerrainType

Definition at line 568 of file map.cpp.

References Com_Printf(), Com_StripExtension(), config, f, FILE_APPEND, textureref_t::footstepMarked, footstepsCnt, FS_OpenFile(), FS_Printf(), MAX_OSPATH, name, textureref, and va().

Referenced by ParseBrush().

static void GenerateMaterialFile ( const char *  filename,
int  mipTexIndex,
side_t s 
)
static

Generates material files in case the settings can be guessed from map file.

Definition at line 498 of file map.cpp.

References Com_Printf(), Com_SkipPath(), Com_sprintf(), Com_StripExtension(), config, side_s::contentFlags, CONTENTS_TERRAIN, CONTENTS_WATER, f, FILE_APPEND, FS_OpenFile(), FS_Printf(), textureref_t::materialMarked, materialsCnt, MAX_OSPATH, name, and textureref.

Referenced by ParseBrush().

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.

static int GetPlaneHashValueForDistance ( const vec_t  distance)
inlinestatic

Planes are stored by their distance (resp. the calculated hash) in the plane hash table.

Definition at line 62 of file map.cpp.

References hash, int(), and PLANE_HASHES.

Referenced by AddPlaneToHash(), and FindOrCreateFloatPlane().

static const char* GetUMPName ( const char *  mapFilename)
static

The contract is that the directory name is equal to the base of the ump filename.

Definition at line 1174 of file map.cpp.

References Com_Printf(), Com_SkipPath(), MAX_QPATH, name, and Q_strncpyz().

Referenced by LoadMapFile().

static bool IsInlineModelEntity ( const char *  entName)
inlinestatic

Checks whether this entity is an inline model that should have brushes.

Parameters
[in]entName
Returns
true if the name of the entity implies, that this is an inline model

Definition at line 895 of file map.cpp.

References Q_streq, and Q_strstart().

Referenced by ParseMapEntity().

static void MoveBrushesToWorld ( entity_t mapent)
static

Takes all of the brushes from the current entity and adds them to the world's brush list.

Note
Used by func_group
This will only work if the func_group is the last entity currently known. At the moment, this function is only called by ParseMapEntity and this happens directly after the func_group is parsed, so this is OK.
See also
MoveModelToWorld

Definition at line 831 of file map.cpp.

References entities, entity_t::firstbrush, i, Mem_AllocTypeN, Mem_Free, num_entities, entity_t::numbrushes, nummapbrushes, and Sys_Error().

Referenced by ParseMapEntity().

static void ParseBrush ( entity_t mapent,
const char *  filename 
)
static

Parses a brush from the map file.

See also
FindMiptex
Parameters
[in]mapentThe entity the brush to parse belongs to
[in]filenameThe map filename, used to derive the name for the footsteps file

Definition at line 603 of file map.cpp.

References AddBrushBevels(), side_s::brush, BrushContents(), mapbrush_s::brushnum, CheckFlags(), CheckPropagateParserContentFlags(), Com_Printf(), Com_sprintf(), config, side_s::contentFlags, mapbrush_s::contentFlags, CONTENTS_ACTORCLIP, CONTENTS_DETAIL, CONTENTS_LIGHTCLIP, CONTENTS_ORIGIN, CONTENTS_SOLID, CONTENTS_TERRAIN, CONTENTS_TRANSLUCENT, CONTENTS_WATER, CONTENTS_WEAPONCLIP, CONTENTS_WINDOW, entities, mapbrush_s::entitynum, FindMiptex(), entity_t::firstbrush, GenerateFootstepList(), GenerateMaterialFile(), AABB::getCenter(), GetToken(), i, LAST_VISIBLE_CONTENTS, m, MakeBrushWindings(), MAX_MAP_BRUSHES, MAX_MAP_BRUSHSIDES, MAX_TEXPATH, AABB::maxs, mapbrush_s::mbBox, AABB::mins, brush_texture_s::name, num_entities, entity_t::numbrushes, nummapbrushes, nummapbrushsides, mapbrush_s::numsides, OBJZERO, entity_t::origin, mapbrush_s::original_sides, parsedToken, PlaneFromPoints(), side_s::planenum, PLANENUM_LEAF, Q_strncpyz(), Q_strnull(), brush_texture_s::rotate, brush_texture_s::scale, SetImpliedFlags(), SetKeyValue(), brush_texture_s::shift, SURF_ALPHATEST, SURF_BLEND33, SURF_BLEND66, SURF_FOOTSTEP, SURF_HINT, SURF_SKIP, brush_texture_s::surfaceFlags, side_s::surfaceFlags, Sys_Error(), side_s::texinfo, TexinfoForBrushTexture(), TokenAvailable(), brush_texture_s::value, vec3_origin, VectorCopy, VERB_DUMP, VERB_EXTRA, and Verb_Printf().

Referenced by ParseMapEntity().

static bool ParseMapEntity ( const char *  filename,
const char *  entityString 
)
static
static void ParseUMP ( const char *  name,
char *  entityString,
bool  inherit 
)
static

Parses an ump file that contains the random map definition.

Parameters
[in]nameThe basename of the ump file (without extension)
[in]inheritWhen true, this is called to inherit tile definitions
[out]entityStringAn entity string that is used for all map tiles. Parsed from the ump. from another ump file (no assemblies)

Definition at line 1117 of file map.cpp.

References Com_GetBlock(), Com_Parse(), Com_Printf(), Com_sprintf(), FS_FreeFile(), FS_LoadFile(), length, MAX_QPATH, MAX_TOKEN_CHARS, Q_streq, and Q_strncpyz().

Referenced by LoadMapFile().

static bool PlaneEqual ( const plane_t p,
const vec3_t  normal,
const vec_t  dist 
)
inlinestatic

Checks whether the given normal and distance vectors match the given plane by some epsilon value.

Parameters
pThe plane to compare the normal and distance with
normal
dist
Returns
true if the normal and the distance vector are the same (by some epsilon) as in the given plane

Definition at line 102 of file map.cpp.

References plane_s::dist, MAP_DIST_EPSILON, plane_s::normal, and NORMAL_EPSILON.

Referenced by AddBrushBevels(), and FindOrCreateFloatPlane().

static int16_t PlaneFromPoints ( const mapbrush_t b,
const vec3_t  p0,
const vec3_t  p1,
const vec3_t  p2 
)
static

Builds a plane normal and distance from three points on the plane. If the normal is nearly axial, it will be snapped to be axial. Looks up the plane in the unique planes.

Parameters
[in]bThe brush that the points belong to.
[in]p0Three points on the plane. (A vector with plane coordinates)
[in]p1Three points on the plane. (A vector with plane coordinates)
[in]p2Three points on the plane. (A vector with plane coordinates)
Returns
the index of the plane in the planes list.

Definition at line 227 of file map.cpp.

References mapbrush_s::brushnum, CrossProduct(), DotProduct, FindOrCreateFloatPlane(), light_s::normal, Sys_Error(), VectorNormalize(), VectorNotEmpty, and VectorSubtract.

Referenced by ParseBrush().

static int PlaneTypeForNormal ( const vec3_t  normal)
static

Set the type of the plane according to it's normal vector.

Definition at line 72 of file map.cpp.

References PLANE_ANYX, PLANE_ANYY, PLANE_ANYZ, PLANE_X, PLANE_Y, and PLANE_Z.

Referenced by CreateNewFloatPlane().

static void SnapPlane ( vec3_t  normal,
vec_t dist 
)
inlinestatic

Snaps normal to axis-aligned if it is within an epsilon of axial.

Parameters
[in,out]normal- Plane normal vector (assumed to be unit length)
[in,out]dist- Plane constant - return as rounded to integer if it is within an epsilon of MAP_DIST_EPSILON

Definition at line 186 of file map.cpp.

References MAP_DIST_EPSILON, Q_rint(), and SnapVector().

Referenced by FindOrCreateFloatPlane().

static bool SnapVector ( vec3_t  normal)
inlinestatic

Round the vector to int values.

Parameters
[in,out]normalthe normal vector to snap
Note
Can be used to save net bandwidth

Definition at line 163 of file map.cpp.

References i, NORMAL_EPSILON, and VectorClear.

Referenced by AddBrushBevels(), and SnapPlane().

static void WriteMapBrush ( const mapbrush_t brush,
const int  j,
qFILE f 
)
static

write a brush to the .map file

Parameters
[in]brushThe brush to write
[in]jthe index of the brush in the entity, to label the brush in the comment in the map file
[in]ffile to write to

Definition at line 1032 of file map.cpp.

References brushsides, side_s::contentFlags, FS_Printf(), i, index, brush_texture_s::name, mapbrush_s::numsides, mapbrush_s::original_sides, side_s::planenum, plane_s::planeVector, brush_texture_s::rotate, brush_texture_s::scale, brush_texture_s::shift, brush_texture_s::surfaceFlags, and brush_texture_s::value.

Referenced by WriteMapFile().

static void WriteMapEntities ( qFILE f,
const epair_t e 
)
inlinestatic

Recurse down the epair list.

Note
First writes the last element

Definition at line 1013 of file map.cpp.

References FS_Printf(), epair_s::key, epair_s::next, epair_s::ump, and epair_s::value.

Referenced by WriteMapFile().

Variable Documentation

int c_boxbevels = 0
static

Definition at line 49 of file map.cpp.

Referenced by AddBrushBevels(), and LoadMapFile().

int c_edgebevels = 0
static

Definition at line 50 of file map.cpp.

Referenced by AddBrushBevels(), and LoadMapFile().

int footstepsCnt = 0
static

Amount of footstep surfaces found in this map.

Definition at line 558 of file map.cpp.

Referenced by GenerateFootstepList(), and LoadMapFile().

int materialsCnt = 0
static

How many materials were created for this map.

Definition at line 493 of file map.cpp.

Referenced by GenerateMaterialFile(), and LoadMapFile().

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

plane_t* planehash[PLANE_HASHES]
static

Definition at line 47 of file map.cpp.