doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MapFile.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __MAPFILE_H__
30 #define __MAPFILE_H__
31 
32 /*
33 ===============================================================================
34 
35  Reads or writes the contents of .map files into a standard internal
36  format, which can then be moved into private formats for collision
37  detection, map processing, or editor use.
38 
39  No validation (duplicate planes, null area brushes, etc) is performed.
40  There are no limits to the number of any of the elements in maps.
41  The order of entities, brushes, and sides is maintained.
42 
43 ===============================================================================
44 */
45 
46 const int OLD_MAP_VERSION = 1;
47 const int CURRENT_MAP_VERSION = 2;
49 const float DEFAULT_CURVE_MAX_ERROR = 4.0f;
50 const float DEFAULT_CURVE_MAX_ERROR_CD = 24.0f;
51 const float DEFAULT_CURVE_MAX_LENGTH = -1.0f;
52 const float DEFAULT_CURVE_MAX_LENGTH_CD = -1.0f;
53 
54 
56 public:
58 
60 
62  virtual ~idMapPrimitive( void ) { }
63  int GetType( void ) const { return type; }
64 
65 protected:
66  int type;
67 };
68 
69 
71  friend class idMapBrush;
72 
73 public:
74  idMapBrushSide( void );
75  ~idMapBrushSide( void ) { }
76  const char * GetMaterial( void ) const { return material; }
77  void SetMaterial( const char *p ) { material = p; }
78  const idPlane & GetPlane( void ) const { return plane; }
79  void SetPlane( const idPlane &p ) { plane = p; }
80  void SetTextureMatrix( const idVec3 mat[2] ) { texMat[0] = mat[0]; texMat[1] = mat[1]; }
81  void GetTextureMatrix( idVec3 &mat1, idVec3 &mat2 ) { mat1 = texMat[0]; mat2 = texMat[1]; }
82  void GetTextureVectors( idVec4 v[2] ) const;
83 
84 protected:
89 };
90 
91 ID_INLINE idMapBrushSide::idMapBrushSide( void ) {
92  plane.Zero();
93  texMat[0].Zero();
94  texMat[1].Zero();
95  origin.Zero();
96 }
97 
98 
99 class idMapBrush : public idMapPrimitive {
100 public:
101  idMapBrush( void ) { type = TYPE_BRUSH; sides.Resize( 8, 4 ); }
102  ~idMapBrush( void ) { sides.DeleteContents( true ); }
103  static idMapBrush * Parse( idLexer &src, const idVec3 &origin, bool newFormat = true, float version = CURRENT_MAP_VERSION );
104  static idMapBrush * ParseQ3( idLexer &src, const idVec3 &origin );
105  bool Write( idFile *fp, int primitiveNum, const idVec3 &origin ) const;
106  int GetNumSides( void ) const { return sides.Num(); }
107  int AddSide( idMapBrushSide *side ) { return sides.Append( side ); }
108  idMapBrushSide * GetSide( int i ) const { return sides[i]; }
109  unsigned int GetGeometryCRC( void ) const;
110 
111 protected:
112  int numSides;
114 };
115 
116 
117 class idMapPatch : public idMapPrimitive, public idSurface_Patch {
118 public:
119  idMapPatch( void );
120  idMapPatch( int maxPatchWidth, int maxPatchHeight );
121  ~idMapPatch( void ) { }
122  static idMapPatch * Parse( idLexer &src, const idVec3 &origin, bool patchDef3 = true, float version = CURRENT_MAP_VERSION );
123  bool Write( idFile *fp, int primitiveNum, const idVec3 &origin ) const;
124  const char * GetMaterial( void ) const { return material; }
125  void SetMaterial( const char *p ) { material = p; }
126  int GetHorzSubdivisions( void ) const { return horzSubdivisions; }
127  int GetVertSubdivisions( void ) const { return vertSubdivisions; }
128  bool GetExplicitlySubdivided( void ) const { return explicitSubdivisions; }
132  unsigned int GetGeometryCRC( void ) const;
133 
134 protected:
139 };
140 
141 ID_INLINE idMapPatch::idMapPatch( void ) {
142  type = TYPE_PATCH;
144  explicitSubdivisions = false;
145  width = height = 0;
146  maxWidth = maxHeight = 0;
147  expanded = false;
148 }
149 
150 ID_INLINE idMapPatch::idMapPatch( int maxPatchWidth, int maxPatchHeight ) {
151  type = TYPE_PATCH;
153  explicitSubdivisions = false;
154  width = height = 0;
155  maxWidth = maxPatchWidth;
156  maxHeight = maxPatchHeight;
158  expanded = false;
159 }
160 
161 
162 class idMapEntity {
163  friend class idMapFile;
164 
165 public:
167 
168 public:
169  idMapEntity( void ) { epairs.SetHashSize( 64 ); }
171  static idMapEntity * Parse( idLexer &src, bool worldSpawn = false, float version = CURRENT_MAP_VERSION );
172  bool Write( idFile *fp, int entityNum ) const;
173  int GetNumPrimitives( void ) const { return primitives.Num(); }
174  idMapPrimitive * GetPrimitive( int i ) const { return primitives[i]; }
176  unsigned int GetGeometryCRC( void ) const;
177  void RemovePrimitiveData();
178 
179 protected:
181 };
182 
183 
184 class idMapFile {
185 public:
186  idMapFile( void );
187  ~idMapFile( void ) { entities.DeleteContents( true ); }
188 
189  // filename does not require an extension
190  // normally this will use a .reg file instead of a .map file if it exists,
191  // which is what the game and dmap want, but the editor will want to always
192  // load a .map file
193  bool Parse( const char *filename, bool ignoreRegion = false, bool osPath = false );
194  bool Write( const char *fileName, const char *ext, bool fromBasePath = true );
195  // get the number of entities in the map
196  int GetNumEntities( void ) const { return entities.Num(); }
197  // get the specified entity
198  idMapEntity * GetEntity( int i ) const { return entities[i]; }
199  // get the name without file extension
200  const char * GetName( void ) const { return name; }
201  // get the file time
202  ID_TIME_T GetFileTime( void ) const { return fileTime; }
203  // get CRC for the map geometry
204  // texture coordinates and entity key/value pairs are not taken into account
205  unsigned int GetGeometryCRC( void ) const { return geometryCRC; }
206  // returns true if the file on disk changed
207  bool NeedsReload();
208 
209  int AddEntity( idMapEntity *mapentity );
210  idMapEntity * FindEntity( const char *name );
211  void RemoveEntity( idMapEntity *mapEnt );
212  void RemoveEntities( const char *classname );
213  void RemoveAllEntities();
214  void RemovePrimitiveData();
216 
217 protected:
218  float version;
219  ID_TIME_T fileTime;
220  unsigned int geometryCRC;
224 
225 private:
226  void SetGeometryCRC( void );
227 };
228 
229 ID_INLINE idMapFile::idMapFile( void ) {
231  fileTime = 0;
232  geometryCRC = 0;
233  entities.Resize( 1024, 256 );
234  hasPrimitiveData = false;
235 }
236 
237 #endif /* !__MAPFILE_H__ */
int GetNumSides(void) const
Definition: MapFile.h:106
const idPlane & GetPlane(void) const
Definition: MapFile.h:78
int GetType(void) const
Definition: MapFile.h:63
~idMapBrush(void)
Definition: MapFile.h:102
const float DEFAULT_CURVE_MAX_ERROR_CD
Definition: MapFile.h:50
idList< idMapEntity * > entities
Definition: MapFile.h:221
~idMapFile(void)
Definition: MapFile.h:187
idMapEntity * GetEntity(int i) const
Definition: MapFile.h:198
idMapBrush(void)
Definition: MapFile.h:101
idList< idDrawVert > verts
Definition: Surface.h:96
unsigned int GetGeometryCRC(void) const
Definition: MapFile.h:205
void AddPrimitive(idMapPrimitive *p)
Definition: MapFile.h:175
idMapBrushSide * GetSide(int i) const
Definition: MapFile.h:108
int GetVertSubdivisions(void) const
Definition: MapFile.h:127
idMapEntity * FindEntity(const char *name)
Definition: MapFile.cpp:895
const GLdouble * v
Definition: glext.h:2936
int AddSide(idMapBrushSide *side)
Definition: MapFile.h:107
void SetNum(int newnum, bool resize=true)
Definition: List.h:289
idVec3 origin
Definition: MapFile.h:88
unsigned int GetGeometryCRC(void) const
Definition: MapFile.cpp:253
void SetExplicitlySubdivided(bool b)
Definition: MapFile.h:131
static idMapBrush * Parse(idLexer &src, const idVec3 &origin, bool newFormat=true, float version=CURRENT_MAP_VERSION)
Definition: MapFile.cpp:276
unsigned int GetGeometryCRC(void) const
Definition: MapFile.cpp:516
GLenum GLsizei n
Definition: glext.h:3705
bool Write(idFile *fp, int primitiveNum, const idVec3 &origin) const
Definition: MapFile.cpp:221
int GetHorzSubdivisions(void) const
Definition: MapFile.h:126
Definition: Vector.h:316
float version
Definition: MapFile.h:218
bool Write(idFile *fp, int primitiveNum, const idVec3 &origin) const
Definition: MapFile.cpp:485
const char * GetMaterial(void) const
Definition: MapFile.h:124
static idMapBrush * ParseQ3(idLexer &src, const idVec3 &origin)
Definition: MapFile.cpp:409
idMapBrushSide(void)
Definition: MapFile.h:91
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
ID_TIME_T fileTime
Definition: MapFile.h:219
void RemoveAllEntities()
Definition: MapFile.cpp:936
idPlane plane
Definition: MapFile.h:86
GLuint src
Definition: glext.h:5390
idList< idMapPrimitive * > primitives
Definition: MapFile.h:180
~idMapEntity(void)
Definition: MapFile.h:170
int i
Definition: process.py:33
const int CURRENT_MAP_VERSION
Definition: MapFile.h:47
idVec3 texMat[2]
Definition: MapFile.h:87
int numSides
Definition: MapFile.h:112
int vertSubdivisions
Definition: MapFile.h:137
int horzSubdivisions
Definition: MapFile.h:136
idDict epairs
Definition: MapFile.h:166
struct version_s version
Definition: File.h:50
void RemovePrimitiveData()
Definition: MapFile.cpp:946
Definition: Lexer.h:137
void SetPlane(const idPlane &p)
Definition: MapFile.h:79
const float DEFAULT_CURVE_MAX_ERROR
Definition: MapFile.h:49
void RemoveEntities(const char *classname)
Definition: MapFile.cpp:920
void SetMaterial(const char *p)
Definition: MapFile.h:77
unsigned int GetGeometryCRC(void) const
Definition: MapFile.cpp:693
Definition: Vector.h:808
static idMapEntity * Parse(idLexer &src, bool worldSpawn=false, float version=CURRENT_MAP_VERSION)
Definition: MapFile.cpp:538
int GetNumEntities(void) const
Definition: MapFile.h:196
const float DEFAULT_CURVE_MAX_LENGTH_CD
Definition: MapFile.h:52
bool Parse(const char *filename, bool ignoreRegion=false, bool osPath=false)
Definition: MapFile.cpp:720
Definition: Dict.h:65
idMapPrimitive(void)
Definition: MapFile.h:61
ID_TIME_T GetFileTime(void) const
Definition: MapFile.h:202
bool Write(const char *fileName, const char *ext, bool fromBasePath=true)
Definition: MapFile.cpp:833
void GetTextureMatrix(idVec3 &mat1, idVec3 &mat2)
Definition: MapFile.h:81
const int DEFAULT_CURVE_SUBDIVISION
Definition: MapFile.h:48
~idMapPatch(void)
Definition: MapFile.h:121
idDict epairs
Definition: MapFile.h:59
Definition: Plane.h:71
~idMapBrushSide(void)
Definition: MapFile.h:75
bool GetExplicitlySubdivided(void) const
Definition: MapFile.h:128
void SetVertSubdivisions(int n)
Definition: MapFile.h:130
void DeleteContents(bool clear)
Definition: List.h:207
void SetMaterial(const char *p)
Definition: MapFile.h:125
GLenum GLsizei width
Definition: glext.h:2846
void GetTextureVectors(idVec4 v[2]) const
Definition: MapFile.cpp:93
void SetHashSize(int hashSize)
Definition: Dict.h:182
GLenum GLsizei GLsizei height
Definition: glext.h:2856
unsigned int geometryCRC
Definition: MapFile.h:220
idStr material
Definition: MapFile.h:85
void RemoveEntity(idMapEntity *mapEnt)
Definition: MapFile.cpp:910
bool NeedsReload()
Definition: MapFile.cpp:959
idStr name
Definition: MapFile.h:222
GLubyte GLubyte b
Definition: glext.h:4662
bool hasPrimitiveData
Definition: MapFile.h:223
idList< idMapBrushSide * > sides
Definition: MapFile.h:113
int Append(const type &obj)
Definition: List.h:646
bool explicitSubdivisions
Definition: MapFile.h:138
idMapPrimitive * GetPrimitive(int i) const
Definition: MapFile.h:174
int Num(void) const
Definition: List.h:265
const float DEFAULT_CURVE_MAX_LENGTH
Definition: MapFile.h:51
const GLcharARB * name
Definition: glext.h:3629
idMapEntity(void)
Definition: MapFile.h:169
Definition: Str.h:116
void SetTextureMatrix(const idVec3 mat[2])
Definition: MapFile.h:80
const char * GetMaterial(void) const
Definition: MapFile.h:76
bool Write(idFile *fp, int entityNum) const
Definition: MapFile.cpp:646
void SetHorzSubdivisions(int n)
Definition: MapFile.h:129
void Zero(void)
Definition: Plane.h:229
virtual ~idMapPrimitive(void)
Definition: MapFile.h:62
void RemovePrimitiveData()
Definition: MapFile.cpp:684
idMapPatch(void)
Definition: MapFile.h:141
bool HasPrimitiveData()
Definition: MapFile.h:215
int AddEntity(idMapEntity *mapentity)
Definition: MapFile.cpp:885
void SetGeometryCRC(void)
Definition: MapFile.cpp:871
static idMapPatch * Parse(idLexer &src, const idVec3 &origin, bool patchDef3=true, float version=CURRENT_MAP_VERSION)
Definition: MapFile.cpp:111
GLfloat GLfloat p
Definition: glext.h:4674
int GetNumPrimitives(void) const
Definition: MapFile.h:173
void Zero(void)
Definition: Vector.h:415
const char * GetName(void) const
Definition: MapFile.h:200
const int OLD_MAP_VERSION
Definition: MapFile.h:46
void Resize(int newsize)
Definition: List.h:360
idStr material
Definition: MapFile.h:135
idMapFile(void)
Definition: MapFile.h:229