fix(fps): the battle music stops after a fight above a 60 fps cap #1224
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1224
Loading…
Reference in a new issue
No description provided.
Delete branch "CraftyCorvid/Longshot:fix/bgm-high-fps"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: fix · Risk: low · Tested on: Linux, RTX 5090 · Needs: Windows, any GPU (a build and a fight at a cap above 60)
Why
With a Frame rate cap above 60, the battle music often keeps playing after a fight is over: it follows you into other
areas and only a reload stops it, until the next fight. Sometimes it instead stays at the lower volume it had while you
walked away from the enemy. Fixes #112. See #414 (the same battle music report, beside other high-fps sound issues) and
https://git.notrexed.dev/Hookshot/Hookshot/issues/2961.
The cause: the game marks each change to the fight (it started, it ended, the enemy's distance changed the volume) with a
flag it sets for a single frame. Since #2470 the music manager runs at most 60 times a second above a 60 cap, so at 120 fps
it sees about half of those flags, and a quarter at 240. When it misses the "fight over" one, the battle music never stops.
How to reproduce
Seen on: Linux (CachyOS), RTX 5090, NVIDIA 620.70
Settings and switches: Frame rate cap 240 (the game ran at about 120 fps), defaults otherwise
Steps: start a fight (the battle music comes in), then end it by beating the enemy or walking away; repeat a few times
Expected: the battle music stops at each fight's end
Actual: at some ends (about half at 120 fps) it keeps playing until the next fight or a reload; once it stayed at a
lower volume
What changed
The music manager now gets every one-frame change flag, even on frames where the 60 Hz limit holds it back: on those frames
the sound job's gate saves the flags, and the music manager's next update handles them. It also counts a whole 60 Hz step
on each update instead of the frame's own fraction of one, so its own timers keep real time.
[[0x84c9dda0]]+0x4898: bit 5 the battle music's name, bit 1 its distancevolume, bits 2 and 6) is read by the music manager's update
f_83373400(game::Bgm), which runs inside the sound jobf_80435300.hos_oot_sound_gate(host/oot_high_fps.c) ORs the byte into a latch on every phase of a frame it holds;the update's head takes the latch (
hos_oot_bgm_begin) and its four reads of the byte get it (hos_oot_bgm_flags),hooked by
patch_bgm_flagsinnx2/oot_patches.py. A flag the update saw on a frame it ran is not latched, so none ishandled twice (bit 6 counts down). At a cap of 60 the gate holds no frame and nothing changes.
frame's own time its clock ran at 60 / fps of real time (0.56 measured at 120 fps): stop delays, fades, the rest counter
and the time-of-day property at half speed at 120. Its two loads now go through
hos_oot_sound_stepand the newhos_oot_sound_seconds(patch_bgm_time): a whole step and that step's seconds while the gate holds the job.host/oot_high_fps.h: the why, andoot_sound_seconds. Both patches warn when the update is not found once.Measurements
Verdict: fixed: every one-frame change flag reaches the music manager (30 of 72 were lost in the check before), its
clock keeps real time (0.576 of it before), and in a played session at a cap of 240 every fight end stopped the battle
music (one of four was lost before).
Baseline: the in-game "before" runs are on base
71b1edd8(main as of nightly-351) and on this branch's first fix alone(5576d723, for the played session);
host/oot_high_fps.*andnx2/oot_patches.pythere are the same as on mainac778751, so main has the same behaviour. The game-free check is main against this PR.Hardware: CachyOS Linux 7.3.4, RTX 5090, NVIDIA 620.70, Ryzen 7 9800X3D, 62 GB
Scene: clock: Link's house (Kokiri Forest, child), headless, caps 60 / 120 / 240; played: a dungeon (area music
BGM_Dungeon), windowed, cap 240 (about 120 fps)
Method: clock: the music manager found in guest memory by its vtable through the control bridge, its one-second
accumulator and rest counter read 30 s apart. Played: fights started and ended by hand while a watcher read the game's
memory 2,800 times a second (the flag byte, the battle state and the music's properties), nothing written.
How to reproduce:
python -I -B tests/test_high_fps_fixes.py; in the game, a cap of 120 or 240, a few fights ended bybeating the enemy or walking away
ac778751065f5121The played session before the fix (watcher log, ms from its start;
97e464b9is the music's battle BGM property):After:
Clock, from the probe's log:
Flags and settings
None.
Testing
Tested: Linux (CachyOS), RTX 5090, NVIDIA 620.70:
python -I -B tests/test_high_fps_fixes.pyfails on main (2 of5) and passes here; it also fails with the latch removed (30 of 72 lost) and with flags latched on frames the update runs
(42 of 72 handled twice). The game built as a pack over base
71b1edd8(both patches applied once, no warning); the clockruns above at caps 60, 120 and 240; a played session at a cap of 240 (about 120 fps) with fights ended by beating the
enemy and by walking away, the music stopping each time by ear and in the watcher's log.
host/oot_high_fps.csyntax-checked with
-Wall -Wextrafor Windows (x86_64-w64-mingw32-gcc) and Linux (gcc, clang): no warnings, as on main.python -I -B tests/run_all.py: 594 passed, 16 failed, 83 skipped; the same 16 fail on main on this PC (no zstandard orVulkan headers here): test_linux_update, test_make_game_cache, test_crt_options, test_bug_report_defaults,
test_dlss_feature_size, test_failed_compile_keeps_objects, test_guest_imported, test_lift_lookups, test_linux_preflight,
test_missing_nup, test_mods_size_table, test_pending_guest_import, test_run_all_changed, test_walk_key, test_walk,
test_vk_occlusion_queries.
Not tested: a Windows build with llvm-mingw and a Windows run (this PC is Linux); AMD and Intel GPUs (the change is
CPU-side game logic, no GPU path); a game really at 240 fps (this PC reached about 120 under the 240 cap); bit 6 of the
flags (it never fired in the played session).
Must be tested:
expecting the battle music to stop every time and not to stay at a lower volume (by hand, or Test Farm: @Beanstalk
windows, a build of this PR and a few fights at a 120 cap, the battle music stopping after each).
Risks
What could break: the music manager above a 60 cap. A flag latched on a held frame is handled one update (one 60 Hz
frame) late; one bit set on two held frames between two updates is handled once (only bit 6 counts, and it did not fire
in play). The latch reads the byte at the address the music manager last read; it is the battle manager's, which lives as
long as the game. At a cap of 60 the gate never holds a frame, so the game runs as before.
Turning it off: revert the commits.
Compatibility: the lifted game changes (two functions' text), so the game is built again; saves,
longshot_options.iniand the shader and pipeline caches are untouched.Issues
Fixes #112
See #414
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).mainand passing here.tests/that reads changed source updated in this PR, not weakened.syntax-checked with x86_64-w64-mingw32-gcc: needs a Windows build, see Must be tested.)
🤖 Generated with Claude Code
Tested in game: RTX 5090, NVIDIA 620.70, Linux (CachyOS): played in a dungeon at a Frame rate cap of 240 (about 120 fps), fights ended by beating the enemy and by walking away: the battle music stopped every time (3 of 3; before, 1 of 4 fight ends left it playing until the next fight, once at a lower volume). The game's memory was watched meanwhile: the one-frame change flags the music manager had missed now reach it on its next run (8.4 ms later). Headless, Link's house: the music manager's clock 1.000 of real time at caps 120 and 240 (0.576 / 0.551 before), 0.999 at a cap of 60.
@Beanstalk windows, any GPU: build this PR (it needs a Windows llvm-mingw build; I could only build and play it on Linux), set the Frame rate cap to 120, then start and end a few fights (beat the enemy, and walk away from one), expecting the battle music to stop after each fight and not to stay at a lower volume. The music manager's log line to look for:
oot_patches: the music manager's change flags kept above 60 fps in code_045.cin the build, and nooot_patches: WARNINGabout the music manager.@CraftyCorvid only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it.@llun approval of
065f512recorded. This diff touches sensitive paths, so a second member ofBigBeansmust approve it too.Beanstalk test farm
Commit
065f512· tier double-reviewed · approved by llun (👍 on CraftyCorvid's request), mooki · dashboardWhat will be tested · AI plan (
gpt-6.1-terra)On Windows, timed lift builds compare build times, followed by a short Dodongo's Cavern gameplay smoke test at 60 and 120 FPS caps. The cap comparison exercises the changed high-FPS path and its 60 FPS control; the gameplay runs take about 13 minutes per tester, apart from builds. Crashes, failed map transitions, or a substantial frame-time regression fail the plan. The farm cannot verify battle-music playback, fight outcomes, or the music clock, so the reported audio fix remains unverified by this plan.
0or2.Done (started 20:42 UTC, last report 23:00 UTC). Comment
@Beanstalkto run it again.This diff touches sensitive paths, so it needs two members of
BigBeans:nx2/oot_patches.pyNVIDIA GeForce RTX 4090, 621.14.0frame_rate_cap=0frame_rate_cap=2Measurements · windows
Verdict: pass on windows (1/1 report): no rule failed and no PR run crashed.
Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu
NVIDIA GeForce RTX 4090, 621.14.0AMD Ryzen 7 7700X 8-Core Processor, 32 GB RAMScene: dodongo-smoke, from a new save; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); dodongo-smoke: 1 game start a side, cavern 20 s after 5 s warm-up; timed builds: main and this PR each built 2 times a cache, alternating, each a whole build in a fresh folder (lift; shader preparation not timed); each number the median of the runs, then of 1 report
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)ac77875065f512frame_rate_cap=0· cavern · frame time (p99) (ms)frame_rate_cap=2· cavern · frame time (p99) (ms)Build times (each a median of the timed builds; caches: lift = the lift again (no kept lift, main's compiled objects kept))
ac77875065f512Flags and settings
frame_rate_cap0,2Markdown for the PR description
@Beanstalk wrote in #1224 (comment):
@Beanstalk
WIP: fix(fps): the battle music stops after a fight above a 60 fps capto fix(fps): the battle music stops after a fight above a 60 fps cap