[Scummvm-cvs-logs] SF.net SVN: scummvm:[52026] scummvm/branches/gsoc2010-plugins/base

toneman1138 at users.sourceforge.net toneman1138 at users.sourceforge.net
Thu Aug 12 08:00:19 CEST 2010


Revision: 52026
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52026&view=rev
Author:   toneman1138
Date:     2010-08-12 06:00:19 +0000 (Thu, 12 Aug 2010)

Log Message:
-----------
Refined first refinement of new plugin design. Tested successfully adding/removing/running games on Linux with only one engine plugin loaded at a time

Modified Paths:
--------------
    scummvm/branches/gsoc2010-plugins/base/main.cpp
    scummvm/branches/gsoc2010-plugins/base/plugins.cpp
    scummvm/branches/gsoc2010-plugins/base/plugins.h

Modified: scummvm/branches/gsoc2010-plugins/base/main.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/base/main.cpp	2010-08-12 04:12:37 UTC (rev 52025)
+++ scummvm/branches/gsoc2010-plugins/base/main.cpp	2010-08-12 06:00:19 UTC (rev 52026)
@@ -345,7 +345,8 @@
 	}
 
 #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();

Modified: scummvm/branches/gsoc2010-plugins/base/plugins.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/base/plugins.cpp	2010-08-12 04:12:37 UTC (rev 52025)
+++ scummvm/branches/gsoc2010-plugins/base/plugins.cpp	2010-08-12 06:00:19 UTC (rev 52026)
@@ -284,6 +284,7 @@
 PluginManager::PluginManager() {
 	// Always add the static plugin provider.
 	addPluginProvider(new StaticPluginProvider());
+	nonEnginePlugs = -1;
 }
 
 PluginManager::~PluginManager() {
@@ -302,29 +303,59 @@
 	_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);
 		}
 	}
-	_pluginsEnd = plugs.end();
-	_currentPlugin = plugs.begin();
-	if (plugs.empty()) return false; //return false if there are no plugins to load.
-	return tryLoadPlugin(*_currentPlugin);
+
+	_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; i<nonEnginePlugs; i++) {
+			++_currentPlugin;
+		}
+		updateNonEnginePlugs = false;
+	}
+
+	if (_allPlugs.empty()) { //TODO: this case is untested.
+		return; //return here if somehow there are no plugins to load.
+	}
+
+	//this loop is for loading all non-engine plugins and the first engine plugin.
+	while (true) {
+		assert(tryLoadPlugin(*_currentPlugin));
+		if ((*_currentPlugin)->getType() == PLUGIN_TYPE_ENGINE) {
+			break;
+		}
+		if (updateNonEnginePlugs) nonEnginePlugs++;
+		++_currentPlugin;
+		if (_currentPlugin == _allPlugs.end()) {
+			break; //break if there were no engine plugins to load.
+		}
+	}
+	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 @@
 
 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 @@
 	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();

Modified: scummvm/branches/gsoc2010-plugins/base/plugins.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/base/plugins.h	2010-08-12 04:12:37 UTC (rev 52025)
+++ scummvm/branches/gsoc2010-plugins/base/plugins.h	2010-08-12 06:00:19 UTC (rev 52026)
@@ -275,8 +275,11 @@
 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 @@
 
 	void addPluginProvider(PluginProvider *pp);
 
-	bool loadFirstPlugin();
+	void loadFirstPlugin();
 	bool loadNextPlugin();
 	
 	void loadPlugins();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list