Skip to content

fix(oot): scale water surface simulation substeps in float above 60 FPS - #2400

Merged
ly05010419 merged 1 commit into
ly05010419:mainfrom
TAKAGIVEGETA:fix/oot-water-substeps
Nov 26, 2026
Merged

ly05010419 merged 1 commit into
ly05010419:mainfrom
TAKAGIVEGETA:fix/oot-water-substeps

Conversation

@TAKAGIVEGETA

@TAKAGIVEGETA TAKAGIVEGETA commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes frozen / lingering water surface ripples in The Legend of Zelda: Ocarina of Time (update 131072) when running above 60 FPS on Mac with patch_oot_timestep().

Root Cause

In the water surface simulation dispatcher (main+0x472e0), the game computes the number of PDE simulation substeps per frame as:

  • main+0x475ac: ldr s0, [x19] — loads the VFR step ratio (60 / actual_fps)
  • main+0x475f4: ldr w8, [x19, #0x4c] — loads the base substeps per 60 Hz frame (6)
  • main+0x475f8: fcvtzs w9, s0 — truncates the float VFR ratio to an integer
  • main+0x4760c: mul w8, w8, w9
  • main+0x47614..0x47618: cmp w8, #1; b.lt 0x49540

When actual_fps > 60 (e.g. 72–90 FPS, or even minor sub-frame jitter at 60 FPS), s0 < 1.0 truncates to w9 = 0, giving total_substeps = 0. The dispatcher skips the entire compute simulation loop (cs26 + N × cs25), leaving existing ripples frozen in the ping-pong heightfields while normal generation (cs29) keeps reading them until frame rate dips below 60 FPS.

(Scanning all references to the VFR global main+0x4c7e890 confirmed main+0x475f8 is the only site truncating s0 < 1.0 to 0.)

8560aaf120afedc05b01e3babcc4d30f 9be3f8cd2d3098bac041eaa62fb9aa02 image

Fix

  • Add an 8-instruction Mac-only veneer inside patch_oot_timestep() (games/oot/runtime/oot_timestep.h) placed at text padding +384..+416 (between the resolution veneers ending at +372 and OOT_VR_CALL_STUB at +512), verifying the 10-word context at main+0x475f4..0x47618 and zero padding before patching main+0x4760c.
  • Replace mul w8, w8, w9 with round_nearest_even(w8 * s0), clamped to >= 1 when w8 * s0 > 0:
    • Pause / s0 <= 0 / NaN → 0 substeps (unchanged)
    • 30 FPS (s0 = 2.0) → 12 substeps (360/s, unchanged)
    • 60 FPS (s0 ≈ 1.0, including 0.99 jitter) → 6 substeps (360/s)
    • 79 FPS (s0 = 0.76) → 5 substeps
    • 90 FPS (s0 = 0.667) → 4 substeps (360/s)
    • 120 FPS (s0 = 0.50) → 3 substeps (360/s)
  • Both ping-pong height/velocity indices flip per substep in the loop body (main+0x48700..0x4871c) and cs29 reads the active index, so odd and even substep counts are safe.
  • Excluded from iOS / TOTK_EXPORT_IOS, and disabled when OOT_REALTIME=0.
  • Extended games/oot/tests/oot_timestep_native.{py,c} to execute and verify the actual veneer words natively on arm64 (including s0 preservation and edge cases).

Testing

  • Mac gameplay (OOT update 131072, Apple Silicon Mac):
    • Rebuilt Ocarina of Time.app via update_runtime.py.
    • Played ~70 minutes (306,300 rendered frames, ~72 FPS average, 90 FPS cap, 1920×1080), including swimming in Hyrule Field's river at 72–90 FPS: ripples propagate and dissipate normally with no frozen rings, and ocarina.log recorded zero [RED] / crash / Metal validation errors.
  • Unit & native tests (on this branch rebased onto main):
    • python3 games/oot/tests/oot_timestep_native.py --work-dir <tmp> — passed.
    • python3 -m unittest discover -s tests -p "*oot*" — 291 tests OK (1 skipped).
    • xcrun clang -std=c11 -O2 -Wall -Wextra -Werror ... -fsyntax-only games/oot/runtime/game_patches_ns2.c — passed.
  • iOS: Not built or tested (oot_timestep.h is Mac-only and excluded from the iOS project and TOTK_EXPORT_IOS).

In update 131072, the water surface simulation dispatcher (main+0x472e0) truncates the VFR step ratio with fcvtzs w9, s0 at main+0x475f8 before multiplying by the base substep count (6) at main+0x4760c. Above 60 FPS (or sub-frame jitter at 60 FPS), s0 < 1 truncates to 0 and skips the compute simulation loop while normal generation keeps reading frozen ripples from the ping-pong heightfields.

Add an 8-instruction Mac veneer in patch_oot_timestep() (at text padding +384, between the resolution veneers and OOT_VR_CALL_STUB) that replaces the multiply at main+0x4760c with round-to-nearest-even(w8 * s0), clamped to >= 1 when w8 * s0 > 0 (preserving 0 on pause, s0 <= 0, or NaN). Extend oot_timestep_native to verify the veneer words natively on arm64.
@ly05010419
ly05010419 merged commit 3e696c2 into ly05010419:main Nov 26, 2026
1 check passed
zplzmzmpl pushed a commit to zplzmzmpl/MacNativeGames that referenced this pull request Nov 27, 2026
…n float above 60 fps

(cherry picked from commit 3e696c2)
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.

2 participants