Change MetaEngine references to PluginObject where possible to make its semantics more generic.
svn-id: r30789
This commit is contained in:
parent
468e9cb056
commit
e4ab5dd339
5 changed files with 48 additions and 36 deletions
|
@ -27,27 +27,27 @@
|
|||
#define BACKENDS_PLUGINS_DYNAMICPLUGIN_H
|
||||
|
||||
#include "base/plugins.h"
|
||||
#include "engines/metaengine.h"
|
||||
|
||||
|
||||
class DynamicPlugin : public Plugin {
|
||||
protected:
|
||||
typedef void (*VoidFunc)();
|
||||
typedef MetaEngine *(*MetaAllocFunc)();
|
||||
typedef PluginObject *(*GetObjectFunc)();
|
||||
|
||||
virtual VoidFunc findSymbol(const char *symbol) = 0;
|
||||
|
||||
public:
|
||||
virtual bool loadPlugin() {
|
||||
// Query the plugin's name
|
||||
MetaAllocFunc metaAlloc = (MetaAllocFunc)findSymbol("PLUGIN_MetaEngine_alloc");
|
||||
if (!metaAlloc) {
|
||||
// Get the plugin's instantiator object
|
||||
GetObjectFunc getObject = (GetObjectFunc)findSymbol("PLUGIN_getObject");
|
||||
if (!getObject) {
|
||||
unloadPlugin();
|
||||
return false;
|
||||
}
|
||||
|
||||
_metaengine = metaAlloc();
|
||||
if (!_metaengine) {
|
||||
// Get the plugin object
|
||||
_pluginObject = getObject();
|
||||
if (!_pluginObject) {
|
||||
unloadPlugin();
|
||||
return false;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
}
|
||||
|
||||
virtual void unloadPlugin() {
|
||||
delete _metaengine;
|
||||
delete _pluginObject;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,48 +25,47 @@
|
|||
|
||||
#include "base/plugins.h"
|
||||
#include "common/util.h"
|
||||
#include "engines/metaengine.h"
|
||||
|
||||
|
||||
const char *Plugin::getName() const {
|
||||
return _metaengine->getName();
|
||||
return _pluginObject->getName();
|
||||
}
|
||||
|
||||
const char *Plugin::getCopyright() const {
|
||||
return _metaengine->getCopyright();
|
||||
return ((MetaEngine*)_pluginObject)->getCopyright();
|
||||
}
|
||||
|
||||
PluginError Plugin::createInstance(OSystem *syst, Engine **engine) const {
|
||||
return _metaengine->createInstance(syst, engine);
|
||||
return ((MetaEngine*)_pluginObject)->createInstance(syst, engine);
|
||||
}
|
||||
|
||||
GameList Plugin::getSupportedGames() const {
|
||||
return _metaengine->getSupportedGames();
|
||||
return ((MetaEngine*)_pluginObject)->getSupportedGames();
|
||||
}
|
||||
|
||||
GameDescriptor Plugin::findGame(const char *gameid) const {
|
||||
return _metaengine->findGame(gameid);
|
||||
return ((MetaEngine*)_pluginObject)->findGame(gameid);
|
||||
}
|
||||
|
||||
GameList Plugin::detectGames(const FSList &fslist) const {
|
||||
return _metaengine->detectGames(fslist);
|
||||
return ((MetaEngine*)_pluginObject)->detectGames(fslist);
|
||||
}
|
||||
|
||||
SaveStateList Plugin::listSaves(const char *target) const {
|
||||
return _metaengine->listSaves(target);
|
||||
return ((MetaEngine*)_pluginObject)->listSaves(target);
|
||||
}
|
||||
|
||||
|
||||
#ifndef DYNAMIC_MODULES
|
||||
class StaticPlugin : public Plugin {
|
||||
public:
|
||||
StaticPlugin(MetaEngine *metaengine) {
|
||||
assert(metaengine);
|
||||
_metaengine = metaengine;
|
||||
StaticPlugin(PluginObject *pluginobject) {
|
||||
assert(pluginobject);
|
||||
_pluginObject = pluginobject;
|
||||
}
|
||||
|
||||
~StaticPlugin() {
|
||||
delete _metaengine;
|
||||
delete _pluginObject;
|
||||
}
|
||||
|
||||
virtual bool loadPlugin() { return true; }
|
||||
|
@ -85,8 +84,8 @@ public:
|
|||
PluginList pl;
|
||||
|
||||
#define LINK_PLUGIN(ID) \
|
||||
extern MetaEngine *g_##ID##_MetaEngine_alloc(); \
|
||||
pl.push_back(new StaticPlugin(g_##ID##_MetaEngine_alloc()));
|
||||
extern PluginObject *g_##ID##_getObject(); \
|
||||
pl.push_back(new StaticPlugin(g_##ID##_getObject()));
|
||||
|
||||
// "Loader" for the static plugins.
|
||||
// Iterate over all registered (static) plugins and load them.
|
||||
|
|
|
@ -33,9 +33,23 @@
|
|||
#include "common/util.h"
|
||||
#include "base/game.h"
|
||||
|
||||
/**
|
||||
* Abstract base class for the plugin objects which handle plugins
|
||||
* instantiation. Subclasses for this may be used for engine plugins
|
||||
* and other types of plugins.
|
||||
*/
|
||||
class PluginObject {
|
||||
public:
|
||||
virtual ~PluginObject() {}
|
||||
|
||||
/** Returns the name of the plugin. */
|
||||
virtual const char *getName() const = 0;
|
||||
};
|
||||
|
||||
#include "engines/metaengine.h"
|
||||
|
||||
class Engine;
|
||||
class FSList;
|
||||
class MetaEngine;
|
||||
class OSystem;
|
||||
|
||||
/**
|
||||
|
@ -45,10 +59,10 @@ class OSystem;
|
|||
*/
|
||||
class Plugin {
|
||||
protected:
|
||||
MetaEngine *_metaengine;
|
||||
PluginObject *_pluginObject;
|
||||
|
||||
public:
|
||||
Plugin() : _metaengine(0) {}
|
||||
Plugin() : _pluginObject(0) {}
|
||||
virtual ~Plugin() {
|
||||
//if (isLoaded())
|
||||
//unloadPlugin();
|
||||
|
@ -81,16 +95,16 @@ public:
|
|||
*/
|
||||
|
||||
#ifndef DYNAMIC_MODULES
|
||||
#define REGISTER_PLUGIN(ID,METAENGINE) \
|
||||
MetaEngine *g_##ID##_MetaEngine_alloc() { \
|
||||
return new METAENGINE(); \
|
||||
#define REGISTER_PLUGIN(ID,PLUGINCLASS) \
|
||||
PluginObject *g_##ID##_getObject() { \
|
||||
return new PLUGINCLASS(); \
|
||||
} \
|
||||
void dummyFuncToAllowTrailingSemicolon()
|
||||
#else
|
||||
#define REGISTER_PLUGIN(ID,METAENGINE) \
|
||||
#define REGISTER_PLUGIN(ID,PLUGINCLASS) \
|
||||
extern "C" { \
|
||||
PLUGIN_EXPORT MetaEngine *PLUGIN_MetaEngine_alloc() { \
|
||||
return new METAENGINE(); \
|
||||
PLUGIN_EXPORT PluginObject *PLUGIN_getObject() { \
|
||||
return new PLUGINCLASS(); \
|
||||
} \
|
||||
} \
|
||||
void dummyFuncToAllowTrailingSemicolon()
|
||||
|
|
|
@ -28,8 +28,10 @@
|
|||
#include "common/scummsys.h"
|
||||
#include "common/str.h"
|
||||
#include "common/error.h"
|
||||
#include "common/fs.h"
|
||||
|
||||
#include "base/game.h"
|
||||
#include "base/plugins.h"
|
||||
|
||||
class Engine;
|
||||
class OSystem;
|
||||
|
@ -42,13 +44,10 @@ class OSystem;
|
|||
* This is then in turn used by the frontend code to detect games,
|
||||
* and instantiate actual Engine objects.
|
||||
*/
|
||||
class MetaEngine {
|
||||
class MetaEngine : public PluginObject {
|
||||
public:
|
||||
virtual ~MetaEngine() {}
|
||||
|
||||
/** Returns the name of the engine. */
|
||||
virtual const char *getName() const = 0;
|
||||
|
||||
/** Returns some copyright information about the engine. */
|
||||
virtual const char *getCopyright() const = 0;
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
_PLUGIN_MetaEngine_alloc
|
||||
_PLUGIN_getObject
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue