upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/gameinput.cpp
diff options
context:
space:
mode:
authorquartz-heron-58 <245169279+quartz-heron-58@users.noreply.github.com>2026-11-25 10:50:03 +0800
committerquartz-heron-58 <245169279+quartz-heron-58@users.noreply.github.com>2026-11-25 10:50:03 +0800
commitcf4f434d23808742a2bea5536aaf662662a64099 (patch)
tree29dc4e3ce8feff1baede3e8401211d8d79287813 /runtime/shims/gameinput.cpp
parent3bc03ba69f30a09fd564287b3c8848c09260af54 (diff)
parent82f033512c449ff505accc65d395c1c5adc9dbee (diff)
Merge main (82f033512) into device-fault; keep only the fence-counter loss
Main now has its own device-fault report (LEONIDA_DEVICE_FAULT=1, from #984) and #980's device-lost line, so this branch's vulkan_device_fault.h, its report code and vk_device_fault_test are dropped in favour of main's. What stays is the case main does not cover: a loss the driver shows only as a timeline counter of UINT64_MAX. VulkanFence::completed() then asks vkDeviceWaitIdle through observe_result, so main's report runs, and marks the device lost when that returns VK_ERROR_DEVICE_LOST. vk_fence_lost_by_counter_test is adapted to main's reporter. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/gameinput.cpp')
-rw-r--r--runtime/shims/gameinput.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp
index 7650b361f..db685e71f 100644
--- a/runtime/shims/gameinput.cpp
+++ b/runtime/shims/gameinput.cpp
@@ -1895,10 +1895,15 @@ void update_keyboard_pad() {
1895 } 1895 }
1896 clip_cursor(active && g_raw_ready && g_cursor_pos.load() == system_cursor_pos && foreground_is_ours()); 1896 clip_cursor(active && g_raw_ready && g_cursor_pos.load() == system_cursor_pos && foreground_is_ours());
1897 for (const auto& b : kKeyBindings) SDL_SetJoystickVirtualButton(g_keyboard.js, b.sdl_button, down[b.sdl_button]); 1897 for (const auto& b : kKeyBindings) SDL_SetJoystickVirtualButton(g_keyboard.js, b.sdl_button, down[b.sdl_button]);
1898 // Timed presses on the keyboard pad, in seconds since its first update. Each press lasts 300 ms. 1898 // LEONIDA_INPUT_SCRIPT="a@70,a@85,start@120" (with LEONIDA_KEYBOARD_PAD=always): timed presses on the keyboard
1899 // pad, in seconds since the pad's first update, each held 300 ms. For unattended boots: the title's first prompt
1900 // waits for a button with no timeout (docs/re/notes/firstframe.md, step 5). Buttons: a b x y start back lb rb
1901 // up down left right. The rsup and rsdown entries replay the right-stick throws logged below.
1902 int right_y = g_keyboard.right_y;
1899 struct ScriptedPress { 1903 struct ScriptedPress {
1900 SDL_GamepadButton button; 1904 SDL_GamepadButton button;
1901 double at; 1905 double at;
1906 int right_y = 0;
1902 }; 1907 };
1903 static const std::vector<ScriptedPress> script = [] { 1908 static const std::vector<ScriptedPress> script = [] {
1904 std::vector<ScriptedPress> out; 1909 std::vector<ScriptedPress> out;
@@ -1925,6 +1930,11 @@ void update_keyboard_pad() {
1925 const double seconds = std::strtod(time, &tail); 1930 const double seconds = std::strtod(time, &tail);
1926 if (tail == time || !std::isfinite(seconds) || seconds < 0 || 1931 if (tail == time || !std::isfinite(seconds) || seconds < 0 ||
1927 item.find_first_not_of(whitespace, tail - item.c_str()) != std::string::npos) continue; 1932 item.find_first_not_of(whitespace, tail - item.c_str()) != std::string::npos) continue;
1933 if (item.compare(first, sep - first, "rsup") == 0 || item.compare(first, sep - first, "rsdown") == 0) {
1934 const bool up = item.compare(first, sep - first, "rsup") == 0;
1935 out.push_back({SDL_GAMEPAD_BUTTON_INVALID, seconds, up ? -kStickFull : kStickFull});
1936 continue;
1937 }
1928 for (const auto& [name, button] : names) { 1938 for (const auto& [name, button] : names) {
1929 if (item.compare(first, sep - first, name) == 0) { 1939 if (item.compare(first, sep - first, name) == 0) {
1930 out.push_back({button, seconds}); 1940 out.push_back({button, seconds});
@@ -1944,8 +1954,13 @@ void update_keyboard_pad() {
1944 bool scripted[SDL_GAMEPAD_BUTTON_COUNT] = {}; 1954 bool scripted[SDL_GAMEPAD_BUTTON_COUNT] = {};
1945 bool named[SDL_GAMEPAD_BUTTON_COUNT] = {}; 1955 bool named[SDL_GAMEPAD_BUTTON_COUNT] = {};
1946 for (const auto& press : script) { 1956 for (const auto& press : script) {
1947 named[press.button] = true; 1957 const bool held = now >= press.at && now < press.at + 0.3;
1948 if (now >= press.at && now < press.at + 0.3) scripted[press.button] = true; 1958 if (press.right_y) {
1959 if (held) right_y = press.right_y;
1960 } else {
1961 named[press.button] = true;
1962 scripted[press.button] |= held;
1963 }
1949 } 1964 }
1950 for (int button = 0; button < SDL_GAMEPAD_BUTTON_COUNT; ++button) { 1965 for (int button = 0; button < SDL_GAMEPAD_BUTTON_COUNT; ++button) {
1951 if (!named[button]) continue; 1966 if (!named[button]) continue;
@@ -1961,7 +1976,7 @@ void update_keyboard_pad() {
1961 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTX, static_cast<Sint16>(lx * reach)); 1976 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTX, static_cast<Sint16>(lx * reach));
1962 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTY, static_cast<Sint16>(ly * reach)); 1977 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTY, static_cast<Sint16>(ly * reach));
1963 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTX, static_cast<Sint16>(g_keyboard.right_x)); 1978 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTX, static_cast<Sint16>(g_keyboard.right_x));
1964 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTY, static_cast<Sint16>(g_keyboard.right_y)); 1979 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTY, static_cast<Sint16>(right_y));
1965 // SDL maps a full-range virtual axis to the trigger, so -32768 is released, 0 half pulled, 32767 full. 1980 // SDL maps a full-range virtual axis to the trigger, so -32768 is released, 0 half pulled, 32767 full.
1966 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, aim ? 32767 : -32768); 1981 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, aim ? 32767 : -32768);
1967 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, fire ? 32767 : -32768); 1982 SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, fire ? 32767 : -32768);
@@ -2032,6 +2047,33 @@ void poll_once() {
2032 read_raw(d, &snap); 2047 read_raw(d, &snap);
2033 const bool guide_changed = d->last_snap.guide != snap.guide; 2048 const bool guide_changed = d->last_snap.guide != snap.guide;
2034 const bool changed = !(d->last_snap == snap); 2049 const bool changed = !(d->last_snap == snap);
2050 // Every press is logged in LEONIDA_INPUT_SCRIPT's own form (name@seconds), so a session played by hand can
2051 // be replayed unattended: join the logged items with commas. The right stick's vertical throws (what scrolls
2052 // a page) are logged as rsup/rsdown. LEONIDA_INPUT_LOG=0 turns the lines off.
2053 {
2054 static const bool log_presses = env("LEONIDA_INPUT_LOG") != "0";
2055 static const ULONGLONG log_origin = GetTickCount64();
2056 if (log_presses) {
2057 static const std::pair<uint32_t, const char*> kNames[] = {
2058 {GameInputGamepadA, "a"}, {GameInputGamepadB, "b"},
2059 {GameInputGamepadX, "x"}, {GameInputGamepadY, "y"},
2060 {GameInputGamepadMenu, "start"}, {GameInputGamepadView, "back"},
2061 {GameInputGamepadLeftShoulder, "lb"}, {GameInputGamepadRightShoulder, "rb"},
2062 {GameInputGamepadDPadUp, "up"}, {GameInputGamepadDPadDown, "down"},
2063 {GameInputGamepadDPadLeft, "left"}, {GameInputGamepadDPadRight, "right"}};
2064 const double at = (GetTickCount64() - log_origin) / 1000.0;
2065 const uint32_t pressed = snap.gamepad.buttons & ~d->last_snap.gamepad.buttons;
2066 for (const auto& n : kNames)
2067 if (pressed & n.first)
2068 std::fprintf(stderr, "[rt] gameinput: press %s@%.1f (%s)\n", n.second, at, d->name.c_str());
2069 const auto throw_of = [](float y) { return y > 0.6f ? 1 : y < -0.6f ? -1 : 0; };
2070 const int was = throw_of(d->last_snap.gamepad.rightThumbstickY);
2071 const int is = throw_of(snap.gamepad.rightThumbstickY);
2072 if (is != was && is != 0)
2073 std::fprintf(stderr, "[rt] gameinput: press %s@%.1f (%s)\n", is > 0 ? "rsup" : "rsdown", at,
2074 d->name.c_str());
2075 }
2076 }
2035 d->last_snap = snap; 2077 d->last_snap = snap;
2036 // A newly opened pad's first sample here is its baseline (active_input.h), so connecting a pad with a button 2078 // A newly opened pad's first sample here is its baseline (active_input.h), so connecting a pad with a button
2037 // held changes nothing. 2079 // held changes nothing.