Skip to content

gameinput: SetParams with the same duration keeps a finite effect's run and timer - #7463

Closed
AirKyzzZ wants to merge 3 commits into
ProjectLeonida:mainfrom
AirKyzzZ:fix/gameinput-setparams-timer
Closed

AirKyzzZ wants to merge 3 commits into
ProjectLeonida:mainfrom
AirKyzzZ:fix/gameinput-setparams-timer

Conversation

@AirKyzzZ

@AirKyzzZ AirKyzzZ commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new RT item (claim)

Depends on: #7385 (same function; this branch is on top of it, so its commit shows here until it lands)

@ItsNotRexed: an exe/recomp PR, as you asked.

What and why

Microsoft's IGameInputForceFeedbackEffect::SetParams reference says the duration timer is not refreshed when the duration doesn't change, only when a different duration is given or the effect is stopped and restarted. ForceFeedbackEffect::sync re-ran SDL's effect and reset run_at_ on every change, so a title that calls SetParams each frame on a finite effect (the documented use) restarted it each time and it never ran out.

When a finite effect is already running with the same total length and play count, the poll thread now only updates SDL's effect and keeps the run and its timer. A new duration or a new play count still runs it again from the start (1 x 200 ms to 2 x 100 ms is the same total length, but SDL needs the 2 iterations). SetState counts its moves to Running in starts_, so a stop and restart between two polls also starts a new run, as the reference says it should.

Tested

Windows 10 22H2 (19045), RTX 2060 / NVIDIA 566.14, Ryzen 5 2600X, clang-cl 23.1.6 + lld-link with the VS 2022 14.44 STL, Windows SDK 10.0.26100, Ninja, SDL3 3.4.20 fetched, at 2ebd361d9:

  • gameinput_test (ctest): 353 checks, 0 failures.
  • With 0e19b9d98's gameinput.cpp (before the play count was kept): 1 failure, the 10 s x 1 to 5 s x 2 check, where SDL is never run with the 2 iterations.
  • At 0e19b9d98, with gameinput: SetParams refuses parameters of another effect kind #7385's gameinput.cpp (4965a5d8e, this PR's parent): 4 failures. Same-duration SetParams runs the effect again, and it is still running when the 200 ms it started with are over. The new-duration and stop/restart checks fail there only because that extra run shifts the run count.

The timing check sleeps 50 ms before SetParams and 180 ms after, so with the fix the 200 ms are always over by then. No upper bound on any sleep.

No game files. AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (no translator change)

Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
…un and timer

Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
@Envyre

Envyre commented Nov 23, 2026

Copy link
Copy Markdown

Code read of 0e19b9d (not run). The approach looks right (locking of starts_ under g().mu, the stop-and-restart bump, pause/mute/expiry still clearing sdl_running_/endless_, kind validated at CreateForceFeedbackEffect). Two points:

  1. same_run (gameinput.cpp:2204) compares only run_for, i.e. length × iterations, not the iteration count. A SetParams from 1 × 200 ms to 2 × 100 ms counts as the same run: update_effect gives SDL the new 100 ms length but run_effect isn't called again, so the running effect keeps its old 1 iteration and stops after 100 ms while the shim's timer (and GameInput) expects 200 ms. The other direction, 2 × 100 to 1 × 200, ends up right only because the shim's timer cuts it at 200 ms. Keeping the iteration count (say an iterations_ member) and requiring iterations == iterations_ in same_run would close it.

  2. Not from this PR: the comment at :2200 says "GameInput's playCount 0 means until stopped, which is what SDL's 0 iterations means", but SDL documents SDL_HAPTIC_INFINITY for "repeat forever"; 0 iterations isn't specified as infinite and I'd not rely on backends treating it so. Mapping playCount 0 to SDL_HAPTIC_INFINITY would match the docs. (I haven't checked each SDL backend's handling of 0.)

AI-assisted (Claude Code).

… even at the same total length

Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
@AirKyzzZ

Copy link
Copy Markdown
Contributor Author

Thanks @Envyre, both points were right.

  1. same_run now also needs the play count to match (iterations_), so 1 x 200 ms to 2 x 100 ms runs the effect again with 2 iterations. New check through the fake haptic source: SetParams from a 10 s wave played once to a 5 s wave played twice must run SDL again with last_iterations == 2, no new sleeps. Tested 2ebd361d9 on RTX 2060 (NVIDIA 566.14), Windows 10 22H2, clang-cl 23.1.6: gameinput_test 353 checks, 0 failures; with 0e19b9d98's gameinput.cpp that check fails (1 failure).
  2. Confirmed in SDL 3.4.20: the header says SDL_HAPTIC_INFINITY, SDL's Linux backend writes 0 to EV_FF as a stop, and so does Wine's dinput path through winebus. Fixed in its own PR on top of this one: gameinput: a force-feedback effect with no duration or a play count of 0 runs with SDL_HAPTIC_INFINITY, not 0 iterations #7815.

@Hubitski

Copy link
Copy Markdown

Tested 1b88f90 (PR head 2ebd361d9 merged into main dde82f27e) on AMD Radeon RX 7800 XT (AMD proprietary 26.11.2 / LLPC, Windows driver 32.0.32029.2010), Windows 11 Pro 10.0.22631: pass.

Setup: MSVC 19.44.35207 (VS 2022 Build Tools), Windows SDK 10.0.26100.0, Visual Studio 17 2022 generator, RelWithDebInfo, SDL3 3.4.20 fetched with -DLEONIDA_SDL3_FETCH=ON. No Vulkan SDK and no game files; this test does not use the GPU.

  • ctest -C RelWithDebInfo -R "^gameinput": 2/2 passed (gameinput_host, gameinput).
  • gameinput_test (direct run): 353 checks, 0 failures, exit 0.

The 353 checks match your Windows 10 run. AI-assisted (Claude Code).

@CourtyardGames

Copy link
Copy Markdown

Tested 2ebd361 on NVIDIA GeForce RTX 4070 SUPER (621.14, Vulkan 1.4.357), Windows 11, MSVC 14.51: pass

  • Read the full diff first (2 files: gameinput.cpp, gameinput_test.cpp): no network, registry or file access beyond the shim's own logic.
  • Fresh worktree build with scripts\build_runtime.ps1 -FetchSdl3 (the repo's hash-pinned SDL3 download, needed because gameinput_test is only built with SDL3).
  • ctest -R gameinput: gameinput 353 checks, 0 failures; gameinput_host passed. The new SetParams checks (other kind refused, same duration keeps the run, new duration reruns, stop and restart reruns, same total length with a new play count reruns) all pass.
  • Control: this PR's test against gameinput.cpp from its merge base with main (cc67780): 353 checks, 8 failures, including the SetParams ones above and a paused effect is stopped in SDL.
  • Full ctest -j6: 234/235 passed; the one failure is d3d12_vulkan_device (copy/resolve cases), which this PR does not touch and which fails the same way on file_system: RemoveDirectory of a read-only GAME: folder fails with ERROR_ACCESS_DENIED, as on the host #7477's build. Not run on main.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants