diff options
| author | Leonida local test <local-test@localhost> | 2026-11-22 23:15:09 +0100 |
|---|---|---|
| committer | Leonida local test <local-test@localhost> | 2026-11-22 23:15:09 +0100 |
| commit | dc01a173970ceccfefefc9e70e6cd31b1eeec43a (patch) | |
| tree | 6c64d024783afb6e06647f1c43779f9b20fe3f86 /runtime/shims/gameinput.cpp | |
| parent | 59aa22ff0ca967db25c0ff8116c52484b7773b5e (diff) | |
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
Diffstat (limited to 'runtime/shims/gameinput.cpp')
| -rw-r--r-- | runtime/shims/gameinput.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
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() { | |||
| 2018 | applied_ = 0; | 2018 | applied_ = 0; |
| 2019 | } | 2019 | } |
| 2020 | 2020 | ||
| 2021 | // What SDL said about the effect, for output_state (gameinput_probe and the tests): the id it returned, whether it is | ||
| 2022 | // running, and its error text when it is not. SDL_GetError is read here, on the poll thread that made the call. | ||
| 2023 | void note_effect(Device* d, int id, bool ran) { | ||
| 2024 | const char* error = ran ? "" : SDL_GetError(); | ||
| 2025 | std::lock_guard lock(g().mu); | ||
| 2026 | d->sent.effect_id = id; | ||
| 2027 | d->sent.effect_ran = ran; | ||
| 2028 | std::snprintf(d->sent.effect_error, sizeof d->sent.effect_error, "%s", error ? error : ""); | ||
| 2029 | } | ||
| 2030 | |||
| 2021 | void ForceFeedbackEffect::sync(Device* d, uint64_t now, bool muted) { | 2031 | void ForceFeedbackEffect::sync(Device* d, uint64_t now, bool muted) { |
| 2022 | GameInputForceFeedbackParams params; | 2032 | GameInputForceFeedbackParams params; |
| 2023 | float gain; | 2033 | float gain; |
| @@ -2066,13 +2076,21 @@ void ForceFeedbackEffect::sync(Device* d, uint64_t now, bool muted) { | |||
| 2066 | } | 2076 | } |
| 2067 | if (sdl_effect_ < 0) { | 2077 | if (sdl_effect_ < 0) { |
| 2068 | sdl_effect_ = haptics().create_effect(d->haptic, &fx); // SDL refused: nothing to drive this effect | 2078 | sdl_effect_ = haptics().create_effect(d->haptic, &fx); // SDL refused: nothing to drive this effect |
| 2069 | if (sdl_effect_ < 0) return; | 2079 | if (sdl_effect_ < 0) { |
| 2080 | note_effect(d, -1, false); | ||
| 2081 | return; | ||
| 2082 | } | ||
| 2070 | } else if (!haptics().update_effect(d->haptic, sdl_effect_, &fx)) { | 2083 | } else if (!haptics().update_effect(d->haptic, sdl_effect_, &fx)) { |
| 2084 | note_effect(d, sdl_effect_, false); | ||
| 2071 | return; | 2085 | return; |
| 2072 | } | 2086 | } |
| 2073 | // GameInput's playCount 0 means "until stopped", which is what SDL's 0 iterations means. | 2087 | // GameInput's playCount 0 means "until stopped", which is what SDL's 0 iterations means. |
| 2074 | const uint32_t iterations = endless ? 0 : play_count(params); | 2088 | const uint32_t iterations = endless ? 0 : play_count(params); |
| 2075 | if (!haptics().run_effect(d->haptic, sdl_effect_, iterations)) return; | 2089 | if (!haptics().run_effect(d->haptic, sdl_effect_, iterations)) { |
| 2090 | note_effect(d, sdl_effect_, false); | ||
| 2091 | return; | ||
| 2092 | } | ||
| 2093 | note_effect(d, sdl_effect_, true); | ||
| 2076 | sdl_running_ = true; | 2094 | sdl_running_ = true; |
| 2077 | applied_ = version; | 2095 | applied_ = version; |
| 2078 | endless_ = endless; | 2096 | endless_ = endless; |