upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/gameinput_test.cpp
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-11-26 18:59:07 +0000
committerClaude <noreply@anthropic.com>2026-11-26 18:59:07 +0000
commit7ffcb8e260d3cedfb0077d924b0be189293c5a2c (patch)
tree59285b61ba869fc779ea5586cc0337b292040e6e /runtime/test/gameinput_test.cpp
parent99f913a2883b6416385790dd3861b3890e142cb0 (diff)
parentf107ae044637ed7b337c96b6aa574c5a96c5da22 (diff)
Merge upstream/main into input-out-of-the-box
docs/gameinput.md conflicted on two passages, both kept: - main's new LEONIDA_INPUT_FILE paragraph, with this branch's sentence on make_game.py running build_runtime.ps1 with -FetchSdl3 (and --no-sdl3) added to main's wording of the build paragraph; - the settings table keeps this branch's LEONIDA_KEYBOARD_PAD default (1, focused; off removes it), which gameinput.cpp reads, and takes main's longer LEONIDA_INPUT_SCRIPT row (button@seconds:hold, the six-reads rule), saying "on unless LEONIDA_KEYBOARD_PAD=off" for the keyboard pad. No code conflicted. Tested: full ctest, 113 of 113, on Linux (the portable subset; the gameinput shim is Windows-only). Changes made by Claude Code (AI-assisted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
-rw-r--r--runtime/test/gameinput_test.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index 9561f44e4..91ea1ebc3 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -1724,10 +1724,12 @@ int main(int argc, char** argv) {
1724 check(create(&input) == S_OK && input, "GameInputCreate returns an instance"); 1724 check(create(&input) == S_OK && input, "GameInputCreate returns an instance");
1725 if (argc == 2 && std::strcmp(argv[1], "--input-script") == 0) { 1725 if (argc == 2 && std::strcmp(argv[1], "--input-script") == 0) {
1726 if (!input) return 1; 1726 if (!input) return 1;
1727 // Only the X after byte 63 is due now. Its later entry must not cancel it. 1727 // Only the X after byte 63 and the Y held 0.6 s are due now. X's later entry must not cancel it; the
1728 // malformed holds at the end hold nothing.
1728 set_env("LEONIDA_INPUT_SCRIPT", 1729 set_env("LEONIDA_INPUT_SCRIPT",
1729 "start@3600,start@3600,start@3600,start@3600,start@3600,start@3600, X@0 \t,x@3600," 1730 "start@3600,start@3600,start@3600,start@3600,start@3600,start@3600, X@0 \t,x@3600,"
1730 "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,"); 1731 "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,y@0:0.6,"
1732 "a@0:0,a@0:-1,a@0:,a@0:x,a@0:inf,a@0:601,a@0:1tail");
1731 set_env("LEONIDA_KEYBOARD_PAD", "1"); 1733 set_env("LEONIDA_KEYBOARD_PAD", "1");
1732 rt::gameinput::set_keyboard_source(fake_key_down, fake_focus); 1734 rt::gameinput::set_keyboard_source(fake_key_down, fake_focus);
1733 rt::gameinput::set_cursor_source(fake_cursor); 1735 rt::gameinput::set_cursor_source(fake_cursor);
@@ -1736,27 +1738,32 @@ int main(int argc, char** argv) {
1736 rt::gameinput::reload_config(); 1738 rt::gameinput::reload_config();
1737 rt::gameinput::poll(); 1739 rt::gameinput::poll();
1738 const auto buttons = pad_state(input, nullptr).buttons; 1740 const auto buttons = pad_state(input, nullptr).buttons;
1739 const auto expected = GameInputGamepadX | GameInputGamepadB; 1741 const auto expected = GameInputGamepadX | GameInputGamepadB | GameInputGamepadY;
1740 check((buttons & expected) == expected, "long script: the spaced X after byte 63 and the physical B are held"); 1742 check((buttons & expected) == expected,
1743 "long script: the spaced X after byte 63, the held Y and the physical B are held");
1741 check((buttons & ~expected) == 0, "malformed script entries hold no extra buttons"); 1744 check((buttons & ~expected) == 0, "malformed script entries hold no extra buttons");
1742 g_focus = false; 1745 g_focus = false;
1743 set_env("LEONIDA_INPUT_SCRIPT", "y@0"); 1746 set_env("LEONIDA_INPUT_SCRIPT", "y@0");
1744 rt::gameinput::reload_config(); 1747 rt::gameinput::reload_config();
1745 rt::gameinput::poll(); 1748 rt::gameinput::poll();
1746 check(pad_state(input, nullptr).buttons == GameInputGamepadX, 1749 check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadY),
1747 "scripted X survives focus loss; reload does not replace it with Y"); 1750 "scripted X and Y survive focus loss; reload does not replace the script with y@0");
1748 Sleep(350); 1751 Sleep(350);
1749 g_focus = true; 1752 g_focus = true;
1750 rt::gameinput::poll(); 1753 rt::gameinput::poll();
1751 // A scripted press lasts its 300 ms and then until the title has read the pads six times since it began 1754 // A scripted press lasts its hold (300 ms, or button@seconds:hold) and then until the title has read the pads
1752 // (update_keyboard_pad: kReads, at most kMaxHold seconds), so a title that polls slowly still sees it. Each 1755 // six times since it began (update_keyboard_pad: kReads), so a title that polls slowly still sees it. Each
1753 // pad_state() is one GetCurrentReading, and this is the third since the X began. 1756 // pad_state() is one GetCurrentReading, and this is the third since X and Y began.
1754 check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadB), 1757 check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadB | GameInputGamepadY),
1755 "long script: past its 300 ms the press is still held while the title has read the pads fewer than six times"); 1758 "long script: past its 300 ms X is still held while the title has read the pads fewer than six times");
1756 for (int i = 0; i < 6; ++i) pad_state(input, nullptr); 1759 for (int i = 0; i < 6; ++i) pad_state(input, nullptr);
1757 rt::gameinput::poll(); 1760 rt::gameinput::poll();
1761 check(pad_state(input, nullptr).buttons == (GameInputGamepadB | GameInputGamepadY),
1762 "long script: X ends once the title has read it, y@0:0.6 is still held for its time, the key stays held");
1763 Sleep(400);
1764 rt::gameinput::poll();
1758 check(pad_state(input, nullptr).buttons == GameInputGamepadB, 1765 check(pad_state(input, nullptr).buttons == GameInputGamepadB,
1759 "long script: the timed press ends once the title has read it, while the physical key stays held"); 1766 "long script: Y is released after its 0.6 s hold, the title having read it six times");
1760 input->Release(); 1767 input->Release();
1761 std::printf("%d checks, %d failures\n", g_checks, g_failures); 1768 std::printf("%d checks, %d failures\n", g_checks, g_failures);
1762 return g_failures ? 1 : 0; 1769 return g_failures ? 1 : 0;