Module Events
In this chapter you'll learn about module boot and shutdown events.
Boot/Shutdown Mechanism
Jenova Module Mapper has a mechanism to call into the compiled Jenova Module when it's loaded and unloaded.
Boot Event
When a compiled Jenova Module gets mapped into memory and prepared for execution by Module Mapper, Interpreter calls JenovaBoot()
function in the module if it is defined.
If the function returns false
Interpreter stops the execution until the next compile.
Shutdown Event
Now when the mapped module is being unloaded before a Hot-Reload or shutdown, Interpreter calls JenovaShutdown()
function in the module if it is defined.
If the function returns false
Interpreter doesn't free the memory occupied by the module.
Usecase
To add the mechanism to your project, Simply create a new C++ Script and in the Create Script window select "Boot" template.
Boot
template to create Boot Script.Here's the basic code for Boot Script :
// Jenova SDK
#include <JenovaSDK.h>
// Jenova Module Is Loading
JENOVA_EXPORT bool JenovaBoot()
{
/* Initialize Your GDExtension Class Here */
return true;
}
// Jenova Module Is Unloading
JENOVA_EXPORT bool JenovaShutdown()
{
/* Dispose Your GDExtension Class Here */
return true;
}
Boot/Shutdown events can be used for the following purposes:
- Registration and Hot-Reloading of Nested Extensions
- Initialization/Release of CUDA, OpenCV, OpenCL, etc.
- Allocation of Global Memory and Variables
- Save/Load Configuration from Disk
- And more...
Activation Method
RegisterBootEvent
— Adds a function to the boot-time execution queue.RegisterShutdownEvent
— Adds a function to the shutdown-time execution queue.UnregisterBootEvent
— Removes a previously registered boot-time function.UnregisterShutdownEvent
— Removes a previously registered shutdown-time function.
Register functions accept an index
parameter that specifies the insertion point within the event queue.
This is important when execution order matters. By default, index
is set to -1
, which appends the function to the end of the queue.
Here's an example :
static struct MyNodeSelfActivator
{
inline MyNodeSelfActivator()
{
RegisterBootEvent(&RegisterMyNode);
RegisterShutdownEvent(&UnregisterMyNode);
}
} inline _self;
You'll learn more about Boot/Shutdown events in Nested Extensions chapter.