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
36class OSystem;
38class MetaEngine;
39
40namespace Audio {
41class Mixer;
42}
43namespace Common {
44class Error;
45class FSDirectory;
46class EventManager;
47class SaveFileManager;
48class TimerManager;
49class FSNode;
50class SeekableReadStream;
51class WriteStream;
52}
53namespace GUI {
54class Debugger;
55class Dialog;
56}
57namespace Graphics {
58struct HotspotInfo;
59}
60
73void GUIErrorMessage(const Common::U32String &msg, const char *url = nullptr);
77void GUIErrorMessage(const Common::String &msg, const char *url = nullptr);
81void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url);
85void GUIErrorMessageWithURL(const Common::String &msg, const char *url);
93template<class... TParam>
94inline void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param) {
95 GUIErrorMessageFormatU32StringPtr(&fmt, Common::forward<TParam>(param)...);
96}
100void GUIErrorMessageFormat(MSVC_PRINTF const char *fmt, ...) GCC_PRINTF(1, 2);
101
102
103class Engine;
104
111public:
112 constexpr PauseToken() : _engine(nullptr) {}
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
139private:
140 constexpr PauseToken(Engine *engine) : _engine(engine) {}
141
142 Engine *_engine;
146 friend class Engine;
147};
148
149class Engine {
150public:
159
160protected:
173
181 virtual int runDialog(GUI::Dialog &dialog);
182
187
188 int32 _activeEnhancements = kEnhGameBreakingBugFixes;
189
194
201
208
209private:
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
274public:
288
297
306
315
323
333
340
345 };
346
347
348
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
408
412 virtual bool hasFeature(EngineFeature f) const { return false; }
413
414 bool enhancementEnabled(int32 cls) const;
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
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
522
527
528protected:
534 virtual void pauseEngineIntern(bool pause);
535
545
552 virtual void drawHotspots();
553
564 virtual bool hotspotDirty() const;
565
569public:
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
613private:
620 void resumeEngine();
624 friend class PauseToken;
625
631 bool warnBeforeOverwritingAutosave();
632
633public:
634
638 bool isPaused() const { return _pauseLevel != 0; }
639
644
654
664
669
678
685
691 uint32 getTotalPlayTime() const;
692
702 void setTotalPlayTime(uint32 time = 0);
703
716
717public:
721 bool existExtractedCDAudioFiles(uint track = 1);
731
736
741
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
780protected:
785};
786
787
799class ChainedGamesManager : public Common::Singleton<ChainedGamesManager> {
800private:
801 struct Game {
802 Common::String target;
803 int slot;
804 };
805
806 Common::Queue<Game> _chainedGames;
807
808public:
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() //FIXME
824extern Engine *g_engine;
826#endif
Definition: mixer.h:70
Definition: engine.h:799
void push(const Common::String &target, const int slot=-1)
bool pop(Common::String &target, int &slot)
bool empty()
Definition: engine.h:817
Definition: array.h:52
Definition: error.h:81
Definition: events.h:491
Definition: fs.h:341
Definition: fs.h:69
Definition: savefile.h:142
Definition: stream.h:745
Definition: singleton.h:42
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: timer.h:40
Definition: ustr.h:57
Definition: stream.h:77
Definition: engine.h:149
static bool shouldQuit()
void defaultSyncSoundSettings()
void saveAutosaveIfEnabled()
bool isDataAndCDAudioReadFromSameCD()
Common::TimerManager * getTimerManager()
Definition: engine.h:707
virtual void drawHotspots()
Common::ErrorCode updateAddOns(const MetaEngine *metaEngine) const
bool isPaused() const
Definition: engine.h:638
virtual Common::Error loadGameStream(Common::SeekableReadStream *stream)
bool loadGameDialog()
virtual int getAutosaveSlot() const
Definition: engine.h:755
virtual void getHotspotPositions(Common::Array< Graphics::HotspotInfo > &hotspots)
virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size)
void openMainMenuDialog()
static void errorAddingAddOnWithoutBaseGame(Common::String addOnName, Common::String gameId)
virtual ~Engine()
bool _showHotspots
Definition: engine.h:193
static bool warnUserAboutUnsupportedAddOn(Common::String addOnName)
virtual bool dirCanBeGameAddOn(const Common::FSDirectory &dir) const
bool existExtractedCDAudioFiles(uint track=1)
virtual Common::String getSaveStateName(int slot) const
Definition: engine.h:450
void setDebugger(GUI::Debugger *debugger)
Definition: engine.h:397
void setGameToLoadSlot(int slot)
bool _hotspotForceRedraw
Definition: engine.h:200
static void warnUserAboutTestingMode()
Common::SaveFileManager * _saveFileMan
Definition: engine.h:172
static void quitGame()
virtual void initializePath(const Common::FSNode &gamePath)
virtual GUI::Debugger * getDebugger() final
Definition: engine.h:389
virtual Common::Error run()=0
void setMetaEngine(MetaEngine *metaEngine)
Definition: engine.h:600
const Common::String _targetName
Definition: engine.h:186
Common::TimerManager * _timer
Definition: engine.h:164
virtual void pauseEngineIntern(bool pause)
static void errorUnsupportedGame(Common::String extraMsg)
void warnMissingExtractedCDAudio()
virtual bool dirMustBeGameAddOn(const Common::FSDirectory &dir) const
virtual bool gameTypeHasAddOns() const
MetaEngine * getMetaEngine() const
Definition: engine.h:595
Engine(OSystem *syst)
GUI::Debugger * getOrCreateDebugger()
Common::EventManager * _eventMan
Definition: engine.h:168
Common::SaveFileManager * getSaveFileManager()
Definition: engine.h:715
virtual bool hotspotDirty() const
OSystem * _system
Definition: engine.h:154
void setTotalPlayTime(uint32 time=0)
virtual void syncSoundSettings()
virtual bool canLoadGameStateCurrently(Common::U32String *msg=nullptr)
virtual Common::Error loadGameState(int slot)
virtual bool canSaveAutosaveCurrently()
Definition: engine.h:745
virtual Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false)
PauseToken pauseEngine()
EngineFeature
Definition: engine.h:282
@ kSupportsHelp
Definition: engine.h:339
@ kSupportsReturnToLauncher
Definition: engine.h:296
@ kSupportsQuitDialogOverride
Definition: engine.h:344
@ kSupportsSavingDuringRuntime
Definition: engine.h:314
@ kSupportsLoadingDuringRuntime
Definition: engine.h:305
@ kSupportsArbitraryResolutions
Definition: engine.h:332
@ kSupportsSubtitleOptions
Definition: engine.h:287
@ kSupportsChangingOptionsDuringRuntime
Definition: engine.h:322
virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false)
virtual void applyGameSettings()
Definition: engine.h:440
void handleAutoSave()
virtual bool hasFeature(EngineFeature f) const
Definition: engine.h:412
bool _hotspotPrevCursorVisible
Definition: engine.h:207
Audio::Mixer * _mixer
Definition: engine.h:158
Common::EventManager * getEventManager()
Definition: engine.h:711
virtual int runDialog(GUI::Dialog &dialog)
virtual void showHotspots(bool show)
virtual bool canSaveGameStateCurrently(Common::U32String *msg=nullptr)
uint32 getTotalPlayTime() const
static bool warnUserAboutUnsupportedGame(Common::String msg=Common::String())
bool saveGameDialog()
GUI::Dialog * _mainMenuDialog
Definition: engine.h:177
virtual void flipMute()
Definition: debugger.h:41
Definition: dialog.h:49
Definition: metaengine.h:126
Definition: metaengine.h:202
Definition: system.h:166
Definition: engine.h:110
void operator=(const PauseToken &)
bool isActive() const
Definition: engine.h:137
PauseToken(const PauseToken &)
void clear()
ErrorCode
Definition: error.h:47
int FORCEINLINE GCC_PRINTF(2, 0) int vsprintf_s(T(&dst)[N]
void GUIErrorMessageFormat(const Common::U32String &fmt, TParam... param)
Definition: engine.h:94
Engine * g_engine
void GUIErrorMessage(const Common::U32String &msg, const char *url=nullptr)
void GUIErrorMessageWithURL(const Common::U32String &msg, const char *url)
void GUIErrorMessageFormatU32StringPtr(const Common::U32String *fmt,...)
Definition: system.h:39
Definition: algorithm.h:29
Definition: formatinfo.h:28