aboutsummaryrefslogtreecommitdiff
path: root/gui/EventRecorder.cpp
diff options
context:
space:
mode:
authorColin Snover2017-11-10 23:06:42 -0600
committerColin Snover2017-12-03 20:26:38 -0600
commitd087c9605ffffdc9053c5efdc83f53658afbe9a6 (patch)
treedc03820fe11d65d683c386512086f62faeb98089 /gui/EventRecorder.cpp
parent55855cab838c2cb48ea02b983924f4c2b53583c1 (diff)
downloadscummvm-rg350-d087c9605ffffdc9053c5efdc83f53658afbe9a6.tar.gz
scummvm-rg350-d087c9605ffffdc9053c5efdc83f53658afbe9a6.tar.bz2
scummvm-rg350-d087c9605ffffdc9053c5efdc83f53658afbe9a6.zip
BASE: Remove bad casts between incompatible Plugin types
Previously, a C-style cast was used to convert a Common::Array<Plugin *>, populated with pointers to StaticPlugin and DynamicPlugin instances, to a Common::Array<PluginSubclass<T> *>, but PluginSubclass<T> is a *sibling* class to StaticPlugin/DynamicPlugin, so this cast was invalid and the results undefined. The methods for retrieving subclasses of plugins can't be easily changed to just generate an array of temporary wrapper objects that expose an identical API which dereferences to the preferred PluginObject subclass because pointers to these objects are retained by other parts of ScummVM, so the wrappers would needed to be persisted or they would need to just re-expose the underlying Plugin object again. This indicated that a way to solve this problem is to have the callers receive Plugin objects and get the PluginObject from the Plugin by explicitly stating their desired type, in a similar manner to std::get(std::variant), so that the pattern used by this patch to solve the problem. Closes gh-1051.
Diffstat (limited to 'gui/EventRecorder.cpp')
-rw-r--r--gui/EventRecorder.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/gui/EventRecorder.cpp b/gui/EventRecorder.cpp
index f1b486d394..39811513e3 100644
--- a/gui/EventRecorder.cpp
+++ b/gui/EventRecorder.cpp
@@ -598,8 +598,7 @@ void EventRecorder::setFileHeader() {
return;
}
TimeDate t;
- const EnginePlugin *plugin = 0;
- GameDescriptor desc = EngineMan.findGame(ConfMan.getActiveDomainName(), &plugin);
+ GameDescriptor desc = EngineMan.findGame(ConfMan.getActiveDomainName());
g_system->getTimeAndDate(t);
if (_author.empty()) {
setAuthor("Unknown Author");
@@ -619,19 +618,19 @@ SDL_Surface *EventRecorder::getSurface(int width, int height) {
bool EventRecorder::switchMode() {
const Common::String gameId = ConfMan.get("gameid");
- const EnginePlugin *plugin = 0;
+ const Plugin *plugin = nullptr;
EngineMan.findGame(gameId, &plugin);
- bool metaInfoSupport = (*plugin)->hasFeature(MetaEngine::kSavesSupportMetaInfo);
+ bool metaInfoSupport = plugin->get<MetaEngine>().hasFeature(MetaEngine::kSavesSupportMetaInfo);
bool featuresSupport = metaInfoSupport &&
g_engine->canSaveGameStateCurrently() &&
- (*plugin)->hasFeature(MetaEngine::kSupportsListSaves) &&
- (*plugin)->hasFeature(MetaEngine::kSupportsDeleteSave);
+ plugin->get<MetaEngine>().hasFeature(MetaEngine::kSupportsListSaves) &&
+ plugin->get<MetaEngine>().hasFeature(MetaEngine::kSupportsDeleteSave);
if (!featuresSupport) {
return false;
}
int emptySlot = 1;
- SaveStateList saveList = (*plugin)->listSaves(gameId.c_str());
+ SaveStateList saveList = plugin->get<MetaEngine>().listSaves(gameId.c_str());
for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) {
int saveSlot = x->getSaveSlot();
if (saveSlot == 0) {
@@ -667,9 +666,9 @@ bool EventRecorder::checkForContinueGame() {
void EventRecorder::deleteTemporarySave() {
if (_temporarySlot == -1) return;
const Common::String gameId = ConfMan.get("gameid");
- const EnginePlugin *plugin = 0;
+ const Plugin *plugin = 0;
EngineMan.findGame(gameId, &plugin);
- (*plugin)->removeSaveState(gameId.c_str(), _temporarySlot);
+ plugin->get<MetaEngine>().removeSaveState(gameId.c_str(), _temporarySlot);
_temporarySlot = -1;
}