#include "map.h"
#include "bsp.h"
#include "check/check.h"
#include "check/checkentities.h"
#include "common/aselib.h"
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_t * | FindTargetEntity (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_t * | planehash [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. |
Definition in file map.c.
#define PLANE_HASHES 1024 |
Definition at line 44 of file map.c.
Referenced by FindOrCreateFloatPlane(), and GetPlaneHashValueForDistance().
static void AddBrushBevels | ( | mapbrush_t * | b | ) | [static] |
Adds any additional planes necessary to allow the brush to be expanded against axial bounding boxes.
Definition at line 288 of file map.c.
References side_s::bevel, c_boxbevels, c_edgebevels, side_s::contentFlags, CrossProduct(), DotProduct, f, FindOrCreateFloatPlane(), i, MAX_MAP_BRUSHSIDES, mapbrush_s::maxs, mapbrush_s::mins, plane_s::normal, light_s::normal, nummapbrushsides, winding_s::numpoints, mapbrush_s::numsides, mapbrush_s::original_sides, winding_s::p, PlaneEqual(), side_s::planenum, qtrue, SnapVector(), Sys_Error(), side_s::texinfo, VectorClear, VectorNormalize(), VectorSubtract, and side_s::winding.
Referenced by ParseBrush().
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] |
If there was an origin brush, offset all of the planes and texinfo.
Definition at line 885 of file map.c.
References side_s::brush, side_s::contentFlags, CONTENTS_TERRAIN, plane_s::dist, DotProduct, FindOrCreateFloatPlane(), entity_t::firstbrush, i, MakeBrushWindings(), plane_s::normal, entity_t::numbrushes, mapbrush_s::numsides, entity_t::origin, mapbrush_s::original_sides, side_s::planenum, SURF_ORIGIN, brush_texture_s::surfaceFlags, side_s::surfaceFlags, side_s::texinfo, and TexinfoForBrushTexture().
Referenced by ParseMapEntity().
static int BrushContents | ( | mapbrush_t * | b | ) | [static] |
Get the content flags for a given brush.
b | The mapbrush to get the content flags for |
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.
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().
Definition at line 118 of file map.c.
References AddPlaneToHash(), AXIAL, plane_s::dist, MAX_MAP_PLANES, plane_s::normal, nummapplanes, PlaneTypeForNormal(), Sys_Error(), type, plane_s::type, vec3_origin, VectorCopy, VectorLength(), and VectorSubtract.
Referenced by FindOrCreateFloatPlane().
Definition at line 195 of file map.c.
References CreateNewFloatPlane(), GetPlaneHashValueForDistance(), hash(), plane_s::hash_chain, i, PLANE_HASHES, PlaneEqual(), and SnapPlane().
Referenced by AddBrushBevels(), AdjustBrushesForOrigin(), BrushFromBounds(), EmitBrushes(), MakeBspBrushList(), and PlaneFromPoints().
entity_t* FindTargetEntity | ( | const char * | target | ) |
Searches the entities array for an entity with the parameter targetname that matches the searched target parameter.
[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.
[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 |
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.
brush | The brush to extract the level flags from |
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.
[in] | entName |
Definition at line 913 of file map.c.
Referenced by ParseMapEntity().
void LoadMapFile | ( | const char * | filename | ) |
Definition at line 1117 of file map.c.
References AddPointToBounds(), c_boxbevels, c_edgebevels, ClearBounds(), Com_Printf(), config, curTile, entities, footstepsCnt, i, LoadScriptFile(), map_maxs, map_mins, mapTiles_t::mapTiles, mapTiles, materialsCnt, MAX_MAP_BRUSHES, MAX_MAP_PLANES, MAX_MAP_SIDES, MAX_WORLD_WIDTH, num_entities, entity_t::numbrushes, nummapbrushes, nummapbrushsides, nummapplanes, mapTiles_t::numTiles, ParseMapEntity(), ValueForKey(), VERB_EXTRA, and Verb_Printf().
Referenced by main().
static qboolean MakeBrushWindings | ( | mapbrush_t * | brush | ) | [static] |
makes basewindings for sides and mins / maxs for the brush
Definition at line 435 of file map.c.
References AddPointToBounds(), BaseWindingForPlane(), side_s::bevel, mapbrush_s::brushnum, ChopWindingInPlace(), ClearBounds(), Com_Printf(), plane_s::dist, mapbrush_s::entitynum, i, MAX_WORLD_WIDTH, mapbrush_s::maxs, mapbrush_s::mins, plane_s::normal, winding_s::numpoints, mapbrush_s::numsides, mapbrush_s::original_sides, winding_s::p, side_s::planenum, qtrue, VectorClear, side_s::visible, and side_s::winding.
Referenced by AdjustBrushesForOrigin(), and ParseBrush().
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.
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.
[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] |
Parsed map entites and brushes.
[in] | filename | The map filename |
Definition at line 945 of file map.c.
References AdjustBrushesForOrigin(), Com_Printf(), config, entities, entity_t::epairs, entity_t::firstbrush, GetToken(), GetVectorForKey(), IsInlineModelEntity(), MAX_MAP_ENTITIES, MoveBrushesToWorld(), epair_s::next, num_entities, entity_t::numbrushes, nummapbrushes, entity_t::origin, ParseBrush(), parsedToken, ParseEpair(), qfalse, qtrue, Sys_Error(), ValueForKey(), and VectorNotEmpty.
Referenced by LoadMapFile().
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.
p | The plane to compare the normal and distance with | |
normal | ||
dist |
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.
[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) |
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().
Snaps normal to axis-aligned if it is within an epsilon of axial.
[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().
Round the vector to int values.
[in,out] | normal | the normal vector to snap |
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
[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().
Recurse down the epair list.
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 | ) |
Definition at line 1055 of file map.c.
References Check_ExtraBrushesForWorldspawn(), entities, entity_t::epairs, qFILE_s::f, f, FILE_WRITE, entity_t::firstbrush, FS_CloseFile(), FS_OpenFile(), FS_Printf(), i, Mem_Free, num_entities, entity_t::numbrushes, entity_t::skip, mapbrush_s::skipWriteBack, Sys_Error(), VERB_NORMAL, Verb_Printf(), WriteMapBrush(), and WriteMapEntities().
Referenced by main().
side_t brushsides[MAX_MAP_SIDES] |
Definition at line 35 of file map.c.
Referenced by Check_SetNodraw(), Check_SurfProp(), Check_SurfProps(), CheckFlagsBasedOnTextures(), CheckMixedFaceContents(), and CheckTexturesBasedOnFlags().
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().
Definition at line 47 of file map.c.
Referenced by LoadMapFile().
Definition at line 47 of file map.c.
Referenced by LoadMapFile().
mapbrush_t mapbrushes[MAX_MAP_BRUSHES] |
Definition at line 32 of file map.c.
Referenced by BeginModel(), Check_BrushIntersection(), Check_ContainedBrushes(), Check_ExtraBrushesForWorldspawn(), Check_FindCompositeSides(), Check_Free(), Check_MapSize(), Check_NearList(), CheckBrushes(), CheckFillLevelFlags(), CheckFlagsBasedOnTextures(), CheckLevelFlags(), CheckMapMicro(), CheckMixedFaceContents(), CheckNodraws(), CheckTexturesBasedOnFlags(), CheckZFighting(), EmitBrushes(), EmitLeaf(), MakeBspBrushList(), MapBrushesBounds(), MarkVisibleSides(), and ProcessLevel().
an index of the planes containing the faces of the brushes
Definition at line 41 of file map.c.
Referenced by BaseWindingForNode(), BrushVolume(), Check_IsPointInsideBrush(), Check_MapBrushVolume(), Check_SidePointsDown(), Check_WindingIntersects(), CreateBrushWindings(), EmitPlanes(), FaceFromPortal(), FacingAndCoincidentTo(), FindPortalSide(), MakeNodePortal(), MergeNodeFaces(), ParallelAndCoincidentTo(), SelectSplitSide(), SplitBrush(), SplitNodePortals(), TestBrushToPlanenum(), and WriteBSPBrushMap().
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().
int nummapbrushes |
Definition at line 33 of file map.c.
Referenced by Check_BrushIntersection(), Check_ContainedBrushes(), Check_FindCompositeSides(), Check_Free(), Check_MapSize(), Check_NearList(), Check_Stats(), CheckBrushes(), CheckFillLevelFlags(), CheckFlagsBasedOnTextures(), CheckLevelFlags(), CheckMapMicro(), CheckMixedFaceContents(), CheckNodraws(), CheckTexturesBasedOnFlags(), CheckZFighting(), EmitBrushes(), LoadMapFile(), MoveBrushesToWorld(), ParseBrush(), ParseMapEntity(), and ProcessLevel().
int nummapbrushsides |
Definition at line 36 of file map.c.
Referenced by AddBrushBevels(), Check_Stats(), LoadMapFile(), and ParseBrush().
int nummapplanes |
Definition at line 42 of file map.c.
Referenced by Check_Stats(), CreateNewFloatPlane(), EmitPlanes(), and LoadMapFile().
brush_texture_t side_brushtextures[MAX_MAP_SIDES] |
Definition at line 38 of file map.c.
Referenced by Check_SetNodraw(), Check_SurfProp(), Check_SurfProps(), CheckFlagsBasedOnTextures(), CheckMixedFaceContents(), and CheckTexturesBasedOnFlags().