diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/main.cpp | 15 | ||||
-rw-r--r-- | base/plugins.cpp | 81 | ||||
-rw-r--r-- | base/plugins.h | 9 |
3 files changed, 80 insertions, 25 deletions
diff --git a/base/main.cpp b/base/main.cpp index e651456ace..8564d64c26 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -105,7 +105,12 @@ 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("%s", " Looking for a plugin supporting this gameid... "); - GameDescriptor game = EngineMan.findGame(gameid, &plugin); + +#if defined(NEW_PLUGIN_DESIGN_FIRST_REFINEMENT) && defined(DYNAMIC_MODULES) + GameDescriptor game = EngineMan.findGameOnePlugAtATime(gameid, &plugin); +#else + GameDescriptor game = EngineMan.findGame(gameid, &plugin); +#endif if (plugin == 0) { printf("failed\n"); @@ -339,8 +344,12 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { settings.erase("debugflags"); } - // Load the plugins. - PluginManager::instance().loadPlugins(); +#if defined(NEW_PLUGIN_DESIGN_FIRST_REFINEMENT) && defined(DYNAMIC_MODULES) //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 // If we received an invalid music parameter via command line we check this here. // We can't check this before loading the music plugins. diff --git a/base/plugins.cpp b/base/plugins.cpp index 5d0be11065..61cc747a41 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -302,6 +302,31 @@ void PluginManager::addPluginProvider(PluginProvider *pp) { _providers.push_back(pp); } +bool PluginManager::loadFirstPlugin() { //TODO: only deal with engine plugins here, and have a separate "loadNonEnginePlugins" function. + unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL); + 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); + } + } + _pluginsEnd = plugs.end(); + _currentPlugin = plugs.begin(); + if (plugs.empty()) return false; //return false if there are no plugins to load. + return tryLoadPlugin(*_currentPlugin); +} + +bool PluginManager::loadNextPlugin() { + // To ensure only one engine plugin is loaded at a time, we unload all engine plugins before loading a new one. + unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL); + ++_currentPlugin; + if (_currentPlugin == _pluginsEnd) return false; //return false if already reached the end of list of plugins. + return tryLoadPlugin(*_currentPlugin); +} + void PluginManager::loadPlugins() { for (ProviderList::iterator pp = _providers.begin(); pp != _providers.end(); @@ -309,7 +334,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() { @@ -340,7 +364,7 @@ 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; - + printf("Plugin loaded is %s\n", plugin->getName()); PluginList::iterator pl = _plugins[plugin->getType()].begin(); while (!found && pl != _plugins[plugin->getType()].end()) { if (!strcmp(plugin->getName(), (*pl)->getName())) { @@ -366,13 +390,24 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) { } } - // Engine plugins #include "engines/metaengine.h" DECLARE_SINGLETON(EngineManager) +GameDescriptor EngineManager::findGameOnePlugAtATime(const Common::String &gameName, const EnginePlugin **plugin) const { + GameDescriptor result; + PluginManager::instance().loadFirstPlugin(); + do { + result = findGame(gameName, plugin); + if (!result.gameid().empty()) { + break; + } + } while (PluginManager::instance().loadNextPlugin()); + return result; +} + GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const { // Find the GameDescriptor for this target const EnginePlugin::List &plugins = getPlugins(); @@ -381,30 +416,36 @@ 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; + + for (iter = plugins.begin(); iter != plugins.end(); ++iter) { + result = (**iter)->findGame(gameName.c_str()); + if (!result.gameid().empty()) { + if (plugin) + *plugin = *iter; + return result; + } } - } return result; } GameList EngineManager::detectGames(const Common::FSList &fslist) const { GameList candidates; - - const EnginePlugin::List &plugins = getPlugins(); - - // Iterate over all known games and for each check if it might be - // the game in the presented directory. + EnginePlugin::List plugins; EnginePlugin::List::const_iterator iter; - for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - candidates.push_back((**iter)->detectGames(fslist)); - } - +#if defined(NEW_PLUGIN_DESIGN_FIRST_REFINEMENT) && defined(DYNAMIC_MODULES) + PluginManager::instance().loadFirstPlugin(); + do { +#endif + plugins = getPlugins(); + // Iterate over all known games and for each check if it might be + // the game in the presented directory. + for (iter = plugins.begin(); iter != plugins.end(); ++iter) { + candidates.push_back((**iter)->detectGames(fslist)); + } +#if defined(NEW_PLUGIN_DESIGN_FIRST_REFINEMENT) && defined(DYNAMIC_MODULES) + } while (PluginManager::instance().loadNextPlugin()); +#endif return candidates; } diff --git a/base/plugins.h b/base/plugins.h index a4c7f114f9..975c815783 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -275,9 +275,11 @@ class PluginManager : public Common::Singleton<PluginManager> { private: PluginList _plugins[PLUGIN_TYPE_MAX]; ProviderList _providers; - + PluginList::iterator _currentPlugin; + PluginList::iterator _pluginsEnd; + bool tryLoadPlugin(Plugin *plugin); - + friend class Common::Singleton<SingletonBaseType>; PluginManager(); @@ -286,6 +288,9 @@ public: void addPluginProvider(PluginProvider *pp); + bool loadFirstPlugin(); + bool loadNextPlugin(); + void loadPlugins(); void unloadPlugins(); void unloadPluginsExcept(PluginType type, const Plugin *plugin); |