SaveGame.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition 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 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. 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.
  18. ===========================================================================
  19. */
  20. #ifndef __SAVEGAME_H__
  21. #define __SAVEGAME_H__
  22. /*
  23. Save game related helper classes.
  24. */
  25. class idSaveGame {
  26. public:
  27. idSaveGame( idFile *savefile, idFile *stringFile, int inVersion );
  28. ~idSaveGame();
  29. void Close();
  30. void WriteDecls();
  31. void AddObject( const idClass *obj );
  32. void Resize( const int count ) { objects.Resize( count ); }
  33. void WriteObjectList();
  34. void Write( const void *buffer, int len );
  35. void WriteInt( const int value );
  36. void WriteJoint( const jointHandle_t value );
  37. void WriteShort( const short value );
  38. void WriteByte( const byte value );
  39. void WriteSignedChar( const signed char value );
  40. void WriteFloat( const float value );
  41. void WriteBool( const bool value );
  42. void WriteString( const char *string );
  43. void WriteVec2( const idVec2 &vec );
  44. void WriteVec3( const idVec3 &vec );
  45. void WriteVec4( const idVec4 &vec );
  46. void WriteVec6( const idVec6 &vec );
  47. void WriteWinding( const idWinding &winding );
  48. void WriteBounds( const idBounds &bounds );
  49. void WriteMat3( const idMat3 &mat );
  50. void WriteAngles( const idAngles &angles );
  51. void WriteObject( const idClass *obj );
  52. void WriteStaticObject( const idClass &obj );
  53. void WriteDict( const idDict *dict );
  54. void WriteMaterial( const idMaterial *material );
  55. void WriteSkin( const idDeclSkin *skin );
  56. void WriteParticle( const idDeclParticle *particle );
  57. void WriteFX( const idDeclFX *fx );
  58. void WriteSoundShader( const idSoundShader *shader );
  59. void WriteModelDef( const class idDeclModelDef *modelDef );
  60. void WriteModel( const idRenderModel *model );
  61. void WriteUserInterface( const idUserInterface *ui, bool unique );
  62. void WriteRenderEntity( const renderEntity_t &renderEntity );
  63. void WriteRenderLight( const renderLight_t &renderLight );
  64. void WriteRefSound( const refSound_t &refSound );
  65. void WriteRenderView( const renderView_t &view );
  66. void WriteUsercmd( const usercmd_t &usercmd );
  67. void WriteContactInfo( const contactInfo_t &contactInfo );
  68. void WriteTrace( const trace_t &trace );
  69. void WriteTraceModel( const idTraceModel &trace );
  70. void WriteClipModel( const class idClipModel *clipModel );
  71. void WriteSoundCommands();
  72. void WriteBuildNumber( const int value );
  73. int GetBuildNumber() const { return version; }
  74. int GetCurrentSaveSize() const { return file->Length(); }
  75. private:
  76. idFile * file;
  77. idFile * stringFile;
  78. idCompressor * compressor;
  79. idList<const idClass *> objects;
  80. int version;
  81. void CallSave_r( const idTypeInfo *cls, const idClass *obj );
  82. struct stringTableIndex_s {
  83. idStr string;
  84. int offset;
  85. };
  86. idHashIndex stringHash;
  87. idList< stringTableIndex_s > stringTable;
  88. int curStringTableOffset;
  89. };
  90. class idRestoreGame {
  91. public:
  92. idRestoreGame( idFile * savefile, idFile * stringTableFile, int saveVersion );
  93. ~idRestoreGame();
  94. void ReadDecls();
  95. void CreateObjects();
  96. void RestoreObjects();
  97. void DeleteObjects();
  98. void Error( VERIFY_FORMAT_STRING const char *fmt, ... );
  99. void Read( void *buffer, int len );
  100. void ReadInt( int &value );
  101. void ReadJoint( jointHandle_t &value );
  102. void ReadShort( short &value );
  103. void ReadByte( byte &value );
  104. void ReadSignedChar( signed char &value );
  105. void ReadFloat( float &value );
  106. void ReadBool( bool &value );
  107. void ReadString( idStr &string );
  108. void ReadVec2( idVec2 &vec );
  109. void ReadVec3( idVec3 &vec );
  110. void ReadVec4( idVec4 &vec );
  111. void ReadVec6( idVec6 &vec );
  112. void ReadWinding( idWinding &winding );
  113. void ReadBounds( idBounds &bounds );
  114. void ReadMat3( idMat3 &mat );
  115. void ReadAngles( idAngles &angles );
  116. void ReadObject( idClass *&obj );
  117. void ReadStaticObject( idClass &obj );
  118. void ReadDict( idDict *dict );
  119. void ReadMaterial( const idMaterial *&material );
  120. void ReadSkin( const idDeclSkin *&skin );
  121. void ReadParticle( const idDeclParticle *&particle );
  122. void ReadFX( const idDeclFX *&fx );
  123. void ReadSoundShader( const idSoundShader *&shader );
  124. void ReadModelDef( const idDeclModelDef *&modelDef );
  125. void ReadModel( idRenderModel *&model );
  126. void ReadUserInterface( idUserInterface *&ui );
  127. void ReadRenderEntity( renderEntity_t &renderEntity );
  128. void ReadRenderLight( renderLight_t &renderLight );
  129. void ReadRefSound( refSound_t &refSound );
  130. void ReadRenderView( renderView_t &view );
  131. void ReadUsercmd( usercmd_t &usercmd );
  132. void ReadContactInfo( contactInfo_t &contactInfo );
  133. void ReadTrace( trace_t &trace );
  134. void ReadTraceModel( idTraceModel &trace );
  135. void ReadClipModel( idClipModel *&clipModel );
  136. void ReadSoundCommands();
  137. // Used to retrieve the saved game buildNumber from within class Restore methods
  138. int GetBuildNumber() const { return version; }
  139. private:
  140. idFile * file;
  141. idFile * stringFile;
  142. idList<idClass *, TAG_SAVEGAMES> objects;
  143. int version;
  144. int stringTableOffset;
  145. void CallRestore_r( const idTypeInfo *cls, idClass *obj );
  146. };
  147. #endif /* !__SAVEGAME_H__*/