mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-31 07:53:36 +00:00
- Added operator-> to Plugin subclasses so they don't have to reimplement the PluginObject subclass interfaces (thanks to Fingolfin for suggesting it)
- Added the PluginSubclass template to help creating Plugin subclasses svn-id: r32082
This commit is contained in:
parent
3db45cc0c8
commit
fe58f0ee4b
@ -23,7 +23,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/engine.h"
|
||||
#include "engines/metaengine.h"
|
||||
#include "base/commandLine.h"
|
||||
#include "base/plugins.h"
|
||||
#include "base/version.h"
|
||||
@ -559,10 +559,10 @@ static void listGames() {
|
||||
printf("Game ID Full Title \n"
|
||||
"-------------------- ------------------------------------------------------\n");
|
||||
|
||||
const EnginePluginList &plugins = EngineMan.getPlugins();
|
||||
EnginePluginList::const_iterator iter = plugins.begin();
|
||||
const EnginePlugin::list &plugins = EngineMan.getPlugins();
|
||||
EnginePlugin::list::const_iterator iter = plugins.begin();
|
||||
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
||||
GameList list = (*iter)->getSupportedGames();
|
||||
GameList list = (**iter)->getSupportedGames();
|
||||
for (GameList::iterator v = list.begin(); v != list.end(); ++v) {
|
||||
printf("%-20s %s\n", v->gameid().c_str(), v->description().c_str());
|
||||
}
|
||||
@ -622,7 +622,7 @@ static void listSaves(const char *target) {
|
||||
}
|
||||
|
||||
// Query the plugin for a list of savegames
|
||||
SaveStateList saveList = plugin->listSaves(target);
|
||||
SaveStateList saveList = (*plugin)->listSaves(target);
|
||||
|
||||
// TODO: Include more info about the target (desc, engine name, ...) ???
|
||||
printf("Saves for target '%s':\n", target);
|
||||
|
@ -32,6 +32,7 @@
|
||||
*/
|
||||
|
||||
#include "engines/engine.h"
|
||||
#include "engines/metaengine.h"
|
||||
#include "base/commandLine.h"
|
||||
#include "base/plugins.h"
|
||||
#include "base/version.h"
|
||||
@ -138,7 +139,7 @@ static int runGame(const EnginePlugin *plugin, OSystem &system, const Common::St
|
||||
|
||||
// Create the game engine
|
||||
Engine *engine = 0;
|
||||
PluginError err = plugin->createInstance(&system, &engine);
|
||||
PluginError err = (*plugin)->createInstance(&system, &engine);
|
||||
if (!engine || err != kNoError) {
|
||||
// TODO: Show an error dialog or so?
|
||||
// TODO: Also take 'err' into consideration...
|
||||
|
@ -301,43 +301,19 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) {
|
||||
|
||||
#include "engines/metaengine.h"
|
||||
|
||||
const char *EnginePlugin::getCopyright() const {
|
||||
return ((MetaEngine*)_pluginObject)->getCopyright();
|
||||
}
|
||||
|
||||
PluginError EnginePlugin::createInstance(OSystem *syst, Engine **engine) const {
|
||||
return ((MetaEngine*)_pluginObject)->createInstance(syst, engine);
|
||||
}
|
||||
|
||||
GameList EnginePlugin::getSupportedGames() const {
|
||||
return ((MetaEngine*)_pluginObject)->getSupportedGames();
|
||||
}
|
||||
|
||||
GameDescriptor EnginePlugin::findGame(const char *gameid) const {
|
||||
return ((MetaEngine*)_pluginObject)->findGame(gameid);
|
||||
}
|
||||
|
||||
GameList EnginePlugin::detectGames(const FSList &fslist) const {
|
||||
return ((MetaEngine*)_pluginObject)->detectGames(fslist);
|
||||
}
|
||||
|
||||
SaveStateList EnginePlugin::listSaves(const char *target) const {
|
||||
return ((MetaEngine*)_pluginObject)->listSaves(target);
|
||||
}
|
||||
|
||||
DECLARE_SINGLETON(EngineManager);
|
||||
|
||||
GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const {
|
||||
// Find the GameDescriptor for this target
|
||||
const EnginePluginList &plugins = getPlugins();
|
||||
const EnginePlugin::list &plugins = getPlugins();
|
||||
GameDescriptor result;
|
||||
|
||||
if (plugin)
|
||||
*plugin = 0;
|
||||
|
||||
EnginePluginList::const_iterator iter = plugins.begin();
|
||||
EnginePlugin::list::const_iterator iter = plugins.begin();
|
||||
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
||||
result = (*iter)->findGame(gameName.c_str());
|
||||
result = (**iter)->findGame(gameName.c_str());
|
||||
if (!result.gameid().empty()) {
|
||||
if (plugin)
|
||||
*plugin = *iter;
|
||||
@ -350,18 +326,18 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Eng
|
||||
GameList EngineManager::detectGames(const FSList &fslist) const {
|
||||
GameList candidates;
|
||||
|
||||
const EnginePluginList &plugins = getPlugins();
|
||||
const EnginePlugin::list &plugins = getPlugins();
|
||||
|
||||
// Iterate over all known games and for each check if it might be
|
||||
// the game in the presented directory.
|
||||
EnginePluginList::const_iterator iter;
|
||||
EnginePlugin::list::const_iterator iter;
|
||||
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
||||
candidates.push_back((*iter)->detectGames(fslist));
|
||||
candidates.push_back((**iter)->detectGames(fslist));
|
||||
}
|
||||
|
||||
return candidates;
|
||||
}
|
||||
|
||||
const EnginePluginList &EngineManager::getPlugins() const {
|
||||
return (const EnginePluginList&)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
|
||||
const EnginePlugin::list &EngineManager::getPlugins() const {
|
||||
return (const EnginePlugin::list&)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
|
||||
}
|
||||
|
@ -141,6 +141,17 @@ public:
|
||||
/** List of plugins. */
|
||||
typedef Common::Array<Plugin *> PluginList;
|
||||
|
||||
/** Template to help defining Plugin subclasses */
|
||||
template<class PO_t>
|
||||
class PluginSubclass : public Plugin {
|
||||
public:
|
||||
PO_t *operator->() const {
|
||||
return (PO_t *)_pluginObject;
|
||||
}
|
||||
|
||||
typedef Common::Array<PluginSubclass *> list;
|
||||
};
|
||||
|
||||
class PluginProvider {
|
||||
public:
|
||||
virtual ~PluginProvider() {}
|
||||
@ -197,21 +208,10 @@ public:
|
||||
|
||||
// Engine plugins
|
||||
|
||||
class Engine;
|
||||
class FSList;
|
||||
class OSystem;
|
||||
class MetaEngine;
|
||||
|
||||
class EnginePlugin : public Plugin {
|
||||
public:
|
||||
const char *getCopyright() const;
|
||||
PluginError createInstance(OSystem *syst, Engine **engine) const;
|
||||
GameList getSupportedGames() const;
|
||||
GameDescriptor findGame(const char *gameid) const;
|
||||
GameList detectGames(const FSList &fslist) const;
|
||||
SaveStateList listSaves(const char *target) const;
|
||||
};
|
||||
|
||||
typedef Common::Array<EnginePlugin *> EnginePluginList;
|
||||
typedef PluginSubclass<MetaEngine> EnginePlugin;
|
||||
|
||||
class EngineManager : public Common::Singleton<EngineManager> {
|
||||
private:
|
||||
@ -220,7 +220,7 @@ private:
|
||||
public:
|
||||
GameDescriptor findGame(const Common::String &gameName, const EnginePlugin **plugin = NULL) const;
|
||||
GameList detectGames(const FSList &fslist) const;
|
||||
const EnginePluginList &getPlugins() const;
|
||||
const EnginePlugin::list &getPlugins() const;
|
||||
};
|
||||
|
||||
/** Shortcut for accessing the engine manager. */
|
||||
|
@ -22,7 +22,7 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "engines/engine.h"
|
||||
#include "engines/metaengine.h"
|
||||
#include "base/plugins.h"
|
||||
#include "base/version.h"
|
||||
#include "common/events.h"
|
||||
@ -128,8 +128,8 @@ AboutDialog::AboutDialog()
|
||||
_lines.push_back("");
|
||||
|
||||
addLine("\\C\\c1""Available engines:");
|
||||
const EnginePluginList &plugins = EngineMan.getPlugins();
|
||||
EnginePluginList::const_iterator iter = plugins.begin();
|
||||
const EnginePlugin::list &plugins = EngineMan.getPlugins();
|
||||
EnginePlugin::list::const_iterator iter = plugins.begin();
|
||||
for (; iter != plugins.end(); ++iter) {
|
||||
Common::String str;
|
||||
str = "\\C";
|
||||
@ -137,7 +137,7 @@ AboutDialog::AboutDialog()
|
||||
addLine(str.c_str());
|
||||
|
||||
str = "\\C\\c2";
|
||||
str += (**iter).getCopyright();
|
||||
str += (**iter)->getCopyright();
|
||||
addLine(str.c_str());
|
||||
|
||||
//addLine("");
|
||||
|
Loading…
x
Reference in New Issue
Block a user