aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorColin Snover2017-11-10 23:06:42 -0600
committerColin Snover2017-12-03 20:26:38 -0600
commitd087c9605ffffdc9053c5efdc83f53658afbe9a6 (patch)
treedc03820fe11d65d683c386512086f62faeb98089 /engines
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 'engines')
-rw-r--r--engines/metaengine.h11
-rw-r--r--engines/neverhood/menumodule.cpp2
-rw-r--r--engines/pegasus/pegasus.cpp4
3 files changed, 6 insertions, 11 deletions
diff --git a/engines/metaengine.h b/engines/metaengine.h
index 568b66ac51..b3aaa96a8f 100644
--- a/engines/metaengine.h
+++ b/engines/metaengine.h
@@ -262,20 +262,15 @@ public:
//@}
};
-
-// Engine plugins
-
-typedef PluginSubclass<MetaEngine> EnginePlugin;
-
/**
* Singleton class which manages all Engine plugins.
*/
class EngineManager : public Common::Singleton<EngineManager> {
public:
- GameDescriptor findGameInLoadedPlugins(const Common::String &gameName, const EnginePlugin **plugin = NULL) const;
- GameDescriptor findGame(const Common::String &gameName, const EnginePlugin **plugin = NULL) const;
+ GameDescriptor findGameInLoadedPlugins(const Common::String &gameName, const Plugin **plugin = NULL) const;
+ GameDescriptor findGame(const Common::String &gameName, const Plugin **plugin = NULL) const;
GameList detectGames(const Common::FSList &fslist) const;
- const EnginePlugin::List &getPlugins() const;
+ const PluginList &getPlugins() const;
};
/** Convenience shortcut for accessing the engine manager. */
diff --git a/engines/neverhood/menumodule.cpp b/engines/neverhood/menumodule.cpp
index e58dd31f03..e3996a2507 100644
--- a/engines/neverhood/menumodule.cpp
+++ b/engines/neverhood/menumodule.cpp
@@ -870,7 +870,7 @@ void SavegameListBox::pageDown() {
}
int GameStateMenu::scummVMSaveLoadDialog(bool isSave, Common::String &saveDesc) {
- const EnginePlugin *plugin = NULL;
+ const Plugin *plugin = nullptr;
EngineMan.findGame(ConfMan.get("gameid"), &plugin);
GUI::SaveLoadChooser *dialog;
Common::String desc;
diff --git a/engines/pegasus/pegasus.cpp b/engines/pegasus/pegasus.cpp
index 5f756449dd..f2c0afba5c 100644
--- a/engines/pegasus/pegasus.cpp
+++ b/engines/pegasus/pegasus.cpp
@@ -356,7 +356,7 @@ Common::Error PegasusEngine::showLoadDialog() {
Common::String gameId = ConfMan.get("gameid");
- const EnginePlugin *plugin = 0;
+ const Plugin *plugin = nullptr;
EngineMan.findGame(gameId, &plugin);
int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
@@ -380,7 +380,7 @@ Common::Error PegasusEngine::showSaveDialog() {
Common::String gameId = ConfMan.get("gameid");
- const EnginePlugin *plugin = 0;
+ const Plugin *plugin = nullptr;
EngineMan.findGame(gameId, &plugin);
int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());