The engine’s debug tools

Work packets: WP-130: Debug tools (the operations, the console commands, the script verbs and the hit overlay) and WP-131: The ImGui debug panel (the panel). This page explains how to use them.

These tools let you set up a test without playing up to it: enter a room, set a [Game] value, give a clue or an item. They also show which sprite a click would reach. There are three ways to use them, and all three run the same operations:

Tool How you open it What it’s for
The debug console Ctrl+Alt+D in a running game Typed commands while you play
test_script verbs The test_script key in the game’s config domain Live runs that set their own state, repeatably
The ImGui panel Launch with --debugflags=imgui Point and click: room list, value table, buttons

The design follows Legendary Arena’s operator panel (below). The panel uses Dear ImGui rather than the Tweakpane library that Legendary Arena uses, for the reasons under the panel.

One write path

Every change goes through one set of operations in engines/terraglyph/debug_tools.cpp. Each one calls the engine’s own setter, the same one the game uses in play: showRoom(), setGameString(), giveClue(), Inventory. So a room entered from the panel plays its music, script and opening, and a clue lands in the first free CluesFound slot with its owner.

The debug console

Press Ctrl+Alt+D in a running game. The commands that change state:

Command What it does
room ROOM_NAME Enters the room through showRoom(). art_list ROOM_ lists the names.
game Lists the [Game] section.
game KEY Prints one value.
game KEY VALUE Sets it. Flags take Yes or No, the values getGameFlag() reads.
clues Lists CluesFound0-4 and ClueOwners0-4.
clue SUSPECT Gives the clue that suspect gives, once (giveClue()).
inv_add OBJ_NAME Puts an inventory object in the first free slot.
inv_remove OBJ_NAME Takes it out of its slot.
hits [on\|off] Turns the hit overlay on or off.
hits at X Y Prints the sprite a click at X, Y would reach: its index, kind, object, label, destination, rollover and hit type.

The read-only commands: inv (the toolbar), profile (the whole profile), art_list and art_info (the art archive), and sound_list, sound_play Section.Clip, sound_stop and movie ID (plays BK.ID, then returns to the room).

test_script verbs

A test_script key in the game’s config domain plays steps inside the engine without using the host’s mouse (§9 of the integration contract). The steps are separated by ;. Besides the input verbs (move, click, down, up, wait, shot, save, load, type, key, quit), it takes the debug verbs:

Verb Same as
room ROOM_NAME the console’s room
game KEY VALUE game KEY VALUE
give OBJ_NAME inv_add
take OBJ_NAME inv_remove
clue SUSPECT clue
hits on / hits off hits
sound Section.Clip, sound_stop, movie ID sound_play, sound_stop, movie

With these, a live run can start from a new game and set everything else in its own script, so the test’s setup is written down in the script itself. For example:

[pk]
test_script=wait 3000; room ROOM_P04_Town; game Whodunit JESTER; game WellVisited Yes; give OBJ_INV_RUBY; hits on; shot town-hits; quit

The panel can’t be driven this way: ImGui reads SDL’s events, not the engine’s, so click never reaches it.

The hit overlay

With the overlay on, each point of the visible 640×480 is tinted by the kind of sprite that hitTest() returns there. A 1-pixel outline marks where that sprite changes. Because it comes from hitTest() itself, not from the sprites’ bounds, it shows exactly what a click would reach. Masks, polygons, hidden sprites and depth order are all accounted for.

Colour Kind
Green Exit
Yellow Clickable
Cyan Inventory
Magenta Requires (gated on an item or a value)
Orange Character
White Ghost
Blue Engine (the toolbar)
Grey Any other kind
Untinted Layers (backgrounds and scenery that take no click)

The ImGui panel

The panel on Phantom's Gardener's House: the Room window with its room list, and the Hits window over the hit overlay, which shows the exit in green, the curtain that needs an item in magenta, the drawers in yellow and the gang in orange.

Why Dear ImGui, not Tweakpane

Legendary Arena’s panel puts its setter controls in a Tweakpane pane (The shape it takes). The Herbs vs. Ailments design names Tweakpane as the debug-panel library shared by both games. The article’s open question on the UI library was answered by D-24689 §6: a lazily loaded Vue panel, with Tweakpane for the setters. TerraGlyph uses Dear ImGui instead, for these reasons:

The costs. The panel works only in desktop builds, because ImGui needs an SDL backend, so the TV builds have no panel. It also reads SDL’s input events, not the engine’s, so a test_script run can’t click it. A browser pane, by contrast, could be driven by a browser-automation tool. The script verbs cover what a scripted run needs, and the panel is for hands-on sessions.

Building it

ScummVM vendors Dear ImGui. configure builds it when FreeType and an SDL backend are present, and when an enabled engine names the imgui component (TerraGlyph’s configure.engine does). In MSYS2 UCRT64:

pacman -S mingw-w64-ucrt-x86_64-freetype
./configure --disable-all-engines --enable-engine=terraglyph

configure should report ImGui... yes. To build without the panel, pass --disable-imgui. With FreeType installed, every desktop build links FreeType, libpng and their dependencies, with or without ImGui. Make-Release.ps1 collects the DLLs with ldd, so release bundles pick them up without any change.

Opening it

Launch with ScummVM’s common imgui debug channel:

$env:PATH = "C:\msys64\ucrt64\bin;$env:PATH"
& .\scummvm.exe --debugflags=imgui,script --debuglevel=1 --logfile=panel.log pk

Without the channel, the panel isn’t drawn and no render callback is set, so the game runs as it does in a build without ImGui. The script channel and --logfile keep the Debug: lines, which are the only record of what the panel changed.

The windows

The View menu at the top shows or hides each window. Room, Game values and Hits are open at the start.

Window What it shows What you can do
Room The current room, whether it has its own room class, and the profile’s StartRoom Filter the room list, then double-click a room to enter it
Game values The [Game] section as a table Tick a Yes/No flag, step a number, or edit text and press Enter; add a new key with Set
Clues The villain (Whodunit) and the five clue slots with their owners A button per suspect gives that suspect’s clue; it greys out once that suspect has given one
Inventory The toolbar’s items Take one out; filter every inventory object and Give one
Hits The overlay’s legend and the sprite under the mouse: its object, label, destination, rollover and hit type Turn the overlay on or off
Sound and movies Sounds and movies as tabs Filter and Play a sound, or Stop; play any movie from 00 to 74 (the room comes back after it)
Profile The profile as a save holds it (the original’s <name>.sav) Refresh, or Copy it to the clipboard

The panel doesn’t write anything itself. Each control queues a command in the script’s form (room ROOM_P05_Gardeners_House, game WellVisited Yes), and the game loop runs it before the next tick, through the same dispatcher as the test_script verbs. The queue exists because ImGui’s render callback runs inside updateScreen(), and entering a room redraws the screen, which can’t happen from inside that callback.

Where the design comes from

These tools are modelled on Legendary Arena’s operator panel, described in Why Play Needs a Debug Panel (Legendary Arena’s ewiki, behind Cloudflare Access). That panel follows the Herbs vs. Ailments debug-panel design. Legendary Arena is a turn-based web game with a server and several players, while TerraGlyph is a single-player engine running on one machine. So the rules carry over, but the mechanisms behind them don’t. Here is where each part of the article shows up in TerraGlyph:

Legendary Arena Here
Summary: get to the interesting state fast, instead of playing until the board happens to reach it The same goal. Each “played” packet (WP-100 to WP-129) used to reach its room’s state through a .sav profile written by hand for the run (WP-130).
What it costs today: several full games to verify one fix A wrong key in a hand-written profile meant a wrong start, found only after the run. Now a script sets the state in its own text.
The Herbs vs. Ailments model, and what changes here: controls send intents through the code paths real play uses The same rule (WP-130 D1): only the engine’s own setters, so nothing can build a state the game couldn’t reach. What differs: here nothing is hidden from another player, but the [Game] values never appear on screen; and the gate is a debug channel on a local build, not a debug match on the production server, because there’s no server and nothing is scored.
What the panel shows: every hidden zone, plus the bot’s choices The Game values, Clues, Inventory and Profile windows show the hidden state. In place of the bot’s choices, the hit overlay shows another thing that can’t be seen in play: which sprite a click would reach.
What it lets an operator do: setters, and copying the state as a fixture room, game, clue, give and take. The Profile window’s Copy puts the state on the clipboard in the save’s own format. There’s no “jump to turn N”, because the engine keeps no move log to replay.
The shape it takes: a lazily loaded panel, setters as engine moves, a Tweakpane pane The panel is set up only while its channel is on, and its commands go through the same dispatcher as the script verbs. It uses Dear ImGui, not Tweakpane (why).
Guardrails: operator only, never competitive, everything logged, the engine owns truth Operator only: off unless --debugflags=imgui or the console. Never competitive: nothing is scored, so a save carries no debug marker (WP-130 D3). Everything logged: each change writes a Debug: line. The engine owns truth: one write path.
Edge Cases: boards the rules can’t reach; setting state mid-choice or mid-bot-turn Where a state has no setter of its own (a sprite’s step, a timer), there’s no debug operation for it yet (WP-130 D1). The panel’s commands run between ticks, never inside a frame’s drawing. That’s the same kind of rule as Legendary Arena running its setters only on the operator’s own turn.