From 8a73356a2d6e2d6b7ecefb53e0d5e82484f0e697 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 3 Feb 2008 18:56:47 +0000 Subject: Revised Engine plugin API to only provide a single func which returns a MetaEngine instance. Used this to simplify the rest of the plugin system svn-id: r30780 --- backends/plugins/dynamic-plugin.h | 86 +++++++++++--------------------------- base/plugins.cpp | 41 +++++++++--------- base/plugins.h | 69 ++++-------------------------- engines/agi/detection.cpp | 4 +- engines/agos/detection.cpp | 4 +- engines/cine/detection.cpp | 4 +- engines/cruise/detection.cpp | 4 +- engines/drascula/detection.cpp | 4 +- engines/gob/detection.cpp | 4 +- engines/igor/detection.cpp | 4 +- engines/kyra/detection.cpp | 4 +- engines/lure/detection.cpp | 4 +- engines/metaengine.h | 21 ---------- engines/parallaction/detection.cpp | 4 +- engines/queen/queen.cpp | 4 +- engines/saga/detection.cpp | 4 +- engines/scumm/detection.cpp | 6 +-- engines/sky/sky.cpp | 5 +-- engines/sword1/sword1.cpp | 4 +- engines/sword2/sword2.cpp | 4 +- engines/touche/detection.cpp | 4 +- 21 files changed, 71 insertions(+), 217 deletions(-) diff --git a/backends/plugins/dynamic-plugin.h b/backends/plugins/dynamic-plugin.h index 44b379a625..3ae0b1e644 100644 --- a/backends/plugins/dynamic-plugin.h +++ b/backends/plugins/dynamic-plugin.h @@ -27,95 +27,59 @@ #define BACKENDS_PLUGINS_DYNAMICPLUGIN_H #include "base/plugins.h" - - -/** Type of factory functions which make new Engine objects. */ -typedef PluginError (*EngineFactory)(OSystem *syst, Engine **engine); - -typedef const char *(*NameFunc)(); -typedef GameDescriptor (*GameIDQueryFunc)(const char *gameid); -typedef GameList (*GameIDListFunc)(); -typedef GameList (*DetectFunc)(const FSList &fslist); +#include "engines/metaengine.h" class DynamicPlugin : public Plugin { protected: typedef void (*VoidFunc)(); - Common::String _name; - Common::String _copyright; - GameIDQueryFunc _qf; - EngineFactory _ef; - DetectFunc _df; - GameList _games; + typedef MetaEngine *(*MetaAllocFunc)(); + + MetaEngine *_metaengine; virtual VoidFunc findSymbol(const char *symbol) = 0; public: - DynamicPlugin() : _qf(0), _ef(0), _df(0), _games() {} + DynamicPlugin() : _metaengine(0) {} + ~DynamicPlugin() { + delete _metaengine; + } - const char *getName() const { return _name.c_str(); } - const char *getCopyright() const { return _copyright.c_str(); } + const char *getName() const { + return _metaengine->getName(); + } + + const char *getCopyright() const { + return _metaengine->getCopyright(); + } PluginError createInstance(OSystem *syst, Engine **engine) const { - assert(_ef); - return (*_ef)(syst, engine); + return _metaengine->createInstance(syst, engine); } - GameList getSupportedGames() const { return _games; } + GameList getSupportedGames() const { + return _metaengine->getSupportedGames(); + } GameDescriptor findGame(const char *gameid) const { - assert(_qf); - return (*_qf)(gameid); + return _metaengine->findGame(gameid); } GameList detectGames(const FSList &fslist) const { - assert(_df); - return (*_df)(fslist); + return _metaengine->detectGames(fslist); } virtual bool loadPlugin() { // Query the plugin's name - NameFunc nameFunc = (NameFunc)findSymbol("PLUGIN_name"); - if (!nameFunc) { - unloadPlugin(); - return false; - } - _name = nameFunc(); - - // Query the plugin's copyright - nameFunc = (NameFunc)findSymbol("PLUGIN_copyright"); - if (!nameFunc) { - unloadPlugin(); - return false; - } - _copyright = nameFunc(); - - // Query the plugin for the game ids it supports - GameIDListFunc gameListFunc = (GameIDListFunc)findSymbol("PLUGIN_gameIDList"); - if (!gameListFunc) { - unloadPlugin(); - return false; - } - _games = gameListFunc(); - - // Retrieve the gameid query function - _qf = (GameIDQueryFunc)findSymbol("PLUGIN_findGameID"); - if (!_qf) { - unloadPlugin(); - return false; - } - - // Retrieve the factory function - _ef = (EngineFactory)findSymbol("PLUGIN_createEngine"); - if (!_ef) { + MetaAllocFunc metaAlloc = (MetaAllocFunc)findSymbol("PLUGIN_MetaEngine_alloc"); + if (!metaAlloc) { unloadPlugin(); return false; } - // Retrieve the detector function - _df = (DetectFunc)findSymbol("PLUGIN_detectGames"); - if (!_df) { + _metaengine = metaAlloc(); + if (!_metaengine) { unloadPlugin(); return false; } diff --git a/base/plugins.cpp b/base/plugins.cpp index 7ccd99ce34..67ead04649 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -25,42 +25,47 @@ #include "base/plugins.h" #include "common/util.h" +#include "engines/metaengine.h" #ifndef DYNAMIC_MODULES class StaticPlugin : public Plugin { - PluginRegistrator *_plugin; + MetaEngine *_metaengine; public: - StaticPlugin(PluginRegistrator *plugin) - : _plugin(plugin) { - assert(_plugin); + StaticPlugin(MetaEngine *metaengine) + : _metaengine(metaengine) { + assert(_metaengine); } ~StaticPlugin() { - delete _plugin; + delete _metaengine; } virtual bool loadPlugin() { return true; } virtual void unloadPlugin() {} - const char *getName() const { return _plugin->_name; } - const char *getCopyright() const { return _plugin->_copyright; } + const char *getName() const { + return _metaengine->getName(); + } + + const char *getCopyright() const { + return _metaengine->getCopyright(); + } PluginError createInstance(OSystem *syst, Engine **engine) const { - assert(_plugin->_ef); - return (*_plugin->_ef)(syst, engine); + return _metaengine->createInstance(syst, engine); } - GameList getSupportedGames() const { return _plugin->_games; } + GameList getSupportedGames() const { + return _metaengine->getSupportedGames(); + } GameDescriptor findGame(const char *gameid) const { - assert(_plugin->_qf); - return (*_plugin->_qf)(gameid); + return _metaengine->findGame(gameid); } GameList detectGames(const FSList &fslist) const { - assert(_plugin->_df); - return (*_plugin->_df)(fslist); + return _metaengine->detectGames(fslist); } }; @@ -76,15 +81,11 @@ public: PluginList pl; #define LINK_PLUGIN(ID) \ - extern PluginRegistrator *g_##ID##_PluginReg; \ - extern void g_##ID##_PluginReg_alloc(); \ - g_##ID##_PluginReg_alloc(); \ - plugin = g_##ID##_PluginReg; \ - pl.push_back(new StaticPlugin(plugin)); + extern MetaEngine *g_##ID##_MetaEngine_alloc(); \ + pl.push_back(new StaticPlugin(g_##ID##_MetaEngine_alloc())); // "Loader" for the static plugins. // Iterate over all registered (static) plugins and load them. - PluginRegistrator *plugin; #ifndef DISABLE_SCUMM LINK_PLUGIN(SCUMM) diff --git a/base/plugins.h b/base/plugins.h index b37c4eba29..966d65d959 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -35,6 +35,7 @@ class Engine; class FSList; +class MetaEngine; class OSystem; /** @@ -67,75 +68,25 @@ public: * makes it possible to compile the very same code in a module * both as a static and a dynamic plugin. * - * Each plugin has to define the following functions: - * - GameList Engine_##ID##_gameIDList() - * -> returns a list of gameid/desc pairs. Only used to implement '--list-games'. - * - GameDescriptor Engine_##ID##_findGameID(const char *gameid) - * -> asks the Engine for a GameDescriptor matching the gameid. If that is not - * possible, the engine MUST set the gameid of the returned value to 0. - * Note: This MUST succeed for every gameID on the list returned by - * gameIDList(), but MAY also work for additional gameids (e.g. to support - * obsolete targets). - * - GameList Engine_##ID##_detectGames(const FSList &fslist) - * -> scans through the given file list (usually the contents of a directory), - * and attempts to detects games present in that location. - * - PluginError Engine_##ID##_create(OSystem *syst, Engine **engine) - * -> factory function, create an instance of the Engine class. - * * @todo add some means to query the plugin API version etc. */ #ifndef DYNAMIC_MODULES -#define REGISTER_PLUGIN(ID,name,copyright) \ - PluginRegistrator *g_##ID##_PluginReg; \ - void g_##ID##_PluginReg_alloc() { \ - g_##ID##_PluginReg = new PluginRegistrator(name, copyright, \ - Engine_##ID##_gameIDList(), \ - Engine_##ID##_findGameID, \ - Engine_##ID##_create, \ - Engine_##ID##_detectGames \ - );\ +#define REGISTER_PLUGIN(ID,METAENGINE) \ + MetaEngine *g_##ID##_MetaEngine_alloc() { \ + return new METAENGINE(); \ } \ void dummyFuncToAllowTrailingSemicolon() #else -#define REGISTER_PLUGIN(ID,name,copyright) \ +#define REGISTER_PLUGIN(ID,METAENGINE) \ extern "C" { \ - PLUGIN_EXPORT const char *PLUGIN_name() { return name; } \ - PLUGIN_EXPORT const char *PLUGIN_copyright() { return copyright; } \ - PLUGIN_EXPORT GameList PLUGIN_gameIDList() { return Engine_##ID##_gameIDList(); } \ - PLUGIN_EXPORT GameDescriptor PLUGIN_findGameID(const char *gameid) { return Engine_##ID##_findGameID(gameid); } \ - PLUGIN_EXPORT PluginError PLUGIN_createEngine(OSystem *syst, Engine **engine) { return Engine_##ID##_create(syst, engine); } \ - PLUGIN_EXPORT GameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \ + PLUGIN_EXPORT MetaEngine *PLUGIN_MetaEngine_alloc() { \ + return new METAENGINE(); \ + } \ } \ void dummyFuncToAllowTrailingSemicolon() #endif -#ifndef DYNAMIC_MODULES -/** - * The PluginRegistrator class is used by the static version of REGISTER_PLUGIN - * to allow static 'plugins' to register with the PluginManager. - */ -class PluginRegistrator { - friend class StaticPlugin; -public: - typedef GameDescriptor (*GameIDQueryFunc)(const char *gameid); - typedef PluginError (*EngineFactory)(OSystem *syst, Engine **engine); - typedef GameList (*DetectFunc)(const FSList &fslist); - -protected: - const char *_name; - const char *_copyright; - GameIDQueryFunc _qf; - EngineFactory _ef; - DetectFunc _df; - GameList _games; - -public: - PluginRegistrator(const char *name, const char *copyright, GameList games, GameIDQueryFunc qf, EngineFactory ef, DetectFunc df) - : _name(name), _copyright(copyright), _qf(qf), _ef(ef), _df(df), _games(games) {} -}; -#endif - /** List of plugins. */ typedef Common::Array PluginList; @@ -154,13 +105,9 @@ public: virtual PluginList getPlugins() = 0; }; -//class PluginManager; - /** * Instances of this class manage all plugins, including loading them, * making wrapper objects of class Plugin available, and unloading them. - * - * @todo Add support for dynamic plugins (this may need additional API, e.g. for a plugin path) */ class PluginManager : public Common::Singleton { typedef Common::List ProviderList; diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp index f9d42633af..6a9479c7c5 100644 --- a/engines/agi/detection.cpp +++ b/engines/agi/detection.cpp @@ -2284,7 +2284,5 @@ bool AgiMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common: return res; } -META_COMPATIBILITY_WRAPPER(AGI, AgiMetaEngine); - -REGISTER_PLUGIN(AGI, "AGI preAGI + v2 + v3 Engine", "Sierra AGI Engine (C) Sierra On-Line Software"); +REGISTER_PLUGIN(AGI, AgiMetaEngine); diff --git a/engines/agos/detection.cpp b/engines/agos/detection.cpp index 74ce517f59..73106b65d5 100644 --- a/engines/agos/detection.cpp +++ b/engines/agos/detection.cpp @@ -151,9 +151,7 @@ bool AgosMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common return res; } -META_COMPATIBILITY_WRAPPER(AGOS, AgosMetaEngine); - -REGISTER_PLUGIN(AGOS, "AGOS", "AGOS (C) Adventure Soft"); +REGISTER_PLUGIN(AGOS, AgosMetaEngine); namespace AGOS { diff --git a/engines/cine/detection.cpp b/engines/cine/detection.cpp index fd1769e6b8..af59a106f5 100644 --- a/engines/cine/detection.cpp +++ b/engines/cine/detection.cpp @@ -511,6 +511,4 @@ bool CineMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common return gd != 0; } -META_COMPATIBILITY_WRAPPER(CINE, CineMetaEngine); - -REGISTER_PLUGIN(CINE, "Cinematique evo 1 engine", "Future Wars & Operation Stealth (C) Delphine Software"); +REGISTER_PLUGIN(CINE, CineMetaEngine); diff --git a/engines/cruise/detection.cpp b/engines/cruise/detection.cpp index 2758867c35..a6e3e909c2 100644 --- a/engines/cruise/detection.cpp +++ b/engines/cruise/detection.cpp @@ -146,6 +146,4 @@ bool CruiseMetaEngine::createInstance(OSystem *syst, Engine **engine, const Comm return gd != 0; } -META_COMPATIBILITY_WRAPPER(CRUISE, CruiseMetaEngine); - -REGISTER_PLUGIN(CRUISE, "Cinematique evo 2 engine", "Cruise for a Corpse (C) Delphine Software"); +REGISTER_PLUGIN(CRUISE, CruiseMetaEngine); diff --git a/engines/drascula/detection.cpp b/engines/drascula/detection.cpp index 484869ecaa..63fb6c92ad 100644 --- a/engines/drascula/detection.cpp +++ b/engines/drascula/detection.cpp @@ -186,6 +186,4 @@ bool DrasculaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Co return gd != 0; } -META_COMPATIBILITY_WRAPPER(DRASCULA, DrasculaMetaEngine); - -REGISTER_PLUGIN(DRASCULA, "Drascula Engine", "Drascula Engine (C) 2000 Alcachofa Soft, 1996 (C) Digital Dreams Multimedia, 1994 (C) Emilio de Paz"); +REGISTER_PLUGIN(DRASCULA, DrasculaMetaEngine); diff --git a/engines/gob/detection.cpp b/engines/gob/detection.cpp index a752523bde..b9ba12d224 100644 --- a/engines/gob/detection.cpp +++ b/engines/gob/detection.cpp @@ -1779,9 +1779,7 @@ bool GobMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common: return gd != 0; } -META_COMPATIBILITY_WRAPPER(GOB, GobMetaEngine); - -REGISTER_PLUGIN(GOB, "Gob Engine", "Goblins Games (C) Coktel Vision"); +REGISTER_PLUGIN(GOB, GobMetaEngine); namespace Gob { diff --git a/engines/igor/detection.cpp b/engines/igor/detection.cpp index 6f16e2f30a..dcfc40bcd5 100644 --- a/engines/igor/detection.cpp +++ b/engines/igor/detection.cpp @@ -134,6 +134,4 @@ bool IgorMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common return gd != 0; } -META_COMPATIBILITY_WRAPPER(IGOR, IgorMetaEngine); - -REGISTER_PLUGIN(IGOR, "Igor: Objective Uikokahonia", "Igor: Objective Uikokahonia (C) Pendulo Studios"); +REGISTER_PLUGIN(IGOR, IgorMetaEngine); diff --git a/engines/kyra/detection.cpp b/engines/kyra/detection.cpp index a1bb7c5656..a1556d6e26 100644 --- a/engines/kyra/detection.cpp +++ b/engines/kyra/detection.cpp @@ -484,6 +484,4 @@ bool KyraMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common return res; } -META_COMPATIBILITY_WRAPPER(KYRA, KyraMetaEngine); - -REGISTER_PLUGIN(KYRA, "Legend of Kyrandia Engine", "The Legend of Kyrandia (C) Westwood Studios"); +REGISTER_PLUGIN(KYRA, KyraMetaEngine); diff --git a/engines/lure/detection.cpp b/engines/lure/detection.cpp index 0933054161..66d0c329e8 100644 --- a/engines/lure/detection.cpp +++ b/engines/lure/detection.cpp @@ -197,6 +197,4 @@ bool LureMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common return gd != 0; } -META_COMPATIBILITY_WRAPPER(LURE, LureMetaEngine); - -REGISTER_PLUGIN(LURE, "Lure of the Temptress Engine", "Lure of the Temptress (C) Revolution"); +REGISTER_PLUGIN(LURE, LureMetaEngine); diff --git a/engines/metaengine.h b/engines/metaengine.h index 600968331d..b0b71de126 100644 --- a/engines/metaengine.h +++ b/engines/metaengine.h @@ -57,25 +57,4 @@ public: virtual PluginError createInstance(OSystem *syst, Engine **engine) const = 0; }; - -/** - * The META_COMPATIBILITY_WRAPPER macro is there to ease the transition from the - * old plugin API to the new MetaEngine class. Ultimately, this macro will go - * and REGISTER_PLUGIN will be changed to simply take an ID and a METACLASS. - * Until then, use META_COMPATIBILITY_WRAPPER + REGISTER_PLUGIN. - */ -#define META_COMPATIBILITY_WRAPPER(ID,METACLASS) \ - static MetaEngine &getMetaEngine() { \ - static MetaEngine *meta = 0; \ - if (!meta) meta = new METACLASS(); \ - return *meta; \ - } \ - GameList Engine_##ID##_gameIDList() { return getMetaEngine().getSupportedGames(); } \ - GameDescriptor Engine_##ID##_findGameID(const char *gameid) { return getMetaEngine().findGame(gameid); } \ - PluginError Engine_##ID##_create(OSystem *syst, Engine **engine) { return getMetaEngine().createInstance(syst, engine); } \ - GameList Engine_##ID##_detectGames(const FSList &fslist) { return getMetaEngine().detectGames(fslist); } \ - void dummyFuncToAllowTrailingSemicolon() - - - #endif diff --git a/engines/parallaction/detection.cpp b/engines/parallaction/detection.cpp index b435f8f187..90a46fdc0a 100644 --- a/engines/parallaction/detection.cpp +++ b/engines/parallaction/detection.cpp @@ -218,6 +218,4 @@ bool ParallactionMetaEngine::createInstance(OSystem *syst, Engine **engine, cons return res; } -META_COMPATIBILITY_WRAPPER(PARALLACTION, ParallactionMetaEngine); - -REGISTER_PLUGIN(PARALLACTION, "Parallaction engine", "Nippon Safes Inc. (C) Dynabyte"); +REGISTER_PLUGIN(PARALLACTION, ParallactionMetaEngine); diff --git a/engines/queen/queen.cpp b/engines/queen/queen.cpp index fd1c50abe9..db8e9a94ce 100644 --- a/engines/queen/queen.cpp +++ b/engines/queen/queen.cpp @@ -127,9 +127,7 @@ PluginError QueenMetaEngine::createInstance(OSystem *syst, Engine **engine) cons return kNoError; } -META_COMPATIBILITY_WRAPPER(QUEEN, QueenMetaEngine); - -REGISTER_PLUGIN(QUEEN, "Flight of the Amazon Queen", "Flight of the Amazon Queen (C) John Passfield and Steve Stamatiadis"); +REGISTER_PLUGIN(QUEEN, QueenMetaEngine); namespace Queen { diff --git a/engines/saga/detection.cpp b/engines/saga/detection.cpp index be5c018fbb..3838fd1d9e 100644 --- a/engines/saga/detection.cpp +++ b/engines/saga/detection.cpp @@ -164,9 +164,7 @@ bool SagaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common return gd != 0; } -META_COMPATIBILITY_WRAPPER(SAGA, SagaMetaEngine); - -REGISTER_PLUGIN(SAGA, "SAGA Engine", "Inherit the Earth (C) Wyrmkeep Entertainment"); +REGISTER_PLUGIN(SAGA, SagaMetaEngine); namespace Saga { diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp index d2c889b968..b1f14acc61 100644 --- a/engines/scumm/detection.cpp +++ b/engines/scumm/detection.cpp @@ -928,8 +928,4 @@ const char *ScummMetaEngine::getCopyright() const { "Humongous SCUMM Games (C) Humongous"; } -META_COMPATIBILITY_WRAPPER(SCUMM, ScummMetaEngine); - -REGISTER_PLUGIN(SCUMM, "Scumm Engine", - "LucasArts SCUMM Games (C) LucasArts\n" - "Humongous SCUMM Games (C) Humongous" ); +REGISTER_PLUGIN(SCUMM, ScummMetaEngine); diff --git a/engines/sky/sky.cpp b/engines/sky/sky.cpp index 266faa2c80..6d8c4d36f7 100644 --- a/engines/sky/sky.cpp +++ b/engines/sky/sky.cpp @@ -194,10 +194,7 @@ PluginError SkyMetaEngine::createInstance(OSystem *syst, Engine **engine) const return kNoError; } -META_COMPATIBILITY_WRAPPER(SKY, SkyMetaEngine); - -REGISTER_PLUGIN(SKY, "Beneath a Steel Sky", "Beneath a Steel Sky (C) Revolution"); - +REGISTER_PLUGIN(SKY, SkyMetaEngine); namespace Sky { diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp index 4d99868d98..60559424c5 100644 --- a/engines/sword1/sword1.cpp +++ b/engines/sword1/sword1.cpp @@ -187,9 +187,7 @@ PluginError SwordMetaEngine::createInstance(OSystem *syst, Engine **engine) cons return kNoError; } -META_COMPATIBILITY_WRAPPER(SWORD1, SwordMetaEngine); - -REGISTER_PLUGIN(SWORD1, "Broken Sword", "Broken Sword Games (C) Revolution"); +REGISTER_PLUGIN(SWORD1, SwordMetaEngine); namespace Sword1 { diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index 8e9b69db5c..29530529e8 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -180,9 +180,7 @@ PluginError Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) con return kNoGameDataFoundError; } -META_COMPATIBILITY_WRAPPER(SWORD2, Sword2MetaEngine); - -REGISTER_PLUGIN(SWORD2, "Broken Sword 2", "Broken Sword Games (C) Revolution"); +REGISTER_PLUGIN(SWORD2, Sword2MetaEngine); namespace Sword2 { diff --git a/engines/touche/detection.cpp b/engines/touche/detection.cpp index 8d3d88fb7c..828fb43c6d 100644 --- a/engines/touche/detection.cpp +++ b/engines/touche/detection.cpp @@ -147,6 +147,4 @@ bool ToucheMetaEngine::createInstance(OSystem *syst, Engine **engine, const Comm return gd != 0; } -META_COMPATIBILITY_WRAPPER(TOUCHE, ToucheMetaEngine); - -REGISTER_PLUGIN(TOUCHE, "Touche Engine", "Touche: The Adventures of the 5th Musketeer (C) Clipper Software"); +REGISTER_PLUGIN(TOUCHE, ToucheMetaEngine); -- cgit v1.2.3