ScummVM API documentation
engine.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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ENGINES_ENGINE_H
24 #define ENGINES_ENGINE_H
25 
26 #include "common/scummsys.h"
27 #include "common/str.h"
28 #include "common/language.h"
29 #include "common/platform.h"
30 #include "common/queue.h"
31 #include "common/singleton.h"
32 
33 class OSystem;
35 class MetaEngine;
36 
37 namespace Audio {
38 class Mixer;
39 }
40 namespace Common {
41 class Error;
42 class EventManager;
43 class SaveFileManager;
44 class TimerManager;
45 class FSNode;
46 class SeekableReadStream;
47 class WriteStream;
48 }
49 namespace GUI {
50 class Debugger;
51 class Dialog;
52 }
53 
67 void GUIErrorMessage(const Common::U32String &msg, const char *url = nullptr);
72 void GUIErrorMessage(const Common::String &msg, const char *url = nullptr);
77 void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url);
82 void GUIErrorMessageWithURL(const Common::String &msg, const char *url);
87 void GUIErrorMessageFormat(Common::U32String fmt, ...);
92 void GUIErrorMessageFormat(const char *fmt, ...) GCC_PRINTF(1, 2);
93 
94 
95 class Engine;
96 
102 class PauseToken {
103 public:
104  PauseToken();
108  PauseToken(const PauseToken &);
109 #if __cplusplus >= 201103L
110  PauseToken(PauseToken &&);
111 #endif
112  ~PauseToken();
116  void operator=(const PauseToken &);
117 #if __cplusplus >= 201103L
118  void operator=(PauseToken &&);
119 #endif
120 
125  void clear();
126 
131  bool isActive() const { return _engine != nullptr; }
132 
133 private:
134  PauseToken(Engine *);
135 
136  Engine *_engine;
140  friend class Engine;
141 };
142 
143 class Engine {
144 public:
148  OSystem *_system;
152  Audio::Mixer *_mixer;
153 
154 protected:
158  Common::TimerManager *_timer;
162  Common::EventManager *_eventMan;
166  Common::SaveFileManager *_saveFileMan;
167 
171  GUI::Dialog *_mainMenuDialog;
175  virtual int runDialog(GUI::Dialog &dialog);
176 
180  const Common::String _targetName;
181 
182 private:
190  int _pauseLevel;
191 
195  uint32 _pauseStartTime;
196 
202  int32 _engineStartTime;
203 
207  const int _autosaveInterval;
208 
212  int _lastAutosaveTime;
213 
220  int _saveSlotToLoad;
221 
225  GUI::Debugger *_debugger;
226 public:
227 
228 
242 
251 
260 
269 
277 
286  kSupportsArbitraryResolutions
287  };
288 
289 
290 
300  Engine(OSystem *syst);
304  virtual ~Engine();
305 
314  virtual void initializePath(const Common::FSNode &gamePath);
315 
321  virtual Common::Error run() = 0;
322 
326  virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size);
327 
331  virtual GUI::Debugger *getDebugger() { return _debugger; }
332 
339  void setDebugger(GUI::Debugger *debugger) {
340  assert(!_debugger);
341  _debugger = debugger;
342  }
343 
349  GUI::Debugger *getOrCreateDebugger();
350 
354  virtual bool hasFeature(EngineFeature f) const { return false; }
355 
373  virtual void syncSoundSettings();
374 
380  virtual void applyGameSettings() {}
381 
385  virtual void flipMute();
386 
390  virtual Common::String getSaveStateName(int slot) const {
391  return Common::String::format("%s.%03d", _targetName.c_str(), slot);
392  }
393 
401  virtual Common::Error loadGameState(int slot);
402 
410  virtual Common::Error loadGameStream(Common::SeekableReadStream *stream);
411 
421  void setGameToLoadSlot(int slot);
422 
426  virtual bool canLoadGameStateCurrently();
427 
437  virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false);
438 
447  virtual Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false);
448 
452  virtual bool canSaveGameStateCurrently();
453 
457  bool saveGameDialog();
458 
462  bool loadGameDialog();
463 
464 protected:
470  virtual void pauseEngineIntern(bool pause);
471 
475 public:
476 
482  static void quitGame();
483 
488  static bool shouldQuit();
489 
493  static MetaEngineDetection &getMetaEngineDetection();
494 
498  static MetaEngine &getMetaEngine();
499 
510  PauseToken pauseEngine();
511 private:
518  void resumeEngine();
522  friend class PauseToken;
523 
524 public:
525 
529  bool isPaused() const { return _pauseLevel != 0; }
530 
534  void openMainMenuDialog();
535 
541  static bool warnUserAboutUnsupportedGame();
542 
549  static void errorUnsupportedGame(Common::String &extraMsg);
550 
556  uint32 getTotalPlayTime() const;
557 
567  void setTotalPlayTime(uint32 time = 0);
568 
572  inline Common::TimerManager *getTimerManager() { return _timer; }
576  inline Common::EventManager *getEventManager() { return _eventMan; }
580  inline Common::SaveFileManager *getSaveFileManager() { return _saveFileMan; }
581 
582 public:
584  void checkCD();
585 
586 
590  void handleAutoSave();
591 
595  void saveAutosaveIfEnabled();
596 
600  virtual bool canSaveAutosaveCurrently() {
601  return canSaveGameStateCurrently();
602  }
603 
609  virtual int getAutosaveSlot() const {
610  return 0;
611  }
612 
617  bool shouldPerformAutoSave(int lastSaveTime) {
618  // TODO: Remove deprecated method once all engines are refactored
619  // to no longer do autosaves directly themselves
620  return false;
621  }
622 };
623 
624 
636 class ChainedGamesManager : public Common::Singleton<ChainedGamesManager> {
637 private:
638  struct Game {
639  Common::String target;
640  int slot;
641  };
642 
643  Common::Queue<Game> _chainedGames;
644 
645 public:
648  void clear();
650  void push(const Common::String target, const int slot = -1);
652  bool pop(Common::String &target, int &slot);
653 };
654 
656 #define ChainedGamesMan ChainedGamesManager::instance()
657  //FIXME
659 extern Engine *g_engine;
661 #endif
Definition: engine.h:636
virtual int getAutosaveSlot() const
Definition: engine.h:609
Definition: engine.h:102
Common::TimerManager * getTimerManager()
Definition: engine.h:572
Definition: metaengine.h:204
void GUIErrorMessageFormat(Common::U32String fmt,...)
EngineFeature
Definition: engine.h:236
Definition: engine.h:241
bool isActive() const
Definition: engine.h:131
OSystem * _system
Definition: engine.h:148
Definition: metaengine.h:52
Engine * g_engine
Definition: engine.h:250
virtual void applyGameSettings()
Definition: engine.h:380
Definition: advancedDetector.h:33
virtual GUI::Debugger * getDebugger()
Definition: engine.h:331
Definition: metaengine.h:125
void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url)
const Common::String _targetName
Definition: engine.h:180
Common::EventManager * getEventManager()
Definition: engine.h:576
Common::EventManager * _eventMan
Definition: engine.h:162
bool isPaused() const
Definition: engine.h:529
void setDebugger(GUI::Debugger *debugger)
Definition: engine.h:339
GUI::Dialog * _mainMenuDialog
Definition: engine.h:171
void GUIErrorMessage(const Common::U32String &msg, const char *url=nullptr)
Common::TimerManager * _timer
Definition: engine.h:158
Common::SaveFileManager * getSaveFileManager()
Definition: engine.h:580
Definition: engine.h:268
Definition: engine.h:143
Definition: engine.h:37
virtual Common::String getSaveStateName(int slot) const
Definition: engine.h:390
Common::SaveFileManager * _saveFileMan
Definition: engine.h:166
virtual bool hasFeature(EngineFeature f) const
Definition: engine.h:354
bool shouldPerformAutoSave(int lastSaveTime)
Definition: engine.h:617
virtual bool canSaveAutosaveCurrently()
Definition: engine.h:600
Audio::Mixer * _mixer
Definition: engine.h:152