It is built to only work with Win32 so far, in theory, but I would like to find someone who works with linux to port it once I actually get the code written down.
I would like to give a diagram just to show the interaction, although it may not be correctly built: http://i177.photobucket.com/albums/w235 ... iagram.png
Now onto the notes that I have:
Now I will give a little explanation. I did not give the details of the underlying managing structure because this is just a specification. But in case your interested, SPlugin is internally managed.PluginArchitectureNotes
=======================
- Functions that the plugins must define in order to interface with the API
typedef void ( *PFPLUGINREGISTER )( const PluginManager& );
typedef void* ( *PFNPLUGINCREATE )( void );
typedef void ( *PFNPLUGINDESTROY )( void* );
- Unified structure for plugins
struct SPlugin {
PFNPLUGINREGISTER register;
PFNPLUGINCREATE create;
PFNPLUGINDESTROY destroy;
};
- Enumeration for plugins to use
enum EPluginType {
EPT_RENDER_SYSTEM,
EPT_PHYSIC_SYSTEM,
EPT_AUDIO_SYSTEM
};
- The actual plugin manager
class PluginManager {
bool loadPlugin( const String& name );
void unloadPlugin( const String& name );
bool registerPlugin( enum EPluginType pType, const String& pName );
RenderSystem* createRenderSystem( const String& rsName );
PhysicSystem* createPhysicSystem( const String& psName );
AudioSystem* createAudioSystem( const String& asName );
void destroyRenderSystem( RenderSystem* );
void destroyPhysicSystem( PhysicSystem* );
void destroyAudioSystem( AudioSystem* );
};
- Usage
PluginManager* pluginMgr = new PluginManager;
pluginMgr->loadPlugin( "OpenGL2.1RS.dll" );
pluginMgr->loadPlugin( "BulletPS.dll" );
pluginMgr->loadPlugin( "OpenALAS.dll" );
RenderSystem* rsOpenGL = pluginMgr->createRenderSystem("OpenGL2.1");
PhysicSystem* psBullet = pluginMgr->createPhysicSystem("Bullet");
AudioSystem* asOpenAL = pluginMgr->createAudioSystem("OpenAL");
rsOpenGL->beginScene();
rsOpenGL->beginBatch();
rsOpenGL->endBatch();
rsOpenGL->endScene();
pluginMgr->unloadPlugin( "OpenGL2.1RS.dll" );
pluginMgr->unloadPlugin( "BulletPS.dll" );
pluginMgr->unloadPlugin( "OpenALAS.dll" );
The methods are setup to allow dynamic functionality, and to facilitate management of memory. So loadPlugin() loads the DLL into memory, but doesn't not create the actual plugin's data. This is good for deferred loading, or to detect whether the plugin is even available, etc.
In loadPlugin() it gets the DLL from memory, and obtains the three pointer functions needed. Then it calls the PFNPLUGINREGISTER function and passes a reference to itself, PluginManager. The plugin then uses registerPlugin() with its type, and its name. (Note: The name is used by the client later on by the create*() methods.)
Now the create*() methods look up the plugin's registered name, and attempt to create an instance with the plugin's create function. If successful, it passes back an abstract interface which defines what the client may use.
Everything else is self-explanatory. But if you still have questions, then feel free to ask. Please provide comments, improvements, suggestions, and criticisms. Thanks.