ScummVM API documentation
EventRecorder.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 GUI_EVENTRECORDER_H
23#define GUI_EVENTRECORDER_H
24
25#include "common/system.h"
26
27#include "common/events.h"
28#include "common/savefile.h"
29#include "common/singleton.h"
30
31#include "engines/advancedDetector.h"
32
33#ifdef ENABLE_EVENTRECORDER
34
35#include "common/mutex.h"
36#include "common/array.h"
37#include "common/memstream.h"
38#include "backends/mixer/mixer.h"
39#include "common/hashmap.h"
40#include "common/hash-str.h"
41#include "backends/timer/sdl/sdl-timer.h"
42#include "common/config-manager.h"
43#include "common/recorderfile.h"
44#include "backends/saves/recorder/recorder-saves.h"
45#include "backends/mixer/null/null-mixer.h"
46#include "backends/saves/default/default-saves.h"
47
48
49#define g_eventRec (GUI::EventRecorder::instance())
50
51namespace GUI {
52 class OnScreenDialog;
53}
54
55namespace GUI {
56class RandomSource;
57class SeekableReadStream;
58class WriteStream;
59
60
66class EventRecorder : private Common::EventSource, public Common::Singleton<EventRecorder>, private Common::EventObserver {
67 friend class Common::Singleton<SingletonBaseType>;
68 EventRecorder();
69 ~EventRecorder() override;
70public:
72 enum RecordMode {
73 kPassthrough = 0,
74 kRecorderRecord = 1,
75 kRecorderPlayback = 2,
76 kRecorderPlaybackPause = 3,
77 kRecorderUpdate = 4
78 };
79
80 void init(const Common::String &recordFileName, RecordMode mode);
81 void deinit();
82 bool processDelayMillis();
83 void setFastPlayback(bool fastPlayback);
84 uint32 getRandomSeed(const Common::String &name);
85 void processTimeAndDate(TimeDate &td, bool skipRecord);
86 void processMillis(uint32 &millis, bool skipRecord);
87 void processScreenUpdate();
88 void processGameDescription(const ADGameDescription *desc);
89 bool processAutosave();
90 Common::SeekableReadStream *processSaveStream(const Common::String & fileName);
91
94 void preDrawOverlayGui();
95 void postDrawOverlayGui();
96
101 void setAuthor(const Common::String &author) {
102 _author = author;
103 }
104
109 void setNotes(const Common::String &desc){
110 _desc = desc;
111 }
112
117 void setName(const Common::String &name) {
118 _name = name;
119 }
120
125 const Common::String getAuthor() {
126 return _author;
127 }
128
133 const Common::String getNotes() {
134 return _desc;
135 }
136
141 const Common::String getName() {
142 return _name;
143 }
144 void setRedraw(bool redraw) {
145 _needRedraw = redraw;
146 }
147 void setRecordModalDialog(bool record) {
148 _recordModalDialog = record;
149 }
150
151 void registerMixerManager(MixerManager *mixerManager);
152 void registerTimerManager(DefaultTimerManager *timerManager);
153
154 MixerManager *getMixerManager();
155 DefaultTimerManager *getTimerManager();
156
157 void deleteRecord(const Common::String& fileName);
158 bool checkForContinueGame();
159
160 void acquireRecording() {
161 assert(_acquireCount >= 0);
162 if (_acquireCount == 0) {
163 _savedState = _initialized;
164 if (!_recordModalDialog)
165 _initialized = false;
166 }
167 _acquireCount += 1;
168 }
169
170 void releaseRecording() {
171 assert(_acquireCount > 0);
172 _acquireCount -= 1;
173 if (_acquireCount == 0)
174 _initialized = _savedState;
175 }
176
177 RecordMode getRecordMode() const {
178 return _recordMode;
179 }
180
181 Common::StringArray listSaveFiles(const Common::String &pattern);
182 Common::String generateRecordFileName(const Common::String &target);
183
184 Common::SaveFileManager *getSaveManager(Common::SaveFileManager *realSaveManager);
185 SDL_Surface *getSurface(int width, int height);
186 void RegisterEventSource();
187
189 bool grabScreenAndComputeMD5(Graphics::Surface &screen, uint8 md5[16]);
190
191 void updateSubsystems();
192 bool switchMode();
193 void switchFastMode();
194
195#ifdef USE_IMGUI
196 void showImGui();
197#endif
198
199private:
200
201 bool isImGuiRecorderEnabled() const;
202
203 bool pollEvent(Common::Event &ev) override;
204 bool notifyEvent(const Common::Event &event) override;
205 void notifyPoll() override;
206 bool _initialized;
207 volatile uint32 _fakeTimer;
208 TimeDate _lastTimeDate;
209 bool _savedState;
210 int _acquireCount;
211 bool _recordModalDialog;
212 bool _needcontinueGame;
213 int _temporarySlot;
214 Common::String _author;
215 Common::String _desc;
216 Common::String _name;
217
218 Common::SaveFileManager *_realSaveManager;
219 MixerManager *_realMixerManager;
220 DefaultTimerManager *_timerManager;
221 RecorderSaveFileManager _fakeSaveManager;
222 NullMixerManager *_fakeMixerManager;
223 GUI::OnScreenDialog *_controlPanel;
224 Common::RecorderEvent _nextEvent;
225
226 void setFileHeader();
227 void setGameMd5(const ADGameDescription *gameDesc);
228 void getConfig();
229 void getConfigFromDomain(const Common::ConfigManager::Domain *domain);
230 void removeDifferentEntriesInDomain(Common::ConfigManager::Domain *domain);
231 void applyPlaybackSettings();
232
233 void switchMixer();
234 void switchTimerManagers();
235
236 void togglePause();
237
238 void takeScreenshot();
239
240 bool openRecordFile(const Common::String &fileName);
241
242 bool checkGameHash(const ADGameDescription *desc);
243
244 void checkForKeyCode(const Common::Event &event);
249 bool allowMapping() const override { return false; }
250
251 volatile uint32 _lastMillis;
252 uint32 _lastScreenshotTime;
253 uint32 _screenshotPeriod;
254 Common::PlaybackFile *_playbackFile;
255 Common::PlaybackFile *_recordFile;
256
257 void saveScreenShot();
258 void checkRecordedMD5();
259 void deleteTemporarySave();
260 void updateFakeTimer(uint32 millis);
261 void postPlaybackQuit();
262 volatile RecordMode _recordMode;
263 Common::String _recordFileName;
264 bool _fastPlayback;
265 bool _needRedraw;
266 bool _processingMillis;
267 bool _playbackQuitPosted;
268};
269
270} // End of namespace GUI
271
272#endif // ENABLE_EVENTRECORDER
273
274#endif
Definition: config-manager.h:59
Definition: events.h:337
Definition: events.h:278
Definition: recorderfile.h:84
Definition: savefile.h:142
Definition: stream.h:745
Definition: singleton.h:42
Definition: str.h:59
Definition: default-timer.h:47
Definition: onscreendialog.h:30
Definition: mixer.h:31
Definition: null-mixer.h:36
Definition: recorder-saves.h:30
Definition: advancedDetector.h:164
Definition: events.h:218
Definition: recorderfile.h:50
Definition: surface.h:67
Definition: system.h:111