feat(modapi): world.ray and rayAll: what a ray hits by kind, which actor, one passed through #2662
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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!2662
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/modapi-world-rays"
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
world.rayis in the Rust mod API, cast on the physics step's own thread, but Preview: no run had shown it, andhas("world.ray")had no answer at all (the feature table had no line for it, so it was false even with the Previewlist lifted). A first run shows the cast works, and shows its one guess was wrong: the "scenery" preset (48) is every
layer, Link included, so a ray down through him stopped on the top of his head, 1.17 m above his feet. A colliding
camera rig casts the same ray, so its eye would stop on Link too.
This makes rays a feature, with what other engines' raycasts offer (Unity's
Raycast/RaycastAll, Unreal's linetraces, Godot's
intersect_ray), on the same step-thread design:ray(from, to, options?)andrayAll(from, to, options?)(new): the nearest hit, or every hit along theray, nearest first, each body once and an actor's several bodies one hit (at most 16).
rayAllis the game's ownevery-hit ray query (Havok's all-hits collector), built as the game builds it.
RayOptions):ground,objects,characters,wateron by default;player(Link)off, so a ray cast from Link doesn't stop on him at once. Each kind is the game's own entity layers, named in the
binary and checked a bit at a time in a run of the C mod API's rays (#2422).
ignore: an actor's key; the ray passes through its bodies (their collision group, as the game's own helpersput it in a ray's filter).
RayHit): position, normal, distance as before, pluskind,actorKey(the actor whose body it is,for a mod with
actors.read) andinside(the ray started in it).collideasks for the ground alone (Ask::scenery).has("world.ray")is true where the build has the query and both step sites;has("world.rayAll")where it alsohas the every-hit query (
rays.allInit,rays.hitsVtable,rays.hitsClear).How, in short: the query is built as before, its filter set from preset 48 and then given the asked kinds' layers, and
an
ignoregroup.ray's hit kind is the ray cast again with one kind's layers at a time until the same body (by itshandle) is hit; a ray of one kind costs one cast.
rayAllis the game's own every-hit ray query: the ray query's castmethod reads a mode at
+0x8c(0 Havok's closest-hit collector, the ground check's andray's; 1 its all-hitscollector, each hit made a record in the query's hit list at
+0x68). The game's f_83010540 (the water's surface andthe ground under it) builds one with f_83010ac0, which makes the list in the query's own buffer and sets the mode,
casts it with the same executor, walks the list and clears it;
raw_alldoes the same. One cast, whatever the raypasses through; each hit's kind is its body's own layer; each body's nearest record kept and an actor's bodies one hit
(their collision group: Link's two). Which actor a hit is: the listed actor one of whose bodies has the hit's handle, on
the main thread as the answer settles. A slot's ask and answer move behind a lock each that only the state's owner
takes, so they can carry the hits.
Read first:
game/crates/game-core/src/rays.rs(Kind,Ask,Answer,raw,aim,classify,raw_all,contacts_of,cast, the actors' bodies), its layout inlayout/rays.rs(the every-hit query's at the end), therays.*named locations ingame/sites/sites.toml, thenray_askand the answers' JSON ingame/crates/api/src/services/world.rs; the schema'sray,rayAll(world.toml) andRayHit,RayKind,RayOptions(types.toml).docs/dev/reference/world.md's Rays has what was read and run.This is #2422's change, made again on the Rust mod API's own rays; #2422 (the C mod API) can close. Part of #1958's
Modding API; targets
mod-api.Testing
Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24. In the game, quick builds of this head,
through
dev.py game-tests:kokiri-start), rays from 2 m above Link to 3 m below him, all answered a frame after they wereasked: the default kinds meet the ground at his feet (y 118.44), no actor;
player: truethe top of his head withkindplayerand his key; withignorehis key, the ground; from his chest, him at once withinside;ground: false, a miss.rayAllwithplayer: true: him once (two bodies) with his key, then the ground at hisfeet; with
ignorehis key, the ground alone.world.traveland casts straight down throughevery listed actor): the withered Deku Babas met as
characterwith their ownactorKey, byrayandrayAll;grass as
objectwith its own key; the treasure chests and trees asobject(no key: hit on a body their actor'slist does not name, as documented). Water-only rays over a grid met the stream; at open water the default kinds met
its surface as
water,water: falsethe bed 0.20 m below,rayAllthe surface then the bed. Under a ledge,rayAllgave the ledge's two ground bodies, then the water.camera.override.collide's Preview lifted, not in this branch): theeye 6 m behind Link in his house,
collideon, stopped 1.44 m from its pivot, short of the wall; off, 6.00 m; onagain, 1.44 m.
Checks:
cargo test -p game-core(rays: the query as the ground check builds it;ray's nearest by kind in amade-up world answered as the executor does: the default kinds, the characters off, Link asked for and told from the
ground, from inside him, his group passed through, a hit past the end, nothing asked; every hit through the game's
every-hit query faked as the build has it: its constructor's list and mode, an executor filling the list in no order
with Link's two bodies and a floor's two triangles, each thing once and nearest first, kinds from the bodies' layers,
the group passed through, from inside Link, a miss, nothing asked making no query, every list cleared, a list not the
build's refused; without the sort it fails; the slots),
-p api(the answers as RayHits, a key only withactors.read,rayAll's list; the features),-p modtool,-p game-sites,-p sites;cargo check --workspace --all-targets;cargo run -p schema-gen -- --check; rustfmt. Tests that fail onmod-apiitself and here, onWindows:
api'sa_content_mods_changed_module_runs_again_and_its_outputs_are_servedandmodtool'seden_and_ryujinx_mods_are_found_with_their_switches.Still to test:
camera.override.collidestays Preview here until its own change lifts it)mise run rustandmise run test(by hand, or CI)Measurements
Nothing measured: with no ray asked the step sites stay off, as before. A ray is the game's own query:
rayone castplus one per kind tried to tell its kind (none when one kind is asked),
rayAllone cast of the game's every-hitquery, whatever it passes through. They run on the physics step's thread, after its step.
Risks
Only mods that cast rays, and a colliding camera rig (still Preview), reach this code. The camera rig's ray now asks
for the ground alone (preset 48 hit Link before, the rig's own pivot). A build whose every-hit query differs (its hit
list's vtable not the build's) gets no
rayAll:has()false, nothing read or cleared. The test game still has no world to cast against:has("world.ray")is false there, asbefore (a fake caster for tests is a follow-up). The generated docs' schema hash conflicts with any other schema
change: whichever merges later needs
cargo run -p schema-genagain.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.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
world.ray was Preview, and has("world.ray") had no answer (the feature table had no line for it). A first run of the step-thread cast shows it works, and that its "scenery" preset (48) is every layer, Link included: a ray down through Link stopped on his head, as would a colliding camera rig's. - ray(from, to, options?) and rayAll (new): the nearest hit, or every hit along the ray, nearest first, each body once, at most 16. - RayOptions: ground, objects, characters, water on, player (Link) off by default; ignore, an actor's key whose bodies the ray passes through (their collision group, as f_80e86ac0 puts it in a ray's filter). - RayHit: kind (RayKind), actorKey (for a mod with actors.read), inside, beside position, normal, distance. - The camera rig's ray asks for the ground alone (Ask::scenery). - has("world.ray") and has("world.rayAll") follow game_core::rays::features. game_core::rays sets the filter's entity layers by kind (each checked a bit at a time in the C mod API's run, #2422), tells a hit's kind by casting again with one kind at a time until the same body is hit, and for rayAll casts the other kinds from just past each hit while stepping through the hit body with its own kind alone (an overlapping body of that kind met at once is the same thing: Link's two bodies are one hit). A hit's actor is the listed actor one of whose bodies has the hit's handle, found as the answer settles. A slot's ask and answer sit behind a lock each that only the state's owner takes. Tests: game-core's rays (the query with the kind's layers and the body handle; a made-up world answered as the game's executor: the kind by a one-kind cast, every hit along the ray, Link's two bodies one hit with the floor at his feet, Link passed through by his group, a ray from inside him, nothing asked a miss with no cast); api's world (the answers as RayHits, the actor's key only with actors.read, rayAll's list) and features. This replaces #2422, which made rays on the C mod API. Co-Authored-By: Claude Opus 5.5 <[email protected]>Tested in game: Windows 11, RTX 4060 Laptop, a quick build of this head: a probe mod's test passes in Link's house (dev.py game-tests, kokiri-start): rays down through Link meet the ground at his feet by default, his head with player: true and his key, the ground again with ignore his key, him at once from his chest (inside), and rayAll gives him once then the ground at his feet. Characters, objects and water are still to meet in this port.
@review
Recommendation: Request changes. The new rayAll implementation can omit or repeat hits. Its behavior and physics-step cost also need broader in-game validation.
Adds kind filters, actor identification and ignore options to world rays, plus rayAll. The API is more useful to mods, but its repeated casts add physics-step work and currently do not reliably return every body.
Blocking (4): must change before merging.
game/crates/game-core/src/rays.rs:409: The fixed five-metre search limit silently drops later bodies of the same kind. (more on the line) Do: Find the exit without a fixed five-metre cutoff, or use a query that can exclude already reported bodies; add a test with a thick body and a later body of the same kind.game/crates/game-core/src/rays.rs:413: Treating any same-kind body encountered at the current step as the previous body discards distinct overlapping or closely spaced bodies. (more on the line) Do: Track and exclude the actual hit handles while finding subsequent hits, and test distinct overlapping and closely spaced bodies of the same kind.game/crates/game-core/src/rays.rs:404: The continuation excludes only the most recent kind, so it can report a previously returned body again. (more on the line) Do: Keep the handles already returned across the entire ray and exclude them from subsequent queries; test overlapping bodies of different kinds.@​fixor@​rebasetry first). (for the author)Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
game/crates/game-core/src/rays.rs:409: The physics-step cost of the new multi-hit search has not been measured. (more on the line) Do: Measure frame times and physics-step time with representative single and multiple rayAll requests on the base and this head, using repeated runs in the same scene. (@fixdoes its part first: Replace the repeated 10 cm casts with a query that excludes reported bodies or otherwise bounds the work more tightly.)game/crates/api/src/services/camera.rs:420: The changed collision behavior and the remaining ray kinds need in-game validation on the affected paths. (more on the line) Do: Run the documented camera, character, object and water cases in game, and exercise the ray path on Linux.@fixcan do L1, L2, L3 and L4.Checks: Still running:
Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request),Third-party parts / The same as upstream (pull_request).More: does it help, other systems, switches, what was read
Does it help: Unproven: the Windows probe shows the ground and player cases working in Link's house, but characters, objects, water and the camera rig have not been exercised in this port. No timing comparison is supplied for the additional casts.
Other systems: The same casting path serves mod rays and colliding camera rigs on Windows and Linux. The reported run covers Windows and one NVIDIA GPU; Linux, the camera rig, other collision kinds and the cost of multiple rays remain untested.
Switches: No environment switches added or changed. RayOptions defaults ground, objects, characters and water on and player off; ignore is unset. Those defaults match the stated use, but the untested kinds still need validation.
Reviewed:
35dd1e3505against3391f978eb: Read the repository instructions and contribution rules, PR template, commit and diff, ray implementation and layout, world service, feature handling and schema. Skimmed the generated documentation and recorded run; the combined output of the full ray and feature file read was truncated, and the camera service and other documentation were read around the changes rather than in full. docs/review-checklist.md was absent.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no code, tests, or project scripts were run. The author reports a Windows game probe and Rust checks; CI still has checks running.
Overlaps and merge order: No overlapping pull request could be checked in the closed network; the description says this replaces #2422.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -418,2 +418,3 @@#[allow(clippy::cast_possible_truncation, reason = "a place in a map, within 100 km: a float's")]let ask = game_core::rays::Ask { from: pivot.map(|v| v as f32), to: to.map(|v| v as f32) };// (the scenery alone: never Link, whom the rig looks at, nor an actor walking by)let ask = game_core::rays::Ask::scenery(pivot.map(|v| v as f32), to.map(|v| v as f32));L5 (should fix): The changed collision behavior and the remaining ray kinds need in-game validation on the affected paths.
When: The reported probe covers ground and player on Windows, but does not exercise a colliding camera rig or this implementation's character, object and water hits; Linux has not been run.
Do: Run the documented camera, character, object and water cases in game, and exercise the ray path on Linux.
@ -129,0 +401,4 @@if first >= line.len {return Some(None);}let others = ask.kinds & !kind.bit();L3 (blocking): The continuation excludes only the most recent kind, so it can report a previously returned body again.
When: When a ray enters a player body and then an overlapping object, the cast for other kinds finds the object from inside it. Continuing after that object enables the player kind again while still inside the player, returning the player a second time and potentially alternating until the 16-hit limit.
Do: Keep the handles already returned across the entire ray and exclude them from subsequent queries; test overlapping bodies of different kinds.
@ -129,0 +406,4 @@let other = raw(g, start, ask.to, layers_of(others), ask.group)?.map(|raw| Next { raw, start, kind: Err(others) });let mut same_kind = None;let mut s = first;for _ in 0..THROUGH_STEPS {L1 (blocking): The fixed five-metre search limit silently drops later bodies of the same kind.
When: If a ray enters a ground body more than five metres thick and another ground body lies beyond it, all 50 casts still meet the first body. same_kind stays empty and rayAll omits the later body, even when the ray extends beyond it.
Do: Find the exit without a fixed five-metre cutoff, or use a query that can exclude already reported bodies; add a test with a thick body and a later body of the same kind.
L4 (should fix): The physics-step cost of the new multi-hit search has not been measured.
When: A rayAll that enters a thick body can issue 50 additional queries for that hit, and a mod may request 64 rays in a frame; this work runs on the physics-step thread.
Do: Measure frame times and physics-step time with representative single and multiple rayAll requests on the base and this head, using repeated runs in the same scene.
@ -129,0 +410,4 @@let at = line.at(s);match raw(g, at, ask.to, kind.layers(), ask.group)? {None => break,Some(x) if same(&x, h) || dist(at, x.pos) < 1e-3 => {L2 (blocking): Treating any same-kind body encountered at the current step as the previous body discards distinct overlapping or closely spaced bodies.
When: After hitting one character, a second character overlapping it, or beginning within the next 10 cm step, is returned at the new cast's start. The distance check advances through it without ever adding its handle, so rayAll does not return each body.
Do: Track and exclude the actual hit handles while finding subsequent hits, and test distinct overlapping and closely spaced bodies of the same kind.
Working on this now. My agent lost the plot at some point on RayAll especially. Havok has a built-in way to get all raycast hits, there's no reason we should be building our own. Cost shouldn't be able to be reduced now, since we're reflecting the games built-in raycast functions as we should be.
Will test the mod-api camera changes
35dd1e35056193f97bc3Review answered, on
6193f97b(rebased on currentmod-api):rayAllis now the game's own every-hit ray query. The ray query's cast method has an all-hits mode (+0x8c= 1: Havok's all-hits collector, each hit a record in the query's hit list at+0x68), and the game builds such a query itself (f_83010540, with f_83010ac0).raw_allbuilds it the same way, casts it once with the same executor, and walks and clears the list as the game's reader does. Nothing is stepped or cut off: every body the ray crosses is in the list, each body once (an actor's several bodies as one, by their collision group), each hit's kind its body's own layer.game-core's tests fake the every-hit query as the build has it (overlapping bodies, hits out of order, a floor's two triangles, a group passed through).rayAllis one cast of the game's own every-hit query, whatever it passes through; there is no work of ours left in it to bound.collidestays Preview in this branch; on a local build with it lifted, the eye 6 m behind Link stopped 1.44 m out, short of his house's wall (6.00 m with it off). A by-hand camera playtest is in Still to test, and Linux is CI's.6193f97bc3694a243848Rebased again on current
mod-api(#2657 and #2658 merged; only the generated docs conflicted):694a2438. The ray probe passes in the game on it (built with #2663 on top). Note for whoever runsschema-gen --checkonmod-apiitself:game/settings_abi.his committed one trailing newline short of what the generator writes, so the check reports it stale there too; this branch leaves that file asmod-apihas it.694a243848494e13254dRebased on current
mod-api(f8193c1e):494e1325, only the generated docs made again.cargo test -p game-core -p api -p game-sites -p sites,cargo check --workspace --all-targetsandschema-gen --checkas before (the api test that fails onmod-apiitself,a_content_mods_changed_module_runs_again_and_its_outputs_are_served, still the one).settings_abi.hnow matches its generator onmod-api, so my note about it above no longer applies.@review
Recommendation: Approve. The recorded game runs show the ray kinds and collision query working, and the repeated multi-hit search has been replaced. The pull request is still reported as unmergeable, so its mergeability needs to be settled. Nothing blocking is left. Recommend approval; not approved on the forge.
Adds filtered single-hit and multi-hit rays to the mod API, including hit kinds and actor identification. The multi-hit implementation now uses the game's collector in one cast, at the cost of reading and deduplicating its records.
Questions (1) (not confirmed from the code; they don't hold the recommendation)
Since the last review (on
35dd1e3505)Resolved: L1 (The fixed five-metre search limit silently drops later bodies of the same kind.); L2 (Treating any same-kind body encountered at the current step as the previous body discards…); L3 (The continuation excludes only the most recent kind, so it can report a previously returne…); L4 (The physics-step cost of the new multi-hit search has not been measured.); L5 (The changed collision behavior and the remaining ray kinds need in-game validation on the…); L6 (It conflicts with its base branch: bring it up to date (
@​fixor@​rebasetry first).)Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes for the tested behavior: the author reports successful ray and rayAll probes on Windows in Link's house and Kokiri Forest. Physics-step cost has not been measured.
Other systems: The physics step and Preview camera collision use the ray path. Windows NVIDIA results are reported; Linux and a by-hand camera playtest remain unreported.
Switches: No switches added, changed or removed. Ray options default to ground, objects, characters and water on, and player off.
Reviewed:
494e13254dagainstf8193c1ed1: Read AGENTS.md, CONTRIBUTING.md, the ray implementation's production paths, the ray layout and calls, feature wiring, site changes, and the supplied description and comments. The full diff, remaining changed files, tests, generated documentation and linked project standards were not read in full; the named review checklist was absent.; nothing run (a code review).Checked and fine:
Testing: No commands or tests were run. The author reports Windows in-game probes and game-free checks; Linux and a camera playtest remain outstanding.
Overlaps and merge order: The description identifies #2422 as the earlier C mod API change; its current status was not available.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
WIP: feat(modapi): world.ray and rayAll: what a ray hits by kind, which actor, one passed throughto feat(modapi): world.ray and rayAll: what a ray hits by kind, which actor, one passed through