upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/gameinput_probe.cpp
diff options
context:
space:
mode:
authorJack UK <janzeiser@web.de>2026-11-22 14:26:06 +0100
committerJack UK <janzeiser@web.de>2026-11-22 14:26:06 +0100
commitc608a6567940a1ed2c2cc144163e76c348e7fa12 (patch)
tree7a14b49ceaae9fa84a31fb46b5e764b531682a15 /runtime/test/gameinput_probe.cpp
parent41f448261e1de8a410b4d760e69a7e5656cef858 (diff)
GameInput: motion support via SDL sensors (#660 follow-up)
Expose SDL3's gyroscope and accelerometer through the GameInput shim: - gameinput_abi.h: GameInputMotionAccuracy, GameInputMotionInfo and GameInputMotionState with the v0 layouts (Microsoft's public docs), size asserts included. - The shim enables both sensors when a pad with them is opened, reads the latest sample each poll, and reports GameInputKindMotion plus a GameInputMotionInfo on such pads. GetMotionState returns the state as signed fractions of the motionInfo maxima (2 g accel, 2000 deg/s gyro, the shim's choice since SDL exposes no sensor range; VERIFY). All-zero accel means no sample yet, so readings before the device's first sample carry no motion. Magnetic field and orientation stay zero and Unknown: SDL has no compass and nothing synthesises a quaternion. Pads with sensors stream a reading every ~8 ms so motion is not stuck at the last button event; other pads keep the old change-driven behaviour. - GetCurrentReading and GetNextReading with a device filter now reject kinds the device does not support (READING_NOT_FOUND), matching the v0 docs and the device-less path, so a motion query on a plain pad fails instead of returning a reading without motion. - gameinput_test: a virtual pad with SDL sensors covers kind/motionInfo presence, no-motion-before-first-sample, normalisation, accuracy values, the +-1 clamp, the cadence, and the plain-pad rejection. gameinput_probe prints the live accel and gyro fractions. - docs/gameinput.md: a Motion section, the API table, and VERIFY notes for the chosen maxima and the unprovided members. Tested: gameinput_test 185/185 and ctest 90/90 (RelWithDebInfo) on Windows 11 Pro 10.0.26200; SDL3 3.4.20 via -DLEONIDA_SDL3_FETCH=ON. Follows: #660. AI-assisted (ZCode agent).
Diffstat (limited to 'runtime/test/gameinput_probe.cpp')
-rw-r--r--runtime/test/gameinput_probe.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/runtime/test/gameinput_probe.cpp b/runtime/test/gameinput_probe.cpp
index aa077b257..32ddf5d91 100644
--- a/runtime/test/gameinput_probe.cpp
+++ b/runtime/test/gameinput_probe.cpp
@@ -85,12 +85,17 @@ int main(int argc, char** argv) {
85 if (input->GetCurrentReading(GameInputKindGamepad, nullptr, &r) == S_OK) { 85 if (input->GetCurrentReading(GameInputKindGamepad, nullptr, &r) == S_OK) {
86 GameInputGamepadState s{}; 86 GameInputGamepadState s{};
87 GameInputUiNavigationState ui{}; 87 GameInputUiNavigationState ui{};
88 GameInputMotionState m{};
89 const bool motion = r->GetMotionState(&m);
88 r->GetGamepadState(&s); 90 r->GetGamepadState(&s);
89 r->GetUiNavigationState(&ui); 91 r->GetUiNavigationState(&ui);
90 std::printf("\rbuttons=%04x ui=%06x LT=%.2f RT=%.2f L=(%+.2f,%+.2f) R=(%+.2f,%+.2f) seq=%llu ", s.buttons, 92 std::printf("\rbuttons=%04x ui=%06x LT=%.2f RT=%.2f L=(%+.2f,%+.2f) R=(%+.2f,%+.2f) seq=%llu ", s.buttons,
91 ui.buttons, s.leftTrigger, s.rightTrigger, s.leftThumbstickX, s.leftThumbstickY, 93 ui.buttons, s.leftTrigger, s.rightTrigger, s.leftThumbstickX, s.leftThumbstickY,
92 s.rightThumbstickX, s.rightThumbstickY, 94 s.rightThumbstickX, s.rightThumbstickY,
93 static_cast<unsigned long long>(r->GetSequenceNumber(GameInputKindGamepad))); 95 static_cast<unsigned long long>(r->GetSequenceNumber(GameInputKindGamepad)));
96 if (motion) // fractions of motionInfo's maxima: accel includes gravity, so a resting pad shows ~0.5 g
97 std::printf("\n[a]=(%+.2f,%+.2f,%+.2f) [w]=(%+.2f,%+.2f,%+.2f) ", m.accelerationX, m.accelerationY,
98 m.accelerationZ, m.angularVelocityX, m.angularVelocityY, m.angularVelocityZ);
94 std::fflush(stdout); 99 std::fflush(stdout);
95 r->Release(); 100 r->Release();
96 } 101 }