diff options
author | Torbjörn Andersson | 2014-12-30 10:47:51 +0100 |
---|---|---|
committer | Torbjörn Andersson | 2014-12-30 10:47:51 +0100 |
commit | cc916625d9025ffaa898854c4de19da5dc2e2925 (patch) | |
tree | 8986dbcee3db5b8850680f42e9b2117c13822e25 | |
parent | f74ba29753de23bad9a07f531fc4c03ea3375594 (diff) | |
download | scummvm-rg350-cc916625d9025ffaa898854c4de19da5dc2e2925.tar.gz scummvm-rg350-cc916625d9025ffaa898854c4de19da5dc2e2925.tar.bz2 scummvm-rg350-cc916625d9025ffaa898854c4de19da5dc2e2925.zip |
SCUMM: Add a "chained games manager"
This replaces the somewhat ugly use of the config manager to store
the chained games.
-rw-r--r-- | base/main.cpp | 38 | ||||
-rw-r--r-- | engines/engine.cpp | 31 | ||||
-rw-r--r-- | engines/engine.h | 28 | ||||
-rw-r--r-- | engines/scumm/scumm.cpp | 3 |
4 files changed, 69 insertions, 31 deletions
diff --git a/base/main.cpp b/base/main.cpp index b9bd97dbef..0f5ebc7845 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -529,43 +529,21 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { // at. At the time of writing, this is used for the Maniac Mansion // easter egg in Day of the Tentacle. - Common::String chainedGames, nextGame, saveSlot; + Common::String chainedGame; + int saveSlot = -1; - if (ConfMan.hasKey("chained_games", Common::ConfigManager::kTransientDomain)) { - chainedGames = ConfMan.get("chained_games", Common::ConfigManager::kTransientDomain); - } + ChainedGamesMan.pop(chainedGame, saveSlot); // Discard any command line options. It's unlikely that the user // wanted to apply them to *all* games ever launched. ConfMan.getDomain(Common::ConfigManager::kTransientDomain)->clear(); - if (!chainedGames.empty()) { - if (chainedGames.contains(',')) { - for (uint i = 0; i < chainedGames.size(); i++) { - if (chainedGames[i] == ',') { - chainedGames.erase(0, i + 1); - break; - } - nextGame += chainedGames[i]; - } - ConfMan.set("chained_games", chainedGames, Common::ConfigManager::kTransientDomain); - } else { - nextGame = chainedGames; - chainedGames.clear(); - ConfMan.removeKey("chained_games", Common::ConfigManager::kTransientDomain); - } - if (nextGame.contains(':')) { - for (int i = nextGame.size() - 1; i >= 0; i--) { - if (nextGame[i] == ':') { - nextGame.erase(i); - break; - } - saveSlot = nextGame[i] + saveSlot; - } - ConfMan.setInt("save_slot", atoi(saveSlot.c_str()), Common::ConfigManager::kTransientDomain); + if (!chainedGame.empty()) { + if (saveSlot != -1) { + ConfMan.setInt("save_slot", saveSlot, Common::ConfigManager::kTransientDomain); } - // Start the next game - ConfMan.setActiveDomain(nextGame); + // Start the chained game + ConfMan.setActiveDomain(chainedGame); } else { // Clear the active config domain ConfMan.setActiveDomain(""); diff --git a/engines/engine.cpp b/engines/engine.cpp index c63437f800..24008dd073 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -45,6 +45,7 @@ #include "common/taskbar.h" #include "common/textconsole.h" #include "common/translation.h" +#include "common/singleton.h" #include "backends/keymapper/keymapper.h" @@ -101,6 +102,36 @@ static void defaultErrorHandler(const char *msg) { } } +// Chained games manager + +ChainedGamesManager::ChainedGamesManager() { + clear(); +} + +void ChainedGamesManager::clear() { + _chainedGames.clear(); +} + +void ChainedGamesManager::push(const Common::String target, const int slot) { + Game game; + game.target = target; + game.slot = slot; + _chainedGames.push(game); +} + +bool ChainedGamesManager::pop(Common::String &target, int &slot) { + if (_chainedGames.empty()) { + return false; + } + Game game = _chainedGames.pop(); + target = game.target; + slot = game.slot; + return true; +} + +namespace Common { +DECLARE_SINGLETON(ChainedGamesManager); +} Engine::Engine(OSystem *syst) : _system(syst), diff --git a/engines/engine.h b/engines/engine.h index e325cc1ba2..d3415d584c 100644 --- a/engines/engine.h +++ b/engines/engine.h @@ -27,6 +27,8 @@ #include "common/str.h" #include "common/language.h" #include "common/platform.h" +#include "common/queue.h" +#include "common/singleton.h" class OSystem; @@ -334,6 +336,32 @@ protected: }; +// Chained games + +/** + * Singleton class which manages chained games. A chained game is one that + * starts automatically, optionally loading a saved game, instead of returning + * to the launcher. + */ +class ChainedGamesManager : public Common::Singleton<ChainedGamesManager> { +private: + struct Game { + Common::String target; + int slot; + }; + + Common::Queue<Game> _chainedGames; + +public: + ChainedGamesManager(); + void clear(); + void push(const Common::String target, const int slot = -1); + bool pop(Common::String &target, int &slot); +}; + +/** Convenience shortcut for accessing the chained games manager. */ +#define ChainedGamesMan ChainedGamesManager::instance() + // FIXME: HACK for MidiEmu & error() extern Engine *g_engine; diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp index 34ae957951..9518ed4e5c 100644 --- a/engines/scumm/scumm.cpp +++ b/engines/scumm/scumm.cpp @@ -2625,7 +2625,8 @@ bool ScummEngine::startManiac() { // Set up the chanined games to Maniac Mansion, and then back // to the current game again with that save slot. - ConfMan.set("chained_games", maniacTarget + "," + ConfMan.getActiveDomainName() + ":100", Common::ConfigManager::kTransientDomain); + ChainedGamesMan.push(maniacTarget); + ChainedGamesMan.push(ConfMan.getActiveDomainName(), 100); // Force a return to the launcher. This will start the first // chained game. |