aboutsummaryrefslogtreecommitdiff
path: root/base/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'base/main.cpp')
-rw-r--r--base/main.cpp45
1 files changed, 36 insertions, 9 deletions
diff --git a/base/main.cpp b/base/main.cpp
index 7afba3db37..2958dea283 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -48,12 +48,14 @@
#include "common/system.h"
#include "common/tokenizer.h"
#include "common/translation.h"
+#include "common/debug-channels.h" /* for debug manager */
-#include "gui/GuiManager.h"
+#include "gui/gui-manager.h"
#include "gui/message.h"
#include "gui/error.h"
#include "sound/mididrv.h"
+#include "sound/musicplugin.h" /* for music manager */
#include "backends/keymapper/keymapper.h"
@@ -104,7 +106,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(ONE_PLUGIN_AT_A_TIME) && defined(DYNAMIC_MODULES)
+ GameDescriptor game = EngineMan.findGameOnePluginAtATime(gameid, &plugin);
+#else
+ GameDescriptor game = EngineMan.findGame(gameid, &plugin);
+#endif
if (plugin == 0) {
printf("failed\n");
@@ -309,7 +316,7 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
Common::StringMap settings;
command = Base::parseCommandLine(settings, argc, argv);
- // Load the config file (possibly overriden via command line):
+ // Load the config file (possibly overridden via command line):
if (settings.contains("config")) {
ConfMan.loadConfigFile(settings["config"]);
settings.erase("config");
@@ -335,8 +342,13 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
settings.erase("debugflags");
}
- // Load the plugins.
- PluginManager::instance().loadPlugins();
+#if defined(ONE_PLUGIN_AT_A_TIME) && defined(DYNAMIC_MODULES)
+ // Only load non-engine plugins and first engine plugin initially in this case.
+ PluginManager::instance().loadNonEnginePluginsAndEnumerate();
+#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.
@@ -352,6 +364,7 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
// config file and the plugins have been loaded.
Common::Error res;
+ // TODO: deal with settings that require plugins to be loaded
if ((res = Base::processSettings(command, settings)) != Common::kArgumentNotProcessed)
return res;
@@ -361,6 +374,12 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
setupGraphics(system);
+ // Init the different managers that are used by the engines.
+ // Do it here to prevent fragmentation later
+ system.getAudioCDManager();
+ MusicManager::instance();
+ Common::DebugManager::instance();
+
// Init the event manager. As the virtual keyboard is loaded here, it must
// take place after the backend is initiated and the screen has been setup
system.getEventManager()->init();
@@ -394,6 +413,13 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
// Try to run the game
Common::Error result = runGame(plugin, system, specialDebug);
+ #if defined(ONE_PLUGIN_AT_A_TIME) && defined(DYNAMIC_MODULES)
+ // do our best to prevent fragmentation by unloading as soon as we can
+ PluginManager::instance().unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false);
+ // reallocate the config manager to get rid of any fragmentation
+ ConfMan.defragment();
+ #endif
+
// Did an error occur ?
if (result != Common::kNoError) {
// Shows an informative error dialog if starting the selected game failed.
@@ -419,11 +445,11 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
ConfMan.setActiveDomain("");
// PluginManager::instance().unloadPlugins();
+
+#if !defined(ONE_PLUGIN_AT_A_TIME)
PluginManager::instance().loadPlugins();
+#endif
} else {
- // A dialog would be nicer, but we don't have any
- // screen to draw on yet.
- warning("%s", _("Could not find any engine capable of running the selected game"));
GUI::displayErrorDialog(_("Could not find any engine capable of running the selected game"));
}
@@ -433,9 +459,10 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
}
PluginManager::instance().unloadPlugins();
PluginManager::destroy();
+ GUI::GuiManager::destroy();
Common::ConfigManager::destroy();
Common::SearchManager::destroy();
- GUI::GuiManager::destroy();
+ Common::TranslationManager::destroy();
return 0;
}