ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
51 namespace GUI {
52  class OnScreenDialog;
53 }
54 
55 namespace GUI {
56 class RandomSource;
57 class SeekableReadStream;
58 class WriteStream;
59 
60 
66 class EventRecorder : private Common::EventSource, public Common::Singleton<EventRecorder>, private Common::EventObserver {
67  friend class Common::Singleton<SingletonBaseType>;
68  EventRecorder();
69  ~EventRecorder() override;
70 public:
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  uint32 getRandomSeed(const Common::String &name);
84  void processTimeAndDate(TimeDate &td, bool skipRecord);
85  void processMillis(uint32 &millis, bool skipRecord);
86  void processScreenUpdate();
87  void processGameDescription(const ADGameDescription *desc);
88  bool processAutosave();
89  Common::SeekableReadStream *processSaveStream(const Common::String & fileName);
90 
93  void preDrawOverlayGui();
94  void postDrawOverlayGui();
95 
100  void setAuthor(const Common::String &author) {
101  _author = author;
102  }
103 
108  void setNotes(const Common::String &desc){
109  _desc = desc;
110  }
111 
116  void setName(const Common::String &name) {
117  _name = name;
118  }
119 
124  const Common::String getAuthor() {
125  return _author;
126  }
127 
132  const Common::String getNotes() {
133  return _desc;
134  }
135 
140  const Common::String getName() {
141  return _name;
142  }
143  void setRedraw(bool redraw) {
144  _needRedraw = redraw;
145  }
146 
147  void registerMixerManager(MixerManager *mixerManager);
148  void registerTimerManager(DefaultTimerManager *timerManager);
149 
150  MixerManager *getMixerManager();
151  DefaultTimerManager *getTimerManager();
152 
153  void deleteRecord(const Common::String& fileName);
154  bool checkForContinueGame();
155 
156  void acquireRecording() {
157  assert(_acquireCount >= 0);
158  if (_acquireCount == 0) {
159  _savedState = _initialized;
160  _initialized = false;
161  }
162  _acquireCount += 1;
163  }
164 
165  void releaseRecording() {
166  assert(_acquireCount > 0);
167  _acquireCount -= 1;
168  if (_acquireCount == 0)
169  _initialized = _savedState;
170  }
171 
172  RecordMode getRecordMode() const {
173  return _recordMode;
174  }
175 
176  Common::StringArray listSaveFiles(const Common::String &pattern);
177  Common::String generateRecordFileName(const Common::String &target);
178 
179  Common::SaveFileManager *getSaveManager(Common::SaveFileManager *realSaveManager);
180  SDL_Surface *getSurface(int width, int height);
181  void RegisterEventSource();
182 
184  bool grabScreenAndComputeMD5(Graphics::Surface &screen, uint8 md5[16]);
185 
186  void updateSubsystems();
187  bool switchMode();
188  void switchFastMode();
189 
190 private:
191  bool pollEvent(Common::Event &ev) override;
192  bool notifyEvent(const Common::Event &event) override;
193  bool _initialized;
194  volatile uint32 _fakeTimer;
195  TimeDate _lastTimeDate;
196  bool _savedState;
197  int _acquireCount;
198  bool _needcontinueGame;
199  int _temporarySlot;
200  Common::String _author;
201  Common::String _desc;
202  Common::String _name;
203 
204  Common::SaveFileManager *_realSaveManager;
205  MixerManager *_realMixerManager;
206  DefaultTimerManager *_timerManager;
207  RecorderSaveFileManager _fakeSaveManager;
208  NullMixerManager *_fakeMixerManager;
209  GUI::OnScreenDialog *_controlPanel;
210  Common::RecorderEvent _nextEvent;
211 
212  void setFileHeader();
213  void setGameMd5(const ADGameDescription *gameDesc);
214  void getConfig();
215  void getConfigFromDomain(const Common::ConfigManager::Domain *domain);
216  void removeDifferentEntriesInDomain(Common::ConfigManager::Domain *domain);
217  void applyPlaybackSettings();
218 
219  void switchMixer();
220  void switchTimerManagers();
221 
222  void togglePause();
223 
224  void takeScreenshot();
225 
226  bool openRecordFile(const Common::String &fileName);
227 
228  bool checkGameHash(const ADGameDescription *desc);
229 
230  void checkForKeyCode(const Common::Event &event);
235  bool allowMapping() const override { return false; }
236 
237  volatile uint32 _lastMillis;
238  uint32 _lastScreenshotTime;
239  uint32 _screenshotPeriod;
240  Common::PlaybackFile *_playbackFile;
241  Common::PlaybackFile *_recordFile;
242 
243  void saveScreenShot();
244  void checkRecordedMD5();
245  void deleteTemporarySave();
246  void updateFakeTimer(uint32 millis);
247  volatile RecordMode _recordMode;
248  Common::String _recordFileName;
249  bool _fastPlayback;
250  bool _needRedraw;
251  bool _processingMillis;
252 };
253 
254 } // End of namespace GUI
255 
256 #endif // ENABLE_EVENTRECORDER
257 
258 #endif
Definition: recorderfile.h:45
Definition: recorder-saves.h:30
Definition: system.h:106
Definition: str.h:59
Definition: surface.h:67
Definition: advancedDetector.h:163
Definition: default-timer.h:32
Definition: recorderfile.h:79
Definition: stream.h:745
Definition: system.h:46
Definition: events.h:318
Definition: events.h:199
Definition: config-manager.h:59
Definition: mixer.h:31
Definition: onscreendialog.h:30
Definition: savefile.h:142
Definition: events.h:259
Definition: null-mixer.h:36
Definition: singleton.h:42