diff options
| author | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 19:08:54 +0100 |
|---|---|---|
| committer | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 19:08:54 +0100 |
| commit | 3af42c619253941610d9809e8a28a07e8dfdfdf2 (patch) | |
| tree | a675793195f8bc69c3caebb0e9614ecfb65e1c4c /runtime/test/gameinput_test.cpp | |
| parent | e6af0a0931639ff33cdd4a28289da984f194c87e (diff) | |
| parent | ec8ec4c9a46c6623f1a9c125afd3566da97f1e0c (diff) | |
merge: preserve upstream changes alongside the asset fix
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
| -rw-r--r-- | runtime/test/gameinput_test.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index f525d1cb9..a65b444a1 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -393,6 +393,33 @@ void test_keyboard_pad_sticks(IGameInput* input, IGameInputDevice* kb) { | |||
| 393 | } | 393 | } |
| 394 | check(monotonic && polls < 100 && sticks_at_rest(st), "keyboard pad: right stick decays to 0 when the mouse stops"); | 394 | check(monotonic && polls < 100 && sticks_at_rest(st), "keyboard pad: right stick decays to 0 when the mouse stops"); |
| 395 | 395 | ||
| 396 | // LEONIDA_MOUSE_SENSITIVITY scales the axis units per count: 2 doubles, 0.5 halves; out of range clamps. | ||
| 397 | auto settle = [&] { | ||
| 398 | for (int i = 0; i < 200 && !sticks_at_rest(pad_state(input, kb)); ++i) rt::gameinput::poll(); | ||
| 399 | }; | ||
| 400 | set_env("LEONIDA_MOUSE_SENSITIVITY", "2"); | ||
| 401 | rt::gameinput::reload_config(); | ||
| 402 | g_cursor_x += 10; | ||
| 403 | rt::gameinput::poll(); | ||
| 404 | check(approx(pad_state(input, kb).rightThumbstickX, 20480 / 32767.0f), "keyboard pad: mouse sensitivity 2 doubles the stick"); | ||
| 405 | settle(); | ||
| 406 | set_env("LEONIDA_MOUSE_SENSITIVITY", "0.5"); | ||
| 407 | rt::gameinput::reload_config(); | ||
| 408 | g_cursor_x -= 10; | ||
| 409 | rt::gameinput::poll(); | ||
| 410 | check(approx(pad_state(input, kb).rightThumbstickX, -5120 / 32767.0f), "keyboard pad: mouse sensitivity 0.5 halves the stick"); | ||
| 411 | settle(); | ||
| 412 | set_env("LEONIDA_MOUSE_SENSITIVITY", "100"); | ||
| 413 | rt::gameinput::reload_config(); | ||
| 414 | check(rt::gameinput::config().mouse_sensitivity == 10.0f, "keyboard pad: mouse sensitivity clamps to 10"); | ||
| 415 | set_env("LEONIDA_MOUSE_SENSITIVITY", "0"); | ||
| 416 | rt::gameinput::reload_config(); | ||
| 417 | check(approx(rt::gameinput::config().mouse_sensitivity, 0.1f), "keyboard pad: mouse sensitivity clamps to 0.1"); | ||
| 418 | set_env("LEONIDA_MOUSE_SENSITIVITY", nullptr); | ||
| 419 | rt::gameinput::reload_config(); | ||
| 420 | check(rt::gameinput::config().mouse_sensitivity == 1.0f && rt::gameinput::config().ds_trigger_gain == 1.0f, | ||
| 421 | "keyboard pad: mouse sensitivity defaults to 1 and leaves the trigger gain alone"); | ||
| 422 | |||
| 396 | g_keys[VK_RBUTTON] = true; | 423 | g_keys[VK_RBUTTON] = true; |
| 397 | rt::gameinput::poll(); | 424 | rt::gameinput::poll(); |
| 398 | st = pad_state(input, kb); | 425 | st = pad_state(input, kb); |
| @@ -608,6 +635,20 @@ void test_aggregate_device(IGameInput* input) { | |||
| 608 | IGameInputReading* r = nullptr; | 635 | IGameInputReading* r = nullptr; |
| 609 | check(input->GetCurrentReading(GameInputKindGamepad, agg, &r) == GAMEINPUT_E_READING_NOT_FOUND && !r, | 636 | check(input->GetCurrentReading(GameInputKindGamepad, agg, &r) == GAMEINPUT_E_READING_NOT_FOUND && !r, |
| 610 | "aggregate device returns READING_NOT_FOUND when no pads are connected"); | 637 | "aggregate device returns READING_NOT_FOUND when no pads are connected"); |
| 638 | check(input->GetCurrentReading(GameInputKindKeyboard, agg, &r) == GAMEINPUT_E_READING_NOT_FOUND && !r, | ||
| 639 | "aggregate device returns READING_NOT_FOUND for kind mismatch with no pads"); | ||
| 640 | |||
| 641 | // Callback registration guards for aggregate device | ||
| 642 | GameInputCallbackToken reading_tok = 0xbeef; | ||
| 643 | check(input->RegisterReadingCallback(agg, GameInputKindGamepad, 0.0f, nullptr, on_reading, &reading_tok) == E_NOTIMPL && | ||
| 644 | reading_tok == kInvalidCallbackToken, | ||
| 645 | "RegisterReadingCallback rejects aggregate device with E_NOTIMPL and invalid token"); | ||
| 646 | |||
| 647 | GameInputCallbackToken device_tok = 0xbeef; | ||
| 648 | check(input->RegisterDeviceCallback(agg, GameInputKindGamepad, GameInputDeviceConnected, | ||
| 649 | GameInputBlockingEnumeration, nullptr, on_device, &device_tok) == E_NOTIMPL && | ||
| 650 | device_tok == kInvalidCallbackToken, | ||
| 651 | "RegisterDeviceCallback rejects aggregate device with E_NOTIMPL and invalid token"); | ||
| 611 | 652 | ||
| 612 | // Attach a virtual pad and verify aggregate device yields readings from it | 653 | // Attach a virtual pad and verify aggregate device yields readings from it |
| 613 | Pad xbox; | 654 | Pad xbox; |
| @@ -624,6 +665,10 @@ void test_aggregate_device(IGameInput* input) { | |||
| 624 | r->Release(); | 665 | r->Release(); |
| 625 | } | 666 | } |
| 626 | 667 | ||
| 668 | IGameInputReading* r_mismatch = nullptr; | ||
| 669 | check(input->GetCurrentReading(GameInputKindKeyboard, agg, &r_mismatch) == GAMEINPUT_E_READING_NOT_FOUND && !r_mismatch, | ||
| 670 | "aggregate device rejects kind mismatch even when pad is connected"); | ||
| 671 | |||
| 627 | SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_SOUTH, false); | 672 | SDL_SetJoystickVirtualButton(xbox.js, SDL_GAMEPAD_BUTTON_SOUTH, false); |
| 628 | rt::gameinput::poll(); | 673 | rt::gameinput::poll(); |
| 629 | IGameInputReading* r2 = nullptr; | 674 | IGameInputReading* r2 = nullptr; |
| @@ -1062,6 +1107,17 @@ int main() { | |||
| 1062 | check(input->GetPreviousReading(idle, GameInputKindGamepad, dev, nullptr) == E_POINTER && | 1107 | check(input->GetPreviousReading(idle, GameInputKindGamepad, dev, nullptr) == E_POINTER && |
| 1063 | input->GetPreviousReading(nullptr, GameInputKindGamepad, dev, &hit) == E_INVALIDARG && !hit, | 1108 | input->GetPreviousReading(nullptr, GameInputKindGamepad, dev, &hit) == E_INVALIDARG && !hit, |
| 1064 | "history: a null output is E_POINTER, a null reference E_INVALIDARG"); | 1109 | "history: a null output is E_POINTER, a null reference E_INVALIDARG"); |
| 1110 | // GetTemporalReading: E_NOTIMPL with a null reading, as GameInput v0 itself, for a timestamp in the history, one | ||
| 1111 | // before it and the current time, with and without a device filter. | ||
| 1112 | const uint64_t idle_us = idle->GetTimestamp(); | ||
| 1113 | bool temporal_notimpl = true; | ||
| 1114 | for (const uint64_t at : {idle_us, idle_us - 1'000'000, input->GetCurrentTimestamp()}) | ||
| 1115 | for (IGameInputDevice* filter : {dev, static_cast<IGameInputDevice*>(nullptr)}) { | ||
| 1116 | IGameInputReading* temporal = idle; // a stale value the call must clear | ||
| 1117 | temporal_notimpl &= input->GetTemporalReading(at, filter, &temporal) == E_NOTIMPL && !temporal; | ||
| 1118 | } | ||
| 1119 | check(temporal_notimpl && input->GetTemporalReading(idle_us, dev, nullptr) == E_POINTER, | ||
| 1120 | "history: GetTemporalReading is E_NOTIMPL with a null reading, as in GameInput v0"); | ||
| 1065 | 1121 | ||
| 1066 | // Two pads in one stream, one poll each: A on the Xbox pad, B on the DualSense, Y on the Xbox pad. | 1122 | // Two pads in one stream, one poll each: A on the Xbox pad, B on the DualSense, Y on the Xbox pad. |
| 1067 | IGameInputReading* start = current(input, dev); | 1123 | IGameInputReading* start = current(input, dev); |