ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

engine.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef ENGINES_ENGINE_H
00024 #define ENGINES_ENGINE_H
00025 
00026 #include "common/scummsys.h"
00027 #include "common/str.h"
00028 #include "common/language.h"
00029 #include "common/platform.h"
00030 #include "common/queue.h"
00031 #include "common/singleton.h"
00032 
00033 class OSystem;
00034 class MetaEngine;
00035 
00036 namespace Audio {
00037 class Mixer;
00038 }
00039 namespace Common {
00040 class Error;
00041 class EventManager;
00042 class SaveFileManager;
00043 class TimerManager;
00044 class FSNode;
00045 class SeekableReadStream;
00046 class WriteStream;
00047 }
00048 namespace GUI {
00049 class Debugger;
00050 class Dialog;
00051 }
00052 
00056 void GUIErrorMessage(const Common::String &msg);
00057 void GUIErrorMessageFormat(const char *fmt, ...) GCC_PRINTF(1, 2);
00058 
00059 class Engine;
00060 
00061 
00066 class PauseToken {
00067 public:
00068     PauseToken();
00069     PauseToken(const PauseToken &);
00070 #if __cplusplus >= 201103L
00071     PauseToken(PauseToken &&);
00072 #endif
00073     ~PauseToken();
00074 
00075     void operator=(const PauseToken &);
00076 #if __cplusplus >= 201103L
00077     void operator=(PauseToken &&);
00078 #endif
00079 
00082     void clear();
00083 
00088     bool isActive() const { return _engine != nullptr; }
00089 
00090 private:
00091     PauseToken(Engine *);
00092 
00093     Engine *_engine;
00094 
00095     friend class Engine;
00096 };
00097 
00098 class Engine {
00099 public:
00100     OSystem *_system;
00101     Audio::Mixer *_mixer;
00102 
00103 protected:
00104     Common::TimerManager *_timer;
00105     Common::EventManager *_eventMan;
00106     Common::SaveFileManager *_saveFileMan;
00107 
00108     GUI::Dialog *_mainMenuDialog;
00109     virtual int runDialog(GUI::Dialog &dialog);
00110 
00111     const Common::String _targetName; // target name for saves
00112 
00113 private:
00120     int _pauseLevel;
00121 
00125     uint32 _pauseStartTime;
00126 
00131     int32 _engineStartTime;
00132 
00136     const int _autosaveInterval;
00137 
00141     int _lastAutosaveTime;
00142 
00148     int _saveSlotToLoad;
00149 
00153     GUI::Debugger *_debugger;
00154 public:
00155 
00156 
00162     enum EngineFeature {
00167         kSupportsSubtitleOptions,
00168 
00174         kSupportsReturnToLauncher,
00175 
00182         kSupportsLoadingDuringRuntime,
00183 
00190         kSupportsSavingDuringRuntime,
00191 
00197         kSupportsChangingOptionsDuringRuntime,
00198 
00205         kSupportsArbitraryResolutions, // ResidualVM specific
00206 
00212         kSupportsJoystick // ResidualVM specific
00213     };
00214 
00215 
00216 
00222 
00223     Engine(OSystem *syst);
00224     virtual ~Engine();
00225 
00234     virtual void initializePath(const Common::FSNode &gamePath);
00235 
00240     virtual Common::Error run() = 0;
00241 
00245     virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size);
00246 
00250     virtual GUI::Debugger *getDebugger() { return _debugger; }
00251 
00256     void setDebugger(GUI::Debugger *debugger) {
00257         assert(!_debugger);
00258         _debugger = debugger;
00259     }
00260 
00265     GUI::Debugger *getOrCreateDebugger();
00266 
00270     virtual bool hasFeature(EngineFeature f) const { return false; }
00271 
00287     virtual void syncSoundSettings();
00288 
00294     virtual void applyGameSettings() {}
00295 
00299     virtual void flipMute();
00300 
00304     virtual Common::String getSaveStateName(int slot) const {
00305         return Common::String::format("%s.%03d", _targetName.c_str(), slot);
00306     }
00307 
00313     virtual Common::Error loadGameState(int slot);
00314 
00320     virtual Common::Error loadGameStream(Common::SeekableReadStream *stream);
00321 
00329     void setGameToLoadSlot(int slot);
00330 
00334     virtual bool canLoadGameStateCurrently();
00335 
00343     virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false);
00344 
00351     virtual Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false);
00352 
00356     virtual bool canSaveGameStateCurrently();
00357 
00361     bool saveGameDialog();
00362 
00366     bool loadGameDialog();
00367 
00368 protected:
00373     virtual void pauseEngineIntern(bool pause);
00374 
00376 
00377 
00378 public:
00379 
00384     static void quitGame();
00385 
00390     static bool shouldQuit();
00391 
00392     static MetaEngine &getMetaEngine();
00393 
00402     PauseToken pauseEngine();
00403 private:
00409     void resumeEngine();
00410 
00411     friend class PauseToken;
00412 
00413 public:
00414 
00418     bool isPaused() const { return _pauseLevel != 0; }
00419 
00423     void openMainMenuDialog();
00424 
00430     static bool warnUserAboutUnsupportedGame();
00431 
00437     uint32 getTotalPlayTime() const;
00438 
00448     void setTotalPlayTime(uint32 time = 0);
00449 
00450     inline Common::TimerManager *getTimerManager() { return _timer; }
00451     inline Common::EventManager *getEventManager() { return _eventMan; }
00452     inline Common::SaveFileManager *getSaveFileManager() { return _saveFileMan; }
00453 
00454 public:
00456     void checkCD();
00457 
00458 
00462     void handleAutoSave();
00463 
00467     void saveAutosaveIfEnabled();
00468 
00472     virtual bool canSaveAutosaveCurrently() {
00473         return canSaveGameStateCurrently();
00474     }
00475 
00480     virtual int getAutosaveSlot() const {
00481         return 0;
00482     }
00483 
00484     bool shouldPerformAutoSave(int lastSaveTime) {
00485         // TODO: Remove deprecated method once all engines are refactored
00486         // to no longer do autosaves directly themselves
00487         return false;
00488     }
00489 };
00490 
00491 // Chained games
00492 
00498 class ChainedGamesManager : public Common::Singleton<ChainedGamesManager> {
00499 private:
00500     struct Game {
00501         Common::String target;
00502         int slot;
00503     };
00504 
00505     Common::Queue<Game> _chainedGames;
00506 
00507 public:
00508     ChainedGamesManager();
00509     void clear();
00510     void push(const Common::String target, const int slot = -1);
00511     bool pop(Common::String &target, int &slot);
00512 };
00513 
00515 #define ChainedGamesMan ChainedGamesManager::instance()
00516 
00517 // FIXME: HACK for MidiEmu & error()
00518 extern Engine *g_engine;
00519 
00520 #endif


Generated on Sat Jul 4 2020 05:01:15 for ResidualVM by doxygen 1.7.1
curved edge   curved edge