Skip to main content

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​

Eight sources send block events to the block event dispatcher: the party moves (leave and enter events), a monster is placed or leaves a block (monster enter and exit), an item is dropped or picked up (item placed and removed), an item is used (item used, on the block in front), a wall decoration is used, a spell is cast (on the party block), a timed block script is due (timer) and the step limit is reached (step count, on block [00:00]). If the block has a script and accepts the event, the script runs and can change walls, items, monsters and the party, which can send further events.
Eight kinds of change send events to blocks; a block's script runs only for the events it accepts.

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:

The pages of this chapter​

PageWhat it covers
The game loopOne pass of the loop, in order; how the game ends; a defeated party.
How the systems affect one anotherThe state the systems share, what each change causes, flying objects that hit, scripts started by scripts.
The game clockTicks, the two counters, the sound drivers and the pauses.
Timed updatesThe sixteen periodic updates, temporary walls, the monster update cadence, food.
Character timersThe ten timers of each character and what sets them.
Timed scriptsScripts 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.

Footnotes​

  1. Move the party, place a monster on a block, floor drop or pick-up, use of an inventory item, wall-click dispatchers, spell cast, timed-callback processing and the block event dispatcher. ↩

  2. Settle the level, save a game, pack and unpack a level record and the INF level loader. Comparative source: REF-SCUMM-015, readOriginalSaveFile. ↩