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:
authorMaxime Mansiet <AirKyzzZ@users.noreply.github.com>2026-11-23 03:02:17 +0100
committerMaxime Mansiet <AirKyzzZ@users.noreply.github.com>2026-11-23 03:05:55 +0100
commit0519bc2c8108089c65652f550e8b950f9731eb33 (patch)
tree88764434b3fff1e09a6305bb4b5c12fb3850a61b /runtime/test/gameinput_test.cpp
parent03b09a086592a197db64d91655c6e65c30764d96 (diff)
gameinput: a reading callback's inputKind filter checks what the device supports
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
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 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
244struct MotionReadings {
245 IGameInputDevice* gyro;
246 IGameInputDevice* plain;
247 int gyro_calls, plain_calls;
248};
249void 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
246using rt::gameinput::RawReportSize; 260using 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();