refactor(game)!: the game's code in game/, behind game.h and game_host.h #2411
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2411
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:game-boundary"
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?
Summary
Three pieces of work are about to run side by side: the mod API (and the later Rust port of the game's code), a Rust
host and a Rust renderer. Today the game's code is spread through
host/andgpu/vk/, so all three would edit thesame files. This draws one line between the generic Switch emulation (
host/,gpu/) and everything that is aboutOcarina of Time (
game/), with one header each way, so each track works on its own side.It moves code and adds an interface. No behaviour changes. The C stays C, except Field of view, ported to Rust as
the pattern for the work after.
Based on
mainat3072dda4, which includes the Rust builder from #2286. The 11 game-boundary commits begin withrefactor(game): the hook sites, the game's flags and its frame phases move to game/. The rebase carries forwardmain's heap-retry hooks and widescreen title-card code through the file moves. The heap-test switches initializethrough
game_init().What it does, one commit each:
The game's C moves to
game/, as it is, one area per commit:game/sites/(tables),game/sites.{c,h,def}, the game's flags, the frame phases;host/oot_*, the cheats, texts, the game folder's layout, the HUD on wide screens, Discord,the cheat items' list (from
gpu/vk/);hos_main.c's game half (the Debug tab's tools, the bridge's game commands, the opening's skip, the save trace,Link's pose for the performance summary):
game/oot_tools.c, byte for byte. The start-up stays.The builder follows: the site tables, the lift's host scan and entry hooks, the compile plan (game/*.c with the
host's flags, into the same binary), the carried sources.
The two headers:
host/game_host.h: what the host gives the game (guest memory andCtx,game_call, the RomFS, logging,options, input, the frame's clock, the recordings, the prompts).
game/includes it and nothing else of the host.game/game.h: what the game gives the host and the renderer (game_init, the frame's and input's hooks, thebridge's and the recordings' game commands, the Mods and Cheats pages, the files mods replace).
game/options.h: the game's option ids, out ofvk_api.h, every value unchanged.hos_oot_stateisgame_state, and so on).The boundary check,
tests/test_game_boundary.py.Field of view in Rust:
game/crates/guest(the context, checked guest memory through the lift's own readers,the one crate with
unsafe) andgame/crates/oot(fov.rs, safe code, the same symbolhos_oot_fov, so the siteand the lift don't change).
game/oot_fov.cis gone. Players don't need cargo: the release buildsliblongshot_rs.afor each platform and carries it, keyed by its sources (build-compile'srust.rs); adeveloper's build runs cargo when the sources changed. A parity test runs the deleted C against the Rust.
The game's menu rows move to
game/menu/, as data throughgame.h(GameMenuRow, throughMkwVkHost), addedto the menu by one generic module. Keys unchanged.
Docs:
game/README.md, "The game side" in the architecture page, the AGENTS.md menu rule, the moved paths.Guest words as atomics (
guest::GuestAtomicU32/U64), for the host's sync objects in Rust (asked by the Rusthost and renderer side): checked as a read is, worked on in place with SeqCst atomics, every write marking its
page; a 32-bit word can be waited on and woken.
Read first:
host/game_host.h,game/game.h,game/README.md,game/crates/guest/src/lib.rs,game/crates/oot/src/fov.rs,builder/crates/build-compile/src/rust.rs.Different from the plan, on purpose:
build-driver'ssources::TREE) gaingame/and the Rust's (Cargo.toml,Cargo.lock,longshot-rs);scripts/longshot_builder.py game-rustbuildsliblongshot_rs.awith the pinned Rust;longshot-builder dev release dry-runfails a tree with the game's Rust and no prebuilt library of its sources.game_callstays in the host (host/game_call.c): it takes a virtual core back for the call (hos_thread.c).host/hos_wide_size.hstays in the host: it is the output picture's size, shared by host and renderer.hos_cheats_frame,game_phase_run) rather than onegame_frame; only thestart became
game_init.The review follow-up packages the game Rust archive and its key in
from-sourcebuilds, requires a caller toguarantee lifetime and compatible access when constructing a guest atomic handle, and adds the moved game paths
to the in-game test gate. The guide capture and website settings page read the same row definitions as the game.
Testing
Tested: Linux, GeForce RTX 3090, NVIDIA 620.70.06, native Vulkan with a headless control-bridge run. The
kokiri-start,market-entranceandcastle-gatesaves reached play and exited cleanly. In Kokiri Forest theField of view setting accepted 75%, 100% and 130% while the game continued presenting. Ultrawide menus, Text speed
and Text size accepted their new values. Teleport loaded Hyrule Field and returned to play. The executable was
built at
2fc2e786. The subsequent commits change the website and its tests.The guest API compile-fail checks and in-game gate test failed before their fixes and pass now.
main.reproduce on
main. The intermittent sampler admission case passed on rerun (147 of 147).Linux checks on rebased head
c2435216:test_display_startup_failure(missingbc_claimfixture stub)and
test_title_card_strips(imports the retired Pythonoot_patchesmodule) failed the same way onmain.test_dav1d_av1passed on rerun with the native Linux dav1d library.main.Earlier Linux checks on the stack on #2286's
9adf242f:tests/run_all.py: 716 passed; the failures were #2286's own five (test_linux_update,test_no_release_lookup,test_pipeline_state_computes,test_lifter,test_saveload_warm_cache, failing the same on its head) and two ofthis branch's, fixed since (
test_menu_env_overrides,test_pipeline_tour).scripts/check_host_compile.py): Linux 66units and Windows (llvm-mingw) 65 units, none failed.
tests/test_oot_fov_rust.py: the Rust and the C it replaced agree on all 44,505 cases; the planted changes are seen.tests/test_game_boundary.py: passes (540 files, 1,118 includes), and fails on a planted crossing.Still to test:
main, expecting the same results (by hand).main, expecting no difference; Field of view at 75, 100 and130 % beside the C build, expecting the same readings (by hand).
main(
@Beanstalk build and play this branch on Windows, compared with the rebase base on main).Measurements
The shared
mainbase took 6 min 6 s, including shader preparation. The branch game build took 42 s, and thepack took 44 s in all using the shared base, with no queue wait on the successful build. These are local elapsed
times from one run.
Risks
updating lifts again; the lifted code is the same.
liblongshot_rs.a; a tree whose Rust sources differ from it needscargo. The release's dry run fails if it would ship without one.
MKWVK_API_VERSIONis 48 (the menu's game rows throughMkwVkHost).Follow-ups:
hos_game_is_mkw()and the other games' leftovers: delete them, or put them behind the game interface.gpu/vk/menu/for now, as they need the renderer's hooks:game_speed(the host'sframe clock, set by the Quality presets),
damage_takenandautosave(shown and gated by the Debug tools, a syncedatomic, turned off by the debug warning),
hud_layout, the ninehud_*placement sliders andreset_hud_placement(shown only for Custom, a hint from the environment, placements packed on change, an action),
game_language(inlanguage.txt, its range from the translations). Moved:
field_of_view,text_speed,text_size,skip_title_screen,skip_opening,discord_status,ultrawide_menus.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (See Testing for the two baseline failures and the sampler rerun.)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.MKWVK_API_VERSIONbumped (MkwVkHostorMkwVkRendereringpu/vk/vk_api.hchanged).Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
https://claude.ai/code/session_016o1k1SL5owjRmyLny1gUZf
Op::Checked { fast, slow, helper, args }: the fast value unless slow holds, then a helper's. A Helper is a pure function a function carries (one block of pure ops over Op::Param, ending in a return), written once per module by its name: internal, noinline, cold, memory(none). The writer lowers the op as a branch weighted unlikely around the call and a phi. Op::IsSubnormal (llvm.is.fpclass), FBinOp::Maximum/Minimum (llvm.maximum/minimum) and Reduce::Or for the fast paths' checks. The verifier checks the new ops and every helper; sync.rs syncs nothing for one. words --count-checks counts the fast paths' runs and slow ones, for the semantics check. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e2TsN4jgNUFQPfkAq8lift::Program takes the edits (edits::plan_edits) and writes them in as each function is built: before, after or in place of an instruction, at a conditional branch, at the entry in a block of its own; a wrapped function is lifted as its body f_1<entry> and its wrapper f_<entry> (lift::Lifted), both in its unit. lift::whole plans the edits from the placed sites, host/'s entry hooks (with their size gate) and the patches' Rust data, and keys each function by its edits' key (FunctionEdits::key); EDITS_SOURCES (the edits and sites crates) is in the whole lift's key, LIFTER_SOURCES holds only the edits' lowering, so one patch's or site's change lifts again only the units it lands in. The held mechanism is gone (held.txt, --allow-held, --patched, LiftOptions::patched, LiftOutcome::{held, complete}): an instruction the lifter does not cover stops the lift. gen/edits.txt lists each edited function, its key and what changes it; LiftOutcome::edited counts them. The plan's old records are no longer read, and --check-plan compares the discovery alone. On the supported image: 294518 functions in 495 units, 99 edited, none held; two lifts give the same bytes; one site's table entry changed rewrites one unit. Tests: each form on synthetic functions, verified, through the passes and compiled by clang; the forms run against a C harness of the host's side; the whole lift's cache over a site added and its form changed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e2TsN4jgNUFQPfkAq8- hos_romfs_head of a zstd-stored file decodes its frame's first blocks (hos_zs_frame_head), not the whole file. - A decoded zstd-stored file is kept after its last close, 256 MB of closed copies at most, the least recently used let go first; the most held at once is logged as it grows. - hos_romfs_case finds folders too (mods.c's mod-only listing listed a mod folder the game also has twice), and the very spelling first (of two names that differ in case only, the other could be found). - hos_romfs_ready says whether a RomFS is there: an index open, or a folder that exists (the beside path was set always). - The index is checked at open: every entry within the .nup, sizes sane, the names in strict order (lookups are binary searches); else romfs_index_bad. - Windows: the .nup's handle is overlapped, each read waiting on its thread's event (one synchronous handle served every thread's reads one at a time); a long path is made whole by GetFullPathNameW ("..", a relative path) and extended as \\?\ or \\?\UNC\; the index's path beside image.bin takes either separator and refuses one that does not fit. tests/romfs_test.c checks each (they fail on the code before), with two names that differ in case only and damaged indexes from the Rust side. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e2TsN4jgNUFQPfkAq8The line between the generic host and renderer and the game, as two headers: - host/game_host.h: what the host gives the game. The host's own headers the game's C used (the paths, hos.h's guest memory and Ctx, game_call, the RomFS, the size tables, the settings file, env_on, the picture's size, the input recordings, the control bridge's watches), and the host's functions and values the game declared one by one where it used them. Every game/ file includes it in place of its host includes. - game/game.h: what the game gives the host and the renderer: game_init (the start's read of HOS_OOT_PROTECT_HEARTS, out of hos_main.c), the frame's and input's hooks, the control bridge's and the input recordings' game commands, the Mods and Cheats pages, the performance summary, the files mods replace, the Debug tab's inventory items. The host's files and vk_menu.cpp include it in place of the game's headers and their own prototypes. - game/options.h: the game's option ids (Field of view, Damage taken, the cheats, the HUD's layout...), out of gpu/vk/vk_api.h, which includes it; every value as it was (longshot_options.ini and the recordings hold them). The names the host used that were the game's become generic: hos_oot_{state,current_map,destination,teleport_*, age_ask,sample*,watch,poll,live_action,flight_shortcut_ready,autoload_input} are game_*, HosControlGame's oot_* fields game_*, HosControlOotWatch HosControlGameWatch. No behaviour changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>0550227861072bc50f50072bc50f50f79e6c57c6f79e6c57c67f9fe0170c7f9fe0170cfefe58d751fefe58d7519df487e4cf9df487e4cf3adc0449c52c45672d3459a7b1f86d59a7b1f86da8e25cdb39Moved onto #2286's konvtvqs (
1cf6e4c5, rebased on main): new heada8e25cdb. Same 11 commits; luvxqqxt (the #ifdef fixup) dropped since #2286 has the fix. test_game_boundary passes; the Linux and Windows game builds link.a8e25cdb39c24352169dRebased the 11 game-boundary commits onto
mainat3072dda4, which includes the Rust builder from #2286. The rebase carried the heap-retry and widescreen title-card changes through the file moves. The review fixes are now atebde8714.from-sourcebuilder now compiles and packs the game’s Rust archive with its source key.game/andlongshot-rs/.On Linux with an RTX 3090 and NVIDIA 620.70.06, all three test saves reached gameplay and exited cleanly. Field of view accepted 75%, 100%, and 130% while the game continued presenting. Ultrawide menus, Text speed, and Text size accepted their new values. The game completed a transition from Kokiri Forest to Hyrule Field.
The branch game build took 42 s, and the full pack took 44 s, with no queue wait on the successful run. The shared baseline took 6 min 6 s, including shader preparation. The three-save smoke run took 56 s.
The focused regression checks and all 24 website settings tests passed. The display-startup and title-card-strip failures also reproduce on
main, as does the website Help-page build failure. The sampler test passed on rerun. Windows gameplay and the paired parity runs are still pending.WIP: refactor(game)!: the game's code in game/, behind game.h and game_host.hto refactor(game)!: the game's code in game/, behind game.h and game_host.h