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 
32 class OSystem;
34 class MetaEngine;
35 
36 namespace Audio {
37 class Mixer;
38 }
39 namespace Common {
40 class Error;
41 class EventManager;
42 class SaveFileManager;
43 class TimerManager;
44 class FSNode;
45 class SeekableReadStream;
46 class WriteStream;
47 }
48 namespace GUI {
49 class Debugger;
50 class Dialog;
51 }
52 
65 void GUIErrorMessage(const Common::U32String &msg, const char *url = nullptr);
69 void GUIErrorMessage(const Common::String &msg, const char *url = nullptr);
73 void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url);
77 void GUIErrorMessageWithURL(const Common::String &msg, const char *url);
85 template<class... TParam>
86 inline void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param) {
87  GUIErrorMessageFormatU32StringPtr(&fmt, Common::forward<TParam>(param)...);
88 }
92 void GUIErrorMessageFormat(MSVC_PRINTF 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
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:
153 
154 protected:
167 
175  virtual int runDialog(GUI::Dialog &dialog);
176 
181 
182 private:
186  MetaEngine *_metaEngine;
187 
195  int _pauseLevel;
196 
200  uint32 _pauseStartTime;
201 
207  int32 _engineStartTime;
208 
212  int _autosaveInterval;
213 
217  int _lastAutosaveTime;
218 
225  int _saveSlotToLoad;
226 
230  bool _autoSaving;
231 
235  GUI::Debugger *_debugger;
236 
240  static bool _quitRequested;
241 
242 public:
256 
265 
274 
283 
291 
301 
308 
313  };
314 
315 
316 
326  Engine(OSystem *syst);
330  virtual ~Engine();
331 
340  virtual void initializePath(const Common::FSNode &gamePath);
341 
347  virtual Common::Error run() = 0;
348 
352  virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size);
353 
357  virtual GUI::Debugger *getDebugger() final { return _debugger; }
358 
365  void setDebugger(GUI::Debugger *debugger) {
366  assert(!_debugger);
367  _debugger = debugger;
368  }
369 
375  GUI::Debugger *getOrCreateDebugger();
376 
380  virtual bool hasFeature(EngineFeature f) const { return false; }
381 
399  virtual void syncSoundSettings();
400 
406  virtual void applyGameSettings() {}
407 
411  virtual void flipMute();
412 
416  virtual Common::String getSaveStateName(int slot) const {
417  return Common::String::format("%s.%03d", _targetName.c_str(), slot);
418  }
419 
427  virtual Common::Error loadGameState(int slot);
428 
436  virtual Common::Error loadGameStream(Common::SeekableReadStream *stream);
437 
447  void setGameToLoadSlot(int slot);
448 
454  virtual bool canLoadGameStateCurrently(Common::U32String *msg = nullptr);
455 
465  virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false);
466 
475  virtual Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false);
476 
482  virtual bool canSaveGameStateCurrently(Common::U32String *msg = nullptr);
483 
487  bool saveGameDialog();
488 
492  bool loadGameDialog();
493 
494 protected:
500  virtual void pauseEngineIntern(bool pause);
501 
505 public:
506 
512  static void quitGame();
513 
519  static bool shouldQuit();
520 
524  static MetaEngineDetection &getMetaEngineDetection();
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:102
Common::TimerManager * getTimerManager()
Definition: engine.h:617
Definition: metaengine.h:200
Definition: str.h:59
EngineFeature
Definition: engine.h:250
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: stream.h:77
Definition: error.h:84
Definition: engine.h:255
bool isActive() const
Definition: engine.h:131
Definition: debugger.h:41
Definition: engine.h:307
bool empty()
Definition: engine.h:706
Definition: stream.h:745
OSystem * _system
Definition: engine.h:148
Definition: system.h:45
MetaEngine * getMetaEngine() const
Definition: engine.h:529
Engine * g_engine
Definition: engine.h:264
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:406
Definition: algorithm.h:29
Definition: fs.h:69
void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param)
Definition: engine.h:86
Definition: metaengine.h:139
void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url)
const Common::String _targetName
Definition: engine.h:180
Common::EventManager * getEventManager()
Definition: engine.h:621
Common::EventManager * _eventMan
Definition: engine.h:162
bool isPaused() const
Definition: engine.h:572
void setDebugger(GUI::Debugger *debugger)
Definition: engine.h:365
Definition: dialog.h:49
GUI::Dialog * _mainMenuDialog
Definition: engine.h:171
Definition: engine.h:312
void GUIErrorMessage(const Common::U32String &msg, const char *url=nullptr)
Definition: savefile.h:142
Definition: system.h:167
Common::TimerManager * _timer
Definition: engine.h:158
void setMetaEngine(MetaEngine *metaEngine)
Definition: engine.h:534
Common::SaveFileManager * getSaveFileManager()
Definition: engine.h:625
virtual GUI::Debugger * getDebugger() final
Definition: engine.h:357
Definition: engine.h:282
Definition: events.h:471
Definition: engine.h:143
Definition: system.h:37
virtual Common::String getSaveStateName(int slot) const
Definition: engine.h:416
Common::SaveFileManager * _saveFileMan
Definition: engine.h:166
virtual bool hasFeature(EngineFeature f) const
Definition: engine.h:380
Definition: singleton.h:42
virtual bool canSaveAutosaveCurrently()
Definition: engine.h:655
Audio::Mixer * _mixer
Definition: engine.h:152