From 59aa22ff0ca967db25c0ff8116c52484b7773b5e Mon Sep 17 00:00:00 2001 From: Leonida local test Date: Sun, 22 Nov 2026 23:03:41 +0100 Subject: gameinput: drive a constant force from gameinput_probe (RT-160) `--force-feedback` creates a constant effect at magnitude 1.0 on motor 0 and holds it for a second, so the wheel owner the RT-160 finding asks for can feel the magnitude and the axis instead of only reading `forcefeedback=`; a pad with no force-feedback motor is skipped with the reason printed. Docs and the probe comment name the flag. AI-assisted --- runtime/test/gameinput_probe.cpp | 47 +++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'runtime/test/gameinput_probe.cpp') diff --git a/runtime/test/gameinput_probe.cpp b/runtime/test/gameinput_probe.cpp index 510194f1d..58a6a1010 100644 --- a/runtime/test/gameinput_probe.cpp +++ b/runtime/test/gameinput_probe.cpp @@ -1,13 +1,15 @@ // gameinput_probe: the GameInput shim on a real controller. Not a CTest; run it by hand with a pad connected. // -// gameinput_probe [--seconds N] [--rumble] +// gameinput_probe [--seconds N] [--rumble] [--force-feedback] // // Lists the gamepads the shim sees, with the raw HID report tables of each pad opened through HID, then prints the // live gamepad reading (and its newest raw input report, when there is one) for N seconds (default 10). With // --rumble it first plays, on every pad: the low-frequency motor, the high-frequency motor, the left and the right // impulse trigger, one second each. On a DualSense the trigger steps run in the LEONIDA_DS_TRIGGERS mode (rumble by -// default; set it to resistance to feel that one). Everything goes through GameInputCreate from the shim registry, -// as a title would call it. No game data. +// default; set it to resistance to feel that one). With --force-feedback it then creates a constant force at +// magnitude 1.0 on motor 0 and holds it for a second, which a wheel feels as a steady pull; a pad the shim reports no +// force-feedback motor for is skipped with the reason shown. Everything goes through GameInputCreate from the shim +// registry, as a title would call it. No game data. #include #include @@ -61,16 +63,49 @@ void play(const char* what, GameInputRumbleParams p) { Sleep(300); } +// A constant force at full magnitude on the pad's first motor, held for a second: the effect a wheel feels as a +// steady pull. A pad SDL did not open as a haptic device reports no motor, and the step says so and moves on. +void constant_force() { + for (IGameInputDevice* d : g_devices) { + const GameInputDeviceInfo* i = d->GetDeviceInfo(); + if (i->forceFeedbackMotorCount == 0) { + std::printf("force feedback: %s reports no force-feedback motor; skipped\n", + i->displayName ? i->displayName->data : "?"); + continue; + } + const auto* motor = static_cast(i->forceFeedbackMotorInfo); + std::printf("force feedback: %u motor(s), motor 0 axes=0x%x constant=%d\n", i->forceFeedbackMotorCount, + motor ? static_cast(motor->supportedAxes) : 0u, + motor != nullptr && motor->isConstantEffectSupported); + GameInputForceFeedbackParams p{}; + p.kind = GameInputForceFeedbackConstant; + p.data.constant.magnitude.linearX = 1.0f; + IGameInputForceFeedbackEffect* e = nullptr; + const HRESULT hr = d->CreateForceFeedbackEffect(0, &p, reinterpret_cast(&e)); + if (FAILED(hr) || !e) { + std::printf("force feedback: CreateForceFeedbackEffect failed (0x%08lx)\n", static_cast(hr)); + continue; + } + std::printf("force feedback: constant linearX 1.0 on motor 0, 1 s\n"); + e->SetState(GameInputFeedbackRunning); + Sleep(1000); + e->SetState(GameInputFeedbackStopped); + e->Release(); // the poll thread destroys the SDL effect + Sleep(300); + } +} + } // namespace int main(int argc, char** argv) { int seconds = 10; - bool rumble = false; + bool rumble = false, force_feedback = false; for (int i = 1; i < argc; ++i) { if (!std::strcmp(argv[i], "--seconds") && i + 1 < argc) seconds = std::atoi(argv[++i]); else if (!std::strcmp(argv[i], "--rumble")) rumble = true; + else if (!std::strcmp(argv[i], "--force-feedback")) force_feedback = true; else { - std::printf("usage: gameinput_probe [--seconds N] [--rumble]\n"); + std::printf("usage: gameinput_probe [--seconds N] [--rumble] [--force-feedback]\n"); return 2; } } @@ -98,6 +133,8 @@ int main(int argc, char** argv) { play("left trigger at 30%", {0, 0, 0.3f, 0}); } + if (force_feedback && !g_devices.empty()) constant_force(); + const ULONGLONG end = GetTickCount64() + static_cast(seconds) * 1000; while (GetTickCount64() < end) { IGameInputReading* r = nullptr; -- cgit v1.2.3 From dc01a173970ceccfefefc9e70e6cd31b1eeec43a Mon Sep 17 00:00:00 2001 From: Leonida local test Date: Sun, 22 Nov 2026 23:15:09 +0100 Subject: gameinput: report SDL's effect result from gameinput_probe (RT-160) `--force-feedback` now reads the shim's output state once the poll thread has picked the effect up, and says whether SDL created it and is running it, or why it did not, so a wheel owner can tell a silent drop from a real run. The shim records SDL_CreateHapticEffect's id, SDL_RunHapticEffect's result and SDL's error text per device; gameinput_test asserts the success and the refusal. AI-assisted --- docs/gameinput.md | 4 ++-- runtime/shims/gameinput.cpp | 22 ++++++++++++++++++++-- runtime/shims/gameinput.h | 6 ++++++ runtime/test/gameinput_probe.cpp | 20 ++++++++++++++++++-- runtime/test/gameinput_test.cpp | 26 +++++++++++++++++++++++++- 5 files changed, 71 insertions(+), 7 deletions(-) (limited to 'runtime/test/gameinput_probe.cpp') diff --git a/docs/gameinput.md b/docs/gameinput.md index 0bf367f5a..7b4887023 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md @@ -419,8 +419,8 @@ rests on a transcription rather than on a side-by-side compile. - `gameinput_probe [--seconds N] [--rumble] [--force-feedback]` (by hand, with a pad connected): lists the pads with each one's raw HID report tables (or why it has none), plays each motor and trigger for a second with `--rumble`, holds a constant force at magnitude 1.0 on motor 0 for a second with `--force-feedback` (skipped, with the reason - printed, on a pad the shim reports no force-feedback motor for), then prints the live reading and the newest raw - input report. + printed, on a pad the shim reports no force-feedback motor for), and prints whether SDL created that effect and is + running it, separately from GameInput accepting it, then prints the live reading and the newest raw input report. ## VERIFY diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index 69707f75a..07ca287ff 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp @@ -2018,6 +2018,16 @@ void ForceFeedbackEffect::orphan() { applied_ = 0; } +// What SDL said about the effect, for output_state (gameinput_probe and the tests): the id it returned, whether it is +// running, and its error text when it is not. SDL_GetError is read here, on the poll thread that made the call. +void note_effect(Device* d, int id, bool ran) { + const char* error = ran ? "" : SDL_GetError(); + std::lock_guard lock(g().mu); + d->sent.effect_id = id; + d->sent.effect_ran = ran; + std::snprintf(d->sent.effect_error, sizeof d->sent.effect_error, "%s", error ? error : ""); +} + void ForceFeedbackEffect::sync(Device* d, uint64_t now, bool muted) { GameInputForceFeedbackParams params; float gain; @@ -2066,13 +2076,21 @@ void ForceFeedbackEffect::sync(Device* d, uint64_t now, bool muted) { } if (sdl_effect_ < 0) { sdl_effect_ = haptics().create_effect(d->haptic, &fx); // SDL refused: nothing to drive this effect - if (sdl_effect_ < 0) return; + if (sdl_effect_ < 0) { + note_effect(d, -1, false); + return; + } } else if (!haptics().update_effect(d->haptic, sdl_effect_, &fx)) { + note_effect(d, sdl_effect_, false); return; } // GameInput's playCount 0 means "until stopped", which is what SDL's 0 iterations means. const uint32_t iterations = endless ? 0 : play_count(params); - if (!haptics().run_effect(d->haptic, sdl_effect_, iterations)) return; + if (!haptics().run_effect(d->haptic, sdl_effect_, iterations)) { + note_effect(d, sdl_effect_, false); + return; + } + note_effect(d, sdl_effect_, true); sdl_running_ = true; applied_ = version; endless_ = endless; diff --git a/runtime/shims/gameinput.h b/runtime/shims/gameinput.h index acee24e85..539d19f2d 100644 --- a/runtime/shims/gameinput.h +++ b/runtime/shims/gameinput.h @@ -69,6 +69,12 @@ struct OutputState { bool trigger_rumble = false; // the pad takes SDL_RumbleGamepadTriggers bool force_feedback = false; // SDL opened the pad as a haptic device uint32_t haptic_motors = 0; // haptic motors the pad reports (0 or 2) + // The last force-feedback effect the shim asked SDL for: SDL_CreateHapticEffect's id (-1 when SDL refused), + // whether SDL_RunHapticEffect then returned true, and SDL's error text when a call failed. `force_feedback` only + // says a haptic device was opened; an effect SDL creates but will not run, or refuses outright, shows up here. + int effect_id = -1; + bool effect_ran = false; + char effect_error[128] = {}; }; bool output_state(int i, OutputState* out); diff --git a/runtime/test/gameinput_probe.cpp b/runtime/test/gameinput_probe.cpp index 58a6a1010..1d3202cb5 100644 --- a/runtime/test/gameinput_probe.cpp +++ b/runtime/test/gameinput_probe.cpp @@ -66,7 +66,9 @@ void play(const char* what, GameInputRumbleParams p) { // A constant force at full magnitude on the pad's first motor, held for a second: the effect a wheel feels as a // steady pull. A pad SDL did not open as a haptic device reports no motor, and the step says so and moves on. void constant_force() { - for (IGameInputDevice* d : g_devices) { + // g_devices is in connection order, which is what output_state indexes; the SDL outcome is read back per pad. + for (size_t n = 0; n < g_devices.size(); ++n) { + IGameInputDevice* d = g_devices[n]; const GameInputDeviceInfo* i = d->GetDeviceInfo(); if (i->forceFeedbackMotorCount == 0) { std::printf("force feedback: %s reports no force-feedback motor; skipped\n", @@ -88,7 +90,21 @@ void constant_force() { } std::printf("force feedback: constant linearX 1.0 on motor 0, 1 s\n"); e->SetState(GameInputFeedbackRunning); - Sleep(1000); + Sleep(1000); // the poll thread creates and runs the effect + char seen[256] = "no output state"; + rt::gameinput::OutputState out{}; + if (rt::gameinput::output_state(static_cast(n), &out)) { + if (out.effect_id < 0) { + std::snprintf(seen, sizeof seen, "SDL did not create the effect (%s)", + out.effect_error[0] ? out.effect_error : "no error text"); + } else if (!out.effect_ran) { + std::snprintf(seen, sizeof seen, "SDL created effect %d but did not run it (%s)", out.effect_id, + out.effect_error[0] ? out.effect_error : "no error text"); + } else { + std::snprintf(seen, sizeof seen, "SDL created effect %d and is running it", out.effect_id); + } + } + std::printf("force feedback: %s\n", seen); e->SetState(GameInputFeedbackStopped); e->Release(); // the poll thread destroys the SDL effect Sleep(300); diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index 1389b8f6d..1fab89b5a 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -998,6 +998,7 @@ struct FakeHaptic { SDL_HAPTIC_SAWTOOTHUP | SDL_HAPTIC_SAWTOOTHDOWN | SDL_HAPTIC_RAMP | SDL_HAPTIC_SPRING | SDL_HAPTIC_FRICTION | SDL_HAPTIC_DAMPER | SDL_HAPTIC_INERTIA; int max_effects = 8; + int create_result = 1; // what create returns; negative is SDL refusing the effect int opens = 0, closes = 0, creates = 0, updates = 0, runs = 0, stops = 0, destroys = 0; int gain_calls = 0, last_gain = -1; uint32_t last_iterations = 0; @@ -1017,8 +1018,12 @@ int fake_max_effects(void* h) { return static_cast(h)->max_effects; int fake_create(void* h, const void* e) { FakeHaptic* f = static_cast(h); ++f->creates; + if (f->create_result < 0) { + SDL_SetError("fake: refused"); + return -1; + } f->last = *static_cast(e); - return 1; + return f->create_result; } bool fake_update(void* h, int, const void* e) { FakeHaptic* f = static_cast(h); @@ -1114,6 +1119,9 @@ void test_force_feedback(IGameInput* input) { const int runs0 = g_fake.runs; rt::gameinput::poll(); check(g_fake.creates == 1 && g_fake.runs == runs0 + 1, "force feedback: the poll thread creates and runs the effect"); + rt::gameinput::OutputState sent{}; + check(rt::gameinput::output_state(0, &sent) && sent.effect_id == 1 && sent.effect_ran && !sent.effect_error[0], + "force feedback: the output state reports the effect SDL created and is running"); check(g_fake.last.type == SDL_HAPTIC_CONSTANT && g_fake.last.constant.level == 16384, "force feedback: a constant 0.5 becomes SDL_HAPTIC_CONSTANT level 16384"); check(g_fake.last.constant.length == 60000 && g_fake.last_iterations == 0, @@ -1121,6 +1129,22 @@ void test_force_feedback(IGameInput* input) { rt::gameinput::poll(); check(g_fake.runs == runs0 + 1, "force feedback: an unchanged effect is not re-sent every poll"); + // SDL refusing an effect is visible, not swallowed: the output state carries the failure and SDL's error. + g_fake.create_result = -1; + IGameInputForceFeedbackEffect* refused = nullptr; + check(dev->CreateForceFeedbackEffect(0, ¶ms, reinterpret_cast(&refused)) == S_OK && refused, + "force feedback: GameInput accepts an effect SDL will refuse"); + if (refused) { + rt::gameinput::poll(); + rt::gameinput::OutputState refused_out{}; + check(rt::gameinput::output_state(0, &refused_out) && refused_out.effect_id < 0 && !refused_out.effect_ran && + std::strstr(refused_out.effect_error, "fake: refused"), + "force feedback: SDL refusing the effect is recorded with its error"); + refused->Release(); + rt::gameinput::poll(); // the released effect leaves the device + } + g_fake.create_result = 1; + params.data.constant.magnitude.linearX = -1.0f; check(effect->SetParams(¶ms), "force feedback: SetParams"); rt::gameinput::poll(); -- cgit v1.2.3