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:
authortedin7 <tommasoderosa94@gmail.com>2026-11-23 23:14:07 +0100
committerClaude <noreply@anthropic.com>2026-11-25 13:25:48 +0000
commit9a96b8ba6aaf2fc8ed3f3ad5177d0e3f420dc62c (patch)
treeb2576154c60e467ceb70b3ec2607e827091e63bc /runtime/test/gameinput_test.cpp
parent384abe5b06d08e349f4b4e4394c68f036da47dc7 (diff)
gameinput: preserve controller transitions between polls
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
-rw-r--r--runtime/test/gameinput_test.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index b6658f51c..1cf7112d0 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -1691,6 +1691,47 @@ void test_haptic_motors(IGameInput* input) {
1691 dev->Release(); 1691 dev->Release();
1692} 1692}
1693 1693
1694void test_buffered_gamepad_input(IGameInput* input) {
1695 Pad pad;
1696 attach(pad, "Leonida buffered input pad", 0x045E, 0x0B12, true);
1697 rt::gameinput::poll();
1698 IGameInputReading* idle = current(input, nullptr);
1699 IGameInputDevice* dev = device_of(idle);
1700
1701 GameInputCallbackToken token = 0;
1702 const int callbacks_before = g_reading_events;
1703 check(dev && input->RegisterReadingCallback(dev, GameInputKindGamepad, 0.0f, nullptr, on_reading, &token) == S_OK,
1704 "buffered input: register a reading callback for the virtual pad");
1705
1706 // SDL sees two hardware samples before the shim's next poll. Both end states are neutral again.
1707 SDL_SetJoystickVirtualButton(pad.js, SDL_GAMEPAD_BUTTON_SOUTH, true);
1708 SDL_SetJoystickVirtualAxis(pad.js, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, 32767);
1709 SDL_UpdateGamepads();
1710 SDL_SetJoystickVirtualButton(pad.js, SDL_GAMEPAD_BUTTON_SOUTH, false);
1711 SDL_SetJoystickVirtualAxis(pad.js, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, -32768);
1712 rt::gameinput::poll();
1713
1714 HRESULT end = S_OK;
1715 auto readings = walk(input, idle, dev, true, 8, &end);
1716 GameInputGamepadState pressed{}, released{};
1717 check(readings.size() == 2 && end == GAMEINPUT_E_READING_NOT_FOUND &&
1718 readings[0]->GetGamepadState(&pressed) && pressed.buttons == GameInputGamepadA &&
1719 approx(pressed.leftTrigger, 1.0f) && readings[1]->GetGamepadState(&released) &&
1720 released.buttons == 0 && approx(released.leftTrigger, 0.0f),
1721 "buffered input: history delivers both the short A/trigger press and its release");
1722 IGameInputReading* latest = current(input, dev);
1723 check(latest && readings.size() == 2 && latest == readings.back() &&
1724 g_reading_events - callbacks_before == 2,
1725 "buffered input: two callbacks fire and the current reading stays released");
1726
1727 if (token) input->UnregisterCallback(token, 0);
1728 if (latest) latest->Release();
1729 release_all(readings);
1730 if (idle) idle->Release();
1731 detach(pad);
1732 rt::gameinput::poll();
1733}
1734
1694} // namespace 1735} // namespace
1695 1736
1696int main(int argc, char** argv) { 1737int main(int argc, char** argv) {
@@ -2294,6 +2335,7 @@ int main(int argc, char** argv) {
2294 test_haptic_motors(input); 2335 test_haptic_motors(input);
2295 test_raw_hid(input); 2336 test_raw_hid(input);
2296 test_raw_report_during_reconnect(input); 2337 test_raw_report_during_reconnect(input);
2338 test_buffered_gamepad_input(input);
2297 input->Release(); 2339 input->Release();
2298 2340
2299 std::printf("%d checks, %d failures\n", g_checks, g_failures); 2341 std::printf("%d checks, %d failures\n", g_checks, g_failures);