- 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
5 changed files with 33 additions and 56 deletions
|
@ -23,7 +23,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "engines/engine.h"
|
#include "engines/metaengine.h"
|
||||||
#include "base/commandLine.h"
|
#include "base/commandLine.h"
|
||||||
#include "base/plugins.h"
|
#include "base/plugins.h"
|
||||||
#include "base/version.h"
|
#include "base/version.h"
|
||||||
|
@ -559,10 +559,10 @@ static void listGames() {
|
||||||
printf("Game ID Full Title \n"
|
printf("Game ID Full Title \n"
|
||||||
"-------------------- ------------------------------------------------------\n");
|
"-------------------- ------------------------------------------------------\n");
|
||||||
|
|
||||||
const EnginePluginList &plugins = EngineMan.getPlugins();
|
const EnginePlugin::list &plugins = EngineMan.getPlugins();
|
||||||
EnginePluginList::const_iterator iter = plugins.begin();
|
EnginePlugin::list::const_iterator iter = plugins.begin();
|
||||||
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
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) {
|
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());
|
||||||
}
|
}
|
||||||
|
@ -622,7 +622,7 @@ static void listSaves(const char *target) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the plugin for a list of savegames
|
// 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, ...) ???
|
// TODO: Include more info about the target (desc, engine name, ...) ???
|
||||||
printf("Saves for target '%s':\n", target);
|
printf("Saves for target '%s':\n", target);
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "engines/engine.h"
|
#include "engines/engine.h"
|
||||||
|
#include "engines/metaengine.h"
|
||||||
#include "base/commandLine.h"
|
#include "base/commandLine.h"
|
||||||
#include "base/plugins.h"
|
#include "base/plugins.h"
|
||||||
#include "base/version.h"
|
#include "base/version.h"
|
||||||
|
@ -138,7 +139,7 @@ static int runGame(const EnginePlugin *plugin, OSystem &system, const Common::St
|
||||||
|
|
||||||
// Create the game engine
|
// Create the game engine
|
||||||
Engine *engine = 0;
|
Engine *engine = 0;
|
||||||
PluginError err = plugin->createInstance(&system, &engine);
|
PluginError err = (*plugin)->createInstance(&system, &engine);
|
||||||
if (!engine || err != kNoError) {
|
if (!engine || err != kNoError) {
|
||||||
// TODO: Show an error dialog or so?
|
// TODO: Show an error dialog or so?
|
||||||
// TODO: Also take 'err' into consideration...
|
// TODO: Also take 'err' into consideration...
|
||||||
|
|
|
@ -301,43 +301,19 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) {
|
||||||
|
|
||||||
#include "engines/metaengine.h"
|
#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);
|
DECLARE_SINGLETON(EngineManager);
|
||||||
|
|
||||||
GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const {
|
GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const {
|
||||||
// Find the GameDescriptor for this target
|
// Find the GameDescriptor for this target
|
||||||
const EnginePluginList &plugins = getPlugins();
|
const EnginePlugin::list &plugins = getPlugins();
|
||||||
GameDescriptor result;
|
GameDescriptor result;
|
||||||
|
|
||||||
if (plugin)
|
if (plugin)
|
||||||
*plugin = 0;
|
*plugin = 0;
|
||||||
|
|
||||||
EnginePluginList::const_iterator iter = plugins.begin();
|
EnginePlugin::list::const_iterator iter = plugins.begin();
|
||||||
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
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 (!result.gameid().empty()) {
|
||||||
if (plugin)
|
if (plugin)
|
||||||
*plugin = *iter;
|
*plugin = *iter;
|
||||||
|
@ -350,18 +326,18 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Eng
|
||||||
GameList EngineManager::detectGames(const FSList &fslist) const {
|
GameList EngineManager::detectGames(const FSList &fslist) const {
|
||||||
GameList candidates;
|
GameList candidates;
|
||||||
|
|
||||||
const EnginePluginList &plugins = getPlugins();
|
const EnginePlugin::list &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.
|
||||||
EnginePluginList::const_iterator iter;
|
EnginePlugin::list::const_iterator iter;
|
||||||
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)->detectGames(fslist));
|
||||||
}
|
}
|
||||||
|
|
||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EnginePluginList &EngineManager::getPlugins() const {
|
const EnginePlugin::list &EngineManager::getPlugins() const {
|
||||||
return (const EnginePluginList&)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
|
return (const EnginePlugin::list&)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,6 +141,17 @@ public:
|
||||||
/** List of plugins. */
|
/** List of plugins. */
|
||||||
typedef Common::Array<Plugin *> PluginList;
|
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 {
|
class PluginProvider {
|
||||||
public:
|
public:
|
||||||
virtual ~PluginProvider() {}
|
virtual ~PluginProvider() {}
|
||||||
|
@ -197,21 +208,10 @@ public:
|
||||||
|
|
||||||
// Engine plugins
|
// Engine plugins
|
||||||
|
|
||||||
class Engine;
|
|
||||||
class FSList;
|
class FSList;
|
||||||
class OSystem;
|
class MetaEngine;
|
||||||
|
|
||||||
class EnginePlugin : public Plugin {
|
typedef PluginSubclass<MetaEngine> EnginePlugin;
|
||||||
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;
|
|
||||||
|
|
||||||
class EngineManager : public Common::Singleton<EngineManager> {
|
class EngineManager : public Common::Singleton<EngineManager> {
|
||||||
private:
|
private:
|
||||||
|
@ -220,7 +220,7 @@ private:
|
||||||
public:
|
public:
|
||||||
GameDescriptor findGame(const Common::String &gameName, const EnginePlugin **plugin = NULL) const;
|
GameDescriptor findGame(const Common::String &gameName, const EnginePlugin **plugin = NULL) const;
|
||||||
GameList detectGames(const FSList &fslist) const;
|
GameList detectGames(const FSList &fslist) const;
|
||||||
const EnginePluginList &getPlugins() const;
|
const EnginePlugin::list &getPlugins() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Shortcut for accessing the engine manager. */
|
/** Shortcut for accessing the engine manager. */
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
* $Id$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "engines/engine.h"
|
#include "engines/metaengine.h"
|
||||||
#include "base/plugins.h"
|
#include "base/plugins.h"
|
||||||
#include "base/version.h"
|
#include "base/version.h"
|
||||||
#include "common/events.h"
|
#include "common/events.h"
|
||||||
|
@ -128,8 +128,8 @@ AboutDialog::AboutDialog()
|
||||||
_lines.push_back("");
|
_lines.push_back("");
|
||||||
|
|
||||||
addLine("\\C\\c1""Available engines:");
|
addLine("\\C\\c1""Available engines:");
|
||||||
const EnginePluginList &plugins = EngineMan.getPlugins();
|
const EnginePlugin::list &plugins = EngineMan.getPlugins();
|
||||||
EnginePluginList::const_iterator iter = plugins.begin();
|
EnginePlugin::list::const_iterator iter = plugins.begin();
|
||||||
for (; iter != plugins.end(); ++iter) {
|
for (; iter != plugins.end(); ++iter) {
|
||||||
Common::String str;
|
Common::String str;
|
||||||
str = "\\C";
|
str = "\\C";
|
||||||
|
@ -137,7 +137,7 @@ AboutDialog::AboutDialog()
|
||||||
addLine(str.c_str());
|
addLine(str.c_str());
|
||||||
|
|
||||||
str = "\\C\\c2";
|
str = "\\C\\c2";
|
||||||
str += (**iter).getCopyright();
|
str += (**iter)->getCopyright();
|
||||||
addLine(str.c_str());
|
addLine(str.c_str());
|
||||||
|
|
||||||
//addLine("");
|
//addLine("");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue