Files
vpinball-wasm/package/src/types.ts
T
valknarandClaude Sonnet 5 9479cea280 Add real PinMAME (VPinMAME.Controller) integration for ROM-based tables
Statically links the real PinMAME emulation core (libpinmame) instead of
leaving VPinMAME.Controller creation to fail, which was crashing table
scripts on ROM-based tables before they could spawn a ball. PinMAME's own
run_game()->cpu_run() loop is split into a one-shot init, a per-frame step,
and a one-shot teardown (patches/pinmame/0004) so it runs cooperatively on
the same frame callback as vpinball's own loop instead of on a real
std::thread, which hard-aborts under Emscripten's single-threaded runtime -
three smaller wasm32 portability fixes to libpinmame itself round out the
patch set (0001-0003). Adds pinball.loadRom() to supply a ROM zip, written
to the table-relative pinmame/roms/ path vpinball's own plugin already
checks. Confirmed against a real community ROM-based table: Controller
creation and game identification succeed, and a missing ROM now fails
cleanly instead of crashing the page - actual ROM-driven gameplay is still
unconfirmed since no ROM was available (or sought out) to test with.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SoSarxLgY33Kax5UNXcafZ
2026-08-23 12:09:35 +02:00

73 lines
3.1 KiB
TypeScript

/**
* Public TypeScript surface for vpinball-wasm.
*
* This wraps the raw Emscripten-generated module (dist/vpinball.js) so
* consumers don't need to know about ccall/cwrap/FS internals directly.
*/
export interface LoadPinballOptions {
/** Canvas the engine renders into via SDL3's WebGL2 backend. */
canvas: HTMLCanvasElement;
/**
* Raw bytes of a self-contained .vpx table file to play instead of the
* bundled default table. Real-world tables that reference an external
* .vbs script override or a Music/ folder are not supported this way -
* see the README's "Browser file-loading UX" section.
*/
tableData?: ArrayBuffer;
/** Base URL to fetch dist/vpinball.wasm/.data (and vpinball.js) from. */
baseUrl?: string;
/**
* Called as the wasm binary and preloaded asset package download,
* with a 0-1 fraction of bytes received. Not called at all if the
* browser doesn't support streaming fetch progress (falls back to
* Emscripten's own default loading behavior with no progress callback).
*/
onProgress?: (fraction: number) => void;
}
export interface PinballInstance {
/**
* Stage a different self-contained .vpx table to play on the *next*
* start() call. Does not affect an already-running session - table
* switching mid-session isn't supported; call stop() first (a fresh
* loadPinball() call is the supported way to load a genuinely new
* session with a different table).
*/
loadTable(vpxBytes: ArrayBuffer): void;
/**
* Makes a ROM zip available to PinMAME (VPinMAME.Controller) for a
* ROM-based ("SS"/real-hardware) table's Controller.Run() call - written
* to /tables/pinmame/roms/<gameName>.zip, the table-relative convention
* PinMAME's plugin already looks for before any global settings path.
* gameName is the short ROM/game name the table's own script passes to
* LoadVPM (e.g. "hvymetal"), not the table's display title. Must be
* called before start() (or loadTable(), if switching tables) since
* Controller.Run() reads the filesystem synchronously at table-init
* time. ROM files are copyrighted - only supply ones you're legally
* entitled to use.
*/
loadRom(gameName: string, romZipBytes: ArrayBuffer): void;
/** Start the simulation's main loop. No-op if already running. */
start(): void;
/** Stop the simulation; the engine tears down (script Exit event, settings save) on its next step. */
stop(): void;
/** Tear down the instance immediately and free its WebAssembly memory. */
dispose(): void;
/**
* Request fullscreen on the canvas via the standard Fullscreen API.
* Must be called from within a user gesture (e.g. a click handler) -
* browsers reject fullscreen requests otherwise. Returns the promise
* from the underlying requestFullscreen() call.
*/
requestFullscreen(): Promise<void>;
/**
* Runs arbitrary VBScript against the running table's script interpreter
* (the same entry point the interpreter's own debug console uses).
* Returns false if no table is currently running. Intended for debugging
* and for exercising script-driven engine APIs (e.g. the DMD pixel API)
* from JS - not sandboxed, so only run scripts you trust.
*/
evalScript(script: string): boolean;
}