diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/commandLine.cpp | 35 | ||||
-rw-r--r-- | base/commandLine.h | 2 | ||||
-rw-r--r-- | base/main.cpp | 19 | ||||
-rw-r--r-- | base/plugins.cpp | 81 | ||||
-rw-r--r-- | base/plugins.h | 9 |
5 files changed, 96 insertions, 50 deletions
diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 2f4e78fd80..e36ddfca54 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -598,9 +598,7 @@ static void listTargets() { } /** List all saves states for the given target. */ -static Common::Error listSaves(const char *target) { - Common::Error result = Common::kNoError; - +static void listSaves(const char *target) { // FIXME HACK g_system->initBackend(); @@ -625,14 +623,13 @@ static Common::Error listSaves(const char *target) { GameDescriptor game = EngineMan.findGame(gameid, &plugin); if (!plugin) { - warning("Could not find any plugin to handle target '%s' (gameid '%s')", target, gameid.c_str()); - return Common::kPluginNotFound; + error("Could not find any plugin to handle target '%s' (gameid '%s')", target, gameid.c_str()); + return; } if (!(*plugin)->hasFeature(MetaEngine::kSupportsListSaves)) { // TODO: Include more info about the target (desc, engine name, ...) ??? printf("ScummVM does not support listing save states for target '%s' (gameid '%s') .\n", target, gameid.c_str()); - result = Common::kPluginNotSupportSaves; } else { // Query the plugin for a list of savegames SaveStateList saveList = (*plugin)->listSaves(target); @@ -642,9 +639,6 @@ static Common::Error listSaves(const char *target) { printf(" Slot Description \n" " ---- ------------------------------------------------------\n"); - if (saveList.size() == 0) - result = Common::kNoSavesError; - for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) { printf(" %-4s %s\n", x->save_slot().c_str(), x->description().c_str()); // TODO: Could also iterate over the full hashmap, printing all key-value pairs @@ -653,8 +647,6 @@ static Common::Error listSaves(const char *target) { // Revert to the old active domain ConfMan.setActiveDomain(oldDomain); - - return result; } /** Lists all usable themes */ @@ -867,7 +859,7 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha #endif // DISABLE_COMMAND_LINE -Common::Error processSettings(Common::String &command, Common::StringMap &settings) { +bool processSettings(Common::String &command, Common::StringMap &settings) { #ifndef DISABLE_COMMAND_LINE @@ -876,33 +868,34 @@ Common::Error processSettings(Common::String &command, Common::StringMap &settin // have been loaded. if (command == "list-targets") { listTargets(); - return Common::kNoError; + return false; } else if (command == "list-games") { listGames(); - return Common::kNoError; + return false; } else if (command == "list-saves") { - return listSaves(settings["list-saves"].c_str()); + listSaves(settings["list-saves"].c_str()); + return false; } else if (command == "list-themes") { listThemes(); - return Common::kNoError; + return false; } else if (command == "version") { printf("%s\n", gScummVMFullVersion); printf("Features compiled in: %s\n", gScummVMFeatures); - return Common::kNoError; + return false; } else if (command == "help") { printf(HELP_STRING, s_appName); - return Common::kNoError; + return false; } #ifdef DETECTOR_TESTING_HACK else if (command == "test-detector") { runDetectorTest(); - return Common::kNoError; + return false; } #endif #ifdef UPGRADE_ALL_TARGETS_HACK else if (command == "upgrade-targets") { upgradeTargets(); - return Common::kNoError; + return false; } #endif @@ -974,7 +967,7 @@ Common::Error processSettings(Common::String &command, Common::StringMap &settin ConfMan.set(key, value, Common::ConfigManager::kTransientDomain); } - return Common::kArgumentNotProcessed; + return true; } } // End of namespace Base diff --git a/base/commandLine.h b/base/commandLine.h index c7e8d8b0d0..8801ed17d8 100644 --- a/base/commandLine.h +++ b/base/commandLine.h @@ -33,7 +33,7 @@ namespace Base { void registerDefaults(); Common::String parseCommandLine(Common::StringMap &settings, int argc, const char * const *argv); -Common::Error processSettings(Common::String &command, Common::StringMap &settings); +bool processSettings(Common::String &command, Common::StringMap &settings); } // End of namespace Base diff --git a/base/main.cpp b/base/main.cpp index e651456ace..08d59aafab 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -105,8 +105,13 @@ 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"); warning("%s is an invalid gameid. Use the --list-games option to list supported gameid", gameid.c_str()); @@ -339,8 +344,12 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { settings.erase("debugflags"); } +#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. @@ -354,10 +363,8 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { // Process the remaining command line settings. Must be done after the // config file and the plugins have been loaded. - Common::Error res; - - if ((res = Base::processSettings(command, settings)) != Common::kArgumentNotProcessed) - return res; + if (!Base::processSettings(command, settings)) + return 0; // Init the backend. Must take place after all config data (including // the command line params) was read. @@ -383,7 +390,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 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); |