Tried to unify plugin code for PalmOS and non-PalmOS (hopefully I didn't break the PalmOS code this way, please verify)
svn-id: r19670
This commit is contained in:
parent
b12138458d
commit
8262b6dc2a
2 changed files with 16 additions and 62 deletions
|
@ -86,24 +86,25 @@ GameSettings Plugin::findGame(const char *gameName) const {
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
class StaticPlugin : public Plugin {
|
class StaticPlugin : public Plugin {
|
||||||
const char *_name;
|
PluginRegistrator *_plugin;
|
||||||
EngineFactory _ef;
|
|
||||||
DetectFunc _df;
|
|
||||||
GameList _games;
|
|
||||||
public:
|
public:
|
||||||
StaticPlugin(const char *name, GameList games, EngineFactory ef, DetectFunc df)
|
StaticPlugin(PluginRegistrator *plugin)
|
||||||
: _name(name), _ef(ef), _df(df), _games(games) {
|
: _plugin(plugin) {
|
||||||
|
}
|
||||||
|
|
||||||
|
~StaticPlugin() {
|
||||||
|
delete _plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *getName() const { return _name; }
|
const char *getName() const { return _plugin->_name; }
|
||||||
|
|
||||||
Engine *createInstance(GameDetector *detector, OSystem *syst) const {
|
Engine *createInstance(GameDetector *detector, OSystem *syst) const {
|
||||||
return (*_ef)(detector, syst);
|
return (*_plugin->_ef)(detector, syst);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameList getSupportedGames() const { return _games; }
|
GameList getSupportedGames() const { return _plugin->_games; }
|
||||||
DetectedGameList detectGames(const FSList &fslist) const {
|
DetectedGameList detectGames(const FSList &fslist) const {
|
||||||
return (*_df)(fslist);
|
return (*_plugin->_df)(fslist);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -287,23 +288,13 @@ void PluginManager::loadPlugins() {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if defined(PALMOS_ARM) || defined(PALMOS_DEBUG)
|
|
||||||
#define FREE_PLUGIN(ID) \
|
|
||||||
extern PluginRegistrator *g_##ID##_PluginReg; \
|
|
||||||
delete g_##ID##_PluginReg;
|
|
||||||
|
|
||||||
#define LINK_PLUGIN(ID) \
|
#define LINK_PLUGIN(ID) \
|
||||||
extern PluginRegistrator *g_##ID##_PluginReg; \
|
extern PluginRegistrator *g_##ID##_PluginReg; \
|
||||||
extern void g_##ID##_PluginReg_alloc(); \
|
extern void g_##ID##_PluginReg_alloc(); \
|
||||||
g_##ID##_PluginReg_alloc(); \
|
g_##ID##_PluginReg_alloc(); \
|
||||||
plugin = g_##ID##_PluginReg; \
|
plugin = g_##ID##_PluginReg; \
|
||||||
tryLoadPlugin(new StaticPlugin(plugin->_name, plugin->_games, plugin->_ef, plugin->_df));
|
tryLoadPlugin(new StaticPlugin(plugin));
|
||||||
#else
|
|
||||||
#define LINK_PLUGIN(ID) \
|
|
||||||
extern PluginRegistrator g_##ID##_PluginReg; \
|
|
||||||
plugin = &g_##ID##_PluginReg; \
|
|
||||||
tryLoadPlugin(new StaticPlugin(plugin->_name, plugin->_games, plugin->_ef, plugin->_df));
|
|
||||||
#endif
|
|
||||||
// "Loader" for the static plugins.
|
// "Loader" for the static plugins.
|
||||||
// Iterate over all registered (static) plugins and load them.
|
// Iterate over all registered (static) plugins and load them.
|
||||||
PluginRegistrator *plugin;
|
PluginRegistrator *plugin;
|
||||||
|
@ -341,36 +332,6 @@ void PluginManager::loadPlugins() {
|
||||||
|
|
||||||
void PluginManager::unloadPlugins() {
|
void PluginManager::unloadPlugins() {
|
||||||
unloadPluginsExcept(NULL);
|
unloadPluginsExcept(NULL);
|
||||||
|
|
||||||
#if defined(PALMOS_ARM) || defined(PALMOS_DEBUG)
|
|
||||||
#ifndef DISABLE_SCUMM
|
|
||||||
FREE_PLUGIN(SCUMM)
|
|
||||||
#endif
|
|
||||||
#ifndef DISABLE_SKY
|
|
||||||
FREE_PLUGIN(SKY)
|
|
||||||
#endif
|
|
||||||
#ifndef DISABLE_SWORD1
|
|
||||||
FREE_PLUGIN(SWORD1)
|
|
||||||
#endif
|
|
||||||
#ifndef DISABLE_SWORD2
|
|
||||||
FREE_PLUGIN(SWORD2)
|
|
||||||
#endif
|
|
||||||
#ifndef DISABLE_SIMON
|
|
||||||
FREE_PLUGIN(SIMON)
|
|
||||||
#endif
|
|
||||||
#ifndef DISABLE_QUEEN
|
|
||||||
FREE_PLUGIN(QUEEN)
|
|
||||||
#endif
|
|
||||||
#ifndef DISABLE_SAGA
|
|
||||||
FREE_PLUGIN(SAGA)
|
|
||||||
#endif
|
|
||||||
#ifndef DISABLE_KYRA
|
|
||||||
FREE_PLUGIN(KYRA)
|
|
||||||
#endif
|
|
||||||
#ifndef DISABLE_GOB
|
|
||||||
FREE_PLUGIN(GOB)
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginManager::unloadPluginsExcept(const Plugin *plugin) {
|
void PluginManager::unloadPluginsExcept(const Plugin *plugin) {
|
||||||
|
|
|
@ -26,12 +26,12 @@
|
||||||
#include "common/array.h"
|
#include "common/array.h"
|
||||||
#include "common/singleton.h"
|
#include "common/singleton.h"
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
|
#include "base/gameDetector.h" // For GameSettings
|
||||||
|
|
||||||
class Engine;
|
class Engine;
|
||||||
class FSList;
|
class FSList;
|
||||||
class GameDetector;
|
class GameDetector;
|
||||||
class OSystem;
|
class OSystem;
|
||||||
struct GameSettings;
|
|
||||||
|
|
||||||
/** List of games. */
|
/** List of games. */
|
||||||
typedef Common::Array<GameSettings> GameList;
|
typedef Common::Array<GameSettings> GameList;
|
||||||
|
@ -84,21 +84,15 @@ public:
|
||||||
* both as a static and a dynamic plugin.
|
* both as a static and a dynamic plugin.
|
||||||
*
|
*
|
||||||
* @todo add some means to query the plugin API version etc.
|
* @todo add some means to query the plugin API version etc.
|
||||||
* @todo on Windows, we might need __declspec(dllexport) ?
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(PALMOS_ARM) || defined(PALMOS_DEBUG)
|
#ifndef DYNAMIC_MODULES
|
||||||
#define REGISTER_PLUGIN(ID,name) \
|
#define REGISTER_PLUGIN(ID,name) \
|
||||||
PluginRegistrator *g_##ID##_PluginReg; \
|
PluginRegistrator *g_##ID##_PluginReg; \
|
||||||
void g_##ID##_PluginReg_alloc() { \
|
void g_##ID##_PluginReg_alloc() { \
|
||||||
g_##ID##_PluginReg = new PluginRegistrator(name, Engine_##ID##_gameList(), Engine_##ID##_create, Engine_##ID##_detectGames);\
|
g_##ID##_PluginReg = new PluginRegistrator(name, Engine_##ID##_gameList(), Engine_##ID##_create, Engine_##ID##_detectGames);\
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifndef DYNAMIC_MODULES
|
|
||||||
#define REGISTER_PLUGIN(ID,name) \
|
|
||||||
PluginRegistrator g_##ID##_PluginReg(name, Engine_##ID##_gameList(), Engine_##ID##_create, Engine_##ID##_detectGames);
|
|
||||||
#else
|
|
||||||
#define REGISTER_PLUGIN(ID,name) \
|
#define REGISTER_PLUGIN(ID,name) \
|
||||||
extern "C" { \
|
extern "C" { \
|
||||||
PLUGIN_EXPORT const char *PLUGIN_name() { return name; } \
|
PLUGIN_EXPORT const char *PLUGIN_name() { return name; } \
|
||||||
|
@ -107,7 +101,6 @@ public:
|
||||||
PLUGIN_EXPORT DetectedGameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \
|
PLUGIN_EXPORT DetectedGameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DYNAMIC_MODULES
|
#ifndef DYNAMIC_MODULES
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +108,7 @@ public:
|
||||||
* to allow static 'plugins' to register with the PluginManager.
|
* to allow static 'plugins' to register with the PluginManager.
|
||||||
*/
|
*/
|
||||||
class PluginRegistrator {
|
class PluginRegistrator {
|
||||||
friend class PluginManager;
|
friend class StaticPlugin;
|
||||||
public:
|
public:
|
||||||
typedef Engine *(*EngineFactory)(GameDetector *detector, OSystem *syst);
|
typedef Engine *(*EngineFactory)(GameDetector *detector, OSystem *syst);
|
||||||
typedef DetectedGameList (*DetectFunc)(const FSList &fslist);
|
typedef DetectedGameList (*DetectFunc)(const FSList &fslist);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue