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:
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
-rw-r--r--runtime/test/gameinput_test.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index 97a20321a..7217dc37b 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -244,6 +244,20 @@ GameInputMotionState motion_state(IGameInput* input, IGameInputDevice* dev, bool
244 return ms; 244 return ms;
245} 245}
246 246
247struct MotionReadings {
248 IGameInputDevice* gyro;
249 IGameInputDevice* plain;
250 int gyro_calls, plain_calls;
251};
252void CALLBACK on_motion_reading(GameInputCallbackToken, void* context, IGameInputReading* reading, bool) {
253 auto* seen = static_cast<MotionReadings*>(context);
254 IGameInputDevice* dev = nullptr;
255 if (reading) reading->GetDevice(&dev);
256 if (dev == seen->gyro) ++seen->gyro_calls;
257 if (dev == seen->plain) ++seen->plain_calls;
258 if (dev) dev->Release();
259}
260
247// ---- raw HID (RT-175) ------------------------------------------------------------------------------------------- 261// ---- raw HID (RT-175) -------------------------------------------------------------------------------------------
248 262
249using rt::gameinput::RawReportSize; 263using rt::gameinput::RawReportSize;
@@ -632,6 +646,19 @@ void test_motion(IGameInput* input) {
632 } 646 }
633 if (first) first->Release(); 647 if (first) first->Release();
634 648
649 MotionReadings seen{mdev, pdev, 0, 0};
650 GameInputCallbackToken motion_token = 0;
651 check(input->RegisterReadingCallback(nullptr, GameInputKindMotion, 0.0f, &seen, on_motion_reading, &motion_token) == S_OK,
652 "motion: RegisterReadingCallback(GameInputKindMotion)");
653 for (int i = 0; i < 4; ++i) {
654 SDL_SetJoystickVirtualButton(gyro_pad.js, SDL_GAMEPAD_BUTTON_SOUTH, i % 2 == 0);
655 SDL_SetJoystickVirtualButton(plain.js, SDL_GAMEPAD_BUTTON_SOUTH, i % 2 == 0);
656 rt::gameinput::poll();
657 }
658 input->UnregisterCallback(motion_token, 0);
659 check(seen.gyro_calls > 0 && seen.plain_calls == 0,
660 "motion: a Motion reading callback fires for the gyro pad's readings, not for the plain pad's");
661
635 detach(gyro_pad); 662 detach(gyro_pad);
636 detach(plain); 663 detach(plain);
637 rt::gameinput::poll(); 664 rt::gameinput::poll();