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:
authormarquezini <felipemarquesini10@gmail.com>2026-11-22 16:32:27 -0300
committermarquezini <felipemarquesini10@gmail.com>2026-11-22 16:32:48 -0300
commitf5907ef65ab326d92db9d4035b2899e4fe57b688 (patch)
tree35804b3d3a38d528098be436a9d84d90631e83c2 /runtime/test/gameinput_test.cpp
parente7c83353c7aabdffa873f963f20d9ab6a1b938a9 (diff)
parent162821017ea3c286c8bec860f3ff94f037912061 (diff)
Merge main (873a952a) into the RT-176 branch
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
-rw-r--r--runtime/test/gameinput_test.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index 5156cbe82..d2b80c010 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -403,6 +403,33 @@ void test_keyboard_pad_sticks(IGameInput* input, IGameInputDevice* kb) {
403 } 403 }
404 check(monotonic && polls < 100 && sticks_at_rest(st), "keyboard pad: right stick decays to 0 when the mouse stops"); 404 check(monotonic && polls < 100 && sticks_at_rest(st), "keyboard pad: right stick decays to 0 when the mouse stops");
405 405
406 // LEONIDA_MOUSE_SENSITIVITY scales the axis units per count: 2 doubles, 0.5 halves; out of range clamps.
407 auto settle = [&] {
408 for (int i = 0; i < 200 && !sticks_at_rest(pad_state(input, kb)); ++i) rt::gameinput::poll();
409 };
410 set_env("LEONIDA_MOUSE_SENSITIVITY", "2");
411 rt::gameinput::reload_config();
412 g_cursor_x += 10;
413 rt::gameinput::poll();
414 check(approx(pad_state(input, kb).rightThumbstickX, 20480 / 32767.0f), "keyboard pad: mouse sensitivity 2 doubles the stick");
415 settle();
416 set_env("LEONIDA_MOUSE_SENSITIVITY", "0.5");
417 rt::gameinput::reload_config();
418 g_cursor_x -= 10;
419 rt::gameinput::poll();
420 check(approx(pad_state(input, kb).rightThumbstickX, -5120 / 32767.0f), "keyboard pad: mouse sensitivity 0.5 halves the stick");
421 settle();
422 set_env("LEONIDA_MOUSE_SENSITIVITY", "100");
423 rt::gameinput::reload_config();
424 check(rt::gameinput::config().mouse_sensitivity == 10.0f, "keyboard pad: mouse sensitivity clamps to 10");
425 set_env("LEONIDA_MOUSE_SENSITIVITY", "0");
426 rt::gameinput::reload_config();
427 check(approx(rt::gameinput::config().mouse_sensitivity, 0.1f), "keyboard pad: mouse sensitivity clamps to 0.1");
428 set_env("LEONIDA_MOUSE_SENSITIVITY", nullptr);
429 rt::gameinput::reload_config();
430 check(rt::gameinput::config().mouse_sensitivity == 1.0f && rt::gameinput::config().ds_trigger_gain == 1.0f,
431 "keyboard pad: mouse sensitivity defaults to 1 and leaves the trigger gain alone");
432
406 g_keys[VK_RBUTTON] = true; 433 g_keys[VK_RBUTTON] = true;
407 rt::gameinput::poll(); 434 rt::gameinput::poll();
408 st = pad_state(input, kb); 435 st = pad_state(input, kb);
@@ -618,6 +645,20 @@ void test_aggregate_device(IGameInput* input) {
618 IGameInputReading* r = nullptr; 645 IGameInputReading* r = nullptr;
619 check(input->GetCurrentReading(GameInputKindGamepad, agg, &r) == GAMEINPUT_E_READING_NOT_FOUND && !r, 646 check(input->GetCurrentReading(GameInputKindGamepad, agg, &r) == GAMEINPUT_E_READING_NOT_FOUND && !r,
620 "aggregate device returns READING_NOT_FOUND when no pads are connected"); 647 "aggregate device returns READING_NOT_FOUND when no pads are connected");
648 check(input->GetCurrentReading(GameInputKindKeyboard, agg, &r) == GAMEINPUT_E_READING_NOT_FOUND && !r,
649 "aggregate device returns READING_NOT_FOUND for kind mismatch with no pads");
650
651 // Callback registration guards for aggregate device
652 GameInputCallbackToken reading_tok = 0xbeef;
653 check(input->RegisterReadingCallback(agg, GameInputKindGamepad, 0.0f, nullptr, on_reading, &reading_tok) == E_NOTIMPL &&
654 reading_tok == kInvalidCallbackToken,
655 "RegisterReadingCallback rejects aggregate device with E_NOTIMPL and invalid token");
656
657 GameInputCallbackToken device_tok = 0xbeef;
658 check(input->RegisterDeviceCallback(agg, GameInputKindGamepad, GameInputDeviceConnected,
659 GameInputBlockingEnumeration, nullptr, on_device, &device_tok) == E_NOTIMPL &&
660 device_tok == kInvalidCallbackToken,
661 "RegisterDeviceCallback rejects aggregate device with E_NOTIMPL and invalid token");
621 662
622 // Attach a virtual pad and verify aggregate device yields readings from it 663 // Attach a virtual pad and verify aggregate device yields readings from it
623 Pad xbox; 664 Pad xbox;
@@ -634,6 +675,10 @@ void test_aggregate_device(IGameInput* input) {
634 r->Release(); 675 r->Release();
635 } 676 }
636 677
678 IGameInputReading* r_mismatch = nullptr;
679 check(input->GetCurrentReading(GameInputKindKeyboard, agg, &r_mismatch) == GAMEINPUT_E_READING_NOT_FOUND && !r_mismatch,
680 "aggregate device rejects kind mismatch even when pad is connected");
681
637 SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_SOUTH, false); 682 SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_SOUTH, false);
638 rt::gameinput::poll(); 683 rt::gameinput::poll();
639 IGameInputReading* r2 = nullptr; 684 IGameInputReading* r2 = nullptr;
@@ -1120,6 +1165,17 @@ int main() {
1120 check(input->GetPreviousReading(idle, GameInputKindGamepad, dev, nullptr) == E_POINTER && 1165 check(input->GetPreviousReading(idle, GameInputKindGamepad, dev, nullptr) == E_POINTER &&
1121 input->GetPreviousReading(nullptr, GameInputKindGamepad, dev, &hit) == E_INVALIDARG && !hit, 1166 input->GetPreviousReading(nullptr, GameInputKindGamepad, dev, &hit) == E_INVALIDARG && !hit,
1122 "history: a null output is E_POINTER, a null reference E_INVALIDARG"); 1167 "history: a null output is E_POINTER, a null reference E_INVALIDARG");
1168 // GetTemporalReading: E_NOTIMPL with a null reading, as GameInput v0 itself, for a timestamp in the history, one
1169 // before it and the current time, with and without a device filter.
1170 const uint64_t idle_us = idle->GetTimestamp();
1171 bool temporal_notimpl = true;
1172 for (const uint64_t at : {idle_us, idle_us - 1'000'000, input->GetCurrentTimestamp()})
1173 for (IGameInputDevice* filter : {dev, static_cast<IGameInputDevice*>(nullptr)}) {
1174 IGameInputReading* temporal = idle; // a stale value the call must clear
1175 temporal_notimpl &= input->GetTemporalReading(at, filter, &temporal) == E_NOTIMPL && !temporal;
1176 }
1177 check(temporal_notimpl && input->GetTemporalReading(idle_us, dev, nullptr) == E_POINTER,
1178 "history: GetTemporalReading is E_NOTIMPL with a null reading, as in GameInput v0");
1123 1179
1124 // Two pads in one stream, one poll each: A on the Xbox pad, B on the DualSense, Y on the Xbox pad. 1180 // Two pads in one stream, one poll each: A on the Xbox pad, B on the DualSense, Y on the Xbox pad.
1125 IGameInputReading* start = current(input, dev); 1181 IGameInputReading* start = current(input, dev);