upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorLeonida local test <local-test@localhost>2026-11-22 23:15:09 +0100
committerLeonida local test <local-test@localhost>2026-11-22 23:15:09 +0100
commitdc01a173970ceccfefefc9e70e6cd31b1eeec43a (patch)
tree6c64d024783afb6e06647f1c43779f9b20fe3f86 /runtime
parent59aa22ff0ca967db25c0ff8116c52484b7773b5e (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')
-rw-r--r--runtime/shims/gameinput.cpp22
-rw-r--r--runtime/shims/gameinput.h6
-rw-r--r--runtime/test/gameinput_probe.cpp20
-rw-r--r--runtime/test/gameinput_test.cpp26
4 files changed, 69 insertions, 5 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;
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 {
69 bool trigger_rumble = false; // the pad takes SDL_RumbleGamepadTriggers 69 bool trigger_rumble = false; // the pad takes SDL_RumbleGamepadTriggers
70 bool force_feedback = false; // SDL opened the pad as a haptic device 70 bool force_feedback = false; // SDL opened the pad as a haptic device
71 uint32_t haptic_motors = 0; // haptic motors the pad reports (0 or 2) 71 uint32_t haptic_motors = 0; // haptic motors the pad reports (0 or 2)
72 // The last force-feedback effect the shim asked SDL for: SDL_CreateHapticEffect's id (-1 when SDL refused),
73 // whether SDL_RunHapticEffect then returned true, and SDL's error text when a call failed. `force_feedback` only
74 // says a haptic device was opened; an effect SDL creates but will not run, or refuses outright, shows up here.
75 int effect_id = -1;
76 bool effect_ran = false;
77 char effect_error[128] = {};
72}; 78};
73bool output_state(int i, OutputState* out); 79bool output_state(int i, OutputState* out);
74 80
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) {
66// A constant force at full magnitude on the pad's first motor, held for a second: the effect a wheel feels as a 66// A constant force at full magnitude on the pad's first motor, held for a second: the effect a wheel feels as a
67// steady pull. A pad SDL did not open as a haptic device reports no motor, and the step says so and moves on. 67// steady pull. A pad SDL did not open as a haptic device reports no motor, and the step says so and moves on.
68void constant_force() { 68void constant_force() {
69 for (IGameInputDevice* d : g_devices) { 69 // g_devices is in connection order, which is what output_state indexes; the SDL outcome is read back per pad.
70 for (size_t n = 0; n < g_devices.size(); ++n) {
71 IGameInputDevice* d = g_devices[n];
70 const GameInputDeviceInfo* i = d->GetDeviceInfo(); 72 const GameInputDeviceInfo* i = d->GetDeviceInfo();
71 if (i->forceFeedbackMotorCount == 0) { 73 if (i->forceFeedbackMotorCount == 0) {
72 std::printf("force feedback: %s reports no force-feedback motor; skipped\n", 74 std::printf("force feedback: %s reports no force-feedback motor; skipped\n",
@@ -88,7 +90,21 @@ void constant_force() {
88 } 90 }
89 std::printf("force feedback: constant linearX 1.0 on motor 0, 1 s\n"); 91 std::printf("force feedback: constant linearX 1.0 on motor 0, 1 s\n");
90 e->SetState(GameInputFeedbackRunning); 92 e->SetState(GameInputFeedbackRunning);
91 Sleep(1000); 93 Sleep(1000); // the poll thread creates and runs the effect
94 char seen[256] = "no output state";
95 rt::gameinput::OutputState out{};
96 if (rt::gameinput::output_state(static_cast<int>(n), &out)) {
97 if (out.effect_id < 0) {
98 std::snprintf(seen, sizeof seen, "SDL did not create the effect (%s)",
99 out.effect_error[0] ? out.effect_error : "no error text");
100 } else if (!out.effect_ran) {
101 std::snprintf(seen, sizeof seen, "SDL created effect %d but did not run it (%s)", out.effect_id,
102 out.effect_error[0] ? out.effect_error : "no error text");
103 } else {
104 std::snprintf(seen, sizeof seen, "SDL created effect %d and is running it", out.effect_id);
105 }
106 }
107 std::printf("force feedback: %s\n", seen);
92 e->SetState(GameInputFeedbackStopped); 108 e->SetState(GameInputFeedbackStopped);
93 e->Release(); // the poll thread destroys the SDL effect 109 e->Release(); // the poll thread destroys the SDL effect
94 Sleep(300); 110 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 {
998 SDL_HAPTIC_SAWTOOTHUP | SDL_HAPTIC_SAWTOOTHDOWN | SDL_HAPTIC_RAMP | SDL_HAPTIC_SPRING | 998 SDL_HAPTIC_SAWTOOTHUP | SDL_HAPTIC_SAWTOOTHDOWN | SDL_HAPTIC_RAMP | SDL_HAPTIC_SPRING |
999 SDL_HAPTIC_FRICTION | SDL_HAPTIC_DAMPER | SDL_HAPTIC_INERTIA; 999 SDL_HAPTIC_FRICTION | SDL_HAPTIC_DAMPER | SDL_HAPTIC_INERTIA;
1000 int max_effects = 8; 1000 int max_effects = 8;
1001 int create_result = 1; // what create returns; negative is SDL refusing the effect
1001 int opens = 0, closes = 0, creates = 0, updates = 0, runs = 0, stops = 0, destroys = 0; 1002 int opens = 0, closes = 0, creates = 0, updates = 0, runs = 0, stops = 0, destroys = 0;
1002 int gain_calls = 0, last_gain = -1; 1003 int gain_calls = 0, last_gain = -1;
1003 uint32_t last_iterations = 0; 1004 uint32_t last_iterations = 0;
@@ -1017,8 +1018,12 @@ int fake_max_effects(void* h) { return static_cast<FakeHaptic*>(h)->max_effects;
1017int fake_create(void* h, const void* e) { 1018int fake_create(void* h, const void* e) {
1018 FakeHaptic* f = static_cast<FakeHaptic*>(h); 1019 FakeHaptic* f = static_cast<FakeHaptic*>(h);
1019 ++f->creates; 1020 ++f->creates;
1021 if (f->create_result < 0) {
1022 SDL_SetError("fake: refused");
1023 return -1;
1024 }
1020 f->last = *static_cast<const SDL_HapticEffect*>(e); 1025 f->last = *static_cast<const SDL_HapticEffect*>(e);
1021 return 1; 1026 return f->create_result;
1022} 1027}
1023bool fake_update(void* h, int, const void* e) { 1028bool fake_update(void* h, int, const void* e) {
1024 FakeHaptic* f = static_cast<FakeHaptic*>(h); 1029 FakeHaptic* f = static_cast<FakeHaptic*>(h);
@@ -1114,6 +1119,9 @@ void test_force_feedback(IGameInput* input) {
1114 const int runs0 = g_fake.runs; 1119 const int runs0 = g_fake.runs;
1115 rt::gameinput::poll(); 1120 rt::gameinput::poll();
1116 check(g_fake.creates == 1 && g_fake.runs == runs0 + 1, "force feedback: the poll thread creates and runs the effect"); 1121 check(g_fake.creates == 1 && g_fake.runs == runs0 + 1, "force feedback: the poll thread creates and runs the effect");
1122 rt::gameinput::OutputState sent{};
1123 check(rt::gameinput::output_state(0, &sent) && sent.effect_id == 1 && sent.effect_ran && !sent.effect_error[0],
1124 "force feedback: the output state reports the effect SDL created and is running");
1117 check(g_fake.last.type == SDL_HAPTIC_CONSTANT && g_fake.last.constant.level == 16384, 1125 check(g_fake.last.type == SDL_HAPTIC_CONSTANT && g_fake.last.constant.level == 16384,
1118 "force feedback: a constant 0.5 becomes SDL_HAPTIC_CONSTANT level 16384"); 1126 "force feedback: a constant 0.5 becomes SDL_HAPTIC_CONSTANT level 16384");
1119 check(g_fake.last.constant.length == 60000 && g_fake.last_iterations == 0, 1127 check(g_fake.last.constant.length == 60000 && g_fake.last_iterations == 0,
@@ -1121,6 +1129,22 @@ void test_force_feedback(IGameInput* input) {
1121 rt::gameinput::poll(); 1129 rt::gameinput::poll();
1122 check(g_fake.runs == runs0 + 1, "force feedback: an unchanged effect is not re-sent every poll"); 1130 check(g_fake.runs == runs0 + 1, "force feedback: an unchanged effect is not re-sent every poll");
1123 1131
1132 // SDL refusing an effect is visible, not swallowed: the output state carries the failure and SDL's error.
1133 g_fake.create_result = -1;
1134 IGameInputForceFeedbackEffect* refused = nullptr;
1135 check(dev->CreateForceFeedbackEffect(0, &params, reinterpret_cast<void**>(&refused)) == S_OK && refused,
1136 "force feedback: GameInput accepts an effect SDL will refuse");
1137 if (refused) {
1138 rt::gameinput::poll();
1139 rt::gameinput::OutputState refused_out{};
1140 check(rt::gameinput::output_state(0, &refused_out) && refused_out.effect_id < 0 && !refused_out.effect_ran &&
1141 std::strstr(refused_out.effect_error, "fake: refused"),
1142 "force feedback: SDL refusing the effect is recorded with its error");
1143 refused->Release();
1144 rt::gameinput::poll(); // the released effect leaves the device
1145 }
1146 g_fake.create_result = 1;
1147
1124 params.data.constant.magnitude.linearX = -1.0f; 1148 params.data.constant.magnitude.linearX = -1.0f;
1125 check(effect->SetParams(&params), "force feedback: SetParams"); 1149 check(effect->SetParams(&params), "force feedback: SetParams");
1126 rt::gameinput::poll(); 1150 rt::gameinput::poll();