diff options
author | Max Horn | 2008-02-04 10:15:21 +0000 |
---|---|---|
committer | Max Horn | 2008-02-04 10:15:21 +0000 |
commit | 5fb7f7a4d66c48be928440c3142b196a479ca94c (patch) | |
tree | 14d1855b57dc2306ef094887a1b735b2722148b1 /base | |
parent | dd7fcd686790ea6a2e9021eac5b9e1c8bff88d26 (diff) | |
download | scummvm-rg350-5fb7f7a4d66c48be928440c3142b196a479ca94c.tar.gz scummvm-rg350-5fb7f7a4d66c48be928440c3142b196a479ca94c.tar.bz2 scummvm-rg350-5fb7f7a4d66c48be928440c3142b196a479ca94c.zip |
Commited updated version of my own patch #1868402: Basic savestate plugin API
svn-id: r30786
Diffstat (limited to 'base')
-rw-r--r-- | base/commandLine.cpp | 52 | ||||
-rw-r--r-- | base/game.cpp | 11 | ||||
-rw-r--r-- | base/game.h | 77 | ||||
-rw-r--r-- | base/plugins.cpp | 4 | ||||
-rw-r--r-- | base/plugins.h | 3 |
5 files changed, 145 insertions, 2 deletions
diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 856ac9e173..59a9c07995 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -350,6 +350,12 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, char **ar DO_LONG_COMMAND("test-detector") END_OPTION + DO_LONG_OPTION("list-saves") + // FIXME: Need to document this. + // TODO: Make the argument optional. If no argument is given, list all savegames + // for all configured targets. + return "list-saves"; + END_OPTION DO_OPTION('c', "config") END_OPTION @@ -571,7 +577,7 @@ static void listTargets() { using namespace Common; const ConfigManager::DomainMap &domains = ConfMan.getGameDomains(); - ConfigManager::DomainMap::const_iterator iter = domains.begin(); + ConfigManager::DomainMap::const_iterator iter; for (iter = domains.begin(); iter != domains.end(); ++iter) { Common::String name(iter->_key); Common::String description(iter->_value.get("description")); @@ -587,9 +593,50 @@ static void listTargets() { } printf("%-20s %s\n", name.c_str(), description.c_str()); + } } +/** List all saves states for the given target. */ +static void listSaves(const char *target) { + // FIXME HACK + g_system->initBackend(); + + // Grab the "target" domain, if any + const Common::ConfigManager::Domain *domain = ConfMan.getDomain(target); + + // Grab the gameid from the domain resp. use the target as gameid + Common::String gameid; + if (domain) + gameid = domain->get("gameid"); + if (gameid.empty()) + gameid = target; + gameid.toLowercase(); // Normalize it to lower case + + // Find the plugin that will handle the specified gameid + const Plugin *plugin = 0; + GameDescriptor game = Base::findGame(gameid, &plugin); + + if (!plugin) { + error("Could not find any plugin to handle gameid '%s' (target '%s')", gameid.c_str(), target); + return; + } + + // Query the plugin for a list of savegames + SaveStateList saveList = plugin->listSaves(target); + + // TODO: Include more info about the target (desc, engine name, ...) ??? + printf("Saves for target '%s':\n", target); + printf(" Slot Description \n" + " ---- ------------------------------------------------------\n"); + + for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) { + printf(" %-4s %s\n", x->save_slot().c_str(), x->description().c_str()); + // TODO: Could also iterate over the full hashmap, printing all key-value pairs + } +} + + #ifdef DETECTOR_TESTING_HACK static void runDetectorTest() { // HACK: The following code can be used to test the detection code of our @@ -671,6 +718,9 @@ bool processSettings(Common::String &command, Common::StringMap &settings) { } else if (command == "list-games") { listGames(); return false; + } else if (command == "list-saves") { + listSaves(settings["list-saves"].c_str()); + return false; } else if (command == "version") { printf("%s\n", gScummVMFullVersion); printf("Features compiled in: %s\n", gScummVMFeatures); diff --git a/base/game.cpp b/base/game.cpp index 9aaaf3a6af..a79cfddec9 100644 --- a/base/game.cpp +++ b/base/game.cpp @@ -25,6 +25,8 @@ #include "base/game.h" #include "base/plugins.h" +#include "graphics/surface.h" + const PlainGameDescriptor *findPlainGameDescriptor(const char *gameid, const PlainGameDescriptor *list) { const PlainGameDescriptor *g = list; @@ -66,6 +68,15 @@ void GameDescriptor::updateDesc(const char *extra) { } } +void SaveStateDescriptor::setThumbnail(Graphics::Surface *t) { + if (_thumbnail && _thumbnail != t) { + _thumbnail->free(); + delete _thumbnail; + } + _thumbnail = t; +} + + namespace Base { // TODO: Find a better name & place for this function. diff --git a/base/game.h b/base/game.h index 0764b7fbac..7dddea7b30 100644 --- a/base/game.h +++ b/base/game.h @@ -30,6 +30,10 @@ #include "common/array.h" #include "common/hash-str.h" +namespace Graphics { + class Surface; +} + /** * A simple structure used to map gameids (like "monkey", "sword1", ...) to * nice human readable and descriptive game titles (like "The Secret of Monkey Island"). @@ -67,7 +71,7 @@ public: setVal("description", pgd.description); } - GameDescriptor(Common::String g, Common::String d, Common::Language l = Common::UNK_LANG, + GameDescriptor(const Common::String &g, const Common::String &d, Common::Language l = Common::UNK_LANG, Common::Platform p = Common::kPlatformUnknown) { setVal("gameid", g); setVal("description", d); @@ -103,6 +107,77 @@ public: } }; +/** + * A hashmap describing details about a given save state. + * TODO + * Guaranteed to contain save_slot, filename and description values. + * Additional ideas: Playtime, creation date, thumbnail, ... + */ +class SaveStateDescriptor : public Common::StringMap { +protected: + Graphics::Surface *_thumbnail; // can be NULL +public: + SaveStateDescriptor() : _thumbnail(0) { + setVal("save_slot", "-1"); // FIXME: default to 0 (first slot) or to -1 (invalid slot) ? + setVal("description", ""); + setVal("filename", ""); + } + + SaveStateDescriptor(int s, const Common::String &d, const Common::String &f) : _thumbnail(0) { + char buf[16]; + sprintf(buf, "%d", s); + setVal("save_slot", buf); + setVal("description", d); + setVal("filename", f); + } + + SaveStateDescriptor(const Common::String &s, const Common::String &d, const Common::String &f) : _thumbnail(0) { + setVal("save_slot", s); + setVal("description", d); + setVal("filename", f); + } + + ~SaveStateDescriptor() { + setThumbnail(0); + } + + /** The saveslot id, as it would be passed to the "-x" command line switch. */ + Common::String &save_slot() { return getVal("save_slot"); } + + /** The saveslot id, as it would be passed to the "-x" command line switch (read-only variant). */ + const Common::String &save_slot() const { return getVal("save_slot"); } + + /** A human readable description of the save state. */ + Common::String &description() { return getVal("description"); } + + /** A human readable description of the save state (read-only variant). */ + const Common::String &description() const { return getVal("description"); } + + /** The filename of the savestate, for use with the SaveFileManager API. */ + Common::String &filename() { return getVal("filename"); } + + /** The filename of the savestate, for use with the SaveFileManager API (read-only variant). */ + const Common::String &filename() const { return getVal("filename"); } + + /** + * Return a thumbnail graphics surface representing the savestate visually + * This is usually a scaled down version of the game graphics. The size + * should be either 160x100 or 160x120 pixels, depending on the aspect + * ratio of the game. If another ratio is required, contact the core team. + * + * TODO: it is probably a bad idea to read this for *all* games at once, + * at least on low-end devices. So this info should probably normally only + * be included optionally. I.e. only upon a query for a specific savegame... + * To this end, add a getFullSaveStateInfo(target, slot) to the plugin API. + */ + const Graphics::Surface *getThumbnail() const { return _thumbnail; } + + + void setThumbnail(Graphics::Surface *t); +}; + +/** List of savestates. */ +typedef Common::Array<SaveStateDescriptor> SaveStateList; class Plugin; diff --git a/base/plugins.cpp b/base/plugins.cpp index 67ead04649..da6fe36826 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -67,6 +67,10 @@ public: GameList detectGames(const FSList &fslist) const { return _metaengine->detectGames(fslist); } + + SaveStateList listSaves(const char *target) const { + return _metaengine->listSaves(target); + } }; class StaticPluginProvider : public PluginProvider { diff --git a/base/plugins.h b/base/plugins.h index 966d65d959..9f8383f165 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -47,6 +47,7 @@ class Plugin { public: virtual ~Plugin() {} +// virtual bool isLoaded() const = 0; // TODO virtual bool loadPlugin() = 0; virtual void unloadPlugin() = 0; @@ -58,6 +59,8 @@ public: virtual GameDescriptor findGame(const char *gameid) const = 0; virtual GameList detectGames(const FSList &fslist) const = 0; + virtual SaveStateList listSaves(const char *target) const = 0; + virtual PluginError createInstance(OSystem *syst, Engine **engine) const = 0; }; |