From 89d76fe5a5f72c18cec97aec419d2f2986ed3953 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Thu, 12 Aug 2010 06:00:19 +0000 Subject: Refined first refinement of new plugin design. Tested successfully adding/removing/running games on Linux with only one engine plugin loaded at a time svn-id: r52026 --- base/main.cpp | 3 ++- base/plugins.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++------------- base/plugins.h | 7 +++++-- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/base/main.cpp b/base/main.cpp index 8564d64c26..028f25dff2 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -345,7 +345,8 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { } #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. + // Only load non-engine plugins and first engine plugin initially in this case. + PluginManager::instance().loadFirstPlugin(); //This should be the only call to loadFirstPlugin external to the PluginManager class. #else // Load the plugins. PluginManager::instance().loadPlugins(); diff --git a/base/plugins.cpp b/base/plugins.cpp index 61cc747a41..1b760fb0b1 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -284,6 +284,7 @@ DECLARE_SINGLETON(PluginManager) PluginManager::PluginManager() { // Always add the static plugin provider. addPluginProvider(new StaticPluginProvider()); + nonEnginePlugs = -1; } PluginManager::~PluginManager() { @@ -302,29 +303,59 @@ 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; +void PluginManager::loadFirstPlugin() { //TODO: rename? It's not quite clear that this loads all non-engine plugins and first engine plugin. + _allPlugs.clear(); 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.push_back(*p); + } + } + + _currentPlugin = _allPlugs.begin(); + + bool updateNonEnginePlugs; + if (nonEnginePlugs == -1) { //TODO: All of this assumes engine plugins will always be last in "plugs". Is this the case? + nonEnginePlugs = 0; + updateNonEnginePlugs = true; + } else { + for (int i=0; igetType() == PLUGIN_TYPE_ENGINE) { + break; + } + if (updateNonEnginePlugs) nonEnginePlugs++; + ++_currentPlugin; + if (_currentPlugin == _allPlugs.end()) { + break; //break if there were no engine plugins to load. } } - _pluginsEnd = plugs.end(); - _currentPlugin = plugs.begin(); - if (plugs.empty()) return false; //return false if there are no plugins to load. - return tryLoadPlugin(*_currentPlugin); + return; } bool PluginManager::loadNextPlugin() { - // To ensure only one engine plugin is loaded at a time, we unload all engine plugins before loading a new one. + //To ensure only one engine plugin is loaded at a time, we unload all engine plugins before trying to load 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); + if (_currentPlugin == _allPlugs.end()) { + loadFirstPlugin(); //load first engine plugin again at this point. + return false; + } + assert(tryLoadPlugin(*_currentPlugin)); + return true; } void PluginManager::loadPlugins() { @@ -398,7 +429,7 @@ DECLARE_SINGLETON(EngineManager) GameDescriptor EngineManager::findGameOnePlugAtATime(const Common::String &gameName, const EnginePlugin **plugin) const { GameDescriptor result; - PluginManager::instance().loadFirstPlugin(); + //PluginManager::instance().loadFirstPlugin(); do { result = findGame(gameName, plugin); if (!result.gameid().empty()) { @@ -434,7 +465,6 @@ GameList EngineManager::detectGames(const Common::FSList &fslist) const { EnginePlugin::List plugins; EnginePlugin::List::const_iterator iter; #if defined(NEW_PLUGIN_DESIGN_FIRST_REFINEMENT) && defined(DYNAMIC_MODULES) - PluginManager::instance().loadFirstPlugin(); do { #endif plugins = getPlugins(); diff --git a/base/plugins.h b/base/plugins.h index 975c815783..1c7b84e338 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -275,8 +275,11 @@ class PluginManager : public Common::Singleton { private: PluginList _plugins[PLUGIN_TYPE_MAX]; ProviderList _providers; + + PluginList _allPlugs; PluginList::iterator _currentPlugin; - PluginList::iterator _pluginsEnd; + + int nonEnginePlugs; bool tryLoadPlugin(Plugin *plugin); @@ -288,7 +291,7 @@ public: void addPluginProvider(PluginProvider *pp); - bool loadFirstPlugin(); + void loadFirstPlugin(); bool loadNextPlugin(); void loadPlugins(); -- cgit v1.2.3