ScummVM API documentation
recorderfile.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef COMMON_RECORDERFILE_H
23#define COMMON_RECORDERFILE_H
24
25#include "common/scummsys.h"
26#include "common/events.h"
27#include "common/mutex.h"
28#include "common/memstream.h"
29#include "common/config-manager.h"
30#include "common/savefile.h"
31
32//capacity of records buffer
33#define kMaxBufferedRecords 10000
34#define kRecordBuffSize sizeof(RecorderEvent) * kMaxBufferedRecords
35
36namespace Graphics {
37class ManagedSurface;
38}
39
40namespace Common {
41
42enum RecorderEventType {
43 kRecorderEventTypeNormal = 0,
44 kRecorderEventTypeTimer = 1,
45 kRecorderEventTypeTimeDate = 2,
46 kRecorderEventTypeScreenUpdate = 3,
47 kRecorderEventTypePoll = 4,
48};
49
51 RecorderEventType recordedtype;
52 union {
53 uint32 time;
54 TimeDate timeDate;
55 };
56
58 recordedtype = kRecorderEventTypeNormal;
59 time = 0;
60 timeDate.tm_sec = 0;
61 timeDate.tm_min = 0;
62 timeDate.tm_hour = 0;
63 timeDate.tm_mday = 0;
64 timeDate.tm_mon = 0;
65 timeDate.tm_year = 0;
66 timeDate.tm_wday = 0;
67 }
68
69 RecorderEvent(const Event &e) : Event(e) {
70 recordedtype = kRecorderEventTypeNormal;
71 time = 0;
72 timeDate.tm_sec = 0;
73 timeDate.tm_min = 0;
74 timeDate.tm_hour = 0;
75 timeDate.tm_mday = 0;
76 timeDate.tm_mon = 0;
77 timeDate.tm_year = 0;
78 timeDate.tm_wday = 0;
79 }
80};
81
82
83
86 enum fileMode {
87 kRead = 0,
88 kWrite = 1,
89 kClosed = 2
90 };
91 enum PlaybackFileState {
92 kFileStateCheckFormat,
93 kFileStateCheckVersion,
94 kFileStateProcessHash,
95 kFileStateProcessHeader,
96 kFileStateProcessRandom,
97 kFileStateSelectSection,
98 kFileStateProcessSettings,
99 kFileStateProcessSave,
100 kFileStateDone,
101 kFileStateError
102 };
103 enum FileTag {
104 kFormatIdTag = MKTAG('P','B','C','K'),
105 kVersionTag = MKTAG('V','E','R','S'),
106 kHeaderSectionTag = MKTAG('H','E','A','D'),
107 kHashSectionTag = MKTAG('H','A','S','H'),
108 kRandomSectionTag = MKTAG('R','A','N','D'),
109 kEventTag = MKTAG('E','V','N','T'),
110 kScreenShotTag = MKTAG('T','H','M','B'),
111 kSettingsSectionTag = MKTAG('S','E','T','T'),
112 kAuthorTag = MKTAG('H','A','U','T'),
113 kCommentsTag = MKTAG('H','C','M','T'),
114 kNameTag = MKTAG('H','N','A','M'),
115 kHashRecordTag = MKTAG('H','R','C','D'),
116 kRandomRecordTag = MKTAG('R','R','C','D'),
117 kSettingsRecordTag = MKTAG('S','R','E','C'),
118 kSettingsRecordKeyTag = MKTAG('S','K','E','Y'),
119 kSettingsRecordValueTag = MKTAG('S','V','A','L'),
120 kSaveTag = MKTAG('S','A','V','E'),
121 kSaveRecordTag = MKTAG('R','S','A','V'),
122 kSaveRecordNameTag = MKTAG('S','N','A','M'),
123 kSaveRecordBufferTag = MKTAG('S','B','U','F'),
124 kMD5Tag = MKTAG('M','D','5',' ')
125 };
126 struct ChunkHeader {
127 FileTag id;
128 uint32 len;
129 };
130public:
132 byte *buffer;
133 uint32 size;
134 };
136 String fileName;
137 String author;
138 String name;
139 String notes;
140 String description;
141 StringMap hashRecords;
142 StringMap settingsRecords;
144 RandomSeedsDictionary randomSourceRecords;
145 };
146 PlaybackFile();
148
149 bool openWrite(const String &fileName);
150 bool openRead(const String &fileName);
151 void close();
152
153 bool hasNextEvent() const;
154 RecorderEvent getNextEvent();
155 void writeEvent(const RecorderEvent &event);
156
157 void saveScreenShot(const Graphics::ManagedSurface &screen, const byte md5[16]);
158 void saveScreenShot(const Graphics::Surface &screen, const byte md5[16]);
159 Graphics::ManagedSurface *getScreenShot(int number);
160 int getScreensCount();
161
162 bool isEventsBufferEmpty() const;
163 PlaybackFileHeader &getHeader() {return _header;}
164 void updateHeader();
165 void addSaveFile(const String &fileName, InSaveFile *saveStream);
166
167 uint32 getVersion() const {return _version;}
168private:
169 Array<byte> _tmpBuffer;
170 WriteStream *_recordFile;
171 WriteStream *_writeStream;
172 WriteStream *_screenshotsFile;
173 MemoryReadStream _tmpPlaybackFile;
174 SeekableReadStream *_readStream;
175 SeekableMemoryWriteStream _tmpRecordFile;
176
177 fileMode _mode;
178 bool _headerDumped;
179 int _recordCount;
180 uint32 _eventsSize;
181 PlaybackFileHeader _header;
182 PlaybackFileState _playbackParseState;
183 uint32 _version;
184
185 void skipHeader();
186 bool parseHeader();
187 bool processChunk(ChunkHeader &nextChunk);
188 void returnToChunkHeader();
189
190 bool readSaveRecord();
191 void checkRecordedMD5();
192 bool readChunkHeader(ChunkHeader &nextChunk);
193 void processRndSeedRecord(ChunkHeader chunk);
194 bool processSettingsRecord();
195
196 bool checkPlaybackFileVersion();
197
198 void dumpHeaderToFile();
199 void writeSaveFilesSection();
200 void writeGameSettings();
201 void writeHeaderSection();
202 void writeGameHash();
203 void writeRandomRecords();
204
205 void dumpRecordsToFile();
206
207 String readString(int len);
208 void readHashMap(ChunkHeader chunk);
209
210 bool skipToNextScreenshot();
211 void readEvent(RecorderEvent& event);
212 void readEventsToBuffer(uint32 size);
213};
214
215} // End of namespace Common
216
217#endif
Definition: recorderfile.h:84
Definition: stream.h:745
Definition: str.h:59
Definition: managed_surface.h:51
#define MKTAG(a0, a1, a2, a3)
Definition: endian.h:188
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: events.h:218
Definition: recorderfile.h:135
Definition: recorderfile.h:131
Definition: recorderfile.h:50
Definition: surface.h:67
Definition: system.h:111
int tm_year
Definition: system.h:117
int tm_mon
Definition: system.h:116
int tm_wday
Definition: system.h:118
int tm_mday
Definition: system.h:115
int tm_sec
Definition: system.h:112
int tm_min
Definition: system.h:113
int tm_hour
Definition: system.h:114