ScummVM Integration Contract

Status: Scaffold — sections populated as Phase 2 implementation lands ScummVM version pin: c553503d9d433726b22b43b3a6a0a86fd00125e9 (scummvm/scummvm master, 2026-11-13, “SCUMM: Hotspot highlighting with object names”). This is the base of the fork’s scooby-engine branch (barefootbetters/scummvm), pinned by WP-010. Signatures below are checked against this commit. Engine location: engines/terraglyph/ (within the ScummVM fork) Vision doc reference: docs/01-VISION.md — “Engine Contract (ScummVM Requirements)” section is the high-altitude principles; this doc owns the concrete API surface.


What this doc is

The terraglyph engine must conform to ScummVM’s engine architecture and integration model — not as a general reimplementation, but as a ScummVM-compatible engine module. This document enumerates the concrete integration points: which classes to subclass, which APIs to call, which files to ship, and what each Phase 2 work item has to satisfy before upstream will accept the engine.

This doc has its own lifecycle: it tracks ScummVM upstream conventions (which change between releases) separately from the vision doc (which tracks the project’s evolving understanding of the games themselves). Pin a ScummVM commit hash in the header above before relying on any specific signature called out below.


Acceptance gates (TL;DR)

The following are the upstream-merge-blocking items. Phase 5 cannot ship a PR unless every one of these is true:

  1. Engine compiles cleanly against the pinned ScummVM commit.
  2. Engine is registered via MetaEngineDetection and discovered by ScummVM’s launcher.
  3. Detection works on at least Showdown without false positives on unrelated game files.
  4. All file I/O goes through Common::File / Common::Archive — no fopen, no std::ifstream, no raw POSIX/Win32 file calls.
  5. All audio plays through Audio::Mixer; no direct DirectSound or platform audio calls.
  6. Bink video plays through ScummVM’s built-in Video::BinkDecoder; binkw32.dll is not loaded.
  7. Engine is single-threaded; no pthread, no std::thread, no worker threads.
  8. Code conforms to ScummVM’s code style (see §11).
  9. All source files carry the GPL-3.0 license header.
  10. Engine is declared ADGF_TESTING (or higher) in detection.

1. Engine class

Requirement: Implement a subclass of Engine providing the main run loop.

Upstream reference: engines/engine.h, engines/engine.cpp. See ScummVM wiki HOWTO-Add a new engine.

Acceptance criterion: TerraglyphEngine::run() drives a cooperative event-pumping loop (calling _system->getEventManager()->pollEvent() each frame), returns Common::kNoError on clean exit, and contains no platform-specific surfaces or windowing calls. syncSoundSettings() is called once on startup (constructor or top of run(), per the engine’s preference) before any audio plays, so the user’s ScummVM volume preferences take effect on the first frame.

Implementation notes: WP-010 scaffold (2026-11-13): TerraglyphEngine::run() sets up 640 × 480 RGB565 with initGraphics(), returns kUnsupportedColorMode if the backend cannot provide it, calls syncSoundSettings(), then pumps events through a Graphics::FrameLimiter at 60 fps until shouldQuit().


2. MetaEngine and detection

Requirement: Provide both a MetaEngineDetection subclass (for game discovery) and a MetaEngine subclass (for engine instantiation). These are deliberately split in current ScummVM.

Upstream reference: engines/metaengine.h, engines/advancedDetector.h. Recent example to copy structure from: BOLT engine and beholdnec/scummvm-funhouse.

Acceptance criterion: The ScummVM launcher’s “Add Game” dialog discovers a mounted Showdown disc without prompting the user to identify it manually.

Implementation notes: WP-010 and WP-012 (2026-11-14). TerraglyphMetaEngineDetection derives from AdvancedMetaEngineDetection<Terraglyph::TerraglyphGameDescription> and TerraglyphMetaEngine from AdvancedMetaEngine<Terraglyph::TerraglyphGameDescription>, so createInstance() receives the extended description (§3) and passes it to the engine. Detection was checked with scummvm --detect --path=<disc root> on each mounted ISO. That is the same advanced-detector code the “Add Game” dialog runs, but the dialog itself was not clicked through.


3. Game detection table (ADGameDescription)

Requirement: Define an extended ADGameDescription array (AdvancedMetaEngineDetection with a per-entry gen flag — see below). Signature files vary by engine generation per the Phase 1 Engine Lineage finding in docs/01-VISION.md:

Generation Titles Signature files
Gen 1 Showdown, Phantom Scooby.exe, TGIFILE.ART, object.ini (all in \scooby\)
Gen 2 Jinx Scooby.exe, Mummy.mms (in \Jinx\), Mummy.MMP (disc root)
Gen 2 Activity Challenge Bonus.mms, BONUS.MMP, BONUS.MMF (all at the disc root; Scooby.exe is in \INSTALL\HDINSTALL\, so it is not used)
Gen 3 Case File #1 Case File #1.exe (in \MUSEUM\), Museum.MMS (in \MUSEUM\Scripts and Resources\), MuseumCD.MMP (in \Scripts and Resources\)

Case File #2 runs a different engine and has no entry (WP-005). Signature files are the ones WP-012 matches. Earlier drafts of this table listed libexpat.dll and loose *.xml files for Gen 3; the XML is inside the MMFW archives.

Match on file presence, size and MD5. The MD5 covers the first 5,000 bytes, the advanced detector’s default, so detection stays fast on 100 MB archives. Never match on ISO filename or disc directory layout.

Per-entry generation flag. Each detection-table row carries a gen field (or equivalent flag in the flags bitfield) recording which generation the title belongs to. The engine reads this at startup and selects the appropriate archive parser, config parser, and cutscene path. This is the load-bearing piece — without it, the engine would need either runtime format sniffing (slow + brittle) or per-title hardcoded paths (PR-blocking).

Upstream reference: engines/advancedDetector.h; engines/<engine>/detection_tables.h patterns across existing engines. For multi-format engines see existing engines with a flags field carrying format-version info (e.g. AGI’s GType_* field).

Acceptance criterion: Each of the four in-scope ISOs is detected with the correct generation flag (Showdown=1, Phantom=1, Jinx=2, Case File #1=3). Activity Challenge is detected as Gen 2 (WP-013); it is not in a Phase 5 tier yet, so it stays ADGF_UNSUPPORTED. Case File #2 (a different engine, per WP-005) and Case File #3 (a Director title) are not detected. No false positives on a directory containing unrelated DOS/Windows-era game files. (Revised 2026-11-14 by WP-012; the original asked for five ISOs with Case File #2 as Gen 3.)

Implementation notes: WP-012 (2026-11-14). detection.h declares:

enum TerraglyphGeneration { kGen1 = 1, kGen2 = 2, kGen3 = 3 };

struct TerraglyphGameDescription {
	AD_GAME_DESCRIPTION_HELPERS(desc);

	ADGameDescription desc;
	TerraglyphGeneration generation;
};

The engine reads it with TerraglyphEngine::getGeneration(). detection_tables.h has five entries (the fifth added after WP-013):

Game id Title Generation Flag
showdown Showdown in Ghost Town 1 ADGF_UNSTABLE
phantomknight Phantom of the Knight 1 ADGF_UNSTABLE
jinxsphinx Jinx at the Sphinx 2 ADGF_UNSUPPORTED
casefile1 Case File #1: The Glowing Bug Man 3 ADGF_UNSUPPORTED
activitychallenge Activity Challenge 2 ADGF_UNSUPPORTED

4. Resource access — Common::File and Common::Archive

Requirement: All disc reads go through ScummVM’s file abstractions. The engine must not contain fopen, std::ifstream, CreateFileA, or any other direct file API.

Upstream reference: common/file.h, common/archive.h, common/fs.h. SearchMan for path resolution.

Acceptance criterion: A grep -E '(fopen|std::ifstream|CreateFile[AW]?)' engines/terraglyph/ returns no matches outside comments. (Common::File::open() is permitted — only direct OS file APIs are banned.) The TGIFILE.ART parser opens its archive via Common::File::open(name) and exposes individual assets as Common::SeekableReadStream.

Implementation notes: WP-014 (2026-11-14). Terraglyph::ArtArchive (engines/terraglyph/art_archive.{h,cpp}) is a Common::Archive over the Gen 1 TGIFILE.ART.

The grep in the acceptance criterion finds nothing in engines/scooby/ at fork commit 155144012a.


5. Graphics output

Requirement: Render through ScummVM’s graphics manager (OSystem::getPaletteManager(), OSystem::copyRectToScreen(), OSystem::updateScreen()). No DirectDraw, no Direct3D, no platform surfaces. Palette handling per the PaletteManager interface.

Upstream reference: common/system.h (OSystem), graphics/surface.h, graphics/paletteman.h.

Acceptance criterion: Room 1 of Showdown renders at the original resolution in ScummVM’s window on Windows, macOS, and Linux without per-platform code paths in the engine. (Revised 2026-11-14 by WP-015: the original also asked for “the original palette”, but there is none. Pixels are RGB565 truecolour, per WP-002 and WP-001.)

Implementation notes: WP-015 (2026-11-14).


6. Audio

Requirement: All audio plays through Audio::Mixer via the engine’s _mixer member. Decoders come from audio/decoders/ if a standard codec is identified in Phase 1; otherwise a new decoder lives under audio/decoders/ and is contributed alongside the engine PR (or carried in-engine if it is genuinely Scooby-specific).

Upstream reference: audio/mixer.h, audio/audiostream.h, audio/decoders/ (raw, ADPCM, MP3, Vorbis, FLAC).

Acceptance criterion: Music, SFX, and voice all route through Audio::Mixer. Volume sliders in the ScummVM Options dialog control the engine’s audio correctly. No direct DirectSound or platform audio calls.

Implementation notes: WP-019 (2026-11-14). The Gen 1 audio is uncompressed PCM (audio-archives), so the engine needs no new decoder and no licensed code.

WP-020 (2026-11-14): a handle per file, and lip sync.

WP-055 (2026-11-16): a handle per sound effect.

Voice streams (2026-11-16): a handle per voice line. Traced in scooby-exe.

Which sounds play when, beyond the exit scenes (room music, ambience), is room code.


7. Video playback (Bink)

Requirement: Cutscenes play through ScummVM’s built-in Video::BinkDecoder. The engine must not load binkw32.dll or otherwise depend on the original RAD runtime.

Upstream reference: video/bink_decoder.h, video/video_decoder.h.

Acceptance criterion: Every BK.XXX cutscene from Showdown plays start-to-end in ScummVM with correct audio sync and no fallback to external Bink runtime.

Implementation notes: WP-022 (2026-11-14).


8. Save / load

Requirement: Either implement save/load via ScummVM’s Engine::saveGameState / Engine::loadGameState overrides and declare the relevant MetaEngineFeature flags consistently in MetaEngine::hasFeature(), or explicitly return false for those flags and verify the ScummVM GUI correctly hides save/load options. The two must agree — overriding saveGameState without also returning true from hasFeature(kSupportsSavingDuringRuntime) silently breaks the GUI. If the original engine has a save format, prefer reading it for compatibility; if not, document a clean ScummVM-native save format.

Upstream reference: engines/engine.h (save/load virtuals), engines/metaengine.h (MetaEngineFeature::kSupportsSavingDuringRuntime, kSupportsListSaves, etc.), common/savefile.h.

Acceptance criterion: Either (a) save/load works through ScummVM’s standard dialogs and a state saved before a room transition restores correctly after engine restart, or (b) the engine returns MetaEngineFeature flags indicating no save support, and the ScummVM GUI correctly hides save/load options.

Implementation notes: WP-026 (2026-11-14). The original has no slots. It keeps one profile per player, an INI <name>.sav it writes as it plays (scooby-exe). A ScummVM save holds that profile’s text, so the format is the original’s.


9. Debug channels

Requirement: Declare debug channels as a DebugChannelDef table returned from MetaEngineDetection::getDebugChannels(); the engine framework registers them. (At the pin, engines no longer call DebugMan.addDebugChannel() directly. That was this section’s original wording.) Use debugC(level, channel, ...) for diagnostic output. No printf, no fprintf(stderr, ...), no std::cout.

Upstream reference: common/debug.h, common/debug-channels.h.

Acceptance criterion: At minimum these channels exist: resource (file loading), graphics (rendering), audio (mixer routing), script (object.ini interpretation), input (event handling). scummvm --debugflags=resource terraglyph:showdown produces meaningful output.

Implementation notes: WP-010 (2026-11-13). The channels are declared in engines/terraglyph/detection.h (enum) and detection.cpp (table). WP-001 used the same names as Ghidra label prefixes (wp001-labels.txt).

Id Enum Name Covers
1 kDebugResource resource Archive and file loading (TGIFILE.ART, .dat, MMFW)
2 kDebugGraphics graphics Cel decoding and rendering
3 kDebugAudio audio Mixer routing and sound archives
4 kDebugScript script object.ini and room logic
5 kDebugInput input Event handling, hit tests

At the pin, channel values are ids starting at 1, not bit masks.

Live tests (WP-024, 2026-11-14). A test_script key in the game’s config domain plays input inside the engine, without the host’s mouse. It holds steps separated by ;:

With start_room and start_items, it runs a live test minimized, so it doesn’t take over the mouse of a machine in use.

Debug tools (WP-130, WP-131, 2026-11-30). The debug console, the test_script debug verbs (room, game, give, take, clue, hits) and an ImGui panel behind ScummVM’s common imgui channel all set state through one set of operations over the engine’s own setters, each logging a Debug: line on script. A hit overlay tints what hitTest() reaches by sprite kind. How to use them: The engine’s debug tools.


10. Build system integration

Requirement: Three files in engines/terraglyph/ participate in ScummVM’s build:

Detection/engine split requirement: Detection code (MetaEngineDetection) must live in detection.cpp and be linked independently from the engine code (TerraglyphEngine). This is mandatory in current ScummVM — the detection plugin loads without the full engine at game-scan time. Do not put engine logic in detection.cpp and do not put detection table data in scooby.cpp.

Upstream reference: any existing engine’s module.mk (e.g. engines/sci/module.mk), configure.engine. ScummVM’s configure script picks these up automatically when the directory exists.

Acceptance criterion: ./configure --enable-engine=terraglyph && make produces a scummvm binary that includes the engine. ./configure --disable-engine=terraglyph && make produces one that omits it cleanly. No platform-specific build hacks.

Implementation notes: WP-010 (2026-11-13), at the pin, with MSYS2 UCRT64 (g++ 16.2.0, SDL2 2.32.10, GNU Make 4.4.1). The toolchain is chosen for Phase 2–5. Both builds ran out of tree:

configure.engine is add_engine terraglyph "TerraGlyph" no "" "" "highres 16bit" "": off by default, and it needs the 640 × 480 and 16-bit features. module.mk puts scooby.o, console.o and metaengine.o in MODULE_OBJS and detection.o in DETECT_OBJS. There is no POTFILES because there are no translatable strings yet.


11. Code style and licensing

Requirement: Code conforms to ScummVM’s house style — based on broadly the Linux kernel style with ScummVM-specific deviations (tabs for indentation, K&R braces, specific naming conventions, no exceptions). Every source file carries the GPL-3.0-or-later header used elsewhere in the tree.

Upstream reference: ScummVM Code Formatting Conventions; license header on any existing engine source file.

Acceptance criterion: Files pass ScummVM’s devtools/code_check.sh (or whatever the current lint script is at the pinned commit) with zero warnings. License headers present on every .cpp/.h produced by the engine.

Implementation notes: TBD. Add a local pre-commit hook running ScummVM’s lint to catch drift early.


12. Upstream PR checklist

The PR submitted to scummvm/scummvm (Phase 5 deliverable) must satisfy:


References