ScummVM
engine.h
Go to the documentation of this file.
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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ENGINES_ENGINE_H
24 #define ENGINES_ENGINE_H
25 
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 
33 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 
56 void GUIErrorMessage(const Common::String &msg);
57 void GUIErrorMessageFormat(const char *fmt, ...) GCC_PRINTF(1, 2);
58 
59 
60 class Engine {
61 public:
64 
65 protected:
69 
71  virtual int runDialog(GUI::Dialog &dialog);
72 
73  const Common::String _targetName; // target name for saves
74 
75 private:
83 
88 
94 
98  const int _autosaveInterval;
99 
104 
111 
116 public:
117 
118 
130 
137 
145 
152  kSupportsSavingDuringRuntime
153  };
154 
155 
156 
162 
163  Engine(OSystem *syst);
164  virtual ~Engine();
165 
174  virtual void initializePath(const Common::FSNode &gamePath);
175 
180  virtual Common::Error run() = 0;
181 
185  virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size);
186 
190  virtual GUI::Debugger *getDebugger() { return _debugger; }
191 
196  void setDebugger(GUI::Debugger *debugger) {
197  assert(!_debugger);
198  _debugger = debugger;
199  }
200 
205  GUI::Debugger *getOrCreateDebugger();
206 
210  virtual bool hasFeature(EngineFeature f) const { return false; }
211 
212 // virtual EnginePlugin *getMetaEnginePlugin() const;
213 
229  virtual void syncSoundSettings();
230 
234  virtual void flipMute();
235 
239  virtual Common::String getSaveStateName(int slot) const {
240  return Common::String::format("%s.%03d", _targetName.c_str(), slot);
241  }
242 
248  virtual Common::Error loadGameState(int slot);
249 
255  virtual Common::Error loadGameStream(Common::SeekableReadStream *stream);
256 
264  void setGameToLoadSlot(int slot);
265 
269  virtual bool canLoadGameStateCurrently();
270 
278  virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false);
279 
286  virtual Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false);
287 
291  virtual bool canSaveGameStateCurrently();
292 
296  bool saveGameDialog();
297 
301  bool loadGameDialog();
302 
303 protected:
308  virtual void pauseEngineIntern(bool pause);
309 
311 
312 
313 public:
314 
319  static void quitGame();
320 
325  static bool shouldQuit();
326 
327  static MetaEngine &getMetaEngine();
328 
340  void pauseEngine(bool pause);
341 
345  bool isPaused() const { return _pauseLevel != 0; }
346 
350  void openMainMenuDialog();
351 
357  static bool warnUserAboutUnsupportedGame();
358 
364  uint32 getTotalPlayTime() const;
365 
375  void setTotalPlayTime(uint32 time = 0);
376 
377  inline Common::TimerManager *getTimerManager() { return _timer; }
378  inline Common::EventManager *getEventManager() { return _eventMan; }
379  inline Common::SaveFileManager *getSaveFileManager() { return _saveFileMan; }
380 
381 public:
383  void checkCD();
384 
385 
389  void handleAutoSave();
390 
394  void saveAutosaveIfEnabled();
395 
399  virtual bool canSaveAutosaveCurrently() {
400  return canSaveGameStateCurrently();
401  }
402 
407  virtual int getAutosaveSlot() const {
408  return 0;
409  }
410 
411  bool shouldPerformAutoSave(int lastSaveTime) {
412  // TODO: Remove deprecated method once all engines are refactored
413  // to no longer do autosaves directly themselves
414  return false;
415  }
416 };
417 
418 // Chained games
419 
425 class ChainedGamesManager : public Common::Singleton<ChainedGamesManager> {
426 private:
427  struct Game {
429  int slot;
430  };
431 
433 
434 public:
436  void clear();
437  void push(const Common::String target, const int slot = -1);
438  bool pop(Common::String &target, int &slot);
439 };
440 
442 #define ChainedGamesMan ChainedGamesManager::instance()
443 
444 // FIXME: HACK for MidiEmu & error()
445 extern Engine *g_engine;
446 
447 #endif
Common::TimerManager
Definition: timer.h:32
Engine::_saveSlotToLoad
int _saveSlotToLoad
Save slot selected via global main menu.
Definition: engine.h:110
Engine::getEventManager
Common::EventManager * getEventManager()
Definition: engine.h:378
Common::SeekableReadStream
Interface for a seekable & readable data stream.
Definition: stream.h:569
HDB::dialog
static int dialog(lua_State *L)
Definition: lua-script.cpp:929
Glk::Level9::f
FILE * f
Definition: level9_main.cpp:155
scummsys.h
Engine
Definition: engine.h:60
Engine::getSaveStateName
virtual Common::String getSaveStateName(int slot) const
Generates the savegame filename.
Definition: engine.h:239
str.h
Engine::isPaused
bool isPaused() const
Return whether the engine is currently paused or not.
Definition: engine.h:345
Ultima::Nuvie::shouldQuit
bool shouldQuit()
Definition: events.cpp:3801
Engine::kSupportsLoadingDuringRuntime
Loading savestates during runtime is supported, that is, this engine implements loadGameState() and c...
Definition: engine.h:144
g_engine
Engine * g_engine
Definition: engine.cpp:73
Common::EventManager
The EventManager provides user input events to the client code.
Definition: events.h:411
Engine::_system
OSystem * _system
Definition: engine.h:62
Engine::setDebugger
void setDebugger(GUI::Debugger *debugger)
Sets the engine's debugger.
Definition: engine.h:196
Common::String
Simple string class for ScummVM.
Definition: str.h:49
Engine::kSupportsSubtitleOptions
Enables the subtitle speed and toggle items in the Options section of the global main menu.
Definition: engine.h:129
ChainedGamesManager::Game::target
Common::String target
Definition: engine.h:428
Engine::getTimerManager
Common::TimerManager * getTimerManager()
Definition: engine.h:377
uint32
unsigned int uint32
Definition: cdtypes.h:26
ChainedGamesManager::Game::slot
int slot
Definition: engine.h:429
Common::Error
An Error instance pairs an error code with string description providing more details about the error.
Definition: error.h:77
Sword25::pause
int pause(lua_State *L)
Definition: movieplayer_script.cpp:70
queue.h
singleton.h
ChainedGamesManager::clear
void clear()
Definition: engine.cpp:114
DS::CD::checkCD
bool checkCD()
Definition: cdaudio.cpp:519
Common::SaveFileManager
The SaveFileManager is serving as a factory for InSaveFile and OutSaveFile objects.
Definition: savefile.h:82
ChainedGamesManager::pop
bool pop(Common::String &target, int &slot)
Definition: engine.cpp:125
ChainedGamesManager::push
void push(const Common::String target, const int slot=-1)
Definition: engine.cpp:118
ChainedGamesManager::_chainedGames
Common::Queue< Game > _chainedGames
Definition: engine.h:432
Engine::kSupportsRTL
'Return to launcher' feature is supported, i.e., EVENT_RTL is handled either directly,...
Definition: engine.h:136
ChainedGamesManager::Game
Definition: engine.h:427
Common
This is the namespace of the AGOS engine.
Definition: default-audiocd.h:29
ChainedGamesManager
Singleton class which manages chained games.
Definition: engine.h:425
GUI::Debugger
Definition: debugger.h:40
GUIErrorMessage
void GUIErrorMessage(const Common::String &msg)
Initializes graphics and shows error message.
Definition: engine.cpp:394
Engine::_lastAutosaveTime
int _lastAutosaveTime
The last time an autosave was done.
Definition: engine.h:103
language.h
Engine::EngineFeature
EngineFeature
A feature in this context means an ability of the engine which can be either available or not.
Definition: engine.h:124
MetaEngine
A meta engine is essentially a factory for Engine instances with the added ability of listing and det...
Definition: metaengine.h:96
Engine::_mixer
Audio::Mixer * _mixer
Definition: engine.h:63
Common::String::format
static String format(const char *fmt,...) GCC_PRINTF(1
Print formatted data into a String object.
Definition: str.cpp:641
Common::FSNode
FSNode, short for "File System Node", provides an abstraction for file paths, allowing for portable f...
Definition: fs.h:58
Engine::_autosaveInterval
const int _autosaveInterval
Autosave interval.
Definition: engine.h:98
Engine::_pauseStartTime
uint32 _pauseStartTime
The time when the pause was started.
Definition: engine.h:87
Glk::Alan3::quitGame
void quitGame(CONTEXT)
Definition: exe.cpp:201
GUI
Definition: cloudmanager.h:34
fmt
char fmt[4]
Definition: cdaudio.cpp:43
Engine::_saveFileMan
Common::SaveFileManager * _saveFileMan
Definition: engine.h:68
LastExpress::time
uint32 time
Definition: kronos.cpp:48
Engine::_engineStartTime
int32 _engineStartTime
The time when the engine was started.
Definition: engine.h:93
platform.h
Engine::hasFeature
virtual bool hasFeature(EngineFeature f) const
Determine whether the engine supports the specified feature.
Definition: engine.h:210
Common::WriteStream
Generic interface for a writable data stream.
Definition: stream.h:65
Audio::Mixer
The main audio mixer handles mixing of an arbitrary number of audio streams (in the form of AudioStre...
Definition: mixer.h:53
Common::Singleton
Generic template base class for implementing the singleton design pattern.
Definition: singleton.h:34
Engine::_eventMan
Common::EventManager * _eventMan
Definition: engine.h:67
Ultima::Ultima8::Animation::run
Definition: animation.h:32
GUI::Dialog
Definition: dialog.h:49
Graphics::desc
static const BdfFontData desc
Definition: consolefont.cpp:5852
Engine::getAutosaveSlot
virtual int getAutosaveSlot() const
Returns the slot that should be used for autosaves.
Definition: engine.h:407
Engine::getDebugger
virtual GUI::Debugger * getDebugger()
Return the engine's debugger instance, if any.
Definition: engine.h:190
OSystem
Interface for ScummVM backends.
Definition: system.h:114
Engine::shouldPerformAutoSave
bool shouldPerformAutoSave(int lastSaveTime)
Definition: engine.h:411
Engine::_targetName
const Common::String _targetName
Definition: engine.h:73
Engine::canSaveAutosaveCurrently
virtual bool canSaveAutosaveCurrently()
Indicates whether an autosave can currently be saved.
Definition: engine.h:399
Engine::_pauseLevel
int _pauseLevel
The pause level, 0 means 'running', a positive value indicates how often the engine has been paused (...
Definition: engine.h:82
Common::Queue
Variable size Queue class, implemented using our List class.
Definition: queue.h:35
int32
signed int int32
Definition: cdtypes.h:29
GUIErrorMessageFormat
void GUIErrorMessageFormat(const char *fmt,...) GCC_PRINTF(1
Audio
Definition: systemps2.h:44
ChainedGamesManager::ChainedGamesManager
ChainedGamesManager()
Definition: engine.cpp:110
Engine::getSaveFileManager
Common::SaveFileManager * getSaveFileManager()
Definition: engine.h:379
Engine::_mainMenuDialog
GUI::Dialog * _mainMenuDialog
Definition: engine.h:70
Common::String::c_str
const char * c_str() const
Definition: str.h:206
Engine::_timer
Common::TimerManager * _timer
Definition: engine.h:66
Engine::_debugger
GUI::Debugger * _debugger
Optional debugger for the engine.
Definition: engine.h:115