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/error.h"
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 #include "engines/enhancements.h"
33 
34 class OSystem;
36 class MetaEngine;
37 
38 namespace Audio {
39 class Mixer;
40 }
41 namespace Common {
42 class Error;
43 class FSDirectory;
44 class EventManager;
45 class SaveFileManager;
46 class TimerManager;
47 class FSNode;
48 class SeekableReadStream;
49 class WriteStream;
50 }
51 namespace GUI {
52 class Debugger;
53 class Dialog;
54 }
55 
68 void GUIErrorMessage(const Common::U32String &msg, const char *url = nullptr);
72 void GUIErrorMessage(const Common::String &msg, const char *url = nullptr);
76 void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url);
80 void GUIErrorMessageWithURL(const Common::String &msg, const char *url);
88 template<class... TParam>
89 inline void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param) {
90  GUIErrorMessageFormatU32StringPtr(&fmt, Common::forward<TParam>(param)...);
91 }
95 void GUIErrorMessageFormat(MSVC_PRINTF const char *fmt, ...) GCC_PRINTF(1, 2);
96 
97 
98 class Engine;
99 
105 class PauseToken {
106 public:
107  constexpr PauseToken() : _engine(nullptr) {}
111  PauseToken(const PauseToken &);
112 #if __cplusplus >= 201103L
113  PauseToken(PauseToken &&);
114 #endif
115  ~PauseToken();
119  void operator=(const PauseToken &);
120 #if __cplusplus >= 201103L
121  void operator=(PauseToken &&);
122 #endif
123 
128  void clear();
129 
134  bool isActive() const { return _engine != nullptr; }
135 
136 private:
137  constexpr PauseToken(Engine *engine) : _engine(engine) {}
138 
139  Engine *_engine;
143  friend class Engine;
144 };
145 
146 class Engine {
147 public:
156 
157 protected:
170 
178  virtual int runDialog(GUI::Dialog &dialog);
179 
184 
185  int32 _activeEnhancements = kEnhGameBreakingBugFixes;
186 
187 private:
191  MetaEngine *_metaEngine;
192 
200  int _pauseLevel;
201 
205  uint32 _pauseStartTime;
206 
210  int _pauseScreenChangeID;
211 
217  int32 _engineStartTime;
218 
222  int _autosaveInterval;
223 
227  int _lastAutosaveTime;
228 
235  int _saveSlotToLoad;
236 
240  bool _autoSaving;
241 
245  GUI::Debugger *_debugger;
246 
250  static bool _quitRequested;
251 
252 public:
266 
275 
284 
293 
301 
311 
318 
323  };
324 
325 
326 
336  Engine(OSystem *syst);
340  virtual ~Engine();
341 
350  virtual void initializePath(const Common::FSNode &gamePath);
351 
357  virtual Common::Error run() = 0;
358 
362  virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size);
363 
367  virtual GUI::Debugger *getDebugger() final { return _debugger; }
368 
375  void setDebugger(GUI::Debugger *debugger) {
376  assert(!_debugger);
377  _debugger = debugger;
378  }
379 
385  GUI::Debugger *getOrCreateDebugger();
386 
390  virtual bool hasFeature(EngineFeature f) const { return false; }
391 
392  bool enhancementEnabled(int32 cls);
393 
411  virtual void syncSoundSettings();
412 
418  virtual void applyGameSettings() {}
419 
423  virtual void flipMute();
424 
428  virtual Common::String getSaveStateName(int slot) const {
429  return Common::String::format("%s.%03d", _targetName.c_str(), slot);
430  }
431 
439  virtual Common::Error loadGameState(int slot);
440 
448  virtual Common::Error loadGameStream(Common::SeekableReadStream *stream);
449 
459  void setGameToLoadSlot(int slot);
460 
466  virtual bool canLoadGameStateCurrently(Common::U32String *msg = nullptr);
467 
477  virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false);
478 
487  virtual Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false);
488 
494  virtual bool canSaveGameStateCurrently(Common::U32String *msg = nullptr);
495 
499  bool saveGameDialog();
500 
504  bool loadGameDialog();
505 
506 protected:
512  virtual void pauseEngineIntern(bool pause);
513 
517 public:
518 
524  static void quitGame();
525 
531  static bool shouldQuit();
532 
536  inline MetaEngine *getMetaEngine() const { return _metaEngine; }
537 
541  inline void setMetaEngine(MetaEngine *metaEngine) { _metaEngine = metaEngine; }
542 
553  PauseToken pauseEngine();
554 private:
561  void resumeEngine();
565  friend class PauseToken;
566 
572  bool warnBeforeOverwritingAutosave();
573 
574 public:
575 
579  bool isPaused() const { return _pauseLevel != 0; }
580 
584  void openMainMenuDialog();
585 
594  static bool warnUserAboutUnsupportedGame(Common::String msg = Common::String());
595 
604  static bool warnUserAboutUnsupportedAddOn(Common::String addOnName);
605 
613  static void errorAddingAddOnWithoutBaseGame(Common::String addOnName, Common::String gameId);
614 
620  static void errorUnsupportedGame(Common::String extraMsg);
621 
627  uint32 getTotalPlayTime() const;
628 
638  void setTotalPlayTime(uint32 time = 0);
639 
643  inline Common::TimerManager *getTimerManager() { return _timer; }
647  inline Common::EventManager *getEventManager() { return _eventMan; }
651  inline Common::SaveFileManager *getSaveFileManager() { return _saveFileMan; }
652 
653 public:
657  bool existExtractedCDAudioFiles(uint track = 1);
662  bool isDataAndCDAudioReadFromSameCD();
666  void warnMissingExtractedCDAudio();
667 
671  void handleAutoSave();
672 
676  void saveAutosaveIfEnabled();
677 
681  virtual bool canSaveAutosaveCurrently() {
682  return canSaveGameStateCurrently();
683  }
684 
691  virtual int getAutosaveSlot() const {
692  return 0;
693  }
694 
698  virtual bool gameTypeHasAddOns() const;
699 
703  virtual bool dirCanBeGameAddOn(const Common::FSDirectory &dir) const;
704 
708  virtual bool dirMustBeGameAddOn(const Common::FSDirectory &dir) const;
709 
713  Common::ErrorCode updateAddOns(const MetaEngine *metaEngine) const;
714 
715 
716 protected:
720  void defaultSyncSoundSettings();
721 };
722 
723 
735 class ChainedGamesManager : public Common::Singleton<ChainedGamesManager> {
736 private:
737  struct Game {
738  Common::String target;
739  int slot;
740  };
741 
742  Common::Queue<Game> _chainedGames;
743 
744 public:
747  void clear();
749  void push(const Common::String &target, const int slot = -1);
751  bool pop(Common::String &target, int &slot);
753  bool empty() { return _chainedGames.empty(); }
754 };
755 
757 #define ChainedGamesMan ChainedGamesManager::instance()
758  //FIXME
760 extern Engine *g_engine;
762 #endif
Definition: engine.h:735
virtual int getAutosaveSlot() const
Definition: engine.h:691
Definition: engine.h:105
Common::TimerManager * getTimerManager()
Definition: engine.h:643
Definition: metaengine.h:202
Definition: str.h:59
EngineFeature
Definition: engine.h:260
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: stream.h:77
Definition: error.h:81
Definition: engine.h:265
bool isActive() const
Definition: engine.h:134
Definition: debugger.h:41
Definition: engine.h:317
ErrorCode
Definition: error.h:47
bool empty()
Definition: engine.h:753
Definition: stream.h:745
OSystem * _system
Definition: engine.h:151
Definition: system.h:46
MetaEngine * getMetaEngine() const
Definition: engine.h:536
Engine * g_engine
Definition: engine.h:274
int FORCEINLINE GCC_PRINTF(2, 0) int vsprintf_s(T(&dst)[N]
Definition: mixer.h:70
Definition: timer.h:40
void GUIErrorMessageFormatU32StringPtr(const Common::U32String *fmt,...)
Definition: ustr.h:57
virtual void applyGameSettings()
Definition: engine.h:418
Definition: algorithm.h:29
Definition: fs.h:69
void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param)
Definition: engine.h:89
Definition: metaengine.h:126
void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url)
const Common::String _targetName
Definition: engine.h:183
Common::EventManager * getEventManager()
Definition: engine.h:647
Common::EventManager * _eventMan
Definition: engine.h:165
bool isPaused() const
Definition: engine.h:579
void setDebugger(GUI::Debugger *debugger)
Definition: engine.h:375
Definition: dialog.h:49
GUI::Dialog * _mainMenuDialog
Definition: engine.h:174
Definition: engine.h:322
void GUIErrorMessage(const Common::U32String &msg, const char *url=nullptr)
Definition: fs.h:341
Definition: savefile.h:142
Definition: system.h:163
Common::TimerManager * _timer
Definition: engine.h:161
void setMetaEngine(MetaEngine *metaEngine)
Definition: engine.h:541
Common::SaveFileManager * getSaveFileManager()
Definition: engine.h:651
virtual GUI::Debugger * getDebugger() final
Definition: engine.h:367
Definition: engine.h:292
Definition: events.h:483
Definition: engine.h:146
Definition: system.h:38
virtual Common::String getSaveStateName(int slot) const
Definition: engine.h:428
Common::SaveFileManager * _saveFileMan
Definition: engine.h:169
virtual bool hasFeature(EngineFeature f) const
Definition: engine.h:390
Definition: singleton.h:42
virtual bool canSaveAutosaveCurrently()
Definition: engine.h:681
Audio::Mixer * _mixer
Definition: engine.h:155