diff options
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
| -rw-r--r-- | runtime/test/gameinput_test.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index 1389b8f6d..500490e33 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -241,6 +241,20 @@ GameInputMotionState motion_state(IGameInput* input, IGameInputDevice* dev, bool | |||
| 241 | return ms; | 241 | return ms; |
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | struct MotionReadings { | ||
| 245 | IGameInputDevice* gyro; | ||
| 246 | IGameInputDevice* plain; | ||
| 247 | int gyro_calls, plain_calls; | ||
| 248 | }; | ||
| 249 | void CALLBACK on_motion_reading(GameInputCallbackToken, void* context, IGameInputReading* reading, bool) { | ||
| 250 | auto* seen = static_cast<MotionReadings*>(context); | ||
| 251 | IGameInputDevice* dev = nullptr; | ||
| 252 | if (reading) reading->GetDevice(&dev); | ||
| 253 | if (dev == seen->gyro) ++seen->gyro_calls; | ||
| 254 | if (dev == seen->plain) ++seen->plain_calls; | ||
| 255 | if (dev) dev->Release(); | ||
| 256 | } | ||
| 257 | |||
| 244 | // ---- raw HID (RT-175) ------------------------------------------------------------------------------------------- | 258 | // ---- raw HID (RT-175) ------------------------------------------------------------------------------------------- |
| 245 | 259 | ||
| 246 | using rt::gameinput::RawReportSize; | 260 | using rt::gameinput::RawReportSize; |
| @@ -558,6 +572,19 @@ void test_motion(IGameInput* input) { | |||
| 558 | } | 572 | } |
| 559 | if (first) first->Release(); | 573 | if (first) first->Release(); |
| 560 | 574 | ||
| 575 | MotionReadings seen{mdev, pdev, 0, 0}; | ||
| 576 | GameInputCallbackToken motion_token = 0; | ||
| 577 | check(input->RegisterReadingCallback(nullptr, GameInputKindMotion, 0.0f, &seen, on_motion_reading, &motion_token) == S_OK, | ||
| 578 | "motion: RegisterReadingCallback(GameInputKindMotion)"); | ||
| 579 | for (int i = 0; i < 4; ++i) { | ||
| 580 | SDL_SetJoystickVirtualButton(gyro_pad.js, SDL_GAMEPAD_BUTTON_SOUTH, i % 2 == 0); | ||
| 581 | SDL_SetJoystickVirtualButton(plain.js, SDL_GAMEPAD_BUTTON_SOUTH, i % 2 == 0); | ||
| 582 | rt::gameinput::poll(); | ||
| 583 | } | ||
| 584 | input->UnregisterCallback(motion_token, 0); | ||
| 585 | check(seen.gyro_calls > 0 && seen.plain_calls == 0, | ||
| 586 | "motion: a Motion reading callback fires for the gyro pad's readings, not for the plain pad's"); | ||
| 587 | |||
| 561 | detach(gyro_pad); | 588 | detach(gyro_pad); |
| 562 | detach(plain); | 589 | detach(plain); |
| 563 | rt::gameinput::poll(); | 590 | rt::gameinput::poll(); |