The engine
Home · The engine in ten minutes ·
BlockEventMask
In brief
The game runs one loop as fast as it can. Each pass checks that the party can still act, handles the player's input, runs every timed update that is due, such as flying objects, monsters, doors and timers, redraws the view once if anything changed, and plays pending ambient sound. Time is counted in ticks of a shared counter, about 18.2 per second, which stops while the camp menu is open, while a level loads and during some animations.
Much of the game's behavior meets in one place: block events. When the party moves, when a monster enters a block, when an item is dropped, when a timer expires or a spell is cast, the game sends an event to a block. If that block has a script and the event is enabled for it, the script runs, inside the step that sent the event, and can in turn change walls, items, monsters or the party.
How the systems connect
When the party moves, monsters may also notice it; that does not go through a block event.
Each event is a BlockEventMask value. Many
events must be enabled by
LevelBlockStateFlags bits that the
block's INF binding stores in its
LevelBlockRuntime entry; the
step-count event needs no such bit. The details are on the pages of each
system:
- party movement and monsters: noticing the party;
- timers and the step counter: timed scripts;
- walls and level changes: the world;
- what scripts can do: scripts.1
The pages of this chapter
| Page | What it covers |
|---|---|
| The game loop | One pass of the loop, in order; how the game ends; a defeated party. |
| How the systems affect one another | The state the systems share, what each change causes, flying objects that hit, scripts started by scripts. |
| The game clock | Ticks, the two counters, the sound drivers and the pauses. |
| Timed updates | The sixteen periodic updates, temporary walls, the monster update cadence, food. |
| Character timers | The ten timers of each character and what sets them. |
| Timed scripts | Scripts run at a regular interval, and the script run after a number of steps. |
What the engine keeps
Characters, the party's position, every item, the script flags and the options last the whole game. A level's walls, monsters and temporary walls exist for one level at a time and go into its level record when the party leaves. Everything else, including scripts, timed events and the events each block accepts, is read again from the level's files whenever a level is loaded, and objects in flight and doors in motion never survive a save or a level change. Saving and restoring gives the details and a summary table.2
Sources
Locations refer to the game executable reference; comparative sources are listed in the technical references.