mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-06 10:58:01 +00:00
Moved the engine plugin code to engines/metaengine.h; added/clarified/corrected various Doxygen comments for the plugin system
svn-id: r32083
This commit is contained in:
parent
fe58f0ee4b
commit
2bb39e591f
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
// Plugin versioning
|
// Plugin versioning
|
||||||
|
|
||||||
// Global Plugin API version
|
/** Global Plugin API version */
|
||||||
#define PLUGIN_VERSION 1
|
#define PLUGIN_VERSION 1
|
||||||
|
|
||||||
enum PluginType {
|
enum PluginType {
|
||||||
@ -67,14 +67,14 @@ extern int pluginTypeVersions[PLUGIN_TYPE_MAX];
|
|||||||
(defined(ENABLE_##ID) && (ENABLE_##ID == DYNAMIC_PLUGIN) && defined(DYNAMIC_MODULES))
|
(defined(ENABLE_##ID) && (ENABLE_##ID == DYNAMIC_PLUGIN) && defined(DYNAMIC_MODULES))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REGISTER_PLUGIN is a convenience macro meant to ease writing
|
* REGISTER_PLUGIN_STATIC is a convenience macro which is used to declare
|
||||||
* the plugin interface for our modules. In particular, using it
|
* the plugin interface for static plugins. Code (such as game engines)
|
||||||
* makes it possible to compile the very same code in a module
|
* which needs to implement a static plugin can simply invoke this macro
|
||||||
* both as a static and a dynamic plugin.
|
* with a plugin ID, plugin type and PluginObject subclass, and the correct
|
||||||
|
* wrapper code will be inserted.
|
||||||
*
|
*
|
||||||
* @todo add some means to query the plugin API version etc.
|
* @see REGISTER_PLUGIN_DYNAMIC
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define REGISTER_PLUGIN_STATIC(ID,TYPE,PLUGINCLASS) \
|
#define REGISTER_PLUGIN_STATIC(ID,TYPE,PLUGINCLASS) \
|
||||||
PluginType g_##ID##_type = TYPE; \
|
PluginType g_##ID##_type = TYPE; \
|
||||||
PluginObject *g_##ID##_getObject() { \
|
PluginObject *g_##ID##_getObject() { \
|
||||||
@ -84,6 +84,15 @@ extern int pluginTypeVersions[PLUGIN_TYPE_MAX];
|
|||||||
|
|
||||||
#ifdef DYNAMIC_MODULES
|
#ifdef DYNAMIC_MODULES
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REGISTER_PLUGIN_DYNAMIC is a convenience macro which is used to declare
|
||||||
|
* the plugin interface for dynamically loadable plugins. Code (such as game engines)
|
||||||
|
* which needs to implement a dynamic plugin can simply invoke this macro
|
||||||
|
* with a plugin ID, plugin type and PluginObject subclass, and the correct
|
||||||
|
* wrapper code will be inserted.
|
||||||
|
*
|
||||||
|
* @see REGISTER_PLUGIN_STATIC
|
||||||
|
*/
|
||||||
#define REGISTER_PLUGIN_DYNAMIC(ID,TYPE,PLUGINCLASS) \
|
#define REGISTER_PLUGIN_DYNAMIC(ID,TYPE,PLUGINCLASS) \
|
||||||
extern "C" { \
|
extern "C" { \
|
||||||
PLUGIN_EXPORT int32 PLUGIN_getVersion() { return PLUGIN_VERSION; } \
|
PLUGIN_EXPORT int32 PLUGIN_getVersion() { return PLUGIN_VERSION; } \
|
||||||
@ -138,10 +147,14 @@ public:
|
|||||||
const char *getName() const;
|
const char *getName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** List of plugins. */
|
/** List of Plugin instances. */
|
||||||
typedef Common::Array<Plugin *> PluginList;
|
typedef Common::Array<Plugin *> PluginList;
|
||||||
|
|
||||||
/** Template to help defining Plugin subclasses */
|
/**
|
||||||
|
* Convenience template to make it easier defining normal Plugin
|
||||||
|
* subclasses. Namely, the PluginSubclass will manage PluginObjects
|
||||||
|
* of a type specified via the PO_t template parameter.
|
||||||
|
*/
|
||||||
template<class PO_t>
|
template<class PO_t>
|
||||||
class PluginSubclass : public Plugin {
|
class PluginSubclass : public Plugin {
|
||||||
public:
|
public:
|
||||||
@ -152,24 +165,43 @@ public:
|
|||||||
typedef Common::Array<PluginSubclass *> list;
|
typedef Common::Array<PluginSubclass *> list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for Plugin factories. Subclasses of this
|
||||||
|
* are responsible for creating plugin objects, e.g. by loading
|
||||||
|
* loadable modules from storage media; by creating "fake" plugins
|
||||||
|
* from static code; or whatever other means.
|
||||||
|
*/
|
||||||
class PluginProvider {
|
class PluginProvider {
|
||||||
public:
|
public:
|
||||||
virtual ~PluginProvider() {}
|
virtual ~PluginProvider() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of Plugin objects. The caller is responsible for actually
|
* Return a list of Plugin objects. The caller is responsible for actually
|
||||||
* loading/unloading them (by invoking the appropriate methods).
|
* loading/unloading them (by invoking the appropriate Plugin methods).
|
||||||
* Furthermore, the caller is responsible for deleting these objects
|
* Furthermore, the caller is responsible for deleting these objects
|
||||||
* eventually.
|
* eventually.
|
||||||
*/
|
*/
|
||||||
virtual PluginList getPlugins() = 0;
|
virtual PluginList getPlugins() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for Plugin factories which load binary code from files.
|
||||||
|
* Subclasses only have to implement the createPlugin() method, and optionally
|
||||||
|
* can overload the other protected methods to achieve custom behavior.
|
||||||
|
*/
|
||||||
class FilePluginProvider : public PluginProvider {
|
class FilePluginProvider : public PluginProvider {
|
||||||
public:
|
public:
|
||||||
virtual PluginList getPlugins();
|
virtual PluginList getPlugins();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* Create a Plugin instance from a loadable code module with the specified name.
|
||||||
|
* Subclasses of FilePluginProvider have to at least overload this method.
|
||||||
|
* If the file is not found, or does not contain loadable code, 0 is returned instead.
|
||||||
|
*
|
||||||
|
* @param filename the name of the loadable code module
|
||||||
|
* @return a pointer to a Plugin instance, or 0 if an error occured.
|
||||||
|
*/
|
||||||
virtual Plugin* createPlugin(const Common::String &filename) const = 0;
|
virtual Plugin* createPlugin(const Common::String &filename) const = 0;
|
||||||
|
|
||||||
virtual const char* getPrefix() const;
|
virtual const char* getPrefix() const;
|
||||||
@ -179,8 +211,8 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instances of this class manage all plugins, including loading them,
|
* Singleton class which manages all plugins, including loading them,
|
||||||
* making wrapper objects of class Plugin available, and unloading them.
|
* managing all Plugin class instances, and unloading them.
|
||||||
*/
|
*/
|
||||||
class PluginManager : public Common::Singleton<PluginManager> {
|
class PluginManager : public Common::Singleton<PluginManager> {
|
||||||
typedef Common::List<PluginProvider *> ProviderList;
|
typedef Common::List<PluginProvider *> ProviderList;
|
||||||
@ -205,25 +237,4 @@ public:
|
|||||||
const PluginList &getPlugins(PluginType t) { return _plugins[t]; }
|
const PluginList &getPlugins(PluginType t) { return _plugins[t]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Engine plugins
|
|
||||||
|
|
||||||
class FSList;
|
|
||||||
class MetaEngine;
|
|
||||||
|
|
||||||
typedef PluginSubclass<MetaEngine> EnginePlugin;
|
|
||||||
|
|
||||||
class EngineManager : public Common::Singleton<EngineManager> {
|
|
||||||
private:
|
|
||||||
friend class Common::Singleton<SingletonBaseType>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
GameDescriptor findGame(const Common::String &gameName, const EnginePlugin **plugin = NULL) const;
|
|
||||||
GameList detectGames(const FSList &fslist) const;
|
|
||||||
const EnginePlugin::list &getPlugins() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Shortcut for accessing the engine manager. */
|
|
||||||
#define EngineMan EngineManager::instance()
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -93,4 +93,25 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Engine plugins
|
||||||
|
|
||||||
|
typedef PluginSubclass<MetaEngine> EnginePlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton class which manages all Engine plugins.
|
||||||
|
*/
|
||||||
|
class EngineManager : public Common::Singleton<EngineManager> {
|
||||||
|
private:
|
||||||
|
friend class Common::Singleton<SingletonBaseType>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
GameDescriptor findGame(const Common::String &gameName, const EnginePlugin **plugin = NULL) const;
|
||||||
|
GameList detectGames(const FSList &fslist) const;
|
||||||
|
const EnginePlugin::list &getPlugins() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Convenience shortcut for accessing the engine manager. */
|
||||||
|
#define EngineMan EngineManager::instance()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,8 +22,7 @@
|
|||||||
* $Id$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "engines/engine.h"
|
#include "engines/metaengine.h"
|
||||||
#include "base/plugins.h"
|
|
||||||
#include "base/version.h"
|
#include "base/version.h"
|
||||||
|
|
||||||
#include "common/config-manager.h"
|
#include "common/config-manager.h"
|
||||||
|
@ -22,8 +22,7 @@
|
|||||||
* $Id$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "engines/engine.h"
|
#include "engines/metaengine.h"
|
||||||
#include "base/plugins.h"
|
|
||||||
#include "common/events.h"
|
#include "common/events.h"
|
||||||
|
|
||||||
#include "gui/launcher.h" // For addGameToConf()
|
#include "gui/launcher.h" // For addGameToConf()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user