BASE: ENGINES: Change saveload code to adapt to the new MEC class.

- MEC: MetaEngineConnect.
- How do games handle save/load if MetaEngine (detection) is seperate from MetaEngineConnect (engine factory)?

- Most of the changes are quite similiar. ConfMan finds us the relevant MetaEngine, then simply use the new helpers from PluginMan.
- The new helpers will help convert a relevant MetaEngine into the other format or vice versa.
- Once the matching is complete, simply invoke functions by:
plugin->get<MetaEngineConnect>().engineMethod();
- Refer to previous commits to see the new class changes & notes.
This commit is contained in:
aryanrawlani28 2020-08-03 04:16:09 +05:30 committed by Eugene Sandulenko
parent 01efb65931
commit 73cc973ad7
7 changed files with 74 additions and 44 deletions

View File

@ -867,15 +867,18 @@ static Common::Error listSaves(const Common::String &singleTarget) {
// the specified game name, or alternatively whether there is a matching game id.
Common::String currentTarget;
QualifiedGameDescriptor game;
const Plugin *plugin = nullptr;
const Plugin *metaEnginePlugin = nullptr;
const Plugin *enginePlugin = nullptr;
if (ConfMan.hasGameDomain(*i)) {
// The name is a known target
currentTarget = *i;
EngineMan.upgradeTargetIfNecessary(*i);
game = EngineMan.findTarget(*i, &plugin);
game = EngineMan.findTarget(*i, &metaEnginePlugin);
} else if (game = findGameMatchingName(*i), !game.gameId.empty()) {
// The name is a known game id
plugin = EngineMan.findPlugin(game.engineId);
metaEnginePlugin = EngineMan.findPlugin(game.engineId);
currentTarget = createTemporaryTarget(game.engineId, game.gameId);
} else {
return Common::Error(Common::kEnginePluginNotFound, Common::String::format("target '%s'", singleTarget.c_str()));
@ -884,19 +887,30 @@ static Common::Error listSaves(const Common::String &singleTarget) {
// If we actually found a domain, we're going to change the domain
ConfMan.setActiveDomain(currentTarget);
if (!plugin) {
if (!metaEnginePlugin) {
// If the target was specified, treat this as an error, and otherwise skip it.
if (!singleTarget.empty())
return Common::Error(Common::kEnginePluginNotFound,
return Common::Error(Common::kMetaEnginePluginNotFound,
Common::String::format("target '%s'", i->c_str()));
printf("Plugin could not be loaded for target '%s'\n", i->c_str());
printf("MetaEnginePlugin could not be loaded for target '%s'\n", i->c_str());
continue;
} else {
enginePlugin = PluginMan.giveEngineFromMetaEngine(metaEnginePlugin);
if (!enginePlugin) {
// If the target was specified, treat this as an error, and otherwise skip it.
if (!singleTarget.empty())
return Common::Error(Common::kEnginePluginNotFound,
Common::String::format("target '%s'", i->c_str()));
printf("EnginePlugin could not be loaded for target '%s'\n", i->c_str());
continue;
}
}
const MetaEngine &metaEngine = plugin->get<MetaEngine>();
const MetaEngineConnect &metaEngine = enginePlugin->get<MetaEngineConnect>();
Common::String qualifiedGameId = buildQualifiedGameName(game.engineId, game.gameId);
if (!metaEngine.hasFeature(MetaEngine::kSupportsListSaves)) {
if (!metaEngine.hasFeature(MetaEngineConnect::kSupportsListSaves)) {
// If the target was specified, treat this as an error, and otherwise skip it.
if (!singleTarget.empty())
// TODO: Include more info about the target (desc, engine name, ...) ???

View File

@ -531,7 +531,7 @@ void Engine::saveAutosaveIfEnabled() {
if (saveFlag) {
// First check for an existing savegame in the slot, and if present, if it's an autosave
SaveStateDescriptor desc = getMetaEngine().querySaveMetaInfos(
SaveStateDescriptor desc = getMetaEngineConnect().querySaveMetaInfos(
_targetName.c_str(), getAutosaveSlot());
saveFlag = desc.getSaveSlot() == -1 || desc.isAutosave();
}
@ -731,7 +731,7 @@ Common::Error Engine::loadGameState(int slot) {
Common::Error result = loadGameStream(saveFile);
if (result.getCode() == Common::kNoError) {
ExtendedSavegameHeader header;
if (MetaEngine::readSavegameHeader(saveFile, &header))
if (MetaEngineConnect::readSavegameHeader(saveFile, &header))
setTotalPlayTime(header.playtime);
}
@ -757,7 +757,7 @@ Common::Error Engine::saveGameState(int slot, const Common::String &desc, bool i
Common::Error result = saveGameStream(saveFile, isAutosave);
if (result.getCode() == Common::kNoError) {
MetaEngine::appendExtendedSave(saveFile, getTotalPlayTime() / 1000, desc, isAutosave);
MetaEngineConnect::appendExtendedSave(saveFile, getTotalPlayTime() / 1000, desc, isAutosave);
saveFile->finalize();
}

View File

@ -469,14 +469,20 @@ void LauncherDialog::loadGame(int item) {
EngineMan.upgradeTargetIfNecessary(target);
// Look for the plugin
const Plugin *plugin = nullptr;
EngineMan.findTarget(target, &plugin);
const Plugin *metaEnginePlugin = nullptr;
const Plugin *enginePlugin = nullptr;
EngineMan.findTarget(target, &metaEnginePlugin);
if (plugin) {
const MetaEngine &metaEngine = plugin->get<MetaEngine>();
if (metaEngine.hasFeature(MetaEngine::kSupportsListSaves) &&
metaEngine.hasFeature(MetaEngine::kSupportsLoadingDuringStartup)) {
int slot = _loadDialog->runModalWithPluginAndTarget(plugin, target);
// If we found a relevant plugin, find the matching engine plugin.
if (metaEnginePlugin) {
enginePlugin = PluginMan.giveEngineFromMetaEngine(metaEnginePlugin);
}
if (enginePlugin) {
const MetaEngineConnect &metaEngineConnect = enginePlugin->get<MetaEngineConnect>();
if (metaEngineConnect.hasFeature(MetaEngineConnect::kSupportsListSaves) &&
metaEngineConnect.hasFeature(MetaEngineConnect::kSupportsLoadingDuringStartup)) {
int slot = _loadDialog->runModalWithPluginAndTarget(enginePlugin, target);
if (slot >= 0) {
ConfMan.setActiveDomain(_domains[item]);
ConfMan.setInt("save_slot", slot, Common::ConfigManager::kTransientDomain);

View File

@ -103,7 +103,7 @@ void SaveLoadCloudSyncProgressDialog::handleTickle() {
#endif
#ifndef DISABLE_SAVELOADCHOOSER_GRID
SaveLoadChooserType getRequestedSaveLoadDialog(const MetaEngine &metaEngine) {
SaveLoadChooserType getRequestedSaveLoadDialog(const MetaEngineConnect &metaEngine) {
const Common::String &userConfig = ConfMan.get("gui_saveload_chooser", Common::ConfigManager::kApplicationDomain);
// Check (and update if necessary) the theme config here. This catches
@ -114,8 +114,8 @@ SaveLoadChooserType getRequestedSaveLoadDialog(const MetaEngine &metaEngine) {
g_gui.checkScreenChange();
if (g_gui.getWidth() >= 640 && g_gui.getHeight() >= 400
&& metaEngine.hasFeature(MetaEngine::kSavesSupportMetaInfo)
&& metaEngine.hasFeature(MetaEngine::kSavesSupportThumbnail)
&& metaEngine.hasFeature(MetaEngineConnect::kSavesSupportMetaInfo)
&& metaEngine.hasFeature(MetaEngineConnect::kSavesSupportThumbnail)
&& userConfig.equalsIgnoreCase("grid")) {
// In case we are 640x400 or higher, this dialog is not in save mode,
// the user requested the grid dialog and the engines supports it we
@ -182,14 +182,14 @@ void SaveLoadChooserDialog::close() {
Dialog::close();
}
int SaveLoadChooserDialog::run(const Common::String &target, const MetaEngine *metaEngine) {
int SaveLoadChooserDialog::run(const Common::String &target, const MetaEngineConnect *metaEngine) {
_metaEngine = metaEngine;
_target = target;
_delSupport = _metaEngine->hasFeature(MetaEngine::kSupportsDeleteSave);
_metaInfoSupport = _metaEngine->hasFeature(MetaEngine::kSavesSupportMetaInfo);
_thumbnailSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportThumbnail);
_saveDateSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportCreationDate);
_playTimeSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngine::kSavesSupportPlayTime);
_delSupport = _metaEngine->hasFeature(MetaEngineConnect::kSupportsDeleteSave);
_metaInfoSupport = _metaEngine->hasFeature(MetaEngineConnect::kSavesSupportMetaInfo);
_thumbnailSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngineConnect::kSavesSupportThumbnail);
_saveDateSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngineConnect::kSavesSupportCreationDate);
_playTimeSupport = _metaInfoSupport && _metaEngine->hasFeature(MetaEngineConnect::kSavesSupportPlayTime);
return runIntern();
}

View File

@ -65,7 +65,7 @@ enum SaveLoadChooserType {
kSaveLoadDialogGrid = 1
};
SaveLoadChooserType getRequestedSaveLoadDialog(const MetaEngine &metaEngine);
SaveLoadChooserType getRequestedSaveLoadDialog(const MetaEngineConnect &metaEngine);
#endif // !DISABLE_SAVELOADCHOOSER_GRID
class SaveLoadChooserDialog : protected Dialog {
@ -91,7 +91,7 @@ public:
virtual SaveLoadChooserType getType() const = 0;
#endif // !DISABLE_SAVELOADCHOOSER_GRID
int run(const Common::String &target, const MetaEngine *metaEngine);
int run(const Common::String &target, const MetaEngineConnect *metaEngine);
virtual const Common::U32String &getResultString() const = 0;
protected:
@ -110,16 +110,16 @@ protected:
*/
virtual void listSaves();
const bool _saveMode;
const MetaEngine *_metaEngine;
bool _delSupport;
bool _metaInfoSupport;
bool _thumbnailSupport;
bool _saveDateSupport;
bool _playTimeSupport;
Common::String _target;
const bool _saveMode;
const MetaEngineConnect *_metaEngine;
bool _delSupport;
bool _metaInfoSupport;
bool _thumbnailSupport;
bool _saveDateSupport;
bool _playTimeSupport;
Common::String _target;
bool _dialogWasShown;
SaveStateList _saveList;
SaveStateList _saveList;
#ifndef DISABLE_SAVELOADCHOOSER_GRID
ButtonWidget *_listButton;

View File

@ -39,7 +39,7 @@ SaveLoadChooser::~SaveLoadChooser() {
_impl = nullptr;
}
void SaveLoadChooser::selectChooser(const MetaEngine &engine) {
void SaveLoadChooser::selectChooser(const MetaEngineConnect &engine) {
#ifndef DISABLE_SAVELOADCHOOSER_GRID
const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(engine);
if (!_impl || _impl->getType() != requestedType) {
@ -77,14 +77,24 @@ 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.giveEngineFromMetaEngine(plugin);
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(plugin, ConfMan.getActiveDomainName());
return runModalWithPluginAndTarget(enginePlugin, ConfMan.getActiveDomainName());
}
int SaveLoadChooser::runModalWithPluginAndTarget(const Plugin *plugin, const String &target) {
selectChooser(plugin->get<MetaEngine>());
assert(plugin->getType() == PLUGIN_TYPE_ENGINE);
selectChooser(plugin->get<MetaEngineConnect>());
if (!_impl)
return -1;
@ -99,10 +109,10 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const Plugin *plugin, const Str
int ret;
do {
ret = _impl->run(target, &plugin->get<MetaEngine>());
ret = _impl->run(target, &plugin->get<MetaEngineConnect>());
#ifndef DISABLE_SAVELOADCHOOSER_GRID
if (ret == kSwitchSaveLoadDialog) {
selectChooser(plugin->get<MetaEngine>());
selectChooser(plugin->get<MetaEngineConnect>());
}
#endif // !DISABLE_SAVELOADCHOOSER_GRID
} while (ret < -1);

View File

@ -40,7 +40,7 @@ protected:
const U32String _buttonLabel;
const bool _saveMode;
void selectChooser(const MetaEngine &engine);
void selectChooser(const MetaEngineConnect &engine);
public:
SaveLoadChooser(const U32String &title, const U32String &buttonLabel, bool saveMode);
~SaveLoadChooser();