WIP: feat(modapi): game.flags and flagChanged take a mod's content flags by their ids (":Seen") #2287
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!2287
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/modapi-flags-by-id"
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
The runtime takes a mod's content by its id (
items.grant(":Rupee7")), but its flags only by their game names. A modthat declares a flag with
content.flag({ id: "Seen" })had to write"M1a2b3c4d.Seen"everywhere it used it: theFNV-1a hash of its own id, worked out by hand (the flags feature mod computed it with a loop in its script; Magic Singing
hardcoded it).
content.mdlisted this as "not yet".Now
game.flags.get,hasandset, andflagChanged's filter, take a mod's content flags by their ids, as the restof the runtime takes its content:
":id"is the calling mod's own flag,"owner/name:id"another mod's; each is read as the game namecontent.flagmakes (the mod's word and the id). A game name is taken as it is.
flagChangedtells the flag's game name ine.flag, whichever way the listener named it: the filter is kept as thegame name when the listener subscribes, so it matches the event.
:that names no flag (no id after it, an id that is not a declaration's) isUnknownNameError;has()is false.flag()andsetFlag()take the same names, in the fake game and (throughgame.flags) in the game.Read first:
modrt_flag_nameandmodrt_watch_refusedinhost/modapi/game_events.c,mod_content_flag_refinhost/mod_content.c, then the three callers inservices_game.candwrites.c. The fake game:_flagNameinlib/fake-game.js,services.js, and the kept filter inlib/prelude.js.Part of #1958's Modding API; targets
mod-api. It and #2267 both touch the flags feature mod's tests and the generatedAPI files, so whichever merges second takes a short rebase. A later change to #2268 (held for the hooks rework) can name
a flow patch's flags the same way, with this same
mod_content_flag_ref.Testing
Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24, an adult save in Kakariko Village, with
#2267 and #2268 beside it. Magic Singing, changed to name its flags by their ids (
":ButtonsToo") with no hash in itsscript: its script's
flags.set(":ButtonsToo", 1)was written asgame.flags.set Me1c8f220.ButtonsToo 0 -> 1oncein play, and a song played on the buttons went on as the setting says. Checks:
tests/test_game_flag_ids.py(thenaming cut from the sources against an FNV-1a of its own: a game name as it is, the own flag, another mod's, six names
refused; and that get, has, set and flagChanged's on() name the flag first); in the fake game, the flags feature mod (its
own flag read, written and watched as
":Seen",e.flagits game name, a bad name refused), and Magic Singing's owntests;
modapi/generate.py --check;test_game_watch.py,test_game_pause.py,test_heart_containers.py.Still to test:
mise run test, includingtest_modrt.py(the real runtime over the scripted game, which linksgame_events.c) (by hand, or CI)Measurements
Nothing to measure: a name without a
:costs onememchr; a:idname is one FNV-1a over the mod's id per call, andflagChangednames it once, aton().Risks
A game flag's name never holds a
:, so no name that worked before reads anything else now. A filter given as:idtells
e.flagas the game name, which a listener comparinge.flagto the text it gave would not expect: the docs andthe record's doc say so.
Checklist
Ready for review
mod-api; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).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. (the flags feature mod uses":Seen")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
The site forms M2's conversions need beyond entry and after: - entry with can_return: if (on && fn(c)) return;, as nx2/entry_hooks.py's hooks; - return: the function lifted as f_1<address> under a wrapper f_<address> that calls it and then the hook, so every way out (ret, tail call, indirect jump) runs it and the body keeps its locals; - before: before the instruction at offset, of any kind, after its label; - replace: if (on) fn(c); else { the instruction }, a plain instruction only; - branch: before a conditional branch, a non-zero answer takes it. before, replace and branch are emitted by lines of nx2/fastfp.py's copy of the kit's emit_function tagged "# (hooks)" (tests/test_fastfp_override.py takes both tags out before comparing with the kit), from Lifter.site_before, site_replace and site_branch, sent to the emit's processes with the others. Every callback is int fn(Ctx *): only can_return and branch read the answer (hos_text_letter_step returns 0). Inline data rules (rule = mul_f32, scale_f32, note_u64): the compiler's own C inlined at the site, reading a host value named in host/game/sites.def (HOS_VALUE, the feature's own variable): one load and a predicted branch when off, no call. The host fills a value with one atomic store and a table by publishing a new one with one pointer exchange, the old kept until a quiescent point (host/game/sites.c hos_value_set, hos_table_publish, hos_tables_quiesce): no lock on the game's side. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e3nBDxBnhodLguFyEtThe hook site callbacks became int (an entry that can return, a branch) after the text.letterStep site was written, and the two checks still cut "void hos_text_letter_step(", which no source has: both would stop on the missing marker. sites.h and docs/hooks.md said the sites' several subscribers come with the script runtime, which is in without them: they come with the API's hook namespaces. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e3nBDxBnhodLguFyEtThe cloth solve job's text patch (nx2/oot_patches.py patch_cloth_solve: if (!hos_oot_cloth_solve(the frame step at 0x84d61fc8)) { x0 = 0; return; } first in f_81b47080) is the site cloth.solve, the job's entry with can_return, its callback host/oot_sites.c's hos_site_cloth_solve: it reads the step as the patch did and answers 1, x0 = 0, for a frame the gate holds. Identity: the same call with the same word read, before the job saves anything (its first line, the prologue's store, comes after the entry hook as it came after the patch); a held frame returns with x0 = 0 and the stack pointer as given. tests/test_oot_cloth_60.py builds the job with the emitted hook and with the patch's line side by side and checks they solve and hold the same frames in every case (240, 144, 120, 60 and 30 fps, a cap of 60, a step of 0 and NaN, a load), for HOS_FPS_CLOTH_60 unset, 1 and 0. The patch, its constants and its report line are deleted; the job may now get locals. Gates: gate 1 (nx2/test_leaf.py with the table) and gate 3 (Zora's Domain near King Zora at a cap of 240 with HOS_FPS_CLOTH_60=1: the cloth solved some 60 times a second, HOS_FPS_LOG's counts as on main) need a lift and a game run. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e3nBDxBnhodLguFyEtThe camera centering's text patch (nx2/oot_patches.py patch_camera_centering: if (hos_disable_camera_centering()) { x25 = x26; goto L_80645ad8; } on the fall-through of f_80644c80's b.ne at L_8064720c, the follow camera's movement yaw) is the site camera.followYaw, a jump site before +0x2590 to +0xe58, its callback host/oot_sites.c's hos_site_camera_follow_yaw: with the row on, x25 = x26 and the answer 1. Identity: the same call at the same point (+0x2590 is the b.ne's fall-through and no label: nothing else reaches it, so a before site there runs only where the patch's line ran), the same register written, the same label jumped to. The function keeps every flag store now (the jump's edge, which the flow analysis does not see); the patch's goto was not seen either, so this keeps more, never less. The signature takes the b.ne, the call the movement path starts with and its x25 = x26. tests/test_camera_centering.py checks the site and runs a block with the emitted hook and one with the patch's line, row off and on: the same way out, the same registers. The patch, CAM_HEAD and its report entry are deleted: f_80644c80 is no longer named by nx2/oot_patches.py. Gates: gate 1 (nx2/test_leaf.py with the table) and gate 3 (walking with the row on and off on a fixed save: the yaw follows Link's movement only with it off, as on main) need a lift and a game run. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e3nBDxBnhodLguFyEtThe runtime takes a mod's content by its id (items.grant(":Rupee7")), but its flags only by their game names: a mod wrote "M1a2b3c4d.Seen", the hash of its own id worked out by hand (the flags feature mod computed it with FNV-1a in its script). game.flags.get, has and set and flagChanged's filter now take ":Seen", the calling mod's own flag, and "owner/name:Seen", another mod's, as content.flag names them. host/mod_content.c mod_content_flag_ref names it (the mod's word and the id); host/modapi/game_events.c modrt_flag_name hands a game name through as it is and a name with a ":" as that flag's game name, or refuses it (UnknownNameError: a ":" with no declaration's id after it; has() false). flagChanged keeps a ":id" filter as its game name, so the event's flag (its game name, whichever way the listener named it) matches it: modrt_watch_refused may give back another block, which bindings.c hands over by address. The fake game names them the same way (lib/fake-game.js _flagName; its subscribe answers with the filter kept, which lib/prelude.js matches on). The flags feature mod names its own flag ":Seen" and watches it; tests/test_game_flag_ids.py runs the naming, cut from the sources, against FNV-1a of its own, and checks that get, has, set and flagChanged's on() name the flag first. Co-Authored-By: Claude Opus 5.5 <[email protected]>Tested in game: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24, an adult save in Kakariko Village, sandbox off (for the control bridge), with #2267 and #2268 beside it. Magic Singing names its flag by id in its script: flags.set(":ButtonsToo", 1) was written as game.flags.set Me1c8f220.ButtonsToo 0 -> 1 once in play (before that, 'write not now (not in play)' with the same game name), and a Song of Storms played on the buttons went on as that flag says.
50a54a61bdf99bffce6eView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.