home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / idlib / MapFile.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  9KB  |  268 lines

  1.  
  2. #ifndef __MAPFILE_H__
  3. #define __MAPFILE_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.     Reads or writes the contents of .map files into a standard internal
  9.     format, which can then be moved into private formats for collision
  10.     detection, map processing, or editor use.
  11.  
  12.     No validation (duplicate planes, null area brushes, etc) is performed.
  13.     There are no limits to the number of any of the elements in maps.
  14.     The order of entities, brushes, and sides is maintained.
  15.  
  16. ===============================================================================
  17. */
  18.  
  19. const int OLD_MAP_VERSION                    = 1;
  20. const int CURRENT_MAP_VERSION                = 3;
  21. const int DEFAULT_CURVE_SUBDIVISION            = 4;
  22. const float DEFAULT_CURVE_MAX_ERROR            = 4.0f;
  23. const float DEFAULT_CURVE_MAX_ERROR_CD        = 24.0f;
  24. const float DEFAULT_CURVE_MAX_LENGTH        = -1.0f;
  25. const float DEFAULT_CURVE_MAX_LENGTH_CD        = -1.0f;
  26.  
  27.  
  28. class idMapPrimitive {
  29. public:
  30.     enum { TYPE_INVALID = -1, TYPE_BRUSH, TYPE_PATCH };
  31.  
  32.     idDict                    epairs;
  33.  
  34.                             idMapPrimitive( void ) { type = TYPE_INVALID; }
  35.     virtual                    ~idMapPrimitive( void ) { }
  36.     int                        GetType( void ) const { return type; }
  37.  
  38. // RAVEN BEGIN
  39. // rjohnson: added resolve for handling func_groups and other aspects.  Before, radiant would do this processing on a map destroying the original data
  40.     virtual void            AdjustOrigin( idVec3 &delta ) { }
  41. // RAVEN END
  42.  
  43. protected:
  44.     int                        type;
  45. };
  46.  
  47.  
  48. class idMapBrushSide {
  49.     friend class idMapBrush;
  50.  
  51. public:
  52.                             idMapBrushSide( void );
  53.                             ~idMapBrushSide( void ) { }
  54.     const char *            GetMaterial( void ) const { return material; }
  55.     void                    SetMaterial( const char *p ) { material = p; }
  56.     const idPlane &            GetPlane( void ) const { return plane; }
  57.     void                    SetPlane( const idPlane &p ) { plane = p; }
  58.     void                    SetTextureMatrix( const idVec3 mat[2] ) { texMat[0] = mat[0]; texMat[1] = mat[1]; }
  59.     void                    GetTextureMatrix( idVec3 &mat1, idVec3 &mat2 ) { mat1 = texMat[0]; mat2 = texMat[1]; }
  60.     void                    GetTextureVectors( idVec4 v[2] ) const;
  61.  
  62. protected:
  63.     idStr                    material;
  64.     idPlane                    plane;
  65.     idVec3                    texMat[2];
  66.     idVec3                    origin;
  67. };
  68.  
  69. ID_INLINE idMapBrushSide::idMapBrushSide( void ) {
  70.     plane.Zero();
  71.     texMat[0].Zero();
  72.     texMat[1].Zero();
  73.     origin.Zero();
  74. }
  75.  
  76.  
  77. class idMapBrush : public idMapPrimitive {
  78. public:
  79.                             idMapBrush( void ) { type = TYPE_BRUSH; sides.Resize( 8, 4 ); }
  80.                             ~idMapBrush( void ) { sides.DeleteContents( true ); }
  81. // RAVEN BEGIN
  82. // jsinger: changed to be Lexer instead of idLexer so that we have the ability to read binary files
  83.     static idMapBrush *        Parse( Lexer &src, const idVec3 &origin, bool newFormat = true, int version = CURRENT_MAP_VERSION );
  84.     static idMapBrush *        ParseQ3( Lexer &src, const idVec3 &origin );
  85. // RAVEN END
  86.     bool                    Write( idFile *fp, int primitiveNum, const idVec3 &origin ) const;
  87.     int                        GetNumSides( void ) const { return sides.Num(); }
  88.     int                        AddSide( idMapBrushSide *side ) { return sides.Append( side ); }
  89.     idMapBrushSide *        GetSide( int i ) const { return sides[i]; }
  90.     unsigned int            GetGeometryCRC( void ) const;
  91.  
  92. // RAVEN BEGIN
  93. // rjohnson: added resolve for handling func_groups and other aspects.  Before, radiant would do this processing on a map destroying the original data
  94.     virtual void            AdjustOrigin( idVec3 &delta );
  95. // RAVEN END
  96.  
  97. protected:
  98.     idList<idMapBrushSide*> sides;
  99. };
  100.  
  101.  
  102. class idMapPatch : public idMapPrimitive, public idSurface_Patch {
  103. public:
  104.                             idMapPatch( void );
  105.                             idMapPatch( int maxPatchWidth, int maxPatchHeight );
  106.                             ~idMapPatch( void ) { }
  107. // RAVEN BEGIN
  108. // jsinger: changed to be Lexer instead of idLexer so that we have the ability to read binary files
  109.     static idMapPatch *        Parse( Lexer &src, const idVec3 &origin, bool patchDef3 = true, int version = CURRENT_MAP_VERSION );
  110. // RAVEN END
  111.     bool                    Write( idFile *fp, int primitiveNum, const idVec3 &origin ) const;
  112.     const char *            GetMaterial( void ) const { return material; }
  113.     void                    SetMaterial( const char *p ) { material = p; }
  114.     int                        GetHorzSubdivisions( void ) const { return horzSubdivisions; }
  115.     int                        GetVertSubdivisions( void ) const { return vertSubdivisions; }
  116.     bool                    GetExplicitlySubdivided( void ) const { return explicitSubdivisions; }
  117.     void                    SetHorzSubdivisions( int n ) { horzSubdivisions = n; }
  118.     void                    SetVertSubdivisions( int n ) { vertSubdivisions = n; }
  119.     void                    SetExplicitlySubdivided( bool b ) { explicitSubdivisions = b; }
  120.     unsigned int            GetGeometryCRC( void ) const;
  121.  
  122. // RAVEN BEGIN
  123. // rjohnson: added resolve for handling func_groups and other aspects.  Before, radiant would do this processing on a map destroying the original data
  124.     virtual void            AdjustOrigin( idVec3 &delta );
  125. // RAVEN END
  126.  
  127. protected:
  128.     idStr                    material;
  129.     int                        horzSubdivisions;
  130.     int                        vertSubdivisions;
  131.     bool                    explicitSubdivisions;
  132. };
  133.  
  134. ID_INLINE idMapPatch::idMapPatch( void ) {
  135.     type = TYPE_PATCH;
  136.     horzSubdivisions = vertSubdivisions = 0;
  137.     explicitSubdivisions = false;
  138.     width = height = 0;
  139.     maxWidth = maxHeight = 0;
  140.     expanded = false;
  141. }
  142.  
  143. ID_INLINE idMapPatch::idMapPatch( int maxPatchWidth, int maxPatchHeight ) {
  144.     type = TYPE_PATCH;
  145.     horzSubdivisions = vertSubdivisions = 0;
  146.     explicitSubdivisions = false;
  147.     width = height = 0;
  148.     maxWidth = maxPatchWidth;
  149.     maxHeight = maxPatchHeight;
  150.     verts.SetNum( maxWidth * maxHeight );
  151.     expanded = false;
  152. }
  153.  
  154.  
  155. class idMapEntity {
  156.     friend class            idMapFile;
  157.  
  158. public:
  159.     idDict                    epairs;
  160.  
  161. public:
  162.                             idMapEntity( void ) { epairs.SetHashSize( 64 ); }
  163.                             ~idMapEntity( void ) { primitives.DeleteContents( true ); }
  164. // RAVEN BEGIN
  165. // jsinger: changed to be Lexer instead of idLexer so that we have the ability to read binary files
  166.     static idMapEntity *    Parse( Lexer &src, bool worldSpawn = false, int version = CURRENT_MAP_VERSION );
  167. // RAVEN END
  168.     bool                    Write( idFile *fp, int entityNum ) const;
  169.     int                        GetNumPrimitives( void ) const { return primitives.Num(); }
  170.     idMapPrimitive *        GetPrimitive( int i ) const { return primitives[i]; }
  171.     void                    AddPrimitive( idMapPrimitive *p ) { primitives.Append( p ); }
  172.     unsigned int            GetGeometryCRC( void ) const;
  173.     void                    RemovePrimitiveData();
  174.  
  175. protected:
  176.     idList<idMapPrimitive*>    primitives;
  177. };
  178.  
  179.  
  180. class idMapFile {
  181. public:
  182.                             idMapFile( void );
  183. // RAVEN BEGIN
  184. // rhummer: moved body to mapfile.cpp to help debug some odd issues with func_groups
  185.                             ~idMapFile( void ); /*{ entities.DeleteContents( true ); }*/
  186. // RAVEN END
  187.  
  188.                             // filename does not require an extension
  189.                             // normally this will use a .reg file instead of a .map file if it exists,
  190.                             // which is what the game and dmap want, but the editor will want to always
  191.                             // load a .map file
  192.     bool                    Parse( const char *filename, bool ignoreRegion = false, bool osPath = false );
  193.  
  194. // RAVEN BEGIN
  195. // rjohnson: added resolve
  196.     void                    Resolve( void );
  197. // rhummer: added boolean to dictate if the Resolve function has been run on this map.
  198.     bool                    HasBeenResloved() { return mHasBeenResolved; }
  199. // rjohnson: added export
  200.     bool                    Write( const char *fileName, const char *ext, bool fromBasePath = true, bool exportOnly = false );
  201. // RAVEN END
  202.  
  203.                             // get the number of entities in the map
  204.     int                        GetNumEntities( void ) const { return entities.Num(); }
  205.                             // get the specified entity
  206.     idMapEntity *            GetEntity( int i ) const { return entities[i]; }
  207.                             // get the name without file extension
  208.     const char *            GetName( void ) const { return name; }
  209.                             // get the file time
  210.     unsigned int            GetFileTime( void ) const { return fileTime; }
  211.                             // get CRC for the map geometry
  212.                             // texture coordinates and entity key/value pairs are not taken into account
  213.     unsigned int            GetGeometryCRC( void ) const { return geometryCRC; }
  214.                             // returns true if the file on disk changed
  215.     bool                    NeedsReload();
  216.  
  217.     int                        AddEntity( idMapEntity *mapentity );
  218.     idMapEntity *            FindEntity( const char *name );
  219.     void                    RemoveEntity( idMapEntity *mapEnt );
  220.     void                    RemoveEntities( const char *classname );
  221.     void                    RemoveAllEntities();
  222.     void                    RemovePrimitiveData();
  223.     bool                    HasPrimitiveData() { return hasPrimitiveData; }
  224.  
  225. // RAVEN BEGIN
  226. // rjohnson: added export
  227.     bool                    WriteExport( const char *fileName, bool fromBasePath = true );
  228.     bool                    ParseExport( const char *filename, bool osPath = false );
  229.  
  230.     bool                    HasExportEntities(void) { return mHasExportEntities; }
  231. // RAVEN END
  232.  
  233. protected:
  234.     int                        version;
  235.     unsigned int            fileTime;
  236.     unsigned int            geometryCRC;
  237.     idList<idMapEntity *>    entities;
  238.     idStr                    name;
  239.     bool                    hasPrimitiveData;
  240.  
  241. // RAVEN BEGIN
  242. // rjohnson: added export
  243.     idList<idMapEntity *>    mExportEntities;
  244.     bool                    mHasExportEntities;
  245. // rhummer: Added to inform if func_groups some how disappeared between the loading and saving of the map file.
  246.     bool                    mHasFuncGroups;
  247. // rhummer: Added to notify that this map has been resloved, so func_groups have been removed.
  248.     bool                    mHasBeenResolved;
  249. // RAVEN END
  250.  
  251. private:
  252.     void                    SetGeometryCRC( void );
  253. };
  254.  
  255. ID_INLINE idMapFile::idMapFile( void ) {
  256.     version = CURRENT_MAP_VERSION;
  257.     fileTime = 0;
  258.     geometryCRC = 0;
  259.     entities.Resize( 1024, 256 );
  260.     hasPrimitiveData = false;
  261. // RAVEN BEGIN
  262. // rhummer: Used to make sure func_groups don't disappear.
  263.     mHasFuncGroups = false;
  264. // RAVEN END
  265. }
  266.  
  267. #endif /* !__MAPFILE_H__ */
  268.