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.
This commit is contained in:
parent
55855cab83
commit
d087c9605f
17 changed files with 117 additions and 132 deletions
|
@ -457,7 +457,7 @@ DECLARE_SINGLETON(EngineManager);
|
|||
* For the uncached version, we first try to find the plugin using the gameId
|
||||
* and only if we can't find it there, we loop through the plugins.
|
||||
**/
|
||||
GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const {
|
||||
GameDescriptor EngineManager::findGame(const Common::String &gameName, const Plugin **plugin) const {
|
||||
GameDescriptor result;
|
||||
|
||||
// First look for the game using the plugins in memory. This is critical
|
||||
|
@ -493,18 +493,18 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Eng
|
|||
/**
|
||||
* Find the game within the plugins loaded in memory
|
||||
**/
|
||||
GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &gameName, const EnginePlugin **plugin) const {
|
||||
GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &gameName, const Plugin **plugin) const {
|
||||
// Find the GameDescriptor for this target
|
||||
const EnginePlugin::List &plugins = getPlugins();
|
||||
const PluginList &plugins = getPlugins();
|
||||
GameDescriptor result;
|
||||
|
||||
if (plugin)
|
||||
*plugin = 0;
|
||||
|
||||
EnginePlugin::List::const_iterator iter;
|
||||
PluginList::const_iterator iter;
|
||||
|
||||
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
||||
result = (**iter)->findGame(gameName.c_str());
|
||||
result = (*iter)->get<MetaEngine>().findGame(gameName.c_str());
|
||||
if (!result.gameid().empty()) {
|
||||
if (plugin)
|
||||
*plugin = *iter;
|
||||
|
@ -516,22 +516,22 @@ GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &game
|
|||
|
||||
GameList EngineManager::detectGames(const Common::FSList &fslist) const {
|
||||
GameList candidates;
|
||||
EnginePlugin::List plugins;
|
||||
EnginePlugin::List::const_iterator iter;
|
||||
PluginList plugins;
|
||||
PluginList::const_iterator iter;
|
||||
PluginManager::instance().loadFirstPlugin();
|
||||
do {
|
||||
plugins = getPlugins();
|
||||
// Iterate over all known games and for each check if it might be
|
||||
// the game in the presented directory.
|
||||
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
||||
candidates.push_back((**iter)->detectGames(fslist));
|
||||
candidates.push_back((*iter)->get<MetaEngine>().detectGames(fslist));
|
||||
}
|
||||
} while (PluginManager::instance().loadNextPlugin());
|
||||
return candidates;
|
||||
}
|
||||
|
||||
const EnginePlugin::List &EngineManager::getPlugins() const {
|
||||
return (const EnginePlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
|
||||
const PluginList &EngineManager::getPlugins() const {
|
||||
return PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -543,6 +543,6 @@ namespace Common {
|
|||
DECLARE_SINGLETON(MusicManager);
|
||||
}
|
||||
|
||||
const MusicPlugin::List &MusicManager::getPlugins() const {
|
||||
return (const MusicPlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_MUSIC);
|
||||
const PluginList &MusicManager::getPlugins() const {
|
||||
return PluginManager::instance().getPlugins(PLUGIN_TYPE_MUSIC);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue