diff options
-rw-r--r-- | base/main.cpp | 9 | ||||
-rw-r--r-- | base/plugins.cpp | 47 | ||||
-rw-r--r-- | base/plugins.h | 7 |
3 files changed, 48 insertions, 15 deletions
diff --git a/base/main.cpp b/base/main.cpp index 2658d1dc67..e3eb18b79d 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -103,8 +103,9 @@ static const EnginePlugin *detectPlugin() { // Query the plugins and find one that will handle the specified gameid printf("User picked target '%s' (gameid '%s')...\n", ConfMan.getActiveDomainName().c_str(), gameid.c_str()); printf(" Looking for a plugin supporting this gameid... "); + GameDescriptor game = EngineMan.findGame(gameid, &plugin); - + if (plugin == 0) { printf("failed\n"); warning("%s is an invalid gameid. Use the --list-games option to list supported gameid", gameid.c_str()); @@ -335,8 +336,12 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { settings.erase("debugflags"); } +#ifdef NEW_PLUGIN_DESIGN_FIRST_REFINEMENT //note: I'm going to refactor this name later :P + // Don't load the plugins initially in this case. +#else // Load the plugins. PluginManager::instance().loadPlugins(); +#endif // Process the remaining command line settings. Must be done after the // config file and the plugins have been loaded. @@ -367,7 +372,7 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { // Unless a game was specified, show the launcher dialog if (0 == ConfMan.getActiveDomain()) launcherDialog(); - + // FIXME: We're now looping the launcher. This, of course, doesn't // work as well as it should. In theory everything should be destroyed // cleanly, so this is now enabled to encourage people to fix bits :) diff --git a/base/plugins.cpp b/base/plugins.cpp index 6c80da65d4..e0ab85babb 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -306,6 +306,26 @@ void PluginManager::addPluginProvider(PluginProvider *pp) { _providers.push_back(pp); } +bool PluginManager::loadFirstPlugin() { + PluginList plugs; + for (ProviderList::iterator pp = _providers.begin(); + pp != _providers.end(); + ++pp) { + PluginList pl((*pp)->getPlugins()); + for (PluginList::iterator p = pl.begin(); p != pl.end(); ++p) { + plugs.push_back(*p); + } + } + _allPlugs = plugs.begin(); + return tryLoadPlugin(*_allPlugs); //TODO: return false if no plugins! +} + +bool PluginManager::loadNextPlugin() { + unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL); + ++_allPlugs; + return tryLoadPlugin(*_allPlugs); //TODO: return false if got to the end of list of plugins. +} + void PluginManager::loadPlugins() { for (ProviderList::iterator pp = _providers.begin(); pp != _providers.end(); @@ -313,7 +333,6 @@ void PluginManager::loadPlugins() { PluginList pl((*pp)->getPlugins()); Common::for_each(pl.begin(), pl.end(), Common::bind1st(Common::mem_fun(&PluginManager::tryLoadPlugin), this)); } - } void PluginManager::unloadPlugins() { @@ -344,7 +363,6 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) { // The plugin is valid, see if it provides the same module as an // already loaded one and should replace it. bool found = false; - PluginList::iterator pl = _plugins[plugin->getType()].begin(); while (!found && pl != _plugins[plugin->getType()].end()) { if (!strcmp(plugin->getName(), (*pl)->getName())) { @@ -370,7 +388,6 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) { } } - // Engine plugins #include "engines/metaengine.h" @@ -385,15 +402,23 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Eng if (plugin) *plugin = 0; - EnginePlugin::List::const_iterator iter = plugins.begin(); - for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - result = (**iter)->findGame(gameName.c_str()); - if (!result.gameid().empty()) { - if (plugin) - *plugin = *iter; - break; + EnginePlugin::List::const_iterator iter; + +#ifdef NEW_PLUGIN_DESIGN_FIRST_REFINEMENT + PluginManager::instance().loadFirstPlugin(); + do { +#endif + for (iter = plugins.begin(); iter != plugins.end(); ++iter) { + result = (**iter)->findGame(gameName.c_str()); + if (!result.gameid().empty()) { + if (plugin) + *plugin = *iter; + return result; + } } - } +#ifdef NEW_PLUGIN_DESIGN_FIRST_REFINEMENT + } while(PluginManager::instance().loadNextPlugin()); +#endif return result; } diff --git a/base/plugins.h b/base/plugins.h index a4c7f114f9..5697055e54 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -275,9 +275,10 @@ class PluginManager : public Common::Singleton<PluginManager> { private: PluginList _plugins[PLUGIN_TYPE_MAX]; ProviderList _providers; - + PluginList::iterator _allPlugs; + bool tryLoadPlugin(Plugin *plugin); - + friend class Common::Singleton<SingletonBaseType>; PluginManager(); @@ -286,6 +287,8 @@ public: void addPluginProvider(PluginProvider *pp); + bool loadFirstPlugin(); + bool loadNextPlugin(); void loadPlugins(); void unloadPlugins(); void unloadPluginsExcept(PluginType type, const Plugin *plugin); |