[TOC]
Many systems in Banshee are implemented through plugins, libraries that are separate from the core of the engine and can be dynamically loaded or unloaded. If possible, it is the prefered way of extending the engine.
The default Banshee @ref BansheeEngine::CoreApplication "Application" supports plugins for the following systems:
The supported plugins will be automatically loaded and unloaded by the application as needed, all you need to do is to provide names of their libraries to the @ref BansheeEngine::START_UP_DESC "START_UP_DESC" used to initialize the application. All plugins should be in the same folder as the main application executable.
Aside from the supported plugins you can also create fully custom plugins that you load or unload manually.
All supported plugins implement an informal interface through global "extern" methods. The interface supports three methods:
You may choose to implement some, or none of these, although usually at least loadPlugin() method is needed so the plugin can register itself with the necessary system. A simple implementation might look like so:
extern "C" BS_MYPLUGIN_EXPORT void* loadPlugin()
{
// Do something on load
return nullptr; // Not used
}
extern "C" BS_MYPLUGIN_EXPORT void updatePlugin()
{
// Do something every frame
}
extern "C" BS_MYPLUGIN_EXPORT void unloadPlugin()
{
// Do something before unload
}
It's important that all instances of types (classes/structs) from the plugin are deleted before plugin unload happens. If this doesn't happen, and an object instance is deleted after the plugin has been unloaded you will end up with a corrupt virtual function table and a crash. Normally this is handled for you, but it's good to keep in mind depending on what your plugin is doing.
The exact implementations of these methods differ depending for which system are you implementing a plugin for, but we won't go into details for individual systems here. In most cases it just involves registering the plugin instance using some global manager. For example check "BsSLPlugin.cpp" in the @ref BansheeSL plugin, which registers a new importer that supports ".bsl" files.
Custom plugins can do whatever you wish, engine has no expectations from them so its up to your to load/unload them and to call their methods.
To load a custom plugin you can use:
loadPlugin method, if yours accepts one.Both of those methods internally call @ref BansheeEngine::DynLibManager "DynLibManager". You can use it directly if you do not need the plugin interface (loadPlugin and etc.), it has two methods:
Once the library is loaded you can use the @ref BansheeEngine::DynLib "DynLib" object, and its @ref BansheeEngine::DynLib::getSymbol "DynLib::getSymbol" method to retrieve a function pointer within the dynamic library, and call into it. For example if we wanted to retrieve a function pointer for the loadPlugin method from the previous chapter:
// Load library
DynLib* myLibrary = DynLibManager::instance().load("myPlugin");
// Retrieve function pointer (symbol)
typedef void* (*LoadPluginFunc)();
LoadPluginFunc loadPluginFunc = (LoadPluginFunc)myLibrary->getSymbol("loadPlugin");
// Call the function
loadPluginFunc();
// Assuming we're done, unload the plugin
DynLibManager::instance().unload(myLibrary);