WP-130: Debug tools — state setters and the hit overlay (Gen 1)
Status: ✅ Done (2026-11-30). Fork PR barefootbetters/scummvm#55 merged on 2026-11-30 (merge commit bcefc97cf4). Decisions D1–D4 approved by Jeff, 2026-11-30.
Phase: 5 (tooling for the rooms-played packets).
Depends on: WP-116 ✅ (where handleEvent() came in), WP-026 ✅ (the profile’s Game
section), WP-031 ✅ (giveClue()).
Unblocks: WP-131, the ImGui panel, which
calls this packet’s operations.
Companion EC: none (inline checklist under Exit criteria).
Pre-flight: pre-flight-WP-130-2026-11-30. Required: the packet modifies engines/terraglyph/**.
Targets generation(s): Gen 1, both titles.
Estimated effort: half a day.
Goal
Make it quick to reach a game state and to see what the mouse will hit.
This packet adds no dependency: it extends the debug console and the
test_script driver that are already there.
The model is Legendary Arena’s operator panel (Why Play Needs a Debug Panel, behind Cloudflare Access) and the Herbs vs. Ailments panel it follows. Both start from the same rule: get to the interesting state fast, and change state only through the code paths real play uses.
Background
What it costs today
Each “played” packet (22 so far, WP-100 to WP-129) checks a room live. A
session reaches the room’s state from a profile: a <name>.sav with the
right [Game] keys and StartRoom, written by hand for the run. Then the
test_script key (runTestScript(), terraglyph.cpp) plays the input. A
wrong key in the profile means a wrong start, and you find out only after
the run. Nothing on screen shows which sprite a click will reach.
What exists (fork scooby-engine, e1dd7bea63)
- The debug console (
console.cpp,GUI::Debugger, Ctrl+Alt+D) has 11 commands:roomenters a room throughshowRoom(), the full entry with music, script and opening;inv,inv_addandinv_removeshow and change the toolbar;profileprints the profile;art_list,art_info,sound_list,sound_play,sound_stopandmoviebrowse the assets.
- The
test_scriptdriver takesmove,click,down,up,wait,shot,save,load,type,keyandquit. All of them are input or a save slot. None of them sets state. - The engine’s own setters:
setGameFlag(),setGameInt()andsetGameString()for the[Game]section,giveClue()(clues.cpp) andInventory::addItem()/removeItem(). - The hit walk:
Room::hitTest()(0x4311F0) returns the first sprite front to back whose cels or polygon pass. Each sprite keeps its placement kind (Room::Kind: exit, clickable, inventory, requires, character, ghost…), but the kind is private toRoom.
What is missing
- Reading or setting a
[Game]value. No console command or script verb reachessetGame*().profileprints the whole profile, read-only. - Giving a clue.
giveClue()has no command. - Setting state from a script.
test_scriptcan’t enter a room, set a value or give an item, so every run needs its own profile. - Seeing the hit areas. No view shows which sprite
hitTest()returns at each point, or what kind it is.
Scope
In scope
- One set of operations, in
debug_tools.cpp/.h. Each one calls the engine’s own setter and writes one log line that startsDebug:(for exampleDebug: Game WellVisited = Yes). The console (item 2), the script verbs (item 3) and the WP-131 panel all call these, and none of them writes state any other way.gotoRoom(name):showRoom(), asroomdoes now (moved here).setGameValue(key, value):setGameString(), soYes/Noare the flag valuesgetGameFlag()reads.giveClue(suspect): the engine’sgiveClue(), so a clue lands in the first freeCluesFoundslot with its owner, as it does in play.addItem(obj)/removeItem(obj):Inventory, asinv_add/inv_removedo now (moved here).setHitOverlay(on): item 4.
- Console commands.
game: list the[Game]section.game KEY: print one value.game KEY VALUE: set it.clues: listCluesFound0-4andClueOwners0-4.clue SUSPECT:giveClue().hits [on|off]: the overlay.room,inv_addandinv_removekeep their names and call the operations.
test_scriptverbs:room NAME,game KEY VALUE,give OBJ,take OBJ,clue SUSPECT,hits on|off. They parse their string arguments instead of the%d %dthe input verbs read. With them a live run starts from a new game or a short base profile and sets the rest in the script, where the run’s own text records it.- The hit overlay. With it on, every point of the visible 640×480
where
hitTest()returns a sprite is tinted by that sprite’s kind, with a 1-pixel outline where the result changes. It’s drawn on the screen copy afterdrawRoom(), never into the room surface. So ashotshows it andRoom::draw()is unchanged.Roomgets a publicgetKind(sprite).- It is computed from
hitTest()itself, not from the sprites’ bounds, so it shows exactly what a click would reach: masks, polygons, hidden sprites and depth order included. - It’s recomputed when the room’s draw list or a sprite’s frame changes, not every tick. If a full pass is too slow at 36 ticks per second, it samples every second pixel. The pre-flight measures the cost.
- With the console open, the hovered point’s sprite prints its index,
kind, object, label, destination, rollover and hit type (
hits at X Y).
- It is computed from
- Self-test,
debug_tools_check.cpp, in the check list interraglyph.cpp:- each operation, read back through the engine’s own getter;
- at three points in a room (an exit, a clickable, nothing), the
overlay’s kind is the kind of the sprite
hitTest()returns.
Out of scope
- The ImGui panel (WP-131).
- The Hotspot Magnet’s targets. Once WP-107
lands, a later packet can draw
Room::getHitBox()and the magnet’s target on the same overlay. - Any write that bypasses the engine’s setters (a raw sprite state, a timer).
- A marker in the saved profile. See D3.
Decisions for Jeff
Jeff, 2026-11-30: “Yes, approve all”. Every recommendation below is the decision.
| # | Question | Options | Recommendation (approved) |
|---|---|---|---|
| D1 | How setters change state | (a) only through the engine’s own setters; (b) raw writes allowed where no setter exists | (a). It’s the Herbs vs. Ailments and Legendary Arena rule: a setter can’t build a state the game’s own code couldn’t. Where a state has no setter (a sprite’s step, a timer), the setter waits until the room’s code has one. |
| D2 | Where the setters are reachable | (a) console and test_script; (b) console only |
(a). The script is how sessions run the live checks. A verb there removes a hand-written profile from every “played” packet. |
| D3 | Mark a profile that a setter touched | (a) no marker, the Debug: log line only; (b) a Debugged=Yes key in [Game] |
(a). Nothing is scored, so there’s nothing to protect. A [Game] key would be written into the original’s .sav format and read by nothing. |
| D4 | Overlay gate | (a) a console command and a script verb; (b) also a key binding | (a). A key binding would be live for players too, and ScummVM’s keymapper would have to own it. The console is already the debug gate. |
Dependencies
- WP-116 ✅:
handleEvent(), the event path the script verbs feed. - WP-026 ✅ and WP-031 ✅: the
[Game]section andgiveClue().
Execution
- Pre-flight: confirm the operations’ setters and their callers, and time
one full
hitTest()pass over 640×480 in the largest room. - Write the expected self-test lines from the setters’ code before the run.
- Add
debug_tools.cpp/.h, moveroom,inv_addandinv_removeonto it, add the console commands and the script verbs. - Add
Room::getKind()and the overlay. - Self-test, then a live scripted run: from a new game,
room,game,giveandhits on, with ashot. - Fork PR against
scooby-engine, using the style checker. Staged by name.
Exit criteria
- Expectations first. The new self-test lines were written before the run.
- Self-test. Each operation reads back through the engine’s getter.
The overlay matches
hitTest()at the three points (an exit, a clickable and a layer: see below for why not “nothing”). The rest of the self-test matches the WP-129 run but for the random keys. No new warnings. - One path. Every state write in the console commands and the
script verbs goes through
debug_tools.cpp. A search ofconsole.cppandrunTestScript()finds no directsetGame*,giveClueorInventorycall. - Live. A scripted run from a fresh launch enters a Phantom room,
sets
[Game]values, gives an item and turns the overlay on. Itsshotshows the exits and clickables tinted by kind, and the log has oneDebug:line for each. - Process. The fork PR against
scooby-engineis open (merged on 2026-11-30).
Result
Evidence labels: log (a self-test’s debug log), live (session) (a scripted run this session drove and read, with screenshots).
- The change (source). On
wp-130-debug-tools(fb9ec5f62a), fork PR barefootbetters/scummvm#55:debug_tools.cpp: the operationsdebugGotoRoom(),debugSetGameValue(),debugGiveClue(),debugAddItem(),debugRemoveItem()andsetHitOverlay(), and the overlay itself;debug_tools.h: each kind’s name and colour, shared with the console;debug_tools_check.cpp: the check, run aftercheckAllMovies();- the console commands, the script verbs,
Room::getKind()with the kind enum made public, andisSuspect()inclues.cpp.
The operations are engine members defined in their own file, as the clue and profile code are, so the header holds only the kind helpers.
Room::getHitType()was already there. -
Self-test (log). Phantom, three runs; the last, on the committed code:
debug tools check room: ROOM_P04_Town 1, now ROOM_P04_Town; ROOM_Nowhere 0, now ROOM_P04_Town debug tools check game: Yes flag 1, No flag 0, 7 int 7, empty key 0 debug tools check clue: villain JESTER; EWAN 1, owner 1, found 1, slots 1; EWAN again 1, slots 1; NOBODY 0, slots 1 debug tools check items: OBJ_INV_BOTTLE_FULL add 1, slot 0 OBJ_INV_BOTTLE_FULL; remove 1, slot 0 -; remove again 0; NOT_AN_ITEM add 0 debug tools check hits: exit at (434,134) OBJ_P04_TO_P11 kind exit, overlay ok; clickable at (318,144) OBJ_P04_TOWN_HOTSPOT2 kind clickable, overlay ok; layer at (2,2) - kind layer, overlay ok; nothing none; step 2, 35 ms; pixels: layer 208464, character 30308, exit 57852, clickable 5240, engine 5336The other 1,984 check lines match the WP-129 run (
wp129.log) except for 15 a side, all per-run random picks: the drawbridge’s banners and flags, Ewan’s question and one of his wrong-answer lines, Maria’s item places, and a scream in the room of doors. The two logs have the same 18 warnings. The build has no warnings, and the style checker finds nothing in the source. - What I got wrong first.
- Nothing to hit. I expected a point in the town where
hitTest()returns nothing. There’s none: the background layer takes a hit on 208,464 of the 307,200 pixels, and the sprites cover the rest. A click on the background reaches the layer, which does nothing with it. - The cost. A full pass took 145 ms, too slow while the room animates.
Both changed the code after the first run:
- Layers are left untinted, so the overlay isn’t a grey wash over two-thirds of the screen. The check’s third point is a layer, which must come out unchanged.
- The overlay samples every second point: 35 to 42 ms a pass.
- The check line now counts the pixels by kind.
- Nothing to hit. I expected a point in the town where
- Live (session). One run from a fresh launch at the title, no profile:
- The script steps
room ROOM_P04_Town,game Whodunit JESTER,game WellVisited Yes,give OBJ_INV_RUBY,clue EWAN,hits on,hits offandtake OBJ_INV_RUBYeach logged theirDebug:line, andclue EWANitsGenerated clue 0 (EWAN_K) from EWAN, the villain JESTER. Debug: hits pass 37 ms.room ROOM_Nowhere,game Bad=Key x,give NOT_AN_ITEMandclue NOBODYwere each refused with a warning.- The screenshots:
- with the overlay on: the doors, the path and the right-hand edge green (exits); the shutters, the lamp post and the sign yellow (clickables); the gang orange; the toolbar blue; the ruby in its slot;
- with it off: the room as it was;
- after
take: the slot empty.
- The script steps
Deliverables
- Fork:
wp-130-debug-tools, PR barefootbetters/scummvm#55 (fb9ec5f62a), merged on 2026-11-30 asbcefc97cf4. Staged by name:debug_tools.{h,cpp},debug_tools_check.cpp,console.{h,cpp},room.h,clues.cpp,terraglyph.{h,cpp},module.mk. - Docs: this packet, its pre-flight
and the index row. The new verbs are listed in the
test_scriptcomment interraglyph.cpp. - Local only: the self-test and live logs, the screenshots and the expected text.