Event
The event system is used for level scripting, these consist of event blocks with logic and triggers. In earlier versions of the engine these were stored as bytecode called ScriptPCode. In Soul Reaver 2 and later they were transpiled to C code and stored as native code. The event system was removed in Tomb Raider Underworld.
Storage
The location of the stored native code depends per platform, usually they are in the level DRM file as DLL file.
Platform | Description |
---|---|
PC, PS2, PSP, Xbox | Stored as PE/DLL in the level DRM |
Wii, GameCube | Stored as ELF file in level DRM (with full symbols) |
Xbox 360 | Stored as seperate DLL files next to the game executable |
Mac | Included in main executable together with game code (Apple doesn’t allow W^X) |
PS3 | Stored as SPRX modules in a seperate folder next to the game executable (eg.sprx, gr.sprx) |
Exports
On most platforms the event executable files usually expose several exports used by the game, such as:
- EventMain
- EventDebug
- EventRelocate
- CallTrigger
- IsTriggerActive
EventMain
This is the main function which is called every frame, it lead to all event blocks being called.
The prototype of EventMain is:
void EventMain(GameTracker* gameTracker, StreamUnit* unit, GlobalData* globalData);
EventDebug
This export exposes a structure with the names of all variables and event variables used by the script.
struct EventVar
{
const char* name;
int variable; // Offset in the save eventVars array
};
struct UnsavedVar
{
const char* name;
void* variable; // Pointer to the variable
};
struct EventDebug
{
EventVar* eventVars // Null terminated array
UnsavedVar* unsavedVars // Null terminated array
};
CallTrigger
This function calls a trigger in a script.
void CallTrigger(int triggerId);
State
There are two types of variables for events, event variables and unsaved variables. Unsaved variables are traditional variables in memory. Event variables are global variables shared between levels and saved in the savegame.