DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

SaveGame.h (6820B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 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.
     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 __SAVEGAME_H__
     30 #define __SAVEGAME_H__
     31 
     32 /*
     33 
     34 Save game related helper classes.
     35 
     36 */
     37 
     38 class idSaveGame {
     39 public:
     40 							idSaveGame( idFile *savefile, idFile *stringFile, int inVersion );
     41 							~idSaveGame();
     42 
     43 	void					Close();
     44 
     45 	void					WriteDecls();
     46 	
     47 	void					AddObject( const idClass *obj );
     48 	void					Resize( const int count ) { objects.Resize( count ); }
     49 	void					WriteObjectList();
     50 
     51 	void					Write( const void *buffer, int len );
     52 	void					WriteInt( const int value );
     53 	void					WriteJoint( const jointHandle_t value );
     54 	void					WriteShort( const short value );
     55 	void					WriteByte( const byte value );
     56 	void					WriteSignedChar( const signed char value );
     57 	void					WriteFloat( const float value );
     58 	void					WriteBool( const bool value );
     59 	void					WriteString( const char *string );
     60 	void					WriteVec2( const idVec2 &vec );
     61 	void					WriteVec3( const idVec3 &vec );
     62 	void					WriteVec4( const idVec4 &vec );
     63 	void					WriteVec6( const idVec6 &vec );
     64 	void					WriteWinding( const idWinding &winding );
     65 	void					WriteBounds( const idBounds &bounds );
     66 	void					WriteMat3( const idMat3 &mat );
     67 	void					WriteAngles( const idAngles &angles );
     68 	void					WriteObject( const idClass *obj );
     69 	void					WriteStaticObject( const idClass &obj );
     70 	void					WriteDict( const idDict *dict );
     71 	void					WriteMaterial( const idMaterial *material );
     72 	void					WriteSkin( const idDeclSkin *skin );
     73 	void					WriteParticle( const idDeclParticle *particle );
     74 	void					WriteFX( const idDeclFX *fx );
     75 	void					WriteSoundShader( const idSoundShader *shader );
     76 	void					WriteModelDef( const class idDeclModelDef *modelDef );
     77 	void					WriteModel( const idRenderModel *model );
     78 	void					WriteUserInterface( const idUserInterface *ui, bool unique );
     79 	void					WriteRenderEntity( const renderEntity_t &renderEntity );
     80 	void					WriteRenderLight( const renderLight_t &renderLight );
     81 	void					WriteRefSound( const refSound_t &refSound );
     82 	void					WriteRenderView( const renderView_t &view );
     83 	void					WriteUsercmd( const usercmd_t &usercmd );
     84 	void					WriteContactInfo( const contactInfo_t &contactInfo );
     85 	void					WriteTrace( const trace_t &trace );
     86 	void					WriteTraceModel( const idTraceModel &trace );
     87 	void					WriteClipModel( const class idClipModel *clipModel );
     88 	void					WriteSoundCommands();
     89 
     90 	void					WriteBuildNumber( const int value );
     91 
     92 	int						GetBuildNumber() const { return version; }
     93 
     94 	int						GetCurrentSaveSize() const { return file->Length(); }
     95 
     96 private:
     97 	idFile *				file;
     98 	idFile *				stringFile;
     99 	idCompressor *			compressor;
    100 
    101 	idList<const idClass *>	objects;
    102 	int						version;
    103 
    104 	void					CallSave_r( const idTypeInfo *cls, const idClass *obj );
    105 
    106 	struct stringTableIndex_s {
    107 		idStr		string;
    108 		int			offset;
    109 	};
    110 
    111 	idHashIndex						stringHash;
    112 	idList< stringTableIndex_s >	stringTable;
    113 	int								curStringTableOffset;
    114 
    115 };
    116 
    117 class idRestoreGame {
    118 public:
    119 							idRestoreGame( idFile * savefile, idFile * stringTableFile, int saveVersion );
    120 							~idRestoreGame();
    121 
    122 	void					ReadDecls();
    123 
    124 	void					CreateObjects();
    125 	void					RestoreObjects();
    126 	void					DeleteObjects();
    127 
    128 	void					Error( VERIFY_FORMAT_STRING const char *fmt, ... );
    129 
    130 	void					Read( void *buffer, int len );
    131 	void					ReadInt( int &value );
    132 	void					ReadJoint( jointHandle_t &value );
    133 	void					ReadShort( short &value );
    134 	void					ReadByte( byte &value );
    135 	void					ReadSignedChar( signed char &value );
    136 	void					ReadFloat( float &value );
    137 	void					ReadBool( bool &value );
    138 	void					ReadString( idStr &string );
    139 	void					ReadVec2( idVec2 &vec );
    140 	void					ReadVec3( idVec3 &vec );
    141 	void					ReadVec4( idVec4 &vec );
    142 	void					ReadVec6( idVec6 &vec );
    143 	void					ReadWinding( idWinding &winding );
    144 	void					ReadBounds( idBounds &bounds );
    145 	void					ReadMat3( idMat3 &mat );
    146 	void					ReadAngles( idAngles &angles );
    147 	void					ReadObject( idClass *&obj );
    148 	void					ReadStaticObject( idClass &obj );
    149 	void					ReadDict( idDict *dict );
    150 	void					ReadMaterial( const idMaterial *&material );
    151 	void					ReadSkin( const idDeclSkin *&skin );
    152 	void					ReadParticle( const idDeclParticle *&particle );
    153 	void					ReadFX( const idDeclFX *&fx );
    154 	void					ReadSoundShader( const idSoundShader *&shader );
    155 	void					ReadModelDef( const idDeclModelDef *&modelDef );
    156 	void					ReadModel( idRenderModel *&model );
    157 	void					ReadUserInterface( idUserInterface *&ui );
    158 	void					ReadRenderEntity( renderEntity_t &renderEntity );
    159 	void					ReadRenderLight( renderLight_t &renderLight );
    160 	void					ReadRefSound( refSound_t &refSound );
    161 	void					ReadRenderView( renderView_t &view );
    162 	void					ReadUsercmd( usercmd_t &usercmd );
    163 	void					ReadContactInfo( contactInfo_t &contactInfo );
    164 	void					ReadTrace( trace_t &trace );
    165 	void					ReadTraceModel( idTraceModel &trace );
    166 	void					ReadClipModel( idClipModel *&clipModel );
    167 	void					ReadSoundCommands();
    168 
    169 	//						Used to retrieve the saved game buildNumber from within class Restore methods
    170 	int						GetBuildNumber() const { return version; }
    171 
    172 private:
    173 	idFile *		file;
    174 	idFile *		stringFile;
    175 	idList<idClass *, TAG_SAVEGAMES>		objects;
    176 	int						version;
    177 	int						stringTableOffset;
    178 
    179 	void					CallRestore_r( const idTypeInfo *cls, idClass *obj );
    180 };
    181 
    182 #endif /* !__SAVEGAME_H__*/