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)

What is missing

Scope

In scope

  1. One set of operations, in debug_tools.cpp / .h. Each one calls the engine’s own setter and writes one log line that starts Debug: (for example Debug: 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(), as room does now (moved here).
    • setGameValue(key, value): setGameString(), so Yes / No are the flag values getGameFlag() reads.
    • giveClue(suspect): the engine’s giveClue(), so a clue lands in the first free CluesFound slot with its owner, as it does in play.
    • addItem(obj) / removeItem(obj): Inventory, as inv_add / inv_remove do now (moved here).
    • setHitOverlay(on): item 4.
  2. Console commands.
    • game: list the [Game] section. game KEY: print one value. game KEY VALUE: set it.
    • clues: list CluesFound0-4 and ClueOwners0-4. clue SUSPECT: giveClue().
    • hits [on|off]: the overlay.
    • room, inv_add and inv_remove keep their names and call the operations.
  3. test_script verbs: room NAME, game KEY VALUE, give OBJ, take OBJ, clue SUSPECT, hits on|off. They parse their string arguments instead of the %d %d the 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.
  4. 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 after drawRoom(), never into the room surface. So a shot shows it and Room::draw() is unchanged. Room gets a public getKind(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).
  5. Self-test, debug_tools_check.cpp, in the check list in terraglyph.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

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

Execution

  1. Pre-flight: confirm the operations’ setters and their callers, and time one full hitTest() pass over 640×480 in the largest room.
  2. Write the expected self-test lines from the setters’ code before the run.
  3. Add debug_tools.cpp / .h, move room, inv_add and inv_remove onto it, add the console commands and the script verbs.
  4. Add Room::getKind() and the overlay.
  5. Self-test, then a live scripted run: from a new game, room, game, give and hits on, with a shot.
  6. Fork PR against scooby-engine, using the style checker. Staged by name.

Exit criteria

  1. Expectations first. The new self-test lines were written before the run.
  2. 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.
  3. One path. Every state write in the console commands and the script verbs goes through debug_tools.cpp. A search of console.cpp and runTestScript() finds no direct setGame*, giveClue or Inventory call.
  4. Live. A scripted run from a fresh launch enters a Phantom room, sets [Game] values, gives an item and turns the overlay on. Its shot shows the exits and clickables tinted by kind, and the log has one Debug: line for each.
  5. Process. The fork PR against scooby-engine is 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).

Deliverables