BASE: Avoid calling PluginMan.getEngineFromMetaEngine where possible

This commit is contained in:
Cameron Cawley 2021-02-05 23:30:58 +00:00
parent 5c0b76ec34
commit a1890ede9c
22 changed files with 70 additions and 85 deletions

View file

@ -26,6 +26,7 @@
#include "gui/saveload.h"
#include "gui/saveload-dialog.h"
#include "engines/engine.h"
#include "engines/metaengine.h"
namespace GUI {
@ -39,7 +40,7 @@ SaveLoadChooser::~SaveLoadChooser() {
_impl = nullptr;
}
void SaveLoadChooser::selectChooser(const MetaEngine &engine) {
void SaveLoadChooser::selectChooser(const MetaEngine *engine) {
#ifndef DISABLE_SAVELOADCHOOSER_GRID
const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(engine);
if (!_impl || _impl->getType() != requestedType) {
@ -76,25 +77,14 @@ Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) con
}
int SaveLoadChooser::runModalWithCurrentTarget() {
const Plugin *plugin = EngineMan.findPlugin(ConfMan.get("engineid"));
const Plugin *enginePlugin = nullptr;
if (!plugin) {
error("SaveLoadChooser::runModalWithCurrentTarget(): Cannot find plugin");
} else {
enginePlugin = PluginMan.getEngineFromMetaEngine(plugin);
if (!g_engine)
error("No engine is currently active");
if (!enginePlugin) {
error("SaveLoadChooser::runModalWithCurrentTarget(): Couldn't match a Engine from the MetaEngine. \
You will not be able to see savefiles until you have the necessary plugins.");
}
}
return runModalWithPluginAndTarget(enginePlugin, ConfMan.getActiveDomainName());
return runModalWithMetaEngineAndTarget(g_engine->getMetaEngine(), ConfMan.getActiveDomainName());
}
int SaveLoadChooser::runModalWithPluginAndTarget(const Plugin *plugin, const String &target) {
assert(plugin->getType() == PLUGIN_TYPE_ENGINE);
selectChooser(plugin->get<MetaEngine>());
int SaveLoadChooser::runModalWithMetaEngineAndTarget(const MetaEngine *engine, const String &target) {
selectChooser(engine);
if (!_impl)
return -1;
@ -109,10 +99,10 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const Plugin *plugin, const Str
int ret;
do {
ret = _impl->run(target, &plugin->get<MetaEngine>());
ret = _impl->run(target, engine);
#ifndef DISABLE_SAVELOADCHOOSER_GRID
if (ret == kSwitchSaveLoadDialog) {
selectChooser(plugin->get<MetaEngine>());
selectChooser(engine);
}
#endif // !DISABLE_SAVELOADCHOOSER_GRID
} while (ret < -1);