mirror of
https://github.com/libretro/scummvm.git
synced 2024-11-27 03:10:37 +00:00
Initial support for plugin types
svn-id: r30825
This commit is contained in:
parent
49d0b1f91e
commit
c103290e2b
@ -31,6 +31,7 @@
|
||||
|
||||
class DynamicPlugin : public Plugin {
|
||||
protected:
|
||||
typedef int32 (*IntFunc)();
|
||||
typedef void (*VoidFunc)();
|
||||
typedef PluginObject *(*GetObjectFunc)();
|
||||
|
||||
@ -38,6 +39,18 @@ protected:
|
||||
|
||||
public:
|
||||
virtual bool loadPlugin() {
|
||||
// Get the type of the plugin
|
||||
IntFunc typeFunc = (IntFunc)findSymbol("PLUGIN_getType");
|
||||
if (!typeFunc) {
|
||||
unloadPlugin();
|
||||
return false;
|
||||
}
|
||||
_type = (PluginType)typeFunc();
|
||||
if (_type >= PLUGIN_TYPE_MAX) {
|
||||
unloadPlugin();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the plugin's instantiator object
|
||||
GetObjectFunc getObject = (GetObjectFunc)findSymbol("PLUGIN_getObject");
|
||||
if (!getObject) {
|
||||
@ -54,7 +67,7 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual void unloadPlugin() {
|
||||
delete _pluginObject;
|
||||
}
|
||||
|
@ -26,6 +26,9 @@
|
||||
#include "base/plugins.h"
|
||||
#include "common/util.h"
|
||||
|
||||
PluginType Plugin::getType() const {
|
||||
return _type;
|
||||
}
|
||||
|
||||
const char *Plugin::getName() const {
|
||||
return _pluginObject->getName();
|
||||
@ -59,9 +62,11 @@ SaveStateList Plugin::listSaves(const char *target) const {
|
||||
#ifndef DYNAMIC_MODULES
|
||||
class StaticPlugin : public Plugin {
|
||||
public:
|
||||
StaticPlugin(PluginObject *pluginobject) {
|
||||
StaticPlugin(PluginObject *pluginobject, PluginType type) {
|
||||
assert(pluginobject);
|
||||
assert(type < PLUGIN_TYPE_MAX);
|
||||
_pluginObject = pluginobject;
|
||||
_type = type;
|
||||
}
|
||||
|
||||
~StaticPlugin() {
|
||||
@ -84,8 +89,9 @@ public:
|
||||
PluginList pl;
|
||||
|
||||
#define LINK_PLUGIN(ID) \
|
||||
extern PluginType g_##ID##_type; \
|
||||
extern PluginObject *g_##ID##_getObject(); \
|
||||
pl.push_back(new StaticPlugin(g_##ID##_getObject()));
|
||||
pl.push_back(new StaticPlugin(g_##ID##_getObject(), g_##ID##_type));
|
||||
|
||||
// "Loader" for the static plugins.
|
||||
// Iterate over all registered (static) plugins and load them.
|
||||
|
@ -48,6 +48,12 @@ public:
|
||||
|
||||
#include "engines/metaengine.h"
|
||||
|
||||
enum PluginType {
|
||||
PLUGIN_TYPE_ENGINE = 0,
|
||||
|
||||
PLUGIN_TYPE_MAX
|
||||
};
|
||||
|
||||
class Engine;
|
||||
class FSList;
|
||||
class OSystem;
|
||||
@ -60,6 +66,7 @@ class OSystem;
|
||||
class Plugin {
|
||||
protected:
|
||||
PluginObject *_pluginObject;
|
||||
PluginType _type;
|
||||
|
||||
public:
|
||||
Plugin() : _pluginObject(0) {}
|
||||
@ -72,6 +79,7 @@ public:
|
||||
virtual bool loadPlugin() = 0; // TODO: Rename to load() ?
|
||||
virtual void unloadPlugin() = 0; // TODO: Rename to unload() ?
|
||||
|
||||
PluginType getType() const;
|
||||
const char *getName() const;
|
||||
const char *getCopyright() const;
|
||||
|
||||
@ -95,14 +103,16 @@ public:
|
||||
*/
|
||||
|
||||
#ifndef DYNAMIC_MODULES
|
||||
#define REGISTER_PLUGIN(ID,PLUGINCLASS) \
|
||||
#define REGISTER_PLUGIN(ID,TYPE,PLUGINCLASS) \
|
||||
PluginType g_##ID##_type = TYPE; \
|
||||
PluginObject *g_##ID##_getObject() { \
|
||||
return new PLUGINCLASS(); \
|
||||
} \
|
||||
void dummyFuncToAllowTrailingSemicolon()
|
||||
#else
|
||||
#define REGISTER_PLUGIN(ID,PLUGINCLASS) \
|
||||
#define REGISTER_PLUGIN(ID,TYPE,PLUGINCLASS) \
|
||||
extern "C" { \
|
||||
PLUGIN_EXPORT int32 PLUGIN_getType() { return TYPE; } \
|
||||
PLUGIN_EXPORT PluginObject *PLUGIN_getObject() { \
|
||||
return new PLUGINCLASS(); \
|
||||
} \
|
||||
|
@ -2284,5 +2284,4 @@ bool AgiMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common:
|
||||
return res;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(AGI, AgiMetaEngine);
|
||||
|
||||
REGISTER_PLUGIN(AGI, PLUGIN_TYPE_ENGINE, AgiMetaEngine);
|
||||
|
@ -151,7 +151,7 @@ bool AgosMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
|
||||
return res;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(AGOS, AgosMetaEngine);
|
||||
REGISTER_PLUGIN(AGOS, PLUGIN_TYPE_ENGINE, AgosMetaEngine);
|
||||
|
||||
namespace AGOS {
|
||||
|
||||
|
@ -511,4 +511,4 @@ bool CineMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
|
||||
return gd != 0;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(CINE, CineMetaEngine);
|
||||
REGISTER_PLUGIN(CINE, PLUGIN_TYPE_ENGINE, CineMetaEngine);
|
||||
|
@ -146,4 +146,4 @@ bool CruiseMetaEngine::createInstance(OSystem *syst, Engine **engine, const Comm
|
||||
return gd != 0;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(CRUISE, CruiseMetaEngine);
|
||||
REGISTER_PLUGIN(CRUISE, PLUGIN_TYPE_ENGINE, CruiseMetaEngine);
|
||||
|
@ -186,4 +186,4 @@ bool DrasculaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Co
|
||||
return gd != 0;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(DRASCULA, DrasculaMetaEngine);
|
||||
REGISTER_PLUGIN(DRASCULA, PLUGIN_TYPE_ENGINE, DrasculaMetaEngine);
|
||||
|
@ -1779,7 +1779,7 @@ bool GobMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common:
|
||||
return gd != 0;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(GOB, GobMetaEngine);
|
||||
REGISTER_PLUGIN(GOB, PLUGIN_TYPE_ENGINE, GobMetaEngine);
|
||||
|
||||
namespace Gob {
|
||||
|
||||
|
@ -134,4 +134,4 @@ bool IgorMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
|
||||
return gd != 0;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(IGOR, IgorMetaEngine);
|
||||
REGISTER_PLUGIN(IGOR, PLUGIN_TYPE_ENGINE, IgorMetaEngine);
|
||||
|
@ -484,4 +484,4 @@ bool KyraMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
|
||||
return res;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(KYRA, KyraMetaEngine);
|
||||
REGISTER_PLUGIN(KYRA, PLUGIN_TYPE_ENGINE, KyraMetaEngine);
|
||||
|
@ -197,4 +197,4 @@ bool LureMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
|
||||
return gd != 0;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(LURE, LureMetaEngine);
|
||||
REGISTER_PLUGIN(LURE, PLUGIN_TYPE_ENGINE, LureMetaEngine);
|
||||
|
@ -218,4 +218,4 @@ bool ParallactionMetaEngine::createInstance(OSystem *syst, Engine **engine, cons
|
||||
return res;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(PARALLACTION, ParallactionMetaEngine);
|
||||
REGISTER_PLUGIN(PARALLACTION, PLUGIN_TYPE_ENGINE, ParallactionMetaEngine);
|
||||
|
@ -127,7 +127,7 @@ PluginError QueenMetaEngine::createInstance(OSystem *syst, Engine **engine) cons
|
||||
return kNoError;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(QUEEN, QueenMetaEngine);
|
||||
REGISTER_PLUGIN(QUEEN, PLUGIN_TYPE_ENGINE, QueenMetaEngine);
|
||||
|
||||
namespace Queen {
|
||||
|
||||
|
@ -164,7 +164,7 @@ bool SagaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
|
||||
return gd != 0;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(SAGA, SagaMetaEngine);
|
||||
REGISTER_PLUGIN(SAGA, PLUGIN_TYPE_ENGINE, SagaMetaEngine);
|
||||
|
||||
namespace Saga {
|
||||
|
||||
|
@ -964,4 +964,4 @@ SaveStateList ScummMetaEngine::listSaves(const char *target) const {
|
||||
return saveList;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(SCUMM, ScummMetaEngine);
|
||||
REGISTER_PLUGIN(SCUMM, PLUGIN_TYPE_ENGINE, ScummMetaEngine);
|
||||
|
@ -194,7 +194,7 @@ PluginError SkyMetaEngine::createInstance(OSystem *syst, Engine **engine) const
|
||||
return kNoError;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(SKY, SkyMetaEngine);
|
||||
REGISTER_PLUGIN(SKY, PLUGIN_TYPE_ENGINE, SkyMetaEngine);
|
||||
|
||||
namespace Sky {
|
||||
|
||||
|
@ -187,7 +187,7 @@ PluginError SwordMetaEngine::createInstance(OSystem *syst, Engine **engine) cons
|
||||
return kNoError;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(SWORD1, SwordMetaEngine);
|
||||
REGISTER_PLUGIN(SWORD1, PLUGIN_TYPE_ENGINE, SwordMetaEngine);
|
||||
|
||||
namespace Sword1 {
|
||||
|
||||
|
@ -180,7 +180,7 @@ PluginError Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) con
|
||||
return kNoGameDataFoundError;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(SWORD2, Sword2MetaEngine);
|
||||
REGISTER_PLUGIN(SWORD2, PLUGIN_TYPE_ENGINE, Sword2MetaEngine);
|
||||
|
||||
namespace Sword2 {
|
||||
|
||||
|
@ -131,6 +131,7 @@ public:
|
||||
virtual const char *getName() const {
|
||||
return "Touche Engine";
|
||||
}
|
||||
|
||||
virtual const char *getCopyright() const {
|
||||
return "Touche: The Adventures of the 5th Musketeer (C) Clipper Software";
|
||||
}
|
||||
@ -138,7 +139,6 @@ public:
|
||||
virtual bool createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const;
|
||||
};
|
||||
|
||||
|
||||
bool ToucheMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const {
|
||||
const Common::ADGameDescription *gd = encapsulatedDesc.realDesc;
|
||||
if (gd) {
|
||||
@ -147,4 +147,4 @@ bool ToucheMetaEngine::createInstance(OSystem *syst, Engine **engine, const Comm
|
||||
return gd != 0;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN(TOUCHE, ToucheMetaEngine);
|
||||
REGISTER_PLUGIN(TOUCHE, PLUGIN_TYPE_ENGINE, ToucheMetaEngine);
|
||||
|
@ -1 +1,2 @@
|
||||
_PLUGIN_getType
|
||||
_PLUGIN_getObject
|
||||
|
Loading…
Reference in New Issue
Block a user