play: DARNER_SIM_STEP_MAX, raise the title's 1/15 s simulation step cap #323

Open
dnzarc wants to merge 5 commits from dnzarc/Darner:sim-step-cap into Main
First-time contributor

What

A new opt-in switch, DARNER_SIM_STEP_MAX=<seconds> (0.05 to 1, off by default),
raises the ceiling the title's simulation puts on one frame's step, which is a float
of 1/15 s in the image. At load, before any title code runs, the two constants there
are checked and the cap is written; another image, or a different pair of values,
is refused with a line saying so.

image + 0x6159EC0   0.06666667  (1/15 s, the cap; 0x3D888889)
image + 0x6159EC4   0.001       (the floor, checked too)

Why

The title clamps each frame's timers to at most 1/15 s (darner-loader's
frame_rate.rs already documents this at +0x2226040). Below 15 fps game time
therefore falls behind the wall clock:

rendered fps frame world advances speed
30 33 ms 33 ms 100 %
14 71 ms 66.7 ms 93 %
10 100 ms 66.7 ms 67 %
6 167 ms 66.7 ms 40 %

On a 6 GB laptop this layer runs 10-16 fps, so the game is in slow motion most of
the time: the character walks slower when fps dips and normal when it recovers. That
reads as "not smooth" even when the frame rate itself is steady. Issue #296 describes
it and asks for exactly this switch; Foxhound's Foxpatch (by Mahmoud247) raises the
same float, and this makes it a switch instead of a patch on the file.

Tested

RTX 4050 Laptop 6 GB (5,920 MB), i5-12450HX, 23.8 GB RAM, driver 621.24, Windows 11.
v2026.12.03.02 plus this commit, Series S at 960x540, DLSS performance, frame
generation off, texture quality medium, DARNER_THIN_HEAP_ORDER=0:

  • the build starts and plays; the patch line prints simulation step: cap 0.0667 s -> 0.2000 s
  • at 13-16 fps walking and driving no longer slow down with the frame rate
  • the flows that never dip below 15 fps are unchanged by definition

I did not measure how it feels at 5 fps or with driving at speed; the bigger step per
frame is the trade-off, which is why it is off by default.

Diff

  • crates/darner-loader/src/frame_rate.rs: the constants, asked_sim_step_max()
    (parsing and the 0.05..1 range), and patch_sim_step() (verification, one page made
    writable, the old protection restored).
  • apps/darner/src/run.rs: the call, next to the frame-rate sites, before the title runs.
  • README.md: the row, with the table above in short.

Fluxer ID: 1577761092279480320

## What A new opt-in switch, `DARNER_SIM_STEP_MAX=<seconds>` (0.05 to 1, off by default), raises the ceiling the title's simulation puts on one frame's step, which is a float of 1/15 s in the image. At load, before any title code runs, the two constants there are checked and the cap is written; another image, or a different pair of values, is refused with a line saying so. ``` image + 0x6159EC0 0.06666667 (1/15 s, the cap; 0x3D888889) image + 0x6159EC4 0.001 (the floor, checked too) ``` ## Why The title clamps each frame's timers to at most 1/15 s (`darner-loader`'s `frame_rate.rs` already documents this at `+0x2226040`). Below 15 fps game time therefore falls behind the wall clock: | rendered fps | frame | world advances | speed | |---:|---:|---:|---:| | 30 | 33 ms | 33 ms | 100 % | | 14 | 71 ms | 66.7 ms | 93 % | | 10 | 100 ms | 66.7 ms | 67 % | | 6 | 167 ms | 66.7 ms | 40 % | On a 6 GB laptop this layer runs 10-16 fps, so the game is in slow motion most of the time: the character walks slower when fps dips and normal when it recovers. That reads as "not smooth" even when the frame rate itself is steady. Issue #296 describes it and asks for exactly this switch; Foxhound's Foxpatch (by Mahmoud247) raises the same float, and this makes it a switch instead of a patch on the file. ## Tested RTX 4050 Laptop 6 GB (5,920 MB), i5-12450HX, 23.8 GB RAM, driver 621.24, Windows 11. v2026.12.03.02 plus this commit, Series S at 960x540, DLSS performance, frame generation off, texture quality medium, `DARNER_THIN_HEAP_ORDER=0`: - the build starts and plays; the patch line prints `simulation step: cap 0.0667 s -> 0.2000 s` - at 13-16 fps walking and driving no longer slow down with the frame rate - the flows that never dip below 15 fps are unchanged by definition I did not measure how it feels at 5 fps or with driving at speed; the bigger step per frame is the trade-off, which is why it is off by default. ## Diff - `crates/darner-loader/src/frame_rate.rs`: the constants, `asked_sim_step_max()` (parsing and the 0.05..1 range), and `patch_sim_step()` (verification, one page made writable, the old protection restored). - `apps/darner/src/run.rs`: the call, next to the frame-rate sites, before the title runs. - `README.md`: the row, with the table above in short. Fluxer ID: 1577761092279480320
First-time contributor

Independent Windows build, gate, and code-read review of head eccc9116ad2228e3d8b1df2597026fa4ed9d185d, based on main f3840d73d3504c30218debfbc8795b9225447317. Not run in-game.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS.
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS.
  • cargo xtask policy: PASS (asset policy: 555 files ok).
  • cargo test --locked -p darner-loader --lib frame_rate::tests::: PASS (4 passed; 0 failed; 0 ignored; 88 filtered out).
  • cargo test --locked -p darner --bin darner: PASS (148 passed; 0 failed; 1 ignored).
  • cargo doc --locked -p darner-loader --no-deps: completed; emitted three warnings in unchanged crash.rs, heap_sites.rs, and scenes.rs.

Code-read audit

  • asked_sim_step_max correctly rejects non-finite/out-of-range values and leaves the stock cap unchanged when unset (crates/darner-loader/src/frame_rate.rs:292-299). patch_sim_step bounds-checks the RVA and verifies the adjacent stock cap/floor before writing (frame_rate.rs:312-321); the call runs only for --execute, before spawn_main (apps/darner/src/run.rs:912-918, :963-964).
  • Build identity is not checked for this fixed-RVA write. run explicitly continues with unknown images (apps/darner/src/run.rs:498-515), and the new call does not use build; patch_sim_step identifies its target only by two adjacent 32-bit values at one offset (frame_rate.rs:318-321). Require a recognized target build or a stronger image-specific signature before writing, so an unknown executable with those values at that RVA cannot be patched as if it were the supported title.
  • The original page protection can be silently lost. After changing the cap, patch_sim_step discards the result of restoring the prior protection (frame_rate.rs:327-334), then run reports a successful patch (apps/darner/src/run.rs:917). If restoration fails, the image page remains writable with no warning; report that failure rather than treating the operation as fully successful.
  • The documented slow-motion percentages are inconsistent: README says 87% at 14 fps and 45% at 6 (README.md:725), while a 1/15 s cap yields about 93% and 40%, respectively. The module comment's 13-fps figure is about 87%, but its 6-fps figure is also 45% (frame_rate.rs:280-283). The prior interval doc comment also has rounded/// joined on one line (frame_rate.rs:78).
  • The existing frame-rate tests pass, but do not exercise the new environment parser or simulation-cap write; no game run was performed.

Verdict: CHANGES NEEDED.

AI-assisted: yes (GitHub Copilot, Auto mode).

Independent Windows build, gate, and code-read review of head `eccc9116ad2228e3d8b1df2597026fa4ed9d185d`, based on `main` `f3840d73d3504c30218debfbc8795b9225447317`. Not run in-game. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS**. - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS**. - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`). - `cargo test --locked -p darner-loader --lib frame_rate::tests::`: **PASS** (`4 passed; 0 failed; 0 ignored; 88 filtered out`). - `cargo test --locked -p darner --bin darner`: **PASS** (`148 passed; 0 failed; 1 ignored`). - `cargo doc --locked -p darner-loader --no-deps`: completed; emitted three warnings in unchanged `crash.rs`, `heap_sites.rs`, and `scenes.rs`. ### Code-read audit - `asked_sim_step_max` correctly rejects non-finite/out-of-range values and leaves the stock cap unchanged when unset (`crates/darner-loader/src/frame_rate.rs:292-299`). `patch_sim_step` bounds-checks the RVA and verifies the adjacent stock cap/floor before writing (`frame_rate.rs:312-321`); the call runs only for `--execute`, before `spawn_main` (`apps/darner/src/run.rs:912-918`, `:963-964`). - **Build identity is not checked for this fixed-RVA write.** `run` explicitly continues with unknown images (`apps/darner/src/run.rs:498-515`), and the new call does not use `build`; `patch_sim_step` identifies its target only by two adjacent 32-bit values at one offset (`frame_rate.rs:318-321`). Require a recognized target build or a stronger image-specific signature before writing, so an unknown executable with those values at that RVA cannot be patched as if it were the supported title. - **The original page protection can be silently lost.** After changing the cap, `patch_sim_step` discards the result of restoring the prior protection (`frame_rate.rs:327-334`), then `run` reports a successful patch (`apps/darner/src/run.rs:917`). If restoration fails, the image page remains writable with no warning; report that failure rather than treating the operation as fully successful. - The documented slow-motion percentages are inconsistent: README says 87% at 14 fps and 45% at 6 (`README.md:725`), while a 1/15 s cap yields about 93% and 40%, respectively. The module comment's 13-fps figure is about 87%, but its 6-fps figure is also 45% (`frame_rate.rs:280-283`). The prior interval doc comment also has `rounded///` joined on one line (`frame_rate.rs:78`). - The existing frame-rate tests pass, but do not exercise the new environment parser or simulation-cap write; no game run was performed. **Verdict: CHANGES NEEDED.** AI-assisted: yes (GitHub Copilot, Auto mode).
Author
First-time contributor

Thanks for the review. Head is now 7086756 on sim-step-cap (on top of eccc9116); all four points are in:

  • Build identity: the call in run.rs checks build.is_none() and leaves the cap alone, with a line on stderr, when the image is not the known build. The RVA is no longer the only guard.
  • Page protection: patch_sim_step checks the second VirtualProtect and returns an error naming the last OS error instead of reporting success.
  • Numbers: README and the module comment now say about 93 % at 14 fps and 40 % at 6 fps (a 1/15 s cap).
  • Tests: parse_sim_step_max (0.05/1 bounds, NaN, inf, empty, junk) and patches_the_simulation_step_cap (writes 0.2 into a buffer holding the stock pair, returns 1/15, refuses a second patch). The doc line with rounded/// is fixed.

Ran here: gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings) PASS; cargo test -p darner-loader --lib frame_rate: 6 passed; cargo test -p darner --bin darner: 148 passed, 1 ignored. Gate 2 (--all-features) was not run on this host. No game run after these changes: they only touch the start path, and the call site behaves as before for the known build.

Thanks for the review. Head is now 7086756 on sim-step-cap (on top of eccc9116); all four points are in: - Build identity: the call in run.rs checks build.is_none() and leaves the cap alone, with a line on stderr, when the image is not the known build. The RVA is no longer the only guard. - Page protection: patch_sim_step checks the second VirtualProtect and returns an error naming the last OS error instead of reporting success. - Numbers: README and the module comment now say about 93 % at 14 fps and 40 % at 6 fps (a 1/15 s cap). - Tests: parse_sim_step_max (0.05/1 bounds, NaN, inf, empty, junk) and patches_the_simulation_step_cap (writes 0.2 into a buffer holding the stock pair, returns 1/15, refuses a second patch). The doc line with rounded/// is fixed. Ran here: gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings) PASS; cargo test -p darner-loader --lib frame_rate: 6 passed; cargo test -p darner --bin darner: 148 passed, 1 ignored. Gate 2 (--all-features) was not run on this host. No game run after these changes: they only touch the start path, and the call site behaves as before for the known build.
Contributor

Code review only (read the diff at 7086756), nothing built or run. The fixes for the earlier review look right: build check, protection error, numbers, tests. Three more:

  • Is +0x6159EC0 the cap's own variable, or a pooled float literal? MSVC shares identical float constants (__real@3d888889) and lays them out by value, so 1/15 next to 0.001 may be two neighbouring pooled literals. If anything else in the title loads that address, it gets the new value too. The existing patches in frame_rate.rs change code sites (Site, Kind::Load), not literals. If the address has more than one reference, patching the load at the clamp (+0x2226040) the same way would keep the change to the clamp alone.
  • run.rs: the } closing if !execute and darner_loader::report_crashes(); ended up on one line. That is a stray reformat of a line the change doesn't need.
  • The new patch test allocates about 102 MB (SIM_STEP_CAP + 16 bytes) to touch 8. Offsetting base back by SIM_STEP_CAP over a 16-byte buffer tests the same thing.
  • Related: #296.

Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.

Code review only (read the diff at `7086756`), nothing built or run. The fixes for the earlier review look right: build check, protection error, numbers, tests. Three more: - **Is `+0x6159EC0` the cap's own variable, or a pooled float literal?** MSVC shares identical float constants (`__real@3d888889`) and lays them out by value, so 1/15 next to 0.001 may be two neighbouring pooled literals. If anything else in the title loads that address, it gets the new value too. The existing patches in `frame_rate.rs` change code sites (`Site`, `Kind::Load`), not literals. If the address has more than one reference, patching the load at the clamp (`+0x2226040`) the same way would keep the change to the clamp alone. - `run.rs`: the `}` closing `if !execute` and `darner_loader::report_crashes();` ended up on one line. That is a stray reformat of a line the change doesn't need. - The new patch test allocates about 102 MB (`SIM_STEP_CAP + 16` bytes) to touch 8. Offsetting `base` back by `SIM_STEP_CAP` over a 16-byte buffer tests the same thing. - Related: #296. Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
Author
First-time contributor

Head is now f89ffa0. You were right about the literal: a scan of every RIP-relative movss/vmovss in the code sections finds 65 loads of the 1/15 at +0x6159EC0 (and 1,961 of the 0.001 next to it), so changing it in place changed all of them.

The patch now:

  • writes the value into the four zero bytes at +0x6159EC8, which no load reaches (0 found by the same scan);
  • retargets the clamp's own load at +0x2226045 (c5 fa 10 1d 73 3e f3 03, vmovss xmm3,[rip+0x3F33E73] -> +0x6159EC0) to that slot;
  • checks the stock cap, floor, free slot and load bytes first, and refuses another image.

The literal keeps 1/15 for the other loads. In-game the start prints simulation step: cap 0.0667 s -> 0.2000 s and the title runs.

Tests: cargo test -p darner-loader --lib frame_rate -> 6 passed, including the_step_cap_site_is_checked (stock accepted, wrong cap/floor/slot/load refused). The run.rs line and the 16-byte test from your last message are in c907b95.

Head is now f89ffa0. You were right about the literal: a scan of every RIP-relative `movss`/`vmovss` in the code sections finds **65 loads** of the 1/15 at `+0x6159EC0` (and 1,961 of the 0.001 next to it), so changing it in place changed all of them. The patch now: - writes the value into the four zero bytes at `+0x6159EC8`, which no load reaches (0 found by the same scan); - retargets the clamp's own load at `+0x2226045` (`c5 fa 10 1d 73 3e f3 03`, `vmovss xmm3,[rip+0x3F33E73]` -> `+0x6159EC0`) to that slot; - checks the stock cap, floor, free slot and load bytes first, and refuses another image. The literal keeps 1/15 for the other loads. In-game the start prints `simulation step: cap 0.0667 s -> 0.2000 s` and the title runs. Tests: `cargo test -p darner-loader --lib frame_rate` -> 6 passed, including `the_step_cap_site_is_checked` (stock accepted, wrong cap/floor/slot/load refused). The run.rs line and the 16-byte test from your last message are in c907b95.
Author
First-time contributor

Added a note in bfb34ab, from an A/B on the same spot: with the stock 1/15 cap the boats on the water sit still; with DARNER_SIM_STEP_MAX=0.2 (125 ms steps at 8-10 fps) distant boats jitter up and down; with 0.1 (10 fps in real time) they are stable. So 0.1 is the value I would suggest for a PC in this frame-rate range; 0.2 is still there for anyone who wants 5 fps in real time.

Added a note in bfb34ab, from an A/B on the same spot: with the stock 1/15 cap the boats on the water sit still; with `DARNER_SIM_STEP_MAX=0.2` (125 ms steps at 8-10 fps) distant boats jitter up and down; with `0.1` (10 fps in real time) they are stable. So 0.1 is the value I would suggest for a PC in this frame-rate range; 0.2 is still there for anyone who wants 5 fps in real time.
Owner

Test needed — commit bfb34abd; what to check: the change described above

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `bfb34abd`; what to check: the change described above Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'sim-step-cap:dnzarc-sim-step-cap'
git switch 'dnzarc-sim-step-cap'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'dnzarc-sim-step-cap'
git switch 'dnzarc-sim-step-cap'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'dnzarc-sim-step-cap'
git switch 'dnzarc-sim-step-cap'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'dnzarc-sim-step-cap'
git switch 'Main'
git merge --squash 'dnzarc-sim-step-cap'
git switch 'Main'
git merge --ff-only 'dnzarc-sim-step-cap'
git switch 'Main'
git merge 'dnzarc-sim-step-cap'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!323
No description provided.