Event
The event system keeps the game's event entries, runs its Lua event scripts and stores its event flags. This page covers how an event entry is found or added, and how one event flag bit is written.
At a glance
- Scope
SprjEmkSystem(event entries),SprjLuaEventMan(Lua event scripts) andSprjEventFlagMan(event flags).- Verified
event_emk_addis verified;event_flag_writeis edge-verified against constructed cases.- Open
- What the two entry lists hold, what the ids mean, and what any real flag ID means in play.
Summary
The game's event system is three managers working together:
| Manager | What it keeps |
|---|---|
SprjEmkSystem |
event entries, kept in keyed lists |
SprjLuaEventMan |
the Lua event scripts |
SprjEventFlagMan |
event flags |
Adding an event entry
event_emk_add (0x016efd00) is the way into the entry lists:
- It looks for an event entry by id and sub-id in two linked lists.
- If there is none, it allocates, constructs and inserts one in key order.
- It advances a new entry once by a fixed 1/30 s step.
It runs hundreds of times in a minute of gameplay in Iosefka's Clinic.
Writing an event flag
event_flag_write (0x017cfcc0) changes one stored bit. Flags are stored in groups, so the
function first works out which group holds the flag, then which bit in that group:
- It divides the flag ID by the store's configured flags-per-group value.
- It finds an exact matching group in a keyed tree.
- It selects either a direct storage pointer or a stride-based offset into shared storage.
- It sets or clears the bit. Within a byte, flags are numbered from the most significant bit; a
nonzero
enabledargument sets the selected bit and zero clears it while retaining its neighbors.
A missing group, unsupported storage kind, or null storage pointer leaves memory unchanged.
Reading a flag follows the same path. Since #199 the store's layout and lookup are shared code, also used to read flags: an ID that is negative as a signed 32-bit number, a missing group or missing storage reads as a clear flag. The game itself inlines this read where it needs it; one such place is the Chalice Dungeon gate state's level creation (see Frame timing).
This replacement is edge-verified, not fully verified: it matches the original on constructed edge cases, not on recorded gameplay.
How the flag write was verified
The merged source and layout and verification record report matching original-instruction results on 14 constructed edge fixtures. Those cover tree search paths, byte boundaries, set/clear operations, missing groups, and storage selection. Since #199 the write uses the shared store code and was recorded again on 15 fixtures, one more with a group size that is not a power of two.
What the fixtures do not establish
They do not identify a real flag ID's gameplay meaning, establish a zero group-size contract, or replace recorded gameplay cases. No fixture was rerun for this article.
Key functions
| Address | Size | Name | Status | Notes |
|---|---|---|---|---|
0x016efd00 |
368 | event_emk_add |
verified | SprjEmkSystem: find or add an event entry in two keyed lists; first advance with the 1/30 s step (1/60 s in the 60 FPS patches) |
0x017cfcc0 |
177 | event_flag_write |
verified | finds an exact event-flag group in a tree and sets or clears one bit |
Structs and globals
Event entry (0xe0 bytes):
| Offset | Field |
|---|---|
+0x0 |
vtable; slot +0x10 advances the entry by a frame-time descriptor |
+0x28 |
id |
+0x2c |
sub-id (16-bit) |
+0x70 |
next entry |
Patch points
60 FPS++,60FPS (no deltatime)and90 FPS++change the first advance's 1/30 s step to 1/60 s in0x016efd00;BB_TARGET_FPS=60does the same. The patches are described in Frame timing.
Open questions
- What the two lists hold (pending and active entries?), and what the ids are.