From 9016b1e21072e35f85b3dcd1758d47431d32151e Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Sat, 31 Oct 2026 00:46:24 +0300 Subject: [PATCH] Add a virtual test gamepad for stick tests without a controller TOTK_TEST_PAD=,,, attaches an SDL virtual gamepad at start with its sticks at those raw values, so the dead zone and the gamepad path can be tested in a run. On the field save: an 11% drift reached the game as 3.3% at the default 8% zone (the old per-axis cutoff passed 9% on x and dropped y) and not at all at 15% (Link stood still); full deflection reached it as full at 15%. Co-Authored-By: Claude Opus 5.5 --- docs/controls.md | 2 ++ runtime/cfg.c | 2 +- runtime/input_win.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/controls.md b/docs/controls.md index b80fc89c..a351fdcd 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -87,6 +87,8 @@ The stick direction bits (`StickLLeft` to `StickRDown`) are derived from the sti `TOTK_INPUT_RECORD=` (`input_record` in `totk.ini`, or Input recording in the menu) writes the merged input in the same format, one line per button press and per stick segment: events before the world clock starts by tick, the rest timed; a button or stick held when the world clock starts is cut there and goes on as a timed event. The file replays as a script, which makes it the repro to attach to a bug report. +`TOTK_TEST_PAD=,,,` attaches an SDL virtual gamepad at start whose sticks rest at these raw SDL axis values (-32768 to 32767, down is +y), so a drifting or held stick can be tested without a controller: the values go through the gamepad mapping and `TOTK_STICK_DEADZONE` like a real pad's, and `TOTK_INPUT_RECORD` shows what reached the game. + ## RenderDoc capture (blocked) `TOTK_RDOC=[,...]` (`runtime/rdoc_win.c`; `TOTK_RDOC_DIR`, `TOTK_RDOC_DLL`) loads RenderDoc before `vkCreateInstance`. RenderDoc hides `VK_EXT_external_memory_host`, which the back end requires for guest pool imports (`runtime/vk_memory.c`), so device creation fails under it. A capture needs a copy-based pool fallback first. diff --git a/runtime/cfg.c b/runtime/cfg.c index 322917ab..336b24e3 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -48,7 +48,7 @@ static const char *const known[] = { "REPLAY_CHECK", "RESOLVE_CHECK", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES", "ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE", "SHADER_MEMO", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", "SHOTS_FULL", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_US", "STICK_DEADZONE", "SWKBD_ANSWER", - "SWKBD_TEST", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_MEMO", "TEX_VRAM_PRESSURE", "TIMER_1MS", "TRACE", "UBO_SNAPSHOT", "UPSCALER", "VK_DYN_VERTEX", "VK_NO_FLOAT64", + "SWKBD_TEST", "TEST_PAD", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_MEMO", "TEX_VRAM_PRESSURE", "TIMER_1MS", "TRACE", "UBO_SNAPSHOT", "UPSCALER", "VK_DYN_VERTEX", "VK_NO_FLOAT64", "VK_PRESENT", "VK_RECORDER", "VK_SSBO_ALIGN", "VK_SUBGROUP", "VK_SUBGROUP_PIN", "VK_VALIDATION", "VOLUME", "VRAM_HEADROOM", "VS_OUTS", "WB_FENCE_LIMIT", "WINDOW_SIZE", "XLATE", "XLATE_ID", "XLATE_PROCS", "ZSTD_CHECK", "ZSTD_NATIVE", }; diff --git a/runtime/input_win.c b/runtime/input_win.c index 096fef53..d4f0e78d 100644 --- a/runtime/input_win.c +++ b/runtime/input_win.c @@ -515,12 +515,44 @@ static void binds_refresh(void) { input_map_configure(); } +// TOTK_TEST_PAD=,,, (test runs): an SDL virtual gamepad whose sticks rest at these raw SDL axis values +// (-32768..32767, down is +y), attached before the first scan so it is the gamepad the game reads: drift and full +// deflection go through the same mapping and dead zone as a real pad. +static void test_pad_attach(void) { + static SDL_Joystick *joy; // kept open: a virtual joystick's axes are set through an open handle + const char *e = cfg_get("TOTK_TEST_PAD"); + int v[4]; + if (!e || !*e) return; + if (sscanf(e, "%d,%d,%d,%d", &v[0], &v[1], &v[2], &v[3]) != 4) { + rt_log("input: TOTK_TEST_PAD=%s is not ,,,; no test gamepad", e); + return; + } + SDL_VirtualJoystickDesc d; + SDL_INIT_INTERFACE(&d); + d.type = SDL_JOYSTICK_TYPE_GAMEPAD; + d.naxes = SDL_GAMEPAD_AXIS_COUNT; + d.nbuttons = SDL_GAMEPAD_BUTTON_COUNT; + d.name = "TotK test gamepad"; + SDL_JoystickID id = SDL_AttachVirtualJoystick(&d); + joy = id ? SDL_OpenJoystick(id) : NULL; + if (!joy) { + rt_log("input: test gamepad not attached (%s)", SDL_GetError()); + return; + } + static const SDL_GamepadAxis axes[4] = {SDL_GAMEPAD_AXIS_LEFTX, SDL_GAMEPAD_AXIS_LEFTY, SDL_GAMEPAD_AXIS_RIGHTX, + SDL_GAMEPAD_AXIS_RIGHTY}; + for (int i = 0; i < 4; i++) + SDL_SetJoystickVirtualAxis(joy, axes[i], (Sint16)(v[i] < -32768 ? -32768 : v[i] > 32767 ? 32767 : v[i])); + rt_log("input: test gamepad attached, sticks at %d,%d %d,%d", v[0], v[1], v[2], v[3]); +} + static void start(void) { binds_refresh(); const char *e = cfg_get("TOTK_INPUT"); if (e && !strcmp(e, "none")) { state = -1; rt_log("input: disabled (TOTK_INPUT=none)"); return; } if (!SDL_Init(SDL_INIT_GAMEPAD)) { state = -1; rt_log("input: SDL gamepad init failed (%s), keyboard only", SDL_GetError()); } else state = 1; + if (state == 1) test_pad_attach(); if (state == 1) { scan_pads(); if (!pad) rt_log("input: no gamepad (keyboard only until one is connected)");