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:
authorMoonEyes <ducoinbenjamin@yahoo.fr>2026-11-29 02:03:06 +0100
committerGitHub <noreply@github.com>2026-11-29 02:03:06 +0100
commit17f5b935db20e5243be54dd5893960128721bdca (patch)
treedc82fd918f6e6f627d354e23359c7af18714a795 /runtime/shims/gameinput.cpp
parent0ff4dd1c8774f4c4ac06e00808dafdb9712b5575 (diff)
parent4a7084506926240b5770481d8ad0aa5f1a846299 (diff)
Merge pull request #2497 from Tyrannys/rt-gameinput-ffb-haptic-null
gameinput: force-feedback kind changes, SetParams features, locked motor reads, no null memcpy (RT-GAMEINPUT-FFB-HAPTIC-NULL)
Diffstat (limited to 'runtime/shims/gameinput.cpp')
-rw-r--r--runtime/shims/gameinput.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp
index 1e9b33041..4a17b88ae 100644
--- a/runtime/shims/gameinput.cpp
+++ b/runtime/shims/gameinput.cpp
@@ -272,13 +272,13 @@ public:
272 uint32_t STDMETHODCALLTYPE GetControllerAxisCount() override { return kAxisCount; } 272 uint32_t STDMETHODCALLTYPE GetControllerAxisCount() override { return kAxisCount; }
273 uint32_t STDMETHODCALLTYPE GetControllerAxisState(uint32_t count, float* out) override { 273 uint32_t STDMETHODCALLTYPE GetControllerAxisState(uint32_t count, float* out) override {
274 const uint32_t n = out ? std::min(count, kAxisCount) : 0; 274 const uint32_t n = out ? std::min(count, kAxisCount) : 0;
275 std::memcpy(out, s_.axes, n * sizeof(float)); 275 if (n) std::memcpy(out, s_.axes, n * sizeof(float)); // never with a null buffer, even for 0 bytes
276 return n; 276 return n;
277 } 277 }
278 uint32_t STDMETHODCALLTYPE GetControllerButtonCount() override { return kButtonCount; } 278 uint32_t STDMETHODCALLTYPE GetControllerButtonCount() override { return kButtonCount; }
279 uint32_t STDMETHODCALLTYPE GetControllerButtonState(uint32_t count, bool* out) override { 279 uint32_t STDMETHODCALLTYPE GetControllerButtonState(uint32_t count, bool* out) override {
280 const uint32_t n = out ? std::min(count, kButtonCount) : 0; 280 const uint32_t n = out ? std::min(count, kButtonCount) : 0;
281 std::memcpy(out, s_.buttons, n * sizeof(bool)); 281 if (n) std::memcpy(out, s_.buttons, n * sizeof(bool));
282 return n; 282 return n;
283 } 283 }
284 uint32_t STDMETHODCALLTYPE GetControllerSwitchCount() override { return 0; } 284 uint32_t STDMETHODCALLTYPE GetControllerSwitchCount() override { return 0; }
@@ -2224,16 +2224,22 @@ void Device::SetRumbleState(const GameInputRumbleParams* params) {
2224HRESULT Device::CreateForceFeedbackEffect(uint32_t motorIndex, const void* params, void** effect) { 2224HRESULT Device::CreateForceFeedbackEffect(uint32_t motorIndex, const void* params, void** effect) {
2225 if (!effect) return E_POINTER; 2225 if (!effect) return E_POINTER;
2226 *effect = nullptr; 2226 *effect = nullptr;
2227 if (!params || motorIndex >= info.forceFeedbackMotorCount) return E_INVALIDARG; 2227 if (!params) return E_INVALIDARG;
2228 const auto* p = static_cast<const GameInputForceFeedbackParams*>(params); 2228 const auto* p = static_cast<const GameInputForceFeedbackParams*>(params);
2229 // Only what the motor reported. SDL is not asked here: this is a title call, so the cached feature mask decides, 2229 {
2230 // and the poll thread is what finds out if SDL refuses the effect anyway. 2230 // The motor count and features are the poll thread's (open_pad, close_pad), written under g().mu.
2231 if (!valid_kind(p->kind) || !(ff_features & kind_feature(p->kind))) return E_INVALIDARG; 2231 std::lock_guard lock(g().mu);
2232 if (motorIndex >= info.forceFeedbackMotorCount) return E_INVALIDARG;
2233 // Only what the motor reported. SDL is not asked here: this is a title call, so the cached feature mask
2234 // decides, and the poll thread is what finds out if SDL refuses the effect anyway.
2235 if (!valid_kind(p->kind) || !(ff_features & kind_feature(p->kind))) return E_INVALIDARG;
2236 }
2232 *effect = new ForceFeedbackEffect(this, motorIndex, *p); 2237 *effect = new ForceFeedbackEffect(this, motorIndex, *p);
2233 return S_OK; 2238 return S_OK;
2234} 2239}
2235 2240
2236bool Device::IsForceFeedbackMotorPoweredOn(uint32_t motorIndex) { 2241bool Device::IsForceFeedbackMotorPoweredOn(uint32_t motorIndex) {
2242 std::lock_guard lock(g().mu); // haptic and the motor count change on the poll thread
2237 return motorIndex < info.forceFeedbackMotorCount && haptic != nullptr && status.load() != GameInputDeviceNoStatus; 2243 return motorIndex < info.forceFeedbackMotorCount && haptic != nullptr && status.load() != GameInputDeviceNoStatus;
2238} 2244}
2239 2245
@@ -2336,6 +2342,10 @@ void STDMETHODCALLTYPE ForceFeedbackEffect::GetParams(GameInputForceFeedbackPara
2336bool STDMETHODCALLTYPE ForceFeedbackEffect::SetParams(const GameInputForceFeedbackParams* params) { 2342bool STDMETHODCALLTYPE ForceFeedbackEffect::SetParams(const GameInputForceFeedbackParams* params) {
2337 if (!params || !valid_kind(params->kind)) return false; 2343 if (!params || !valid_kind(params->kind)) return false;
2338 std::lock_guard lock(g().mu); 2344 std::lock_guard lock(g().mu);
2345 // The kind is the effect's for life: SetParams changes the parameters of that kind only, and another kind is
2346 // refused with the effect left as it was (a title makes a second effect for it). The motor reported this kind
2347 // when the effect was created, so SDL's effect keeps its type and is only ever updated.
2348 if (params->kind != params_.kind) return false;
2339 params_ = *params; 2349 params_ = *params;
2340 ++version_; 2350 ++version_;
2341 return true; 2351 return true;