upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/gameinput.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/shims/gameinput.cpp')
-rw-r--r--runtime/shims/gameinput.cpp22
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.
2023void 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
2021void ForceFeedbackEffect::sync(Device* d, uint64_t now, bool muted) { 2031void 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;