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/array.h"
26 #include "common/error.h"
27 #include "common/rect.h"
28 #include "common/scummsys.h"
29 #include "common/str.h"
30 #include "common/language.h"
31 #include "common/platform.h"
32 #include "common/queue.h"
33 #include "common/singleton.h"
34 #include "engines/enhancements.h"
35 
36 class OSystem;
38 class MetaEngine;
39 
40 namespace Audio {
41 class Mixer;
42 }
43 namespace Common {
44 class Error;
45 class FSDirectory;
46 class EventManager;
47 class SaveFileManager;
48 class TimerManager;
49 class FSNode;
50 class SeekableReadStream;
51 class WriteStream;
52 }
53 namespace GUI {
54 class Debugger;
55 class Dialog;
56 }
57 namespace Graphics {
58 struct HotspotInfo;
59 }
60 
73 void GUIErrorMessage(const Common::U32String &msg, const char *url = nullptr);
77 void GUIErrorMessage(const Common::String &msg, const char *url = nullptr);
81 void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url);
85 void GUIErrorMessageWithURL(const Common::String &msg, const char *url);
93 template<class... TParam>
94 inline void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param) {
95  GUIErrorMessageFormatU32StringPtr(&fmt, Common::forward<TParam>(param)...);
96 }
100 void GUIErrorMessageFormat(MSVC_PRINTF const char *fmt, ...) GCC_PRINTF(1, 2);
101 
102 
103 class Engine;
104 
110 class PauseToken {
111 public:
112  constexpr PauseToken() : _engine(nullptr) {}
116  PauseToken(const PauseToken &);
117  PauseToken(PauseToken &&);
118  ~PauseToken();
119 
123  void operator=(const PauseToken &);
124  void operator=(PauseToken &&);
125 
131  void clear();
132 
137  bool isActive() const { return _engine != nullptr; }
138 
139 private:
140  constexpr PauseToken(Engine *engine) : _engine(engine) {}
141 
142  Engine *_engine;
146  friend class Engine;
147 };
148 
149 class Engine {
150 public:
159 
160 protected:
173 
181  virtual int runDialog(GUI::Dialog &dialog);
182 
187 
188  int32 _activeEnhancements = kEnhGameBreakingBugFixes;
189 
194 
201 
208 
209 private:
213  MetaEngine *_metaEngine;
214 
222  int _pauseLevel;
223 
227  uint32 _pauseStartTime;
228 
232  int _pauseScreenChangeID;
233 
239  int32 _engineStartTime;
240 
244  int _autosaveInterval;
245 
249  int _lastAutosaveTime;
250 
257  int _saveSlotToLoad;
258 
262  bool _autoSaving;
263 
267  GUI::Debugger *_debugger;
268 
272  static bool _quitRequested;
273 
274 public:
288 
297 
306 
315 
323 
333 
340 
345  };
346 
347 
348 
358  Engine(OSystem *syst);
362  virtual ~Engine();
363 
372  virtual void initializePath(const Common::FSNode &gamePath);
373 
379  virtual Common::Error run() = 0;
380 
384  virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size);
385 
389  virtual GUI::Debugger *getDebugger() final { return _debugger; }
390 
397  void setDebugger(GUI::Debugger *debugger) {
398  assert(!_debugger);
399  _debugger = debugger;
400  }
401 
407  GUI::Debugger *getOrCreateDebugger();
408 
412  virtual bool hasFeature(EngineFeature f) const { return false; }
413 
414  bool enhancementEnabled(int32 cls);
415 
433  virtual void syncSoundSettings();
434 
440  virtual void applyGameSettings() {}
441 
445  virtual void flipMute();
446 
450  virtual Common::String getSaveStateName(int slot) const {
451  return Common::String::format("%s.%03d", _targetName.c_str(), slot);
452  }
453 
461  virtual Common::Error loadGameState(int slot);
462 
470  virtual Common::Error loadGameStream(Common::SeekableReadStream *stream);
471 
481  void setGameToLoadSlot(int slot);
482 
488  virtual bool canLoadGameStateCurrently(Common::U32String *msg = nullptr);
489 
499  virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false);
500 
509  virtual Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false);
510 
516  virtual bool canSaveGameStateCurrently(Common::U32String *msg = nullptr);
517 
521  bool saveGameDialog();
522 
526  bool loadGameDialog();
527 
528 protected:
534  virtual void pauseEngineIntern(bool pause);
535 
544  virtual void getHotspotPositions(Common::Array<Graphics::HotspotInfo> &hotspots);
545 
552  virtual void drawHotspots();
553 
564  virtual bool hotspotDirty() const;
565 
569 public:
570 
576  virtual void showHotspots(bool show);
577 
583  static void quitGame();
584 
590  static bool shouldQuit();
591 
595  inline MetaEngine *getMetaEngine() const { return _metaEngine; }
596 
600  inline void setMetaEngine(MetaEngine *metaEngine) { _metaEngine = metaEngine; }
601 
612  PauseToken pauseEngine();
613 private:
620  void resumeEngine();
624  friend class PauseToken;
625 
631  bool warnBeforeOverwritingAutosave();
632 
633 public:
634 
638  bool isPaused() const { return _pauseLevel != 0; }
639 
643  void openMainMenuDialog();
644 
653  static bool warnUserAboutUnsupportedGame(Common::String msg = Common::String());
654 
663  static bool warnUserAboutUnsupportedAddOn(Common::String addOnName);
664 
668  static void warnUserAboutTestingMode();
669 
677  static void errorAddingAddOnWithoutBaseGame(Common::String addOnName, Common::String gameId);
678 
684  static void errorUnsupportedGame(Common::String extraMsg);
685 
691  uint32 getTotalPlayTime() const;
692 
702  void setTotalPlayTime(uint32 time = 0);
703 
707  inline Common::TimerManager *getTimerManager() { return _timer; }
711  inline Common::EventManager *getEventManager() { return _eventMan; }
715  inline Common::SaveFileManager *getSaveFileManager() { return _saveFileMan; }
716 
717 public:
721  bool existExtractedCDAudioFiles(uint track = 1);
726  bool isDataAndCDAudioReadFromSameCD();
730  void warnMissingExtractedCDAudio();
731 
735  void handleAutoSave();
736 
740  void saveAutosaveIfEnabled();
741 
745  virtual bool canSaveAutosaveCurrently() {
746  return canSaveGameStateCurrently();
747  }
748 
755  virtual int getAutosaveSlot() const {
756  return 0;
757  }
758 
762  virtual bool gameTypeHasAddOns() const;
763 
767  virtual bool dirCanBeGameAddOn(const Common::FSDirectory &dir) const;
768 
772  virtual bool dirMustBeGameAddOn(const Common::FSDirectory &dir) const;
773 
777  Common::ErrorCode updateAddOns(const MetaEngine *metaEngine) const;
778 
779 
780 protected:
784  void defaultSyncSoundSettings();
785 };
786 
787 
799 class ChainedGamesManager : public Common::Singleton<ChainedGamesManager> {
800 private:
801  struct Game {
802  Common::String target;
803  int slot;
804  };
805 
806  Common::Queue<Game> _chainedGames;
807 
808 public:
811  void clear();
813  void push(const Common::String &target, const int slot = -1);
815  bool pop(Common::String &target, int &slot);
817  bool empty() { return _chainedGames.empty(); }
818 };
819 
821 #define ChainedGamesMan ChainedGamesManager::instance()
822  //FIXME
824 extern Engine *g_engine;
826 #endif
Definition: engine.h:799
virtual int getAutosaveSlot() const
Definition: engine.h:755
Definition: engine.h:110
Common::TimerManager * getTimerManager()
Definition: engine.h:707
Definition: metaengine.h:202
bool _hotspotPrevCursorVisible
Definition: engine.h:207
Definition: str.h:59
EngineFeature
Definition: engine.h:282
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: stream.h:77
Definition: error.h:81
bool _showHotspots
Definition: engine.h:193
Definition: engine.h:287
Definition: array.h:52
bool isActive() const
Definition: engine.h:137
Definition: debugger.h:41
Definition: engine.h:339
ErrorCode
Definition: error.h:47
bool empty()
Definition: engine.h:817
Definition: stream.h:745
OSystem * _system
Definition: engine.h:154
Definition: printman.h:30
MetaEngine * getMetaEngine() const
Definition: engine.h:595
Engine * g_engine
Definition: engine.h:296
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:440
Definition: algorithm.h:29
Definition: fs.h:69
Definition: formatinfo.h:28
void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param)
Definition: engine.h:94
Definition: metaengine.h:126
void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url)
const Common::String _targetName
Definition: engine.h:186
Common::EventManager * getEventManager()
Definition: engine.h:711
Common::EventManager * _eventMan
Definition: engine.h:168
bool isPaused() const
Definition: engine.h:638
bool _hotspotForceRedraw
Definition: engine.h:200
void setDebugger(GUI::Debugger *debugger)
Definition: engine.h:397
Definition: dialog.h:49
GUI::Dialog * _mainMenuDialog
Definition: engine.h:177
Definition: engine.h:344
void GUIErrorMessage(const Common::U32String &msg, const char *url=nullptr)
Definition: fs.h:341
Definition: savefile.h:142
Definition: system.h:166
Common::TimerManager * _timer
Definition: engine.h:164
void setMetaEngine(MetaEngine *metaEngine)
Definition: engine.h:600
Common::SaveFileManager * getSaveFileManager()
Definition: engine.h:715
virtual GUI::Debugger * getDebugger() final
Definition: engine.h:389
Definition: engine.h:314
Definition: events.h:491
Definition: engine.h:149
Definition: system.h:39
virtual Common::String getSaveStateName(int slot) const
Definition: engine.h:450
Common::SaveFileManager * _saveFileMan
Definition: engine.h:172
virtual bool hasFeature(EngineFeature f) const
Definition: engine.h:412
Definition: singleton.h:42
virtual bool canSaveAutosaveCurrently()
Definition: engine.h:745
Audio::Mixer * _mixer
Definition: engine.h:158