refactor(host): one reader for longshot_options.ini's lines, not six #979

Open
zeldaootr wants to merge 7 commits from zeldaootr/Longshot:host-options-reader into main
Contributor

Type: refactor · Risk: medium · Tested on: Linux, Steam Deck (RADV VANGOGH) · Needs: Windows, any GPU

Why

Nothing a player should notice: this is a code-structure change. Main has one place that says where longshot_options.ini is (host/options_path.c), but six files of the runtime still each open it and loop over its lines their own way (nn_applet.c, nn_hid.c, nn_audio.c, prompts.c, discord_rpc.c, hos_main.c), and nn_vi.c declared hos_ini_option by hand. A change to how a line is read had to be made six times. Now one header reads the lines, with its own check. No issue in the tracker covers it.

What changed

One header-only reader over hos_options_file() replaces the six loops; it does not find the file. Each reader sees what it saw before, but for one case named below.

  • host/options_read.h (new):
    • hos_options_each: the one fgets loop, a visit per key=value line, the line buffer the caller's.
    • hos_options_text and hos_options_int: the last line that sets a key, as text or as atoi reads it.
  • host/nn_applet.c: ini_text and hos_ini_option are gone; handheld_profile and output_res read through the header. host/nn_vi.c includes it for frame_rate_cap instead of declaring hos_ini_option.
  • host/nn_audio.c (au_menu_output), host/prompts.c (choose_face), host/hos_main.c (the aspect ratio's ultrawide and options_version): one call each.
  • host/nn_hid.c: binds_load visits every line through hos_options_each.
  • host/discord_rpc.c: read_app_id keeps its own 128-byte line, and its own rule that a later invalid discord_app_id= does not erase an earlier valid one.
  • Tests: tests/test_options_file.py + tests/options_file_test.c (new): a missing file, an empty path, an absent key, a repeated key, \r\n, an empty value, a line longer than the buffer, a key that is another's prefix. Nine checks that paste or pin the changed code compile the real header now: test_output_resolution, test_frame_rate_cap_step, test_audio_output_menu, test_bound_keys, test_ocarina_note_bindings, test_ocarina_notes, test_walk_key, test_pad_layout, test_aspect_default.

What differs:

  • A value is cut at a \r that no \n follows, for every reader. The readers that took a number read past it before (audio_output=\r3 was 3 and is 0; a file with CR-only line ends gave binds_load a comma from the next line). The menu writes no such line.
  • hos_main.c reads the file twice at startup (once per key) where it read it once.

The header is not part of options_path.c, and does not include options_path.h: the checks that paste a reader bring a static hos_options_file of their own and link no .c.

Not touched, on purpose: host/hos_crash_dialog.c (it prints the whole file), host/audio_output_devices.c (main's #1001, added while this was open: it reads a device id with a reader and line length of its own), the renderer's own readers in gpu/vk (another module), and the menu, which writes the file.

Measurements

Verdict: nothing to measure: the readers run once at startup, off any per-frame path. It passes: every row the six readers take was seen to apply in the game on a Steam Deck.

Flags and settings

None.

Testing

Tested:

  • In the game, on Steam Deck OLED, SteamOS 3.9.5 (20261023.100), AMD Custom GPU 0932 (RADV VANGOGH), Mesa 26.2.0-devel: headless at 1280x720 with the fixture save, from empty shader caches (no preparation): the child save in Kokiri Forest settled 20 s, a teleport to Hyrule Field, 15 s to settle and 30 s there, driven through the control bridge. Each run to the end. The build that ran is the three branches of this set merged on main a8a30c22 (v3.0.0-rc.4-120-gd01328f1: this PR with the retire-later holder and the switch rule), built for x86-64-v3, not this branch alone; this branch has been rebased onto bbe421f5 since (2026-11-16); the one conflict was an #include line in nn_audio.c beside main's #1001. The log, with the fixture's options file (output_res=1280x720, no bindings) and then with key_x=75, key_y=74,76, options_version=3, frame_rate_cap=1, audio_output=2, button_prompts=2 and a discord_app_id added:
    Reader The fixture's file With the lines added
    nn_applet.c, output_res oe: output resolution 1280x720 the same
    nn_vi.c, frame_rate_cap no cap line vi: frame rate cap 90: pacing, the game's limiter and its time step follow it
    nn_hid.c, binds_load no line (no bindings) hid: 2 controls from longshot_options.ini
    prompts.c, button_prompts prompts: auto: controller "Steam Deck Controller": steamdeck prompts: xbox icons, 16 buttons on these pad's controls
    nn_audio.c, audio_output audio: stereo for the game (the default output has 2 channels) audio: 5.1 for the game (the Insert menu's Audio output)
    discord_rpc.c, discord_app_id discord: no Discord client is running; trying again every 15 s the same (an id was there to try with)
  • The checks of the readers by name (28 of them) on Linux x86-64 (Ryzen 7 5700U), clang 23.1.5, gcc, glslang, spirv-val, the Vulkan and SPIR-V headers, here and on main. A full python3 -I -B tests/run_all.py on main e4d035e9 and on this branch rebased onto it, the same day and PC (6 at once, the PC busy with other builds): main 609 passed, 28 failed, 26 skipped; this branch 611 / 27 / 26. By name every failure here is one of main's but tests/test_pipeline_cache_file.py, a timed check that passes alone on both; test_oot_state_tap and test_pipeline_state_sources failed on main's run only (timing). The branch was then rebased onto main bbe421f5 (two files of main's, neither touched here) and pushed; the full run was not repeated for that step.
  • A reviewer's differential run before this opened: the old loops copied beside the new header, 300,000 random files of keys, =, commas, digits, spaces, \r, \n and lines past 80 bytes. 1,688 differed, every one by a lone \r (above); none with it out of the alphabet.
  • The seven touched host/*.c, -fsyntax-only: gcc for Linux and llvm-mingw 20261104 for Windows, with a stand-in for the generated a64_suyu.h. Clean.

Not tested: Windows, in the game. hos_main.c's ultrawide on a screen wider than 16:9 (the run was headless at 16:9, so both answers give the same picture). test_mods_size_table (no hos_options_file at its link) and test_walk_key (its own code no longer matches nn_hid.c) fail on main, so they say nothing about prompts.c and the Walk key's part of binds_load here.

Must be tested:

  • Windows, any GPU: an install with saved bindings, an Output resolution, a Frame rate cap, an Audio output and Button prompts chosen: start the game, expecting each to apply as on main and hid: N controls from longshot_options.ini in the log (Test Farm: @Beanstalk windows, a start with saved options; or by hand)

Risks

What could break: a saved option ignored at startup (bindings back to defaults, the wrong output size, speakers or prompts) if a reader no longer finds a key. It touches nn_applet.c, nn_vi.c and discord_rpc.c next to the lines the switch-rule PR of this set touches: whichever lands second rebases.
Turning it off: revert the commit.
Compatibility: Nothing changes: longshot_options.ini is read as before, but for a value with a lone \r in it.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main (bbe421f5, 2026-11-16; head c1698a93).
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths.
**Type:** refactor · **Risk:** medium · **Tested on:** Linux, Steam Deck (RADV VANGOGH) · **Needs:** Windows, any GPU ## Why Nothing a player should notice: this is a code-structure change. Main has one place that says where `longshot_options.ini` is (`host/options_path.c`), but six files of the runtime still each open it and loop over its lines their own way (`nn_applet.c`, `nn_hid.c`, `nn_audio.c`, `prompts.c`, `discord_rpc.c`, `hos_main.c`), and `nn_vi.c` declared `hos_ini_option` by hand. A change to how a line is read had to be made six times. Now one header reads the lines, with its own check. No issue in the tracker covers it. ## What changed One header-only reader over `hos_options_file()` replaces the six loops; it does not find the file. Each reader sees what it saw before, but for one case named below. - `host/options_read.h` (new): - `hos_options_each`: the one `fgets` loop, a visit per `key=value` line, the line buffer the caller's. - `hos_options_text` and `hos_options_int`: the last line that sets a key, as text or as `atoi` reads it. - `host/nn_applet.c`: `ini_text` and `hos_ini_option` are gone; `handheld_profile` and `output_res` read through the header. `host/nn_vi.c` includes it for `frame_rate_cap` instead of declaring `hos_ini_option`. - `host/nn_audio.c` (`au_menu_output`), `host/prompts.c` (`choose_face`), `host/hos_main.c` (the aspect ratio's `ultrawide` and `options_version`): one call each. - `host/nn_hid.c`: `binds_load` visits every line through `hos_options_each`. - `host/discord_rpc.c`: `read_app_id` keeps its own 128-byte line, and its own rule that a later invalid `discord_app_id=` does not erase an earlier valid one. - Tests: `tests/test_options_file.py` + `tests/options_file_test.c` (new): a missing file, an empty path, an absent key, a repeated key, `\r\n`, an empty value, a line longer than the buffer, a key that is another's prefix. Nine checks that paste or pin the changed code compile the real header now: `test_output_resolution`, `test_frame_rate_cap_step`, `test_audio_output_menu`, `test_bound_keys`, `test_ocarina_note_bindings`, `test_ocarina_notes`, `test_walk_key`, `test_pad_layout`, `test_aspect_default`. What differs: - A value is cut at a `\r` that no `\n` follows, for every reader. The readers that took a number read past it before (`audio_output=\r3` was 3 and is 0; a file with CR-only line ends gave `binds_load` a comma from the next line). The menu writes no such line. - `hos_main.c` reads the file twice at startup (once per key) where it read it once. The header is not part of `options_path.c`, and does not include `options_path.h`: the checks that paste a reader bring a `static` `hos_options_file` of their own and link no `.c`. Not touched, on purpose: `host/hos_crash_dialog.c` (it prints the whole file), `host/audio_output_devices.c` (main's #1001, added while this was open: it reads a device id with a reader and line length of its own), the renderer's own readers in `gpu/vk` (another module), and the menu, which writes the file. ## Measurements **Verdict:** nothing to measure: the readers run once at startup, off any per-frame path. It passes: every row the six readers take was seen to apply in the game on a Steam Deck. ### Flags and settings None. ## Testing **Tested:** - In the game, on Steam Deck OLED, SteamOS 3.9.5 (20261023.100), AMD Custom GPU 0932 (RADV VANGOGH), Mesa 26.2.0-devel: headless at 1280x720 with the fixture save, from empty shader caches (no preparation): the child save in Kokiri Forest settled 20 s, a teleport to Hyrule Field, 15 s to settle and 30 s there, driven through the control bridge. Each run to the end. The build that ran is the three branches of this set merged on main a8a30c22 (`v3.0.0-rc.4-120-gd01328f1`: this PR with the retire-later holder and the switch rule), built for x86-64-v3, not this branch alone; this branch has been rebased onto bbe421f5 since (2026-11-16); the one conflict was an `#include` line in `nn_audio.c` beside main's #1001. The log, with the fixture's options file (`output_res=1280x720`, no bindings) and then with `key_x=75`, `key_y=74,76`, `options_version=3`, `frame_rate_cap=1`, `audio_output=2`, `button_prompts=2` and a `discord_app_id` added: | Reader | The fixture's file | With the lines added | |---|---|---| | `nn_applet.c`, `output_res` | `oe: output resolution 1280x720` | the same | | `nn_vi.c`, `frame_rate_cap` | no cap line | `vi: frame rate cap 90: pacing, the game's limiter and its time step follow it` | | `nn_hid.c`, `binds_load` | no line (no bindings) | `hid: 2 controls from longshot_options.ini` | | `prompts.c`, `button_prompts` | `prompts: auto: controller "Steam Deck Controller": steamdeck` | `prompts: xbox icons, 16 buttons on these pad's controls` | | `nn_audio.c`, `audio_output` | `audio: stereo for the game (the default output has 2 channels)` | `audio: 5.1 for the game (the Insert menu's Audio output)` | | `discord_rpc.c`, `discord_app_id` | `discord: no Discord client is running; trying again every 15 s` | the same (an id was there to try with) | - The checks of the readers by name (28 of them) on Linux x86-64 (Ryzen 7 5700U), clang 23.1.5, gcc, glslang, spirv-val, the Vulkan and SPIR-V headers, here and on main. A full `python3 -I -B tests/run_all.py` on main e4d035e9 and on this branch rebased onto it, the same day and PC (6 at once, the PC busy with other builds): main 609 passed, 28 failed, 26 skipped; this branch 611 / 27 / 26. By name every failure here is one of main's but `tests/test_pipeline_cache_file.py`, a timed check that passes alone on both; `test_oot_state_tap` and `test_pipeline_state_sources` failed on main's run only (timing). The branch was then rebased onto main bbe421f5 (two files of main's, neither touched here) and pushed; the full run was not repeated for that step. - A reviewer's differential run before this opened: the old loops copied beside the new header, 300,000 random files of keys, `=`, commas, digits, spaces, `\r`, `\n` and lines past 80 bytes. 1,688 differed, every one by a lone `\r` (above); none with it out of the alphabet. - The seven touched `host/*.c`, `-fsyntax-only`: gcc for Linux and llvm-mingw 20261104 for Windows, with a stand-in for the generated `a64_suyu.h`. Clean. **Not tested:** Windows, in the game. `hos_main.c`'s `ultrawide` on a screen wider than 16:9 (the run was headless at 16:9, so both answers give the same picture). `test_mods_size_table` (no `hos_options_file` at its link) and `test_walk_key` (its own code no longer matches `nn_hid.c`) fail on main, so they say nothing about `prompts.c` and the Walk key's part of `binds_load` here. **Must be tested:** - Windows, any GPU: an install with saved bindings, an Output resolution, a Frame rate cap, an Audio output and Button prompts chosen: start the game, expecting each to apply as on main and `hid: N controls from longshot_options.ini` in the log (Test Farm: @Beanstalk windows, a start with saved options; or by hand) ## Risks **What could break:** a saved option ignored at startup (bindings back to defaults, the wrong output size, speakers or prompts) if a reader no longer finds a key. It touches `nn_applet.c`, `nn_vi.c` and `discord_rpc.c` next to the lines the switch-rule PR of this set touches: whichever lands second rebases. **Turning it off:** revert the commit. **Compatibility:** Nothing changes: `longshot_options.ini` is read as before, but for a value with a lone `\r` in it. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main` (bbe421f5, 2026-11-16; head `c1698a93`). - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [x] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths.
Visit every `key=value`, the text of a key (last line wins) and its integer, over `hos_options_file()`, with a game-free check.

Assisted-by: Claude Fable 5.2
Co-Authored-By: Claude Fable 5.2 <[email protected]>
`hos_ini_option` and `ini_text` give way to `hos_options_int` and `hos_options_text`; `nn_vi.c` no longer re-declares an `nn_applet.c` function.

Assisted-by: Claude Fable 5.2
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Assisted-by: Claude Fable 5.2
Co-Authored-By: Claude Fable 5.2 <[email protected]>
The checks that paste `nn_hid.c`'s binding code include the header after their `hos_options_file` stub.

Assisted-by: Claude Fable 5.2
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Assisted-by: Claude Fable 5.2
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Keeps its own 128-byte line buffer, and that a later invalid id leaves an earlier valid one.

Assisted-by: Claude Fable 5.2
Co-Authored-By: Claude Fable 5.2 <[email protected]>
refactor(host): hos_main.c reads ultrawide and options_version through options_read.h
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
e436d19538
Assisted-by: Claude Fable 5.2
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Author
Contributor

Tested in game: Steam Deck OLED, SteamOS 3.9.5 (20261023.100), AMD Custom GPU 0932 (RADV VANGOGH), Mesa 26.2.0-devel. A build of this branch merged with the two other branches of its set on main a8a30c22 (v3.0.0-rc.4-120-gd01328f1), headless at 1280x720, from empty shader caches: the child save in Kokiri Forest, a teleport to Hyrule Field and 45 s there, four runs, each to its end with no device loss. With the fixture's options file the log has 'oe: output resolution 1280x720', auto prompts and stereo; with key_x, key_y, frame_rate_cap=1, audio_output=2, button_prompts=2 and a discord_app_id added it has 'hid: 2 controls from longshot_options.ini', 'vi: frame rate cap 90', 'prompts: xbox icons' and 'audio: 5.1 for the game (the Insert menu's Audio output)'.

Tested in game: Steam Deck OLED, SteamOS 3.9.5 (20261023.100), AMD Custom GPU 0932 (RADV VANGOGH), Mesa 26.2.0-devel. A build of this branch merged with the two other branches of its set on main a8a30c22 (v3.0.0-rc.4-120-gd01328f1), headless at 1280x720, from empty shader caches: the child save in Kokiri Forest, a teleport to Hyrule Field and 45 s there, four runs, each to its end with no device loss. With the fixture's options file the log has 'oe: output resolution 1280x720', auto prompts and stereo; with key_x, key_y, frame_rate_cap=1, audio_output=2, button_prompts=2 and a discord_app_id added it has 'hid: 2 controls from longshot_options.ini', 'vi: frame rate cap 90', 'prompts: xbox icons' and 'audio: 5.1 for the game (the Insert menu's Audio output)'.
zeldaootr changed title from WIP: refactor(host): one reader for longshot_options.ini's lines, not six to refactor(host): one reader for longshot_options.ini's lines, not six 2026-11-16 00:13:54 +00:00
zeldaootr force-pushed host-options-reader from e436d19538
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to c1698a9397
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 5s
2026-11-16 05:04:42 +00:00
Compare
Author
Contributor

Rebased onto main bbe421f5; the description names what changed with it.

Rebased onto main bbe421f5; the description names what changed with it.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 5s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
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 'host-options-reader:zeldaootr-host-options-reader'
git switch 'zeldaootr-host-options-reader'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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
MagicBeanDev/Longshot!979
No description provided.