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:
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
-rw-r--r--runtime/test/gameinput_test.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index be9dc5398..42a59e764 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -1718,10 +1718,12 @@ int main(int argc, char** argv) {
1718 check(create(&input) == S_OK && input, "GameInputCreate returns an instance"); 1718 check(create(&input) == S_OK && input, "GameInputCreate returns an instance");
1719 if (argc == 2 && std::strcmp(argv[1], "--input-script") == 0) { 1719 if (argc == 2 && std::strcmp(argv[1], "--input-script") == 0) {
1720 if (!input) return 1; 1720 if (!input) return 1;
1721 // Only the X after byte 63 is due now. Its later entry must not cancel it. 1721 // 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
1722 // malformed holds at the end hold nothing.
1722 set_env("LEONIDA_INPUT_SCRIPT", 1723 set_env("LEONIDA_INPUT_SCRIPT",
1723 "start@3600,start@3600,start@3600,start@3600,start@3600,start@3600, X@0 \t,x@3600," 1724 "start@3600,start@3600,start@3600,start@3600,start@3600,start@3600, X@0 \t,x@3600,"
1724 "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,"); 1725 "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,y@0:0.6,"
1726 "a@0:0,a@0:-1,a@0:,a@0:x,a@0:inf,a@0:601,a@0:1tail");
1725 set_env("LEONIDA_KEYBOARD_PAD", "1"); 1727 set_env("LEONIDA_KEYBOARD_PAD", "1");
1726 rt::gameinput::set_keyboard_source(fake_key_down, fake_focus); 1728 rt::gameinput::set_keyboard_source(fake_key_down, fake_focus);
1727 rt::gameinput::set_cursor_source(fake_cursor); 1729 rt::gameinput::set_cursor_source(fake_cursor);
@@ -1730,27 +1732,24 @@ int main(int argc, char** argv) {
1730 rt::gameinput::reload_config(); 1732 rt::gameinput::reload_config();
1731 rt::gameinput::poll(); 1733 rt::gameinput::poll();
1732 const auto buttons = pad_state(input, nullptr).buttons; 1734 const auto buttons = pad_state(input, nullptr).buttons;
1733 const auto expected = GameInputGamepadX | GameInputGamepadB; 1735 const auto expected = GameInputGamepadX | GameInputGamepadB | GameInputGamepadY;
1734 check((buttons & expected) == expected, "long script: the spaced X after byte 63 and the physical B are held"); 1736 check((buttons & expected) == expected,
1737 "long script: the spaced X after byte 63, the held Y and the physical B are held");
1735 check((buttons & ~expected) == 0, "malformed script entries hold no extra buttons"); 1738 check((buttons & ~expected) == 0, "malformed script entries hold no extra buttons");
1736 g_focus = false; 1739 g_focus = false;
1737 set_env("LEONIDA_INPUT_SCRIPT", "y@0"); 1740 set_env("LEONIDA_INPUT_SCRIPT", "y@0");
1738 rt::gameinput::reload_config(); 1741 rt::gameinput::reload_config();
1739 rt::gameinput::poll(); 1742 rt::gameinput::poll();
1740 check(pad_state(input, nullptr).buttons == GameInputGamepadX, 1743 check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadY),
1741 "scripted X survives focus loss; reload does not replace it with Y"); 1744 "scripted X and Y survive focus loss; reload does not replace the script with y@0");
1742 Sleep(350); 1745 Sleep(350);
1743 g_focus = true; 1746 g_focus = true;
1744 rt::gameinput::poll(); 1747 rt::gameinput::poll();
1745 // A scripted press lasts its 300 ms and then until the title has read the pads six times since it began 1748 check(pad_state(input, nullptr).buttons == (GameInputGamepadB | GameInputGamepadY),
1746 // (update_keyboard_pad: kReads, at most kMaxHold seconds), so a title that polls slowly still sees it. Each 1749 "long script: X's 0.3 s press ends, y@0:0.6 is still held, the physical key stays held");
1747 // pad_state() is one GetCurrentReading, and this is the third since the X began. 1750 Sleep(400);
1748 check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadB),
1749 "long script: past its 300 ms the press is still held while the title has read the pads fewer than six times");
1750 for (int i = 0; i < 6; ++i) pad_state(input, nullptr);
1751 rt::gameinput::poll(); 1751 rt::gameinput::poll();
1752 check(pad_state(input, nullptr).buttons == GameInputGamepadB, 1752 check(pad_state(input, nullptr).buttons == GameInputGamepadB, "long script: Y is released after its 0.6 s hold");
1753 "long script: the timed press ends once the title has read it, while the physical key stays held");
1754 input->Release(); 1753 input->Release();
1755 std::printf("%d checks, %d failures\n", g_checks, g_failures); 1754 std::printf("%d checks, %d failures\n", g_checks, g_failures);
1756 return g_failures ? 1 : 0; 1755 return g_failures ? 1 : 0;