From c608a6567940a1ed2c2cc144163e76c348e7fa12 Mon Sep 17 00:00:00 2001 From: Jack UK Date: Sun, 22 Nov 2026 14:26:06 +0100 Subject: 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). --- runtime/test/gameinput_probe.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'runtime/test/gameinput_probe.cpp') 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) { if (input->GetCurrentReading(GameInputKindGamepad, nullptr, &r) == S_OK) { GameInputGamepadState s{}; GameInputUiNavigationState ui{}; + GameInputMotionState m{}; + const bool motion = r->GetMotionState(&m); r->GetGamepadState(&s); r->GetUiNavigationState(&ui); std::printf("\rbuttons=%04x ui=%06x LT=%.2f RT=%.2f L=(%+.2f,%+.2f) R=(%+.2f,%+.2f) seq=%llu ", s.buttons, ui.buttons, s.leftTrigger, s.rightTrigger, s.leftThumbstickX, s.leftThumbstickY, s.rightThumbstickX, s.rightThumbstickY, static_cast(r->GetSequenceNumber(GameInputKindGamepad))); + if (motion) // fractions of motionInfo's maxima: accel includes gravity, so a resting pad shows ~0.5 g + std::printf("\n[a]=(%+.2f,%+.2f,%+.2f) [w]=(%+.2f,%+.2f,%+.2f) ", m.accelerationX, m.accelerationY, + m.accelerationZ, m.angularVelocityX, m.angularVelocityY, m.angularVelocityZ); std::fflush(stdout); r->Release(); } -- cgit v1.2.3