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:
authorДмитрий Корлодный <deusex1998@gmail.com>2026-11-28 13:59:13 +0000
committerДмитрий Корлодный <deusex1998@gmail.com>2026-11-28 13:59:13 +0000
commit5fbcc642a52de0f269be65a9dce208dcb87f00fe (patch)
tree518cbe01fe433c290c4cdcd5955bf4585facd68a /runtime/test/gameinput_test.cpp
parentf7e422ee8a307ced9a41e11fb02330b4cb7abdaa (diff)
parent9c49bd5332327e689c5c957786c31b10efb3f32b (diff)
Merge upstream main into PR #1559
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
-rw-r--r--runtime/test/gameinput_test.cpp50
1 files changed, 43 insertions, 7 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index dee7f7d82..314d9293e 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -19,6 +19,7 @@
19#include <cstdio> 19#include <cstdio>
20#include <cstring> 20#include <cstring>
21#include <deque> 21#include <deque>
22#include <limits>
22#include <string> 23#include <string>
23#include <thread> 24#include <thread>
24#include <vector> 25#include <vector>
@@ -777,6 +778,27 @@ void test_keyboard_pad_sticks(IGameInput* input, IGameInputDevice* kb) {
777 check(rt::gameinput::config().mouse_sensitivity == 1.0f && rt::gameinput::config().ds_trigger_gain == 1.0f, 778 check(rt::gameinput::config().mouse_sensitivity == 1.0f && rt::gameinput::config().ds_trigger_gain == 1.0f,
778 "keyboard pad: mouse sensitivity defaults to 1 and leaves the trigger gain alone"); 779 "keyboard pad: mouse sensitivity defaults to 1 and leaves the trigger gain alone");
779 780
781 g_cursor_x += 3'000'000;
782 rt::gameinput::poll();
783 check(approx(pad_state(input, kb).rightThumbstickX, 1),
784 "keyboard pad: a positive jump beyond LONG_MAX axis units stays full right");
785 g_cursor_x -= 3'000'000;
786 rt::gameinput::poll();
787 check(approx(pad_state(input, kb).rightThumbstickX, -1),
788 "keyboard pad: a negative jump beyond LONG_MIN axis units stays full left");
789
790 const int prior_x = g_cursor_x;
791 g_cursor_x = std::numeric_limits<int>::max() - 1;
792 rt::gameinput::poll();
793 settle();
794 g_cursor_x = std::numeric_limits<int>::min() + 2;
795 rt::gameinput::poll();
796 check(approx(pad_state(input, kb).rightThumbstickX, 4096 / 32767.0f),
797 "keyboard pad: the raw cursor counter wrap moves four counts right");
798 g_cursor_x = prior_x;
799 rt::gameinput::poll();
800 settle();
801
780 g_keys[VK_RBUTTON] = true; 802 g_keys[VK_RBUTTON] = true;
781 rt::gameinput::poll(); 803 rt::gameinput::poll();
782 st = pad_state(input, kb); 804 st = pad_state(input, kb);
@@ -1777,10 +1799,12 @@ int main(int argc, char** argv) {
1777 check(create(&input) == S_OK && input, "GameInputCreate returns an instance"); 1799 check(create(&input) == S_OK && input, "GameInputCreate returns an instance");
1778 if (argc == 2 && std::strcmp(argv[1], "--input-script") == 0) { 1800 if (argc == 2 && std::strcmp(argv[1], "--input-script") == 0) {
1779 if (!input) return 1; 1801 if (!input) return 1;
1780 // Only the X after byte 63 is due now. Its later entry must not cancel it. 1802 // 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
1803 // malformed holds at the end hold nothing.
1781 set_env("LEONIDA_INPUT_SCRIPT", 1804 set_env("LEONIDA_INPUT_SCRIPT",
1782 "start@3600,start@3600,start@3600,start@3600,start@3600,start@3600, X@0 \t,x@3600," 1805 "start@3600,start@3600,start@3600,start@3600,start@3600,start@3600, X@0 \t,x@3600,"
1783 "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,"); 1806 "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,y@0:0.6,"
1807 "a@0:0,a@0:-1,a@0:,a@0:x,a@0:inf,a@0:601,a@0:1tail");
1784 set_env("LEONIDA_KEYBOARD_PAD", "1"); 1808 set_env("LEONIDA_KEYBOARD_PAD", "1");
1785 rt::gameinput::set_keyboard_source(fake_key_down, fake_focus); 1809 rt::gameinput::set_keyboard_source(fake_key_down, fake_focus);
1786 rt::gameinput::set_cursor_source(fake_cursor); 1810 rt::gameinput::set_cursor_source(fake_cursor);
@@ -1789,20 +1813,32 @@ int main(int argc, char** argv) {
1789 rt::gameinput::reload_config(); 1813 rt::gameinput::reload_config();
1790 rt::gameinput::poll(); 1814 rt::gameinput::poll();
1791 const auto buttons = pad_state(input, nullptr).buttons; 1815 const auto buttons = pad_state(input, nullptr).buttons;
1792 const auto expected = GameInputGamepadX | GameInputGamepadB; 1816 const auto expected = GameInputGamepadX | GameInputGamepadB | GameInputGamepadY;
1793 check((buttons & expected) == expected, "long script: the spaced X after byte 63 and the physical B are held"); 1817 check((buttons & expected) == expected,
1818 "long script: the spaced X after byte 63, the held Y and the physical B are held");
1794 check((buttons & ~expected) == 0, "malformed script entries hold no extra buttons"); 1819 check((buttons & ~expected) == 0, "malformed script entries hold no extra buttons");
1795 g_focus = false; 1820 g_focus = false;
1796 set_env("LEONIDA_INPUT_SCRIPT", "y@0"); 1821 set_env("LEONIDA_INPUT_SCRIPT", "y@0");
1797 rt::gameinput::reload_config(); 1822 rt::gameinput::reload_config();
1798 rt::gameinput::poll(); 1823 rt::gameinput::poll();
1799 check(pad_state(input, nullptr).buttons == GameInputGamepadX, 1824 check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadY),
1800 "scripted X survives focus loss; reload does not replace it with Y"); 1825 "scripted X and Y survive focus loss; reload does not replace the script with y@0");
1801 Sleep(350); 1826 Sleep(350);
1802 g_focus = true; 1827 g_focus = true;
1803 rt::gameinput::poll(); 1828 rt::gameinput::poll();
1829 // A scripted press lasts its hold (300 ms, or button@seconds:hold) and then until the title has read the pads
1830 // six times since it began (update_keyboard_pad: kReads), so a title that polls slowly still sees it. Each
1831 // pad_state() is one GetCurrentReading, and this is the third since X and Y began.
1832 check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadB | GameInputGamepadY),
1833 "long script: past its 300 ms X is still held while the title has read the pads fewer than six times");
1834 for (int i = 0; i < 6; ++i) pad_state(input, nullptr);
1835 rt::gameinput::poll();
1836 check(pad_state(input, nullptr).buttons == (GameInputGamepadB | GameInputGamepadY),
1837 "long script: X ends once the title has read it, y@0:0.6 is still held for its time, the key stays held");
1838 Sleep(400);
1839 rt::gameinput::poll();
1804 check(pad_state(input, nullptr).buttons == GameInputGamepadB, 1840 check(pad_state(input, nullptr).buttons == GameInputGamepadB,
1805 "long script: the timed press ends while the physical key stays held"); 1841 "long script: Y is released after its 0.6 s hold, the title having read it six times");
1806 input->Release(); 1842 input->Release();
1807 std::printf("%d checks, %d failures\n", g_checks, g_failures); 1843 std::printf("%d checks, %d failures\n", g_checks, g_failures);
1808 return g_failures ? 1 : 0; 1844 return g_failures ? 1 : 0;