Keep separated arrays for each type of plugin

svn-id: r32046
This commit is contained in:
Jordi Vilalta Prat 2008-05-12 01:26:43 +00:00
parent 2c9968fe80
commit 9ba353b9d8
3 changed files with 13 additions and 12 deletions

View File

@ -302,7 +302,7 @@ extern "C" int scummvm_main(int argc, char *argv[]) {
if (plugin) {
// Unload all plugins not needed for this game,
// to save memory
PluginManager::instance().unloadPluginsExcept(plugin);
PluginManager::instance().unloadPluginsExcept(PLUGIN_TYPE_ENGINE, plugin);
// Try to run the game
int result = runGame(plugin, system, specialDebug);
@ -329,7 +329,7 @@ extern "C" int scummvm_main(int argc, char *argv[]) {
launcherDialog(system);
}
PluginManager::instance().unloadPluginsExcept(NULL);
PluginManager::instance().unloadPlugins();
PluginManager::destroy();
Common::ConfigManager::destroy();
GUI::NewGui::destroy();

View File

@ -253,12 +253,13 @@ void PluginManager::loadPlugins() {
}
void PluginManager::unloadPlugins() {
unloadPluginsExcept(NULL);
for (int i = 0; i < PLUGIN_TYPE_MAX; i++)
unloadPluginsExcept((PluginType)i, NULL);
}
void PluginManager::unloadPluginsExcept(const Plugin *plugin) {
void PluginManager::unloadPluginsExcept(PluginType type, const Plugin *plugin) {
Plugin *found = NULL;
for (PluginList::iterator p = _plugins.begin(); p != _plugins.end(); ++p) {
for (PluginList::iterator p = _plugins[type].begin(); p != _plugins[type].end(); ++p) {
if (*p == plugin) {
found = *p;
} else {
@ -266,9 +267,9 @@ void PluginManager::unloadPluginsExcept(const Plugin *plugin) {
delete *p;
}
}
_plugins.clear();
_plugins[type].clear();
if (found != NULL) {
_plugins.push_back(found);
_plugins[type].push_back(found);
}
}
@ -277,7 +278,7 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) {
// Try to load the plugin
if (plugin->loadPlugin()) {
// If successful, add it to the list of known plugins and return.
_plugins.push_back(plugin);
_plugins[plugin->getType()].push_back(plugin);
// TODO/FIXME: We should perform some additional checks here:
// * Check for some kind of "API version" (possibly derived from the
@ -362,5 +363,5 @@ GameList EngineManager::detectGames(const FSList &fslist) const {
}
const EnginePluginList &EngineManager::getPlugins() const {
return (const EnginePluginList&)PluginManager::instance().getPlugins();
return (const EnginePluginList&)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
}

View File

@ -174,7 +174,7 @@ protected:
class PluginManager : public Common::Singleton<PluginManager> {
typedef Common::List<PluginProvider *> ProviderList;
private:
PluginList _plugins;
PluginList _plugins[PLUGIN_TYPE_MAX];
ProviderList _providers;
bool tryLoadPlugin(Plugin *plugin);
@ -189,9 +189,9 @@ public:
void loadPlugins();
void unloadPlugins();
void unloadPluginsExcept(const Plugin *plugin);
void unloadPluginsExcept(PluginType type, const Plugin *plugin);
const PluginList &getPlugins() { return _plugins; }
const PluginList &getPlugins(PluginType t) { return _plugins[t]; }
};