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:
Colin Snover 2017-11-10 23:06:42 -06:00
parent 55855cab83
commit d087c9605f
17 changed files with 117 additions and 132 deletions

View file

@ -92,9 +92,9 @@ MusicType MidiDriver::getMusicType(MidiDriver::DeviceHandle handle) {
return MT_MT32; return MT_MT32;
if (handle) { if (handle) {
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { for (PluginList::const_iterator m = p.begin(); m != p.end(); m++) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) { for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
if (handle == d->getHandle()) if (handle == d->getHandle())
return d->getMusicType(); return d->getMusicType();
@ -107,9 +107,9 @@ MusicType MidiDriver::getMusicType(MidiDriver::DeviceHandle handle) {
Common::String MidiDriver::getDeviceString(DeviceHandle handle, DeviceStringType type) { Common::String MidiDriver::getDeviceString(DeviceHandle handle, DeviceStringType type) {
if (handle) { if (handle) {
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { for (PluginList::const_iterator m = p.begin(); m != p.end(); m++) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) { for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
if (handle == d->getHandle()) { if (handle == d->getHandle()) {
if (type == kDriverName) if (type == kDriverName)
@ -226,7 +226,7 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
// If the selected driver did not match the flags setting, // If the selected driver did not match the flags setting,
// we try to determine a suitable and "optimal" music driver. // we try to determine a suitable and "optimal" music driver.
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
// If only MDT_MIDI but not MDT_PREFER_MT32 or MDT_PREFER_GM is set we prefer the other devices (which will always be // If only MDT_MIDI but not MDT_PREFER_MT32 or MDT_PREFER_GM is set we prefer the other devices (which will always be
// detected since they are hard coded and cannot be disabled). // detected since they are hard coded and cannot be disabled).
bool skipMidi = !(flags & (MDT_PREFER_GM | MDT_PREFER_MT32)); bool skipMidi = !(flags & (MDT_PREFER_GM | MDT_PREFER_MT32));
@ -280,8 +280,8 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
// and there is no preferred MT32 or GM device selected either or if the detected device is unavailable we arrive here. // and there is no preferred MT32 or GM device selected either or if the detected device is unavailable we arrive here.
// If MT32 is preferred we try for the first available device with music type 'MT_MT32' (usually the mt32 emulator). // If MT32 is preferred we try for the first available device with music type 'MT_MT32' (usually the mt32 emulator).
if (flags & MDT_PREFER_MT32) { if (flags & MDT_PREFER_MT32) {
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
if (d->getMusicType() == MT_MT32) { if (d->getMusicType() == MT_MT32) {
hdl = d->getHandle(); hdl = d->getHandle();
@ -295,8 +295,8 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
// Now we default to the first available device with music type 'MT_GM' if not // Now we default to the first available device with music type 'MT_GM' if not
// MT-32 is preferred or if MT-32 is preferred but all other devices have failed. // MT-32 is preferred or if MT-32 is preferred but all other devices have failed.
if (!(flags & MDT_PREFER_MT32) || flags == (MDT_PREFER_MT32 | MDT_MIDI)) { if (!(flags & MDT_PREFER_MT32) || flags == (MDT_PREFER_MT32 | MDT_MIDI)) {
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
if (d->getMusicType() == MT_GM || d->getMusicType() == MT_GS) { if (d->getMusicType() == MT_GM || d->getMusicType() == MT_GS) {
hdl = d->getHandle(); hdl = d->getHandle();
@ -348,8 +348,8 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
tp = MT_AUTO; tp = MT_AUTO;
} }
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
if (d->getMusicType() == tp) { if (d->getMusicType() == tp) {
hdl = d->getHandle(); hdl = d->getHandle();
@ -365,33 +365,35 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
MidiDriver *MidiDriver::createMidi(MidiDriver::DeviceHandle handle) { MidiDriver *MidiDriver::createMidi(MidiDriver::DeviceHandle handle) {
MidiDriver *driver = 0; MidiDriver *driver = 0;
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { for (PluginList::const_iterator m = p.begin(); m != p.end(); m++) {
if (getDeviceString(handle, MidiDriver::kDriverId).equals((**m)->getId())) const MusicPluginObject &musicPlugin = (*m)->get<MusicPluginObject>();
(**m)->createInstance(&driver, handle); if (getDeviceString(handle, MidiDriver::kDriverId).equals(musicPlugin.getId()))
musicPlugin.createInstance(&driver, handle);
} }
return driver; return driver;
} }
bool MidiDriver::checkDevice(MidiDriver::DeviceHandle handle) { bool MidiDriver::checkDevice(MidiDriver::DeviceHandle handle) {
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { for (PluginList::const_iterator m = p.begin(); m != p.end(); m++) {
if (getDeviceString(handle, MidiDriver::kDriverId).equals((**m)->getId())) const MusicPluginObject &musicPlugin = (*m)->get<MusicPluginObject>();
return (**m)->checkDevice(handle); if (getDeviceString(handle, MidiDriver::kDriverId).equals(musicPlugin.getId()))
return musicPlugin.checkDevice(handle);
} }
return false; return false;
} }
MidiDriver::DeviceHandle MidiDriver::getDeviceHandle(const Common::String &identifier) { MidiDriver::DeviceHandle MidiDriver::getDeviceHandle(const Common::String &identifier) {
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
if (p.begin() == p.end()) if (p.begin() == p.end())
error("MidiDriver::getDeviceHandle: Music plugins must be loaded prior to calling this method"); error("MidiDriver::getDeviceHandle: Music plugins must be loaded prior to calling this method");
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { for (PluginList::const_iterator m = p.begin(); m != p.end(); m++) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) { for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
// The music driver id isn't unique, but it will match // The music driver id isn't unique, but it will match
// driver's first device. This is useful when selecting // driver's first device. This is useful when selecting

View file

@ -112,11 +112,6 @@ public:
virtual Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const = 0; virtual Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const = 0;
}; };
// Music plugins
typedef PluginSubclass<MusicPluginObject> MusicPlugin;
/** /**
* Singleton class which manages all Music plugins. * Singleton class which manages all Music plugins.
*/ */
@ -125,7 +120,7 @@ private:
friend class Common::Singleton<SingletonBaseType>; friend class Common::Singleton<SingletonBaseType>;
public: public:
const MusicPlugin::List &getPlugins() const; const PluginList &getPlugins() const;
}; };
/** Convenience shortcut for accessing the Music manager. */ /** Convenience shortcut for accessing the Music manager. */

View file

@ -673,9 +673,9 @@ static void listGames() {
printf("Game ID Full Title \n" printf("Game ID Full Title \n"
"-------------------- ------------------------------------------------------\n"); "-------------------- ------------------------------------------------------\n");
const EnginePlugin::List &plugins = EngineMan.getPlugins(); const PluginList &plugins = EngineMan.getPlugins();
for (EnginePlugin::List::const_iterator iter = plugins.begin(); iter != plugins.end(); ++iter) { for (PluginList::const_iterator iter = plugins.begin(); iter != plugins.end(); ++iter) {
GameList list = (**iter)->getSupportedGames(); GameList list = (*iter)->get<MetaEngine>().getSupportedGames();
for (GameList::iterator v = list.begin(); v != list.end(); ++v) { for (GameList::iterator v = list.begin(); v != list.end(); ++v) {
printf("%-20s %s\n", v->gameid().c_str(), v->description().c_str()); printf("%-20s %s\n", v->gameid().c_str(), v->description().c_str());
} }
@ -741,7 +741,7 @@ static Common::Error listSaves(const char *target) {
gameid.toLowercase(); // Normalize it to lower case gameid.toLowercase(); // Normalize it to lower case
// Find the plugin that will handle the specified gameid // Find the plugin that will handle the specified gameid
const EnginePlugin *plugin = 0; const Plugin *plugin = nullptr;
GameDescriptor game = EngineMan.findGame(gameid, &plugin); GameDescriptor game = EngineMan.findGame(gameid, &plugin);
if (!plugin) { if (!plugin) {
@ -749,13 +749,15 @@ static Common::Error listSaves(const char *target) {
Common::String::format("target '%s', gameid '%s", target, gameid.c_str())); Common::String::format("target '%s', gameid '%s", target, gameid.c_str()));
} }
if (!(*plugin)->hasFeature(MetaEngine::kSupportsListSaves)) { const MetaEngine &metaEngine = plugin->get<MetaEngine>();
if (!metaEngine.hasFeature(MetaEngine::kSupportsListSaves)) {
// TODO: Include more info about the target (desc, engine name, ...) ??? // TODO: Include more info about the target (desc, engine name, ...) ???
return Common::Error(Common::kEnginePluginNotSupportSaves, return Common::Error(Common::kEnginePluginNotSupportSaves,
Common::String::format("target '%s', gameid '%s", target, gameid.c_str())); Common::String::format("target '%s', gameid '%s", target, gameid.c_str()));
} else { } else {
// Query the plugin for a list of saved games // Query the plugin for a list of saved games
SaveStateList saveList = (*plugin)->listSaves(target); SaveStateList saveList = metaEngine.listSaves(target);
if (saveList.size() > 0) { if (saveList.size() > 0) {
// TODO: Include more info about the target (desc, engine name, ...) ??? // TODO: Include more info about the target (desc, engine name, ...) ???
@ -793,13 +795,14 @@ static void listThemes() {
/** Lists all output devices */ /** Lists all output devices */
static void listAudioDevices() { static void listAudioDevices() {
MusicPlugin::List pluginList = MusicMan.getPlugins(); PluginList pluginList = MusicMan.getPlugins();
printf("ID Description\n"); printf("ID Description\n");
printf("------------------------------ ------------------------------------------------\n"); printf("------------------------------ ------------------------------------------------\n");
for (MusicPlugin::List::const_iterator i = pluginList.begin(), iend = pluginList.end(); i != iend; ++i) { for (PluginList::const_iterator i = pluginList.begin(), iend = pluginList.end(); i != iend; ++i) {
MusicDevices deviceList = (**i)->getDevices(); const MusicPluginObject &musicObject = (*i)->get<MusicPluginObject>();
MusicDevices deviceList = musicObject.getDevices();
for (MusicDevices::iterator j = deviceList.begin(), jend = deviceList.end(); j != jend; ++j) { for (MusicDevices::iterator j = deviceList.begin(), jend = deviceList.end(); j != jend; ++j) {
printf("%-30s %s\n", Common::String::format("\"%s\"", j->getCompleteId().c_str()).c_str(), j->getCompleteName().c_str()); printf("%-30s %s\n", Common::String::format("\"%s\"", j->getCompleteId().c_str()).c_str(), j->getCompleteName().c_str());
} }

View file

@ -106,8 +106,8 @@ static bool launcherDialog() {
return (dlg.runModal() != -1); return (dlg.runModal() != -1);
} }
static const EnginePlugin *detectPlugin() { static const Plugin *detectPlugin() {
const EnginePlugin *plugin = 0; const Plugin *plugin = nullptr;
// Make sure the gameid is set in the config manager, and that it is lowercase. // Make sure the gameid is set in the config manager, and that it is lowercase.
Common::String gameid(ConfMan.getActiveDomainName()); Common::String gameid(ConfMan.getActiveDomainName());
@ -141,7 +141,7 @@ static const EnginePlugin *detectPlugin() {
} }
// TODO: specify the possible return values here // TODO: specify the possible return values here
static Common::Error runGame(const EnginePlugin *plugin, OSystem &system, const Common::String &edebuglevels) { static Common::Error runGame(const Plugin *plugin, OSystem &system, const Common::String &edebuglevels) {
// Determine the game data path, for validation and error messages // Determine the game data path, for validation and error messages
Common::FSNode dir(ConfMan.get("path")); Common::FSNode dir(ConfMan.get("path"));
Common::Error err = Common::kNoError; Common::Error err = Common::kNoError;
@ -169,15 +169,16 @@ static Common::Error runGame(const EnginePlugin *plugin, OSystem &system, const
// Create the game engine // Create the game engine
if (err.getCode() == Common::kNoError) { if (err.getCode() == Common::kNoError) {
const MetaEngine &metaEngine = plugin->get<MetaEngine>();
// Set default values for all of the custom engine options // Set default values for all of the custom engine options
// Appareantly some engines query them in their constructor, thus we // Appareantly some engines query them in their constructor, thus we
// need to set this up before instance creation. // need to set this up before instance creation.
const ExtraGuiOptions engineOptions = (*plugin)->getExtraGuiOptions(Common::String()); const ExtraGuiOptions engineOptions = metaEngine.getExtraGuiOptions(Common::String());
for (uint i = 0; i < engineOptions.size(); i++) { for (uint i = 0; i < engineOptions.size(); i++) {
ConfMan.registerDefault(engineOptions[i].configOption, engineOptions[i].defaultState); ConfMan.registerDefault(engineOptions[i].configOption, engineOptions[i].defaultState);
} }
err = (*plugin)->createInstance(&system, &engine); err = metaEngine.createInstance(&system, &engine);
} }
// Check for errors // Check for errors
@ -504,7 +505,7 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
// cleanly, so this is now enabled to encourage people to fix bits :) // cleanly, so this is now enabled to encourage people to fix bits :)
while (0 != ConfMan.getActiveDomain()) { while (0 != ConfMan.getActiveDomain()) {
// Try to find a plugin which feels responsible for the specified game. // Try to find a plugin which feels responsible for the specified game.
const EnginePlugin *plugin = detectPlugin(); const Plugin *plugin = detectPlugin();
if (plugin) { if (plugin) {
// Unload all plugins not needed for this game, // Unload all plugins not needed for this game,
// to save memory // to save memory

View file

@ -457,7 +457,7 @@ DECLARE_SINGLETON(EngineManager);
* For the uncached version, we first try to find the plugin using the gameId * 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. * 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; GameDescriptor result;
// First look for the game using the plugins in memory. This is critical // 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 * 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 // Find the GameDescriptor for this target
const EnginePlugin::List &plugins = getPlugins(); const PluginList &plugins = getPlugins();
GameDescriptor result; GameDescriptor result;
if (plugin) if (plugin)
*plugin = 0; *plugin = 0;
EnginePlugin::List::const_iterator iter; PluginList::const_iterator iter;
for (iter = plugins.begin(); iter != plugins.end(); ++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 (!result.gameid().empty()) {
if (plugin) if (plugin)
*plugin = *iter; *plugin = *iter;
@ -516,22 +516,22 @@ GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &game
GameList EngineManager::detectGames(const Common::FSList &fslist) const { GameList EngineManager::detectGames(const Common::FSList &fslist) const {
GameList candidates; GameList candidates;
EnginePlugin::List plugins; PluginList plugins;
EnginePlugin::List::const_iterator iter; PluginList::const_iterator iter;
PluginManager::instance().loadFirstPlugin(); PluginManager::instance().loadFirstPlugin();
do { do {
plugins = getPlugins(); plugins = getPlugins();
// Iterate over all known games and for each check if it might be // Iterate over all known games and for each check if it might be
// the game in the presented directory. // the game in the presented directory.
for (iter = plugins.begin(); iter != plugins.end(); ++iter) { 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()); } while (PluginManager::instance().loadNextPlugin());
return candidates; return candidates;
} }
const EnginePlugin::List &EngineManager::getPlugins() const { const PluginList &EngineManager::getPlugins() const {
return (const EnginePlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE); return PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
} }
@ -543,6 +543,6 @@ namespace Common {
DECLARE_SINGLETON(MusicManager); DECLARE_SINGLETON(MusicManager);
} }
const MusicPlugin::List &MusicManager::getPlugins() const { const PluginList &MusicManager::getPlugins() const {
return (const MusicPlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_MUSIC); return PluginManager::instance().getPlugins(PLUGIN_TYPE_MUSIC);
} }

View file

@ -190,6 +190,15 @@ public:
PluginType getType() const; PluginType getType() const;
const char *getName() const; const char *getName() const;
template <class T>
T &get() const {
T *pluginObject = dynamic_cast<T *>(_pluginObject);
if (!pluginObject) {
error("Invalid cast of plugin %s", getName());
}
return *pluginObject;
}
/** /**
* The getFileName() function gets the name of the plugin file for those * The getFileName() function gets the name of the plugin file for those
* plugins that have files (ie. not static). It doesn't require the plugin * plugins that have files (ie. not static). It doesn't require the plugin
@ -201,25 +210,6 @@ public:
/** List of Plugin instances. */ /** List of Plugin instances. */
typedef Common::Array<Plugin *> PluginList; typedef Common::Array<Plugin *> PluginList;
/**
* Convenience template to make it easier defining normal Plugin
* subclasses. Namely, the PluginSubclass will manage PluginObjects
* of a type specified via the PO_t template parameter.
*/
template<class PO_t>
class PluginSubclass : public Plugin {
public:
PO_t &operator*() const {
return *(PO_t *)_pluginObject;
}
PO_t *operator->() const {
return (PO_t *)_pluginObject;
}
typedef Common::Array<PluginSubclass *> List;
};
/** /**
* Abstract base class for Plugin factories. Subclasses of this * Abstract base class for Plugin factories. Subclasses of this
* are responsible for creating plugin objects, e.g. by loading * are responsible for creating plugin objects, e.g. by loading

View file

@ -262,20 +262,15 @@ public:
//@} //@}
}; };
// Engine plugins
typedef PluginSubclass<MetaEngine> EnginePlugin;
/** /**
* Singleton class which manages all Engine plugins. * Singleton class which manages all Engine plugins.
*/ */
class EngineManager : public Common::Singleton<EngineManager> { class EngineManager : public Common::Singleton<EngineManager> {
public: public:
GameDescriptor findGameInLoadedPlugins(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 EnginePlugin **plugin = NULL) const; GameDescriptor findGame(const Common::String &gameName, const Plugin **plugin = NULL) const;
GameList detectGames(const Common::FSList &fslist) const; GameList detectGames(const Common::FSList &fslist) const;
const EnginePlugin::List &getPlugins() const; const PluginList &getPlugins() const;
}; };
/** Convenience shortcut for accessing the engine manager. */ /** Convenience shortcut for accessing the engine manager. */

View file

@ -870,7 +870,7 @@ void SavegameListBox::pageDown() {
} }
int GameStateMenu::scummVMSaveLoadDialog(bool isSave, Common::String &saveDesc) { int GameStateMenu::scummVMSaveLoadDialog(bool isSave, Common::String &saveDesc) {
const EnginePlugin *plugin = NULL; const Plugin *plugin = nullptr;
EngineMan.findGame(ConfMan.get("gameid"), &plugin); EngineMan.findGame(ConfMan.get("gameid"), &plugin);
GUI::SaveLoadChooser *dialog; GUI::SaveLoadChooser *dialog;
Common::String desc; Common::String desc;

View file

@ -356,7 +356,7 @@ Common::Error PegasusEngine::showLoadDialog() {
Common::String gameId = ConfMan.get("gameid"); Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0; const Plugin *plugin = nullptr;
EngineMan.findGame(gameId, &plugin); EngineMan.findGame(gameId, &plugin);
int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
@ -380,7 +380,7 @@ Common::Error PegasusEngine::showSaveDialog() {
Common::String gameId = ConfMan.get("gameid"); Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0; const Plugin *plugin = nullptr;
EngineMan.findGame(gameId, &plugin); EngineMan.findGame(gameId, &plugin);
int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); int slot = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());

View file

@ -598,8 +598,7 @@ void EventRecorder::setFileHeader() {
return; return;
} }
TimeDate t; TimeDate t;
const EnginePlugin *plugin = 0; GameDescriptor desc = EngineMan.findGame(ConfMan.getActiveDomainName());
GameDescriptor desc = EngineMan.findGame(ConfMan.getActiveDomainName(), &plugin);
g_system->getTimeAndDate(t); g_system->getTimeAndDate(t);
if (_author.empty()) { if (_author.empty()) {
setAuthor("Unknown Author"); setAuthor("Unknown Author");
@ -619,19 +618,19 @@ SDL_Surface *EventRecorder::getSurface(int width, int height) {
bool EventRecorder::switchMode() { bool EventRecorder::switchMode() {
const Common::String gameId = ConfMan.get("gameid"); const Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0; const Plugin *plugin = nullptr;
EngineMan.findGame(gameId, &plugin); EngineMan.findGame(gameId, &plugin);
bool metaInfoSupport = (*plugin)->hasFeature(MetaEngine::kSavesSupportMetaInfo); bool metaInfoSupport = plugin->get<MetaEngine>().hasFeature(MetaEngine::kSavesSupportMetaInfo);
bool featuresSupport = metaInfoSupport && bool featuresSupport = metaInfoSupport &&
g_engine->canSaveGameStateCurrently() && g_engine->canSaveGameStateCurrently() &&
(*plugin)->hasFeature(MetaEngine::kSupportsListSaves) && plugin->get<MetaEngine>().hasFeature(MetaEngine::kSupportsListSaves) &&
(*plugin)->hasFeature(MetaEngine::kSupportsDeleteSave); plugin->get<MetaEngine>().hasFeature(MetaEngine::kSupportsDeleteSave);
if (!featuresSupport) { if (!featuresSupport) {
return false; return false;
} }
int emptySlot = 1; 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) { for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) {
int saveSlot = x->getSaveSlot(); int saveSlot = x->getSaveSlot();
if (saveSlot == 0) { if (saveSlot == 0) {
@ -667,9 +666,9 @@ bool EventRecorder::checkForContinueGame() {
void EventRecorder::deleteTemporarySave() { void EventRecorder::deleteTemporarySave() {
if (_temporarySlot == -1) return; if (_temporarySlot == -1) return;
const Common::String gameId = ConfMan.get("gameid"); const Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0; const Plugin *plugin = 0;
EngineMan.findGame(gameId, &plugin); EngineMan.findGame(gameId, &plugin);
(*plugin)->removeSaveState(gameId.c_str(), _temporarySlot); plugin->get<MetaEngine>().removeSaveState(gameId.c_str(), _temporarySlot);
_temporarySlot = -1; _temporarySlot = -1;
} }

View file

@ -110,16 +110,16 @@ AboutDialog::AboutDialog()
engines += _("Available engines:"); engines += _("Available engines:");
addLine(engines.c_str()); addLine(engines.c_str());
const EnginePlugin::List &plugins = EngineMan.getPlugins(); const PluginList &plugins = EngineMan.getPlugins();
EnginePlugin::List::const_iterator iter = plugins.begin(); PluginList::const_iterator iter = plugins.begin();
for (; iter != plugins.end(); ++iter) { for (; iter != plugins.end(); ++iter) {
Common::String str; Common::String str;
str = "C0"; str = "C0";
str += (**iter).getName(); str += (*iter)->getName();
addLine(str.c_str()); addLine(str.c_str());
str = "C2"; str = "C2";
str += (**iter)->getOriginalCopyright(); str += (*iter)->get<MetaEngine>().getOriginalCopyright();
addLine(str.c_str()); addLine(str.c_str());
//addLine(""); //addLine("");

View file

@ -97,7 +97,7 @@ protected:
EditGameDialog::EditGameDialog(const String &domain, const String &desc) EditGameDialog::EditGameDialog(const String &domain, const String &desc)
: OptionsDialog(domain, "GameOptions") { : OptionsDialog(domain, "GameOptions") {
// Retrieve all game specific options. // Retrieve all game specific options.
const EnginePlugin *plugin = 0; const Plugin *plugin = nullptr;
// To allow for game domains without a gameid. // To allow for game domains without a gameid.
// TODO: Is it intentional that this is still supported? // TODO: Is it intentional that this is still supported?
String gameId(ConfMan.get("gameid", domain)); String gameId(ConfMan.get("gameid", domain));
@ -107,7 +107,7 @@ EditGameDialog::EditGameDialog(const String &domain, const String &desc)
// implementation. // implementation.
EngineMan.findGame(gameId, &plugin); EngineMan.findGame(gameId, &plugin);
if (plugin) { if (plugin) {
_engineOptions = (*plugin)->getExtraGuiOptions(domain); _engineOptions = plugin->get<MetaEngine>().getExtraGuiOptions(domain);
} else { } else {
warning("Plugin for target \"%s\" not found! Game specific settings might be missing", domain.c_str()); warning("Plugin for target \"%s\" not found! Game specific settings might be missing", domain.c_str());
} }

View file

@ -504,7 +504,7 @@ void LauncherDialog::loadGame(int item) {
if (gameId.empty()) if (gameId.empty())
gameId = _domains[item]; gameId = _domains[item];
const EnginePlugin *plugin = 0; const Plugin *plugin = nullptr;
EngineMan.findGame(gameId, &plugin); EngineMan.findGame(gameId, &plugin);
@ -512,8 +512,9 @@ void LauncherDialog::loadGame(int item) {
target.toLowercase(); target.toLowercase();
if (plugin) { if (plugin) {
if ((*plugin)->hasFeature(MetaEngine::kSupportsListSaves) && const MetaEngine &metaEngine = plugin->get<MetaEngine>();
(*plugin)->hasFeature(MetaEngine::kSupportsLoadingDuringStartup)) { if (metaEngine.hasFeature(MetaEngine::kSupportsListSaves) &&
metaEngine.hasFeature(MetaEngine::kSupportsLoadingDuringStartup)) {
int slot = _loadDialog->runModalWithPluginAndTarget(plugin, target); int slot = _loadDialog->runModalWithPluginAndTarget(plugin, target);
if (slot >= 0) { if (slot >= 0) {
ConfMan.setActiveDomain(_domains[item]); ConfMan.setActiveDomain(_domains[item]);

View file

@ -1040,9 +1040,9 @@ void OptionsDialog::addAudioControls(GuiObject *boss, const Common::String &pref
const Common::String allFlags = MidiDriver::musicType2GUIO((uint32)-1); const Common::String allFlags = MidiDriver::musicType2GUIO((uint32)-1);
bool hasMidiDefined = (strpbrk(_guioptions.c_str(), allFlags.c_str()) != NULL); bool hasMidiDefined = (strpbrk(_guioptions.c_str(), allFlags.c_str()) != NULL);
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
Common::String deviceGuiOption = MidiDriver::musicType2GUIO(d->getMusicType()); Common::String deviceGuiOption = MidiDriver::musicType2GUIO(d->getMusicType());
@ -1078,19 +1078,19 @@ void OptionsDialog::addMIDIControls(GuiObject *boss, const Common::String &prefi
_gmDevicePopUp = new PopUpWidget(boss, prefix + "auPrefGmPopup"); _gmDevicePopUp = new PopUpWidget(boss, prefix + "auPrefGmPopup");
// Populate // Populate
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
// Make sure the null device is the first one in the list to avoid undesired // Make sure the null device is the first one in the list to avoid undesired
// auto detection for users who don't have a saved setting yet. // auto detection for users who don't have a saved setting yet.
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
if (d->getMusicDriverId() == "null") if (d->getMusicDriverId() == "null")
_gmDevicePopUp->appendEntry(_("Don't use General MIDI music"), d->getHandle()); _gmDevicePopUp->appendEntry(_("Don't use General MIDI music"), d->getHandle());
} }
} }
// Now we add the other devices. // Now we add the other devices.
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
if (d->getMusicType() >= MT_GM) { if (d->getMusicType() >= MT_GM) {
if (d->getMusicType() != MT_MT32) if (d->getMusicType() != MT_MT32)
@ -1141,19 +1141,19 @@ void OptionsDialog::addMT32Controls(GuiObject *boss, const Common::String &prefi
// GS Extensions setting // GS Extensions setting
_enableGSCheckbox = new CheckboxWidget(boss, prefix + "mcGSCheckbox", _("Roland GS Device (enable MT-32 mappings)"), _("Check if you want to enable patch mappings to emulate an MT-32 on a Roland GS device")); _enableGSCheckbox = new CheckboxWidget(boss, prefix + "mcGSCheckbox", _("Roland GS Device (enable MT-32 mappings)"), _("Check if you want to enable patch mappings to emulate an MT-32 on a Roland GS device"));
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
// Make sure the null device is the first one in the list to avoid undesired // Make sure the null device is the first one in the list to avoid undesired
// auto detection for users who don't have a saved setting yet. // auto detection for users who don't have a saved setting yet.
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
if (d->getMusicDriverId() == "null") if (d->getMusicDriverId() == "null")
_mt32DevicePopUp->appendEntry(_("Don't use Roland MT-32 music"), d->getHandle()); _mt32DevicePopUp->appendEntry(_("Don't use Roland MT-32 music"), d->getHandle());
} }
} }
// Now we add the other devices. // Now we add the other devices.
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
if (d->getMusicType() >= MT_GM) if (d->getMusicType() >= MT_GM)
_mt32DevicePopUp->appendEntry(d->getCompleteName(), d->getHandle()); _mt32DevicePopUp->appendEntry(d->getCompleteName(), d->getHandle());
@ -1265,10 +1265,10 @@ bool OptionsDialog::loadMusicDeviceSetting(PopUpWidget *popup, Common::String se
if (_domain != Common::ConfigManager::kApplicationDomain || ConfMan.hasKey(setting, _domain) || preferredType) { if (_domain != Common::ConfigManager::kApplicationDomain || ConfMan.hasKey(setting, _domain) || preferredType) {
const Common::String drv = ConfMan.get(setting, (_domain != Common::ConfigManager::kApplicationDomain && !ConfMan.hasKey(setting, _domain)) ? Common::ConfigManager::kApplicationDomain : _domain); const Common::String drv = ConfMan.get(setting, (_domain != Common::ConfigManager::kApplicationDomain && !ConfMan.hasKey(setting, _domain)) ? Common::ConfigManager::kApplicationDomain : _domain);
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
if (setting.empty() ? (preferredType == d->getMusicType()) : (drv == d->getCompleteId())) { if (setting.empty() ? (preferredType == d->getMusicType()) : (drv == d->getCompleteId())) {
popup->setSelectedTag(d->getHandle()); popup->setSelectedTag(d->getHandle());
@ -1285,10 +1285,10 @@ void OptionsDialog::saveMusicDeviceSetting(PopUpWidget *popup, Common::String se
if (!popup || !_enableAudioSettings) if (!popup || !_enableAudioSettings)
return; return;
const MusicPlugin::List p = MusicMan.getPlugins(); const PluginList p = MusicMan.getPlugins();
bool found = false; bool found = false;
for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end() && !found; ++m) { for (PluginList::const_iterator m = p.begin(); m != p.end() && !found; ++m) {
MusicDevices i = (**m)->getDevices(); MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) { for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
if (d->getHandle() == popup->getSelectedTag()) { if (d->getHandle() == popup->getSelectedTag()) {
ConfMan.set(setting, d->getCompleteId(), _domain); ConfMan.set(setting, d->getCompleteId(), _domain);

View file

@ -167,8 +167,7 @@ void RecorderDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
case kRecordCmd: { case kRecordCmd: {
TimeDate t; TimeDate t;
Common::String gameId = ConfMan.get("gameid", _target); Common::String gameId = ConfMan.get("gameid", _target);
const EnginePlugin *plugin = 0; GameDescriptor desc = EngineMan.findGame(gameId);
GameDescriptor desc = EngineMan.findGame(gameId, &plugin);
g_system->getTimeAndDate(t); g_system->getTimeAndDate(t);
EditRecordDialog editDlg(_("Unknown Author"), Common::String::format("%.2d.%.2d.%.4d ", t.tm_mday, t.tm_mon, 1900 + t.tm_year) + desc.description(), ""); EditRecordDialog editDlg(_("Unknown Author"), Common::String::format("%.2d.%.2d.%.4d ", t.tm_mday, t.tm_mon, 1900 + t.tm_year) + desc.description(), "");
if (editDlg.runModal() != kOKCmd) { if (editDlg.runModal() != kOKCmd) {

View file

@ -76,14 +76,14 @@ Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) con
int SaveLoadChooser::runModalWithCurrentTarget() { int SaveLoadChooser::runModalWithCurrentTarget() {
const Common::String gameId = ConfMan.get("gameid"); const Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0; const Plugin *plugin = 0;
EngineMan.findGame(gameId, &plugin); EngineMan.findGame(gameId, &plugin);
return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
} }
int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) { int SaveLoadChooser::runModalWithPluginAndTarget(const Plugin *plugin, const String &target) {
selectChooser(**plugin); selectChooser(plugin->get<MetaEngine>());
if (!_impl) if (!_impl)
return -1; return -1;
@ -98,10 +98,10 @@ int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, con
int ret; int ret;
do { do {
ret = _impl->run(target, &(**plugin)); ret = _impl->run(target, &plugin->get<MetaEngine>());
#ifndef DISABLE_SAVELOADCHOOSER_GRID #ifndef DISABLE_SAVELOADCHOOSER_GRID
if (ret == kSwitchSaveLoadDialog) { if (ret == kSwitchSaveLoadDialog) {
selectChooser(**plugin); selectChooser(plugin->get<MetaEngine>());
} }
#endif // !DISABLE_SAVELOADCHOOSER_GRID #endif // !DISABLE_SAVELOADCHOOSER_GRID
} while (ret < -1); } while (ret < -1);

View file

@ -51,7 +51,7 @@ public:
* @return The selcted save slot. -1 in case none is selected. * @return The selcted save slot. -1 in case none is selected.
*/ */
int runModalWithCurrentTarget(); int runModalWithCurrentTarget();
int runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target); int runModalWithPluginAndTarget(const Plugin *plugin, const String &target);
const Common::String &getResultString() const; const Common::String &getResultString() const;