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 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 ENGINES_ENGINE_H
23 #define ENGINES_ENGINE_H
24 
25 #include "common/scummsys.h"
26 #include "common/str.h"
27 #include "common/language.h"
28 #include "common/platform.h"
29 #include "common/queue.h"
30 #include "common/singleton.h"
31 #include "engines/enhancements.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 
66 void GUIErrorMessage(const Common::U32String &msg, const char *url = nullptr);
70 void GUIErrorMessage(const Common::String &msg, const char *url = nullptr);
74 void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url);
78 void GUIErrorMessageWithURL(const Common::String &msg, const char *url);
86 template<class... TParam>
87 inline void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param) {
88  GUIErrorMessageFormatU32StringPtr(&fmt, Common::forward<TParam>(param)...);
89 }
93 void GUIErrorMessageFormat(MSVC_PRINTF const char *fmt, ...) GCC_PRINTF(1, 2);
94 
95 
96 class Engine;
97 
103 class PauseToken {
104 public:
105  PauseToken();
109  PauseToken(const PauseToken &);
110 #if __cplusplus >= 201103L
112 #endif
113  ~PauseToken();
117  void operator=(const PauseToken &);
118 #if __cplusplus >= 201103L
119  void operator=(PauseToken &&);
120 #endif
121 
126  void clear();
127 
132  bool isActive() const { return _engine != nullptr; }
133 
134 private:
135  PauseToken(Engine *);
136 
137  Engine *_engine;
141  friend class Engine;
142 };
143 
144 class Engine {
145 public:
154 
155 protected:
168 
176  virtual int runDialog(GUI::Dialog &dialog);
177 
182 
183  int32 _activeEnhancements = kEnhGameBreakingBugFixes;
184 
185 private:
189  MetaEngine *_metaEngine;
190 
198  int _pauseLevel;
199 
203  uint32 _pauseStartTime;
204 
210  int32 _engineStartTime;
211 
215  int _autosaveInterval;
216 
220  int _lastAutosaveTime;
221 
228  int _saveSlotToLoad;
229 
233  bool _autoSaving;
234 
238  GUI::Debugger *_debugger;
239 
243  static bool _quitRequested;
244 
245 public:
259 
268 
277 
286 
294 
304 
311 
316  };
317 
318 
319 
329  Engine(OSystem *syst);
333  virtual ~Engine();
334 
343  virtual void initializePath(const Common::FSNode &gamePath);
344 
350  virtual Common::Error run() = 0;
351 
355  virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size);
356 
360  virtual GUI::Debugger *getDebugger() final { return _debugger; }
361 
368  void setDebugger(GUI::Debugger *debugger) {
369  assert(!_debugger);
370  _debugger = debugger;
371  }
372 
378  GUI::Debugger *getOrCreateDebugger();
379 
383  virtual bool hasFeature(EngineFeature f) const { return false; }
384 
385  bool enhancementEnabled(int32 cls);
386 
404  virtual void syncSoundSettings();
405 
411  virtual void applyGameSettings() {}
412 
416  virtual void flipMute();
417 
421  virtual Common::String getSaveStateName(int slot) const {
422  return Common::String::format("%s.%03d", _targetName.c_str(), slot);
423  }
424 
432  virtual Common::Error loadGameState(int slot);
433 
441  virtual Common::Error loadGameStream(Common::SeekableReadStream *stream);
442 
452  void setGameToLoadSlot(int slot);
453 
459  virtual bool canLoadGameStateCurrently(Common::U32String *msg = nullptr);
460 
470  virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false);
471 
480  virtual Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false);
481 
487  virtual bool canSaveGameStateCurrently(Common::U32String *msg = nullptr);
488 
492  bool saveGameDialog();
493 
497  bool loadGameDialog();
498 
499 protected:
505  virtual void pauseEngineIntern(bool pause);
506 
510 public:
511 
517  static void quitGame();
518 
524  static bool shouldQuit();
525 
529  inline MetaEngine *getMetaEngine() const { return _metaEngine; }
530 
534  inline void setMetaEngine(MetaEngine *metaEngine) { _metaEngine = metaEngine; }
535 
546  PauseToken pauseEngine();
547 private:
554  void resumeEngine();
558  friend class PauseToken;
559 
565  bool warnBeforeOverwritingAutosave();
566 
567 public:
568 
572  bool isPaused() const { return _pauseLevel != 0; }
573 
577  void openMainMenuDialog();
578 
587  static bool warnUserAboutUnsupportedGame(Common::String msg = Common::String());
588 
594  static void errorUnsupportedGame(Common::String extraMsg);
595 
601  uint32 getTotalPlayTime() const;
602 
612  void setTotalPlayTime(uint32 time = 0);
613 
617  inline Common::TimerManager *getTimerManager() { return _timer; }
621  inline Common::EventManager *getEventManager() { return _eventMan; }
625  inline Common::SaveFileManager *getSaveFileManager() { return _saveFileMan; }
626 
627 public:
631  bool existExtractedCDAudioFiles(uint track = 1);
636  bool isDataAndCDAudioReadFromSameCD();
640  void warnMissingExtractedCDAudio();
641 
645  void handleAutoSave();
646 
650  void saveAutosaveIfEnabled();
651 
655  virtual bool canSaveAutosaveCurrently() {
656  return canSaveGameStateCurrently();
657  }
658 
665  virtual int getAutosaveSlot() const {
666  return 0;
667  }
668 
669 protected:
673  void defaultSyncSoundSettings();
674 };
675 
676 
688 class ChainedGamesManager : public Common::Singleton<ChainedGamesManager> {
689 private:
690  struct Game {
691  Common::String target;
692  int slot;
693  };
694 
695  Common::Queue<Game> _chainedGames;
696 
697 public:
700  void clear();
702  void push(const Common::String target, const int slot = -1);
704  bool pop(Common::String &target, int &slot);
706  bool empty() { return _chainedGames.empty(); }
707 };
708 
710 #define ChainedGamesMan ChainedGamesManager::instance()
711  //FIXME
713 extern Engine *g_engine;
715 #endif
Definition: engine.h:688
virtual int getAutosaveSlot() const
Definition: engine.h:665
Definition: engine.h:103
Common::TimerManager * getTimerManager()
Definition: engine.h:617
Definition: metaengine.h:196
Definition: str.h:59
EngineFeature
Definition: engine.h:253
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: stream.h:77
Definition: error.h:84
Definition: engine.h:258
bool isActive() const
Definition: engine.h:132
Definition: debugger.h:41
Definition: engine.h:310
bool empty()
Definition: engine.h:706
Definition: stream.h:745
OSystem * _system
Definition: engine.h:149
Definition: system.h:46
MetaEngine * getMetaEngine() const
Definition: engine.h:529
Engine * g_engine
Definition: engine.h:267
int FORCEINLINE GCC_PRINTF(2, 0) int vsprintf_s(T(&dst)[N]
Definition: mixer.h:59
Definition: timer.h:40
void GUIErrorMessageFormatU32StringPtr(const Common::U32String *fmt,...)
Definition: ustr.h:57
virtual void applyGameSettings()
Definition: engine.h:411
Definition: algorithm.h:29
Definition: fs.h:69
void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param)
Definition: engine.h:87
Definition: metaengine.h:126
void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url)
const Common::String _targetName
Definition: engine.h:181
Common::EventManager * getEventManager()
Definition: engine.h:621
Common::EventManager * _eventMan
Definition: engine.h:163
bool isPaused() const
Definition: engine.h:572
void setDebugger(GUI::Debugger *debugger)
Definition: engine.h:368
Definition: dialog.h:49
GUI::Dialog * _mainMenuDialog
Definition: engine.h:172
Definition: engine.h:315
void GUIErrorMessage(const Common::U32String &msg, const char *url=nullptr)
Definition: savefile.h:142
Definition: system.h:161
Common::TimerManager * _timer
Definition: engine.h:159
void setMetaEngine(MetaEngine *metaEngine)
Definition: engine.h:534
Common::SaveFileManager * getSaveFileManager()
Definition: engine.h:625
virtual GUI::Debugger * getDebugger() final
Definition: engine.h:360
Definition: engine.h:285
Definition: events.h:472
Definition: engine.h:144
Definition: system.h:38
virtual Common::String getSaveStateName(int slot) const
Definition: engine.h:421
Common::SaveFileManager * _saveFileMan
Definition: engine.h:167
virtual bool hasFeature(EngineFeature f) const
Definition: engine.h:383
Definition: singleton.h:42
virtual bool canSaveAutosaveCurrently()
Definition: engine.h:655
Audio::Mixer * _mixer
Definition: engine.h:153