ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

recorderfile.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_RECORDERFILE_H
00024 #define COMMON_RECORDERFILE_H
00025 
00026 #include "common/scummsys.h"
00027 #include "common/events.h"
00028 #include "common/mutex.h"
00029 #include "common/memstream.h"
00030 #include "common/config-manager.h"
00031 #include "common/savefile.h"
00032 
00033 //capacity of records buffer
00034 #define kMaxBufferedRecords 10000
00035 #define kRecordBuffSize sizeof(RecorderEvent) * kMaxBufferedRecords
00036 
00037 namespace Common {
00038 
00039 enum RecorderEventType {
00040     kRecorderEventTypeNormal = 0,
00041     kRecorderEventTypeTimer = 1
00042 };
00043 
00044 struct RecorderEvent : Event {
00045     RecorderEventType recordedtype;
00046     uint32 time;
00047 
00048     RecorderEvent() {
00049         recordedtype = kRecorderEventTypeNormal;
00050         time = 0;
00051     }
00052 
00053     RecorderEvent(const Event &e) : Event(e) {
00054         recordedtype = kRecorderEventTypeNormal;
00055         time = 0;
00056     }
00057 };
00058 
00059 
00060 
00061 class PlaybackFile {
00062     typedef HashMap<String, uint32, IgnoreCase_Hash, IgnoreCase_EqualTo> RandomSeedsDictionary;
00063     enum fileMode {
00064         kRead = 0,
00065         kWrite = 1,
00066         kClosed = 2
00067     };
00068     enum PlaybackFileState {
00069         kFileStateCheckFormat,
00070         kFileStateCheckVersion,
00071         kFileStateProcessHash,
00072         kFileStateProcessHeader,
00073         kFileStateProcessRandom,
00074         kFileStateSelectSection,
00075         kFileStateProcessSettings,
00076         kFileStateProcessSave,
00077         kFileStateDone,
00078         kFileStateError
00079     };
00080     enum FileTag {
00081         kFormatIdTag = MKTAG('P','B','C','K'),
00082         kVersionTag = MKTAG('V','E','R','S'),
00083         kHeaderSectionTag = MKTAG('H','E','A','D'),
00084         kHashSectionTag = MKTAG('H','A','S','H'),
00085         kRandomSectionTag = MKTAG('R','A','N','D'),
00086         kEventTag = MKTAG('E','V','N','T'),
00087         kScreenShotTag = MKTAG('B','M','H','T'),
00088         kSettingsSectionTag = MKTAG('S','E','T','T'),
00089         kAuthorTag = MKTAG('H','A','U','T'),
00090         kCommentsTag = MKTAG('H','C','M','T'),
00091         kNameTag = MKTAG('H','N','A','M'),
00092         kHashRecordTag = MKTAG('H','R','C','D'),
00093         kRandomRecordTag = MKTAG('R','R','C','D'),
00094         kSettingsRecordTag = MKTAG('S','R','E','C'),
00095         kSettingsRecordKeyTag = MKTAG('S','K','E','Y'),
00096         kSettingsRecordValueTag = MKTAG('S','V','A','L'),
00097         kSaveTag = MKTAG('S','A','V','E'),
00098         kSaveRecordTag = MKTAG('R','S','A','V'),
00099         kSaveRecordNameTag = MKTAG('S','N','A','M'),
00100         kSaveRecordBufferTag = MKTAG('S','B','U','F'),
00101         kMD5Tag = MKTAG('M','D','5',' ')
00102     };
00103     struct ChunkHeader {
00104         FileTag id;
00105         uint32 len;
00106     };
00107 public:
00108     struct SaveFileBuffer {
00109         byte *buffer;
00110         uint32 size;
00111     };
00112     struct PlaybackFileHeader {
00113         String fileName;
00114         String author;
00115         String name;
00116         String notes;
00117         String description;
00118         StringMap hashRecords;
00119         StringMap settingsRecords;
00120         HashMap<String, SaveFileBuffer> saveFiles;
00121         RandomSeedsDictionary randomSourceRecords;
00122     };
00123     PlaybackFile();
00124     ~PlaybackFile();
00125 
00126     bool openWrite(const String &fileName);
00127     bool openRead(const String &fileName);
00128     void close();
00129 
00130     RecorderEvent getNextEvent();
00131     void writeEvent(const RecorderEvent &event);
00132 
00133     void saveScreenShot(Graphics::Surface &screen, byte md5[16]);
00134     Graphics::Surface *getScreenShot(int number);
00135     int getScreensCount();
00136 
00137     bool isEventsBufferEmpty();
00138     PlaybackFileHeader &getHeader() {return _header;}
00139     void updateHeader();
00140     void addSaveFile(const String &fileName, InSaveFile *saveStream);
00141 private:
00142     WriteStream *_recordFile;
00143     WriteStream *_writeStream;
00144     WriteStream *_screenshotsFile;
00145     MemoryReadStream _tmpPlaybackFile;
00146     SeekableReadStream *_readStream;
00147     SeekableMemoryWriteStream _tmpRecordFile;
00148 
00149     fileMode _mode;
00150     bool _headerDumped;
00151     int _recordCount;
00152     uint32 _eventsSize;
00153     byte _tmpBuffer[kRecordBuffSize];
00154     PlaybackFileHeader _header;
00155     PlaybackFileState _playbackParseState;
00156 
00157     void skipHeader();
00158     bool parseHeader();
00159     bool processChunk(ChunkHeader &nextChunk);
00160     void returnToChunkHeader();
00161 
00162     bool readSaveRecord();
00163     void checkRecordedMD5();
00164     bool readChunkHeader(ChunkHeader &nextChunk);
00165     void processRndSeedRecord(ChunkHeader chunk);
00166     bool processSettingsRecord();
00167 
00168     bool checkPlaybackFileVersion();
00169 
00170     void dumpHeaderToFile();
00171     void writeSaveFilesSection();
00172     void writeGameSettings();
00173     void writeHeaderSection();
00174     void writeGameHash();
00175     void writeRandomRecords();
00176 
00177     void dumpRecordsToFile();
00178 
00179     String readString(int len);
00180     void readHashMap(ChunkHeader chunk);
00181 
00182     bool skipToNextScreenshot();
00183     void readEvent(RecorderEvent& event);
00184     void readEventsToBuffer(uint32 size);
00185     bool grabScreenAndComputeMD5(Graphics::Surface &screen, uint8 md5[16]);
00186 };
00187 
00188 } // End of namespace Common
00189 
00190 #endif


Generated on Sat May 23 2020 05:00:30 for ResidualVM by doxygen 1.7.1
curved edge   curved edge