-
Notifications
You must be signed in to change notification settings - Fork 49
Plugins
Plugins are written in C++ and compiled separately from the engine into a DLL to be distributed with projects. Source code for plugins does not need to be distributed with the plugins.
For now it's recommended to make your plugin in Visual Studio 2012. It must be compiled as a Dynamic Library. When creating a plugin you will need add Torque6.lib to the Additional Dependencies, and the following directories to Additional Includes:
- engine/source/
- engine/lib/assimp/include
- engine/lib/bgfx/include
- engine/lib/bgfx/common/imgui
- engine/lib/bgfx/common/nanovg
- engine/lib/openal/win32
In order to drive the plugin system Torque 6 looks for certain predefined functions in the plugin DLL. These functions must be declared for external use.
You may define and utilize the following predefined functions:
- void create(Plugins::PluginLink _link);
- void processTick();
- void preRender();
- void render();
- void postRender();
They must be defined in the following manner to be exposed to Torque 6 from the DLL:
extern "C"
{
PLUGIN_FUNC void create(Plugins::PluginLink _link);
PLUGIN_FUNC void processTick();
PLUGIN_FUNC void preRender();
PLUGIN_FUNC void render();
PLUGIN_FUNC void postRender();
}
Their usage should be fairly obvious. Create is called when the plugin is first loaded. ProcessTick occurs every tick, and preRender, render, and postRender occur per frame. Create is the only one that needs to be defined. Without create there is no entry point and the plugin will do nothing.
You may have noticed the create function comes with a PluginLink argument. This is a necessary part of the plugin system. In order to communicate with the main engine you must do so through the PluginLink. During the create function you must store the PluginLink for later usage as it is only provided during creation. Here is an example of printing text to the console:
void create(PluginLink _link)
{
_link.Con.printf("Hello World!");
}