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  PauseToken(PauseToken &&);
113  ~PauseToken();
114 
118  void operator=(const PauseToken &);
119  void operator=(PauseToken &&);
120 
126  void clear();
127 
132  bool isActive() const { return _engine != nullptr; }
133 
134 private:
135  constexpr PauseToken(Engine *engine) : _engine(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 
208  int _pauseScreenChangeID;
209 
215  int32 _engineStartTime;
216 
220  int _autosaveInterval;
221 
225  int _lastAutosaveTime;
226 
233  int _saveSlotToLoad;
234 
238  bool _autoSaving;
239 
243  GUI::Debugger *_debugger;
244 
248  static bool _quitRequested;
249 
250 public:
264 
273 
282 
291 
299 
309 
316 
321  };
322 
323 
324 
334  Engine(OSystem *syst);
338  virtual ~Engine();
339 
348  virtual void initializePath(const Common::FSNode &gamePath);
349 
355  virtual Common::Error run() = 0;
356 
360  virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size);
361 
365  virtual GUI::Debugger *getDebugger() final { return _debugger; }
366 
373  void setDebugger(GUI::Debugger *debugger) {
374  assert(!_debugger);
375  _debugger = debugger;
376  }
377 
383  GUI::Debugger *getOrCreateDebugger();
384 
388  virtual bool hasFeature(EngineFeature f) const { return false; }
389 
390  bool enhancementEnabled(int32 cls);
391 
409  virtual void syncSoundSettings();
410 
416  virtual void applyGameSettings() {}
417 
421  virtual void flipMute();
422 
426  virtual Common::String getSaveStateName(int slot) const {
427  return Common::String::format("%s.%03d", _targetName.c_str(), slot);
428  }
429 
437  virtual Common::Error loadGameState(int slot);
438 
446  virtual Common::Error loadGameStream(Common::SeekableReadStream *stream);
447 
457  void setGameToLoadSlot(int slot);
458 
464  virtual bool canLoadGameStateCurrently(Common::U32String *msg = nullptr);
465 
475  virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false);
476 
485  virtual Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false);
486 
492  virtual bool canSaveGameStateCurrently(Common::U32String *msg = nullptr);
493 
497  bool saveGameDialog();
498 
502  bool loadGameDialog();
503 
504 protected:
510  virtual void pauseEngineIntern(bool pause);
511 
515 public:
516 
522  static void quitGame();
523 
529  static bool shouldQuit();
530 
534  inline MetaEngine *getMetaEngine() const { return _metaEngine; }
535 
539  inline void setMetaEngine(MetaEngine *metaEngine) { _metaEngine = metaEngine; }
540 
551  PauseToken pauseEngine();
552 private:
559  void resumeEngine();
563  friend class PauseToken;
564 
570  bool warnBeforeOverwritingAutosave();
571 
572 public:
573 
577  bool isPaused() const { return _pauseLevel != 0; }
578 
582  void openMainMenuDialog();
583 
592  static bool warnUserAboutUnsupportedGame(Common::String msg = Common::String());
593 
602  static bool warnUserAboutUnsupportedAddOn(Common::String addOnName);
603 
611  static void errorAddingAddOnWithoutBaseGame(Common::String addOnName, Common::String gameId);
612 
618  static void errorUnsupportedGame(Common::String extraMsg);
619 
625  uint32 getTotalPlayTime() const;
626 
636  void setTotalPlayTime(uint32 time = 0);
637 
641  inline Common::TimerManager *getTimerManager() { return _timer; }
645  inline Common::EventManager *getEventManager() { return _eventMan; }
649  inline Common::SaveFileManager *getSaveFileManager() { return _saveFileMan; }
650 
651 public:
655  bool existExtractedCDAudioFiles(uint track = 1);
660  bool isDataAndCDAudioReadFromSameCD();
664  void warnMissingExtractedCDAudio();
665 
669  void handleAutoSave();
670 
674  void saveAutosaveIfEnabled();
675 
679  virtual bool canSaveAutosaveCurrently() {
680  return canSaveGameStateCurrently();
681  }
682 
689  virtual int getAutosaveSlot() const {
690  return 0;
691  }
692 
696  virtual bool gameTypeHasAddOns() const;
697 
701  virtual bool dirCanBeGameAddOn(const Common::FSDirectory &dir) const;
702 
706  virtual bool dirMustBeGameAddOn(const Common::FSDirectory &dir) const;
707 
711  Common::ErrorCode updateAddOns(const MetaEngine *metaEngine) const;
712 
713 
714 protected:
718  void defaultSyncSoundSettings();
719 };
720 
721 
733 class ChainedGamesManager : public Common::Singleton<ChainedGamesManager> {
734 private:
735  struct Game {
736  Common::String target;
737  int slot;
738  };
739 
740  Common::Queue<Game> _chainedGames;
741 
742 public:
745  void clear();
747  void push(const Common::String &target, const int slot = -1);
749  bool pop(Common::String &target, int &slot);
751  bool empty() { return _chainedGames.empty(); }
752 };
753 
755 #define ChainedGamesMan ChainedGamesManager::instance()
756  //FIXME
758 extern Engine *g_engine;
760 #endif
Definition: engine.h:733
virtual int getAutosaveSlot() const
Definition: engine.h:689
Definition: engine.h:105
Common::TimerManager * getTimerManager()
Definition: engine.h:641
Definition: metaengine.h:202
Definition: str.h:59
EngineFeature
Definition: engine.h:258
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: stream.h:77
Definition: error.h:81
Definition: engine.h:263
bool isActive() const
Definition: engine.h:132
Definition: debugger.h:41
Definition: engine.h:315
ErrorCode
Definition: error.h:47
bool empty()
Definition: engine.h:751
Definition: stream.h:745
OSystem * _system
Definition: engine.h:149
Definition: system.h:46
MetaEngine * getMetaEngine() const
Definition: engine.h:534
Engine * g_engine
Definition: engine.h:272
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:416
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:181
Common::EventManager * getEventManager()
Definition: engine.h:645
Common::EventManager * _eventMan
Definition: engine.h:163
bool isPaused() const
Definition: engine.h:577
void setDebugger(GUI::Debugger *debugger)
Definition: engine.h:373
Definition: dialog.h:49
GUI::Dialog * _mainMenuDialog
Definition: engine.h:172
Definition: engine.h:320
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:159
void setMetaEngine(MetaEngine *metaEngine)
Definition: engine.h:539
Common::SaveFileManager * getSaveFileManager()
Definition: engine.h:649
virtual GUI::Debugger * getDebugger() final
Definition: engine.h:365
Definition: engine.h:290
Definition: events.h:483
Definition: engine.h:144
Definition: system.h:38
virtual Common::String getSaveStateName(int slot) const
Definition: engine.h:426
Common::SaveFileManager * _saveFileMan
Definition: engine.h:167
virtual bool hasFeature(EngineFeature f) const
Definition: engine.h:388
Definition: singleton.h:42
virtual bool canSaveAutosaveCurrently()
Definition: engine.h:679
Audio::Mixer * _mixer
Definition: engine.h:153