map.c File Reference

#include "map.h"
#include "bsp.h"
#include "check/check.h"
#include "check/checkentities.h"
#include "common/aselib.h"
Include dependency graph for map.c:

Go to the source code of this file.

Defines

#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.
static int PlaneTypeForNormal (const vec3_t normal)
 Set the type of the plane according to it's normal vector.
static qboolean 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.
static void AddPlaneToHash (plane_t *p)
static int CreateNewFloatPlane (vec3_t normal, vec_t dist)
static qboolean SnapVector (vec3_t normal)
 Round the vector to int values.
static void SnapPlane (vec3_t normal, vec_t *dist)
 Snaps normal to axis-aligned if it is within an epsilon of axial.
int FindOrCreateFloatPlane (vec3_t normal, vec_t dist)
static int 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.
static int BrushContents (mapbrush_t *b)
 Get the content flags for a given brush.
byte GetLevelFlagsFromBrush (const mapbrush_t *brush)
 Extract the level flags (1-8) from the content flags of the given brush.
static void AddBrushBevels (mapbrush_t *b)
 Adds any additional planes necessary to allow the brush to be expanded against axial bounding boxes.
static qboolean MakeBrushWindings (mapbrush_t *brush)
 makes basewindings for sides and mins / maxs for the brush
static void CheckFlags (side_t *side, const mapbrush_t *b)
 Checks whether the surface and content flags are correct.
static void GenerateMaterialFile (const char *filename, int mipTexIndex, side_t *s)
 Generates material files in case the settings can be guessed from map file.
static void GenerateFootstepList (const char *filename, int mipTexIndex)
 Generate a list of textures that should have footsteps when walking on them.
static void ParseBrush (entity_t *mapent, const char *filename)
 Parses a brush from the map file.
static void MoveBrushesToWorld (entity_t *mapent)
 Takes all of the brushes from the current entity and adds them to the world's brush list.
static void AdjustBrushesForOrigin (const entity_t *ent)
 If there was an origin brush, offset all of the planes and texinfo.
static qboolean IsInlineModelEntity (const char *entName)
 Checks whether this entity is an inline model that should have brushes.
entity_tFindTargetEntity (const char *target)
 Searches the entities array for an entity with the parameter targetname that matches the searched target parameter.
static qboolean ParseMapEntity (const char *filename)
 Parsed map entites and brushes.
static void WriteMapEntities (qFILE *f, const epair_t *e)
 Recurse down the epair list.
static void WriteMapBrush (const mapbrush_t *brush, const int j, qFILE *f)
 write a brush to the .map file
void WriteMapFile (const char *filename)
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 vec3_t map_mins
static vec3_t map_maxs
static int c_boxbevels = 0
static int c_edgebevels = 0
static int materialsCnt = 0
 How many materials were created for this map.
static int footstepsCnt = 0
 Amount of footstep surfaces found in this map.

Detailed Description

Definition in file map.c.


Define Documentation

#define PLANE_HASHES   1024

Definition at line 44 of file map.c.

Referenced by FindOrCreateFloatPlane(), and GetPlaneHashValueForDistance().


Function Documentation

static void AddBrushBevels ( mapbrush_t b  )  [static]
static void AddPlaneToHash ( plane_t p  )  [inline, static]

Definition at line 111 of file map.c.

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:
b The mapbrush to get the content flags for
Returns:
The calculated content flags

Definition at line 253 of file map.c.

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 
) [inline, static]

Checks whether the surface and content flags are correct.

See also:
ParseBrush
SetImpliedFlags

Definition at line 485 of file map.c.

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 int CreateNewFloatPlane ( vec3_t  normal,
vec_t  dist 
) [inline, static]
int FindOrCreateFloatPlane ( vec3_t  normal,
vec_t  dist 
)
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] target The targetname value that the entity should have that we are looking for

Definition at line 927 of file map.c.

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

Referenced by BuildLights().

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

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

Parameters:
[in] filename Add this texture to the list of textures where we should have footstep sounds for
[in] mipTexIndex The index in the textures array
See also:
SV_GetFootstepSound
Com_GetTerrainType

Definition at line 571 of file map.c.

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

Referenced by ParseBrush().

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

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

Definition at line 499 of file map.c.

References Com_Printf(), Com_SkipPath(), Com_sprintf(), Com_StripExtension(), config, side_s::contentFlags, CONTENTS_TERRAIN, CONTENTS_WATER, qFILE_s::f, f, FILE_APPEND, FS_CloseFile(), FS_OpenFile(), FS_Printf(), textureref_t::materialMarked, materialsCnt, MAX_OSPATH, name, qfalse, qtrue, 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:
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.

static int GetPlaneHashValueForDistance ( const vec_t  distance  )  [inline, static]

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

Definition at line 61 of file map.c.

References hash(), int(), and PLANE_HASHES.

Referenced by AddPlaneToHash(), and FindOrCreateFloatPlane().

static qboolean IsInlineModelEntity ( const char *  entName  )  [inline, static]

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 913 of file map.c.

Referenced by ParseMapEntity().

void LoadMapFile ( const char *  filename  ) 
static qboolean MakeBrushWindings ( mapbrush_t brush  )  [static]
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 847 of file map.c.

References entities, entity_t::firstbrush, i, Mem_Alloc, 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] mapent The entity the brush to parse belongs to
[in] filename The map filename, used to derive the name for the footsteps file

Definition at line 608 of file map.c.

References AddBrushBevels(), side_s::brush, BrushContents(), mapbrush_s::brushnum, CheckFlags(), CheckPropagateParserContentFlags(), Com_Printf(), Com_sprintf(), config, mapbrush_s::contentFlags, side_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(), GetScriptLine(), GetToken(), i, LAST_VISIBLE_CONTENTS, m, MakeBrushWindings(), MAX_MAP_BRUSHES, MAX_MAP_BRUSHSIDES, MAX_TEXPATH, mapbrush_s::maxs, mapbrush_s::mins, brush_texture_s::name, num_entities, entity_t::numbrushes, nummapbrushes, nummapbrushsides, mapbrush_s::numsides, entity_t::origin, mapbrush_s::original_sides, parsedToken, PlaneFromPoints(), side_s::planenum, PLANENUM_LEAF, Q_strncpyz(), qfalse, qtrue, 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(), td, side_s::texinfo, TexinfoForBrushTexture(), TokenAvailable(), brush_texture_s::value, vec3_origin, VectorCenterFromMinsMaxs(), VectorCopy, VERB_DUMP, VERB_EXTRA, and Verb_Printf().

Referenced by ParseMapEntity().

static qboolean ParseMapEntity ( const char *  filename  )  [static]
static qboolean PlaneEqual ( const plane_t p,
const vec3_t  normal,
const vec_t  dist 
) [inline, static]

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

Parameters:
p The 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 101 of file map.c.

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

Referenced by AddBrushBevels(), and FindOrCreateFloatPlane().

static int 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] b The brush that the points belong to.
[in] p0 Three points on the plane. (A vector with plane coordinates)
[in] p1 Three points on the plane. (A vector with plane coordinates)
[in] p2 Three points on the plane. (A vector with plane coordinates)
Returns:
the index of the plane in the planes list.

Definition at line 226 of file map.c.

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  )  [inline, static]

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

Definition at line 71 of file map.c.

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 
) [inline, static]

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 187 of file map.c.

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

Referenced by FindOrCreateFloatPlane().

static qboolean SnapVector ( vec3_t  normal  )  [inline, static]

Round the vector to int values.

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

Definition at line 162 of file map.c.

References i, NORMAL_EPSILON, qfalse, qtrue, 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] brush The brush to write
[in] j the index of the brush in the entity, to label the brush in the comment in the map file
[in] f file to write to

Definition at line 1030 of file map.c.

References side_s::contentFlags, FS_Printf(), 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 
) [inline, static]

Recurse down the epair list.

Note:
First writes the last element

Definition at line 1012 of file map.c.

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

Referenced by WriteMapFile().

void WriteMapFile ( const char *  filename  ) 

Variable Documentation

side_t brushsides[MAX_MAP_SIDES]
int c_boxbevels = 0 [static]

Definition at line 48 of file map.c.

Referenced by AddBrushBevels(), and LoadMapFile().

int c_edgebevels = 0 [static]

Definition at line 49 of file map.c.

Referenced by AddBrushBevels(), and LoadMapFile().

int footstepsCnt = 0 [static]

Amount of footstep surfaces found in this map.

Definition at line 561 of file map.c.

Referenced by GenerateFootstepList(), and LoadMapFile().

vec3_t map_maxs [static]

Definition at line 47 of file map.c.

Referenced by LoadMapFile().

vec3_t map_mins [static]

Definition at line 47 of file map.c.

Referenced by LoadMapFile().

mapbrush_t mapbrushes[MAX_MAP_BRUSHES]
plane_t mapplanes[MAX_MAP_PLANES]
int materialsCnt = 0 [static]

How many materials were created for this map.

Definition at line 494 of file map.c.

Referenced by GenerateMaterialFile(), and LoadMapFile().

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

plane_t* planehash[PLANE_HASHES] [static]

Definition at line 45 of file map.c.


Generated by  doxygen 1.6.2