diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/commandLine.cpp | 10 | ||||
-rw-r--r-- | base/main.cpp | 3 | ||||
-rw-r--r-- | base/plugins.cpp | 40 | ||||
-rw-r--r-- | base/plugins.h | 28 |
4 files changed, 29 insertions, 52 deletions
diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 5b919a495c..d2f286cc4a 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -23,7 +23,7 @@ * */ -#include "engines/engine.h" +#include "engines/metaengine.h" #include "base/commandLine.h" #include "base/plugins.h" #include "base/version.h" @@ -559,10 +559,10 @@ static void listGames() { printf("Game ID Full Title \n" "-------------------- ------------------------------------------------------\n"); - const EnginePluginList &plugins = EngineMan.getPlugins(); - EnginePluginList::const_iterator iter = plugins.begin(); + const EnginePlugin::list &plugins = EngineMan.getPlugins(); + EnginePlugin::list::const_iterator iter = plugins.begin(); for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - GameList list = (*iter)->getSupportedGames(); + 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()); } @@ -622,7 +622,7 @@ static void listSaves(const char *target) { } // Query the plugin for a list of savegames - SaveStateList saveList = plugin->listSaves(target); + SaveStateList saveList = (*plugin)->listSaves(target); // TODO: Include more info about the target (desc, engine name, ...) ??? printf("Saves for target '%s':\n", target); diff --git a/base/main.cpp b/base/main.cpp index 8b697e120d..c36c506d7f 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -32,6 +32,7 @@ */ #include "engines/engine.h" +#include "engines/metaengine.h" #include "base/commandLine.h" #include "base/plugins.h" #include "base/version.h" @@ -138,7 +139,7 @@ static int runGame(const EnginePlugin *plugin, OSystem &system, const Common::St // Create the game engine Engine *engine = 0; - PluginError err = plugin->createInstance(&system, &engine); + PluginError err = (*plugin)->createInstance(&system, &engine); if (!engine || err != kNoError) { // TODO: Show an error dialog or so? // TODO: Also take 'err' into consideration... diff --git a/base/plugins.cpp b/base/plugins.cpp index d2bd9b398a..d4153f17d3 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -301,43 +301,19 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) { #include "engines/metaengine.h" -const char *EnginePlugin::getCopyright() const { - return ((MetaEngine*)_pluginObject)->getCopyright(); -} - -PluginError EnginePlugin::createInstance(OSystem *syst, Engine **engine) const { - return ((MetaEngine*)_pluginObject)->createInstance(syst, engine); -} - -GameList EnginePlugin::getSupportedGames() const { - return ((MetaEngine*)_pluginObject)->getSupportedGames(); -} - -GameDescriptor EnginePlugin::findGame(const char *gameid) const { - return ((MetaEngine*)_pluginObject)->findGame(gameid); -} - -GameList EnginePlugin::detectGames(const FSList &fslist) const { - return ((MetaEngine*)_pluginObject)->detectGames(fslist); -} - -SaveStateList EnginePlugin::listSaves(const char *target) const { - return ((MetaEngine*)_pluginObject)->listSaves(target); -} - DECLARE_SINGLETON(EngineManager); GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const { // Find the GameDescriptor for this target - const EnginePluginList &plugins = getPlugins(); + const EnginePlugin::list &plugins = getPlugins(); GameDescriptor result; if (plugin) *plugin = 0; - EnginePluginList::const_iterator iter = plugins.begin(); + EnginePlugin::list::const_iterator iter = plugins.begin(); for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - result = (*iter)->findGame(gameName.c_str()); + result = (**iter)->findGame(gameName.c_str()); if (!result.gameid().empty()) { if (plugin) *plugin = *iter; @@ -350,18 +326,18 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Eng GameList EngineManager::detectGames(const FSList &fslist) const { GameList candidates; - const EnginePluginList &plugins = getPlugins(); + const EnginePlugin::list &plugins = getPlugins(); // Iterate over all known games and for each check if it might be // the game in the presented directory. - EnginePluginList::const_iterator iter; + EnginePlugin::list::const_iterator iter; for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - candidates.push_back((*iter)->detectGames(fslist)); + candidates.push_back((**iter)->detectGames(fslist)); } return candidates; } -const EnginePluginList &EngineManager::getPlugins() const { - return (const EnginePluginList&)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE); +const EnginePlugin::list &EngineManager::getPlugins() const { + return (const EnginePlugin::list&)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE); } diff --git a/base/plugins.h b/base/plugins.h index 3f2d19fd50..858c8d9106 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -141,6 +141,17 @@ public: /** List of plugins. */ typedef Common::Array<Plugin *> PluginList; +/** Template to help defining Plugin subclasses */ +template<class PO_t> +class PluginSubclass : public Plugin { +public: + PO_t *operator->() const { + return (PO_t *)_pluginObject; + } + + typedef Common::Array<PluginSubclass *> list; +}; + class PluginProvider { public: virtual ~PluginProvider() {} @@ -197,21 +208,10 @@ public: // Engine plugins -class Engine; class FSList; -class OSystem; - -class EnginePlugin : public Plugin { -public: - const char *getCopyright() const; - PluginError createInstance(OSystem *syst, Engine **engine) const; - GameList getSupportedGames() const; - GameDescriptor findGame(const char *gameid) const; - GameList detectGames(const FSList &fslist) const; - SaveStateList listSaves(const char *target) const; -}; +class MetaEngine; -typedef Common::Array<EnginePlugin *> EnginePluginList; +typedef PluginSubclass<MetaEngine> EnginePlugin; class EngineManager : public Common::Singleton<EngineManager> { private: @@ -220,7 +220,7 @@ private: public: GameDescriptor findGame(const Common::String &gameName, const EnginePlugin **plugin = NULL) const; GameList detectGames(const FSList &fslist) const; - const EnginePluginList &getPlugins() const; + const EnginePlugin::list &getPlugins() const; }; /** Shortcut for accessing the engine manager. */ |