Files
psxrecomp/runtime/tests/test_psx_menu_host.c
Shokunin 83f1468860 In-game menu host: a provider-neutral contract (psx_menu_host.h)
psxrecomp owns the contract between the runtime and any in-game menu
frontend. A provider (PsxMenuProvider: attach, event, is_open, set_open,
draw, detach) is registered by the title with psx_menu_set_provider();
none is registered by default, so a title's UI and pin are unchanged.
The runtime offers every provider the same host (PsxMenuHost): pause
(P1, refused in netplay), video get/apply on PsxHostVideoSettings (P4),
mod switch/option set (P5, via the new psx_mod_feature_enable /
psx_mod_feature_set_option shared with the launcher ABI provider),
reload bindings, exit (quit, back to the frontend loop in-process, or a
quick relaunch with the original arguments), disc/tray slots filled by
the tray policy (psx_menu_set_disc_ops), and optional helpers on the
shared launcher ABI both frontends already speak (game info with the
mod catalogue and lobby, settings get/apply with the handoff's filter
translations).

Policies live here, the same for every provider: the lobby is pumped
during play and a started match ends the local session and starts in
the frontend loop (pending launch, seats and signals kept, pumping
stopped so the match port stays free), the menu is closed and its pause
dropped first; the provider detaches before its GL context goes away at
session teardown and attaches to the next one. --launcher sets
RECOMP_LAUNCHER_PREGAME for frontends that boot into the game;
PSX_HIDDEN_WINDOW is a hidden-window test hook that keeps the frontend.
Nothing here includes or names a frontend's own headers or types.
Tests: psx_menu_host_test, host_overlay_test (relaunch quoting).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 15:02:57 -07:00

34 lines
1.6 KiB
C

/* psx_menu_host_test: provider and disc-op registration (psx_menu_host.h). */
#include "psx_menu_host.h"
#include <stdio.h>
static int fails = 0;
#define CHECK(c) do { if (!(c)) { fprintf(stderr, "FAIL %s:%d %s\n", __FILE__, __LINE__, #c); ++fails; } } while (0)
static int attach(void* c, void* w, void* g, const PsxMenuHost* h) { (void)c; (void)w; (void)g; return h != NULL; }
static int count3(void) { return 3; }
static int insert_ok(int d) { return d >= 1 && d <= 3 ? 0 : 2; }
int main(void) {
/* Default: no provider, so a title's own UI is unchanged. */
CHECK(psx_menu_provider() == NULL);
PsxMenuProvider p = {PSX_MENU_ABI_VERSION, "test", NULL, attach, NULL, NULL, NULL, NULL, NULL};
CHECK(psx_menu_set_provider(&p) == 1 && psx_menu_provider() == &p);
/* Another ABI version is refused and leaves the registration alone. */
PsxMenuProvider old = p;
old.abi_version = PSX_MENU_ABI_VERSION + 1;
CHECK(psx_menu_set_provider(&old) == 0 && psx_menu_provider() == &p);
CHECK(psx_menu_set_provider(NULL) == 1 && psx_menu_provider() == NULL);
/* Disc ops: none until the tray policy publishes them. */
CHECK(psx_menu_disc_ops() == NULL);
PsxMenuDiscOps d = {count3, NULL, NULL, insert_ok};
psx_menu_set_disc_ops(&d);
CHECK(psx_menu_disc_ops() == &d && psx_menu_disc_ops()->count() == 3 &&
psx_menu_disc_ops()->insert(2) == 0 && psx_menu_disc_ops()->insert(9) != 0);
psx_menu_set_disc_ops(NULL);
CHECK(psx_menu_disc_ops() == NULL);
if (!fails) printf("psx_menu_host_test: ok\n");
return fails ? 1 : 0;
}