diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/commandLine.cpp | 22 | ||||
-rw-r--r-- | base/game.h | 43 | ||||
-rw-r--r-- | base/main.cpp | 6 | ||||
-rw-r--r-- | base/plugins.cpp | 29 | ||||
-rw-r--r-- | base/plugins.h | 37 |
5 files changed, 60 insertions, 77 deletions
diff --git a/base/commandLine.cpp b/base/commandLine.cpp index b14202c545..46c45bb5d1 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -527,7 +527,7 @@ static void listGames() { for (iter = plugins.begin(); iter != plugins.end(); ++iter) { GameList list = (*iter)->getSupportedGames(); for (GameList::iterator v = list.begin(); v != list.end(); ++v) { - printf("%-20s %s\n", v->gameid.c_str(), v->description.c_str()); + printf("%-20s %s\n", v->gameid().c_str(), v->description().c_str()); } } } @@ -550,8 +550,8 @@ static void listTargets() { // be taken into account, too. Common::String gameid(name); GameDescriptor g = Base::findGame(gameid); - if (g.description.size() > 0) - description = g.description; + if (g["description"].size() > 0) + description = g["description"]; } printf("%-20s %s\n", name.c_str(), description.c_str()); @@ -589,11 +589,11 @@ static void runDetectorTest() { continue; } - DetectedGameList candidates(PluginManager::instance().detectGames(files)); + GameList candidates(PluginManager::instance().detectGames(files)); bool gameidDiffers = false; - DetectedGameList::iterator x; + GameList::iterator x; for (x = candidates.begin(); x != candidates.end(); ++x) { - gameidDiffers |= (scumm_stricmp(gameid.c_str(), x->gameid.c_str()) != 0); + gameidDiffers |= (scumm_stricmp(gameid.c_str(), x->gameid().c_str()) != 0); } if (candidates.empty()) { @@ -616,10 +616,10 @@ static void runDetectorTest() { for (x = candidates.begin(); x != candidates.end(); ++x) { printf(" gameid '%s', desc '%s', language '%s', platform '%s'\n", - x->gameid.c_str(), - x->description.c_str(), - Common::getLanguageCode(x->language), - Common::getPlatformCode(x->platform)); + x->gameid().c_str(), + x->description().c_str(), + Common::getLanguageCode(x->language()), + Common::getPlatformCode(x->platform())); } } int total = domains.size(); @@ -666,7 +666,7 @@ bool processSettings(Common::String &command, Common::StringMap &settings) { // domain (i.e. a target) matching this argument, or alternatively // whether there is a gameid matching that name. if (!command.empty()) { - if (ConfMan.hasGameDomain(command) || Base::findGame(command).gameid.size() > 0) { + if (ConfMan.hasGameDomain(command) || Base::findGame(command)["gameid"].size() > 0) { ConfMan.setActiveDomain(command); } else { usage("Unrecognized game target '%s'", command.c_str()); diff --git a/base/game.h b/base/game.h index eca0050c51..566a63706b 100644 --- a/base/game.h +++ b/base/game.h @@ -26,32 +26,41 @@ #include "common/str.h" #include "common/array.h" +#include "common/hash-str.h" struct PlainGameDescriptor { const char *gameid; const char *description; // TODO: Rename this to "title" or so }; -struct GameDescriptor { - Common::String gameid; - Common::String description; // TODO: Rename this to "title" or so - +class GameDescriptor : public Common::StringMap { +public: GameDescriptor() {} - GameDescriptor(Common::String g, Common::String d) : - gameid(g), description(d) {} + + GameDescriptor(const PlainGameDescriptor &pgd) { + this->operator []("gameid") = pgd.gameid; + this->operator []("description") = pgd.description; + } + + GameDescriptor(Common::String g, Common::String d, Common::Language l = Common::UNK_LANG, + Common::Platform p = Common::kPlatformUnknown) { + this->operator []("gameid") = g; + this->operator []("description") = d; + if (l != Common::UNK_LANG) + this->operator []("language") = Common::getLanguageCode(l); + if (p != Common::kPlatformUnknown) + this->operator []("platform") = Common::getPlatformCode(p); + } /** - * This template constructor allows to easily convert structs that mimic - * GameDescriptor to a real GameDescriptor instance. - * - * Normally, one would just subclass GameDescriptor to get this effect much easier. - * However, subclassing a struct turns it into a non-POD type. One of the - * consequences is that you can't have inline intialized arrays of that type. - * But we heavily rely on those, hence we can't subclass GameDescriptor... + * Update the description string by appending (LANG/PLATFORM/EXTRA) to it. */ - template <class T> - GameDescriptor(const T &g) : - gameid(g.gameid), description(g.description) {} + void updateDesc(const char *extra = 0); + + Common::String &gameid() { return this->operator []("gameid"); } + Common::String &description() { return this->operator []("description"); } + Common::Language language() { return Common::parseLanguage(this->operator []("language")); } + Common::Platform platform() { return Common::parsePlatform(this->operator []("platform")); } }; /** List of games. */ @@ -61,7 +70,7 @@ public: GameList(const GameList &list) : Common::Array<GameDescriptor>(list) {} GameList(const PlainGameDescriptor *g) { while (g->gameid) { - push_back(*g); + push_back(GameDescriptor(g->gameid, g->description)); g++; } } diff --git a/base/main.cpp b/base/main.cpp index 3bd7fe2c8a..156998ab50 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -69,7 +69,7 @@ GameDescriptor findGame(const Common::String &gameName, const Plugin **plugin) { PluginList::const_iterator iter = plugins.begin(); for (iter = plugins.begin(); iter != plugins.end(); ++iter) { result = (*iter)->findGame(gameName.c_str()); - if (!result.gameid.empty()) { + if (!result.gameid().empty()) { if (plugin) *plugin = *iter; break; @@ -126,7 +126,7 @@ static const Plugin *detectMain() { } // FIXME: Do we really need this one? - printf("Trying to start game '%s'\n", game.description.c_str()); + printf("Trying to start game '%s'\n", game.description().c_str()); return plugin; } @@ -191,7 +191,7 @@ static int runGame(const Plugin *plugin, OSystem &system, const Common::String & // Set the window caption to the game name Common::String caption(ConfMan.get("description")); - Common::String desc = Base::findGame(ConfMan.get("gameid")).description; + Common::String desc = Base::findGame(ConfMan.get("gameid")).description(); if (caption.empty() && !desc.empty()) caption = desc; if (caption.empty()) diff --git a/base/plugins.cpp b/base/plugins.cpp index 9f53a66f74..90cbb5de78 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -25,30 +25,33 @@ #include "common/util.h" -void DetectedGame::updateDesc(const char *extra) { +void GameDescriptor::updateDesc(const char *extra) { // TODO: The format used here (LANG/PLATFORM/EXTRA) is not set in stone. // We may want to change the order (PLATFORM/EXTRA/LANG, anybody?), or // the seperator (instead of '/' use ', ' or ' '). - const bool hasCustomLanguage = (language != Common::UNK_LANG); - const bool hasCustomPlatform = (platform != Common::kPlatformUnknown); + const bool hasCustomLanguage = (this->contains("language") && (this->language() != Common::UNK_LANG)); + const bool hasCustomPlatform = (this->contains("platform") && (this->platform() != Common::kPlatformUnknown)); const bool hasExtraDesc = (extra && extra[0]); // Adapt the description string if custom platform/language is set. if (hasCustomLanguage || hasCustomPlatform || hasExtraDesc) { - description += " ("; + Common::String descr = this->description(); + + descr += " ("; if (hasCustomLanguage) - description += Common::getLanguageDescription(language); + descr += Common::getLanguageDescription(this->language()); if (hasCustomPlatform) { if (hasCustomLanguage) - description += "/"; - description += Common::getPlatformDescription(platform); + descr += "/"; + descr += Common::getPlatformDescription(this->platform()); } if (hasExtraDesc) { if (hasCustomPlatform || hasCustomLanguage) - description += "/"; - description += extra; + descr += "/"; + descr += extra; } - description += ")"; + descr += ")"; + this->operator []("description") = descr; } } @@ -86,7 +89,7 @@ public: return (*_plugin->_qf)(gameid); } - DetectedGameList detectGames(const FSList &fslist) const { + GameList detectGames(const FSList &fslist) const { assert(_plugin->_df); return (*_plugin->_df)(fslist); } @@ -247,8 +250,8 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) { } } -DetectedGameList PluginManager::detectGames(const FSList &fslist) const { - DetectedGameList candidates; +GameList PluginManager::detectGames(const FSList &fslist) const { + GameList candidates; // Iterate over all known games and for each check if it might be // the game in the presented directory. diff --git a/base/plugins.h b/base/plugins.h index 9b14f52d57..9b20c6fbdd 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -36,35 +36,6 @@ class FSList; class OSystem; /** - * A detected game. Carries the GameDescriptor, but also (optionally) - * information about the language and platform of the detected game. - */ -struct DetectedGame : public GameDescriptor { - Common::Language language; - Common::Platform platform; - DetectedGame(const char *g = 0, const char *d = 0, - Common::Language l = Common::UNK_LANG, - Common::Platform p = Common::kPlatformUnknown) - : GameDescriptor(g, d), language(l), platform(p) {} - - template <class T> - DetectedGame(const T &game, - Common::Language l = Common::UNK_LANG, - Common::Platform p = Common::kPlatformUnknown) - : GameDescriptor(game.gameid, game.description), language(l), platform(p) {} - - /** - * Update the description string by appending (LANG/PLATFORM/EXTRA) to it. - */ - void updateDesc(const char *extra = 0); -}; - - -/** List of detected games. */ -typedef Common::Array<DetectedGame> DetectedGameList; - - -/** * Error codes which mayb be reported by plugins under various circumstances. * @todo Turn this into a global 'ErrorCode' enum used by all of ScummVM ? */ @@ -96,7 +67,7 @@ public: virtual GameList getSupportedGames() const = 0; virtual GameDescriptor findGame(const char *gameid) const = 0; - virtual DetectedGameList detectGames(const FSList &fslist) const = 0; + virtual GameList detectGames(const FSList &fslist) const = 0; virtual PluginError createInstance(OSystem *syst, Engine **engine) const = 0; }; @@ -146,7 +117,7 @@ public: PLUGIN_EXPORT GameList PLUGIN_gameIDList() { return Engine_##ID##_gameIDList(); } \ PLUGIN_EXPORT GameDescriptor PLUGIN_findGameID(const char *gameid) { return Engine_##ID##_findGameID(gameid); } \ PLUGIN_EXPORT PluginError PLUGIN_createEngine(OSystem *syst, Engine **engine) { return Engine_##ID##_create(syst, engine); } \ - PLUGIN_EXPORT DetectedGameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \ + PLUGIN_EXPORT GameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \ } \ void dummyFuncToAllowTrailingSemicolon() #endif @@ -161,7 +132,7 @@ class PluginRegistrator { public: typedef GameDescriptor (*GameIDQueryFunc)(const char *gameid); typedef PluginError (*EngineFactory)(OSystem *syst, Engine **engine); - typedef DetectedGameList (*DetectFunc)(const FSList &fslist); + typedef GameList (*DetectFunc)(const FSList &fslist); protected: const char *_name; @@ -225,7 +196,7 @@ public: const PluginList &getPlugins() { return _plugins; } - DetectedGameList detectGames(const FSList &fslist) const; + GameList detectGames(const FSList &fslist) const; }; #endif |