feat(modapi): world shapes: sphere, capsule and box casts and overlaps through the game's own shape query #2663
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!2663
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/modapi-world-shapes-rs"
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
#2662 gives mods rays by kind. This adds what other engines offer next to them: shapes swept through the world and
shapes placed in it, against the game's own collision (Unity's
SphereCast/CapsuleCast/BoxCast, theirAlls andOverlapSphere/Capsule/Box; Unreal's sweeps and overlaps; Godot'scast_motionandintersect_shape).sphereCast(from, to, radius, options?),capsuleCast(from, to, radius, height, options?)andboxCast(from, to, halfExtents, options?): the nearest thing the shape touches as its centre goes fromfromtoto. Each has anAll: everything it touches on the way, nearest first, each thing once, at most 16.overlapSphere(center, radius, options?),overlapCapsule(center, radius, height, options?),overlapBox(center, halfExtents, options?): what the shape touches where it is now. Empty means the place is clear.RayOptions): the same kinds (ground, objects, characters, water on; Link off) andignore.ShapeHit, new): the point on the surface, its normal, the shape's centre at that moment (whereit can go and no further), the distance its centre went, the
kind, the actor's key, andinside(touching at thestart; every hit of an overlap).
Each is asked and cast as a ray is: in the same slots, by the physics step on its own thread, settling a Promise a frame
later. The step builds the game's own shape query as its AI builds one on its stack (
QueryPhysicsCastShapeEntitySphere,f_82ac68d0): the game's constructor, the game's class for each shape (its destructor checked against the build's),and the game's own builder for the shape (sphere
f_803bd550, capsulef_80d1eba0, boxf_8047e6f0; the radius ins0, the stepping thread's own put back after), which makes a Havok convex shape in the query's own arena, so nothinggoes on the heap. It runs with
f_805efbc0(Havok'scastShape, or its closest points for an overlap). Every hit comesfrom the one query's collector, its kind from the hit body's own layer: no second query. The collector is the same hit
list, of the same records, as #2662's every-hit ray query's, so both are read by one reader (
contacts_of).Read first:
shape_queryandshape_castingame/crates/game-core/src/rays.rsand theSQ_/CT_offsets in
layout/rays.rs; theshapes.*named locations ingame/sites/sites.toml; then the shapes' functions andcast_askingame/crates/api/src/services/world.rs, and the schema's functions (world.toml) andShapeHit(
types.toml).docs/dev/reference/world.md's Shapes has the query's layout and the run.This is #2438's change, made again on the Rust mod API's rays; #2438 (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 (a quick build before the shape availability and dimensions fix,
rebased on #2662's every-hit
rayAlland currentmod-api, the shapes' hits read by the same reader;dev.py game-tests, the repository'skokiri-start, in Link's house), a probe mod's test passes: a sphere of 0.3 mswept down onto his floor stops with its centre 0.30 m above it, a capsule 1 m tall 0.50 m above it, a box of half
extents 0.2 m 0.20 m above it (each
ground: the sizes reach the game's builders); withplayer: truea sphere stops0.30 m above his head with his key;
sphereCastAllgives him once (his two bodies), then the floor;overlapSphereathis chest gives him, his key and
inside; a small box overlap above his head, nothing. Checks:cargo test -p game-core(rays: #2662's ray tests, and the shape query through the game's functions faked, a collector of Link's two bodies and the floor:each thing once, the nearer body kept, kinds from the bodies' own layers, the distance and centre along the sweep, the
radius in
s0and the site's own put back, the overlap's closest-points flag, a class that is not the build's ownrefused, and the calls in order with the destructor last),
-p api(a shape's hit with its centre, a miss's at thesweep's end; the sizes checked and a capsule of twice its radius or less a sphere),
-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, on Windows:api'sa_content_mods_changed_module_runs_again_and_its_outputs_are_servedand
modtool'seden_and_ryujinx_mods_are_found_with_their_switches.Still to test:
mise run rustandmise run test(by hand, or CI)Measurements
Nothing measured here: a shape costs one query of the game's (its build, its run, its destructor) on the physics
step's thread, after its step, and with none asked nothing runs. The C version measured about 0.15 ms a shape.
Risks
Only mods that cast shapes reach this code. The shape query is the game's own, built as its AI builds it; a build whose
classes or functions differ (a destructor that is not the build's) gets no shapes:
has()false, nothing cast. Thetest game has no world to cast against (as for the rays). 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): a 0.3 m sphere, a 1 m capsule and a 0.2 m box swept down onto his floor each stop their own size above it; a sphere stops 0.3 m above his head with his key; sphereCastAll gives him once then the floor; overlapSphere at his chest gives him, inside. Stacked on #2662.
6ec3436c1c2bc2dcace2Rebased on #2662's new head (
694a2438:rayAllis now the game's own every-hit ray query) and currentmod-api. The shape query's collector is the same hit list, of the same records, as that query's, so the shapes read their hits with #2662'scontacts_of(one reader, not two). In the game on2bc2dcac: the shape probe passes with the same numbers as before, and #2662's ray probe passes on it too.2bc2dcace2a68c64dbc3Rebased on #2662's
494e1325(currentmod-api):a68c64db, only the generated docs made again; the same checks pass.@rebase
I rebased this pull request onto
mod-api(67a113a710): the new head is7ba8253220.Conflicts resolved
Nothing was built or run: read the resolution before merging.
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
a68c64dbc37ba8253220Recommendation: Approve. Shape availability can be advertised for a class that the cast then refuses. The reported game run demonstrates several basic cases, but the remaining collision kinds and Linux still need testing. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
Adds asynchronous sphere, capsule, and box sweeps and overlaps for mods using the game's collision queries. It reuses the ray queue and hit reader, but adds query lifecycle and compatibility checks that need correction.
Should fix (2): not blocking, but worth doing before merging.
game/crates/game-core/src/rays.rs:260: The feature bit checks that class slots exist but does not check their contents or destructors, although the query rejects a mismatched class. (more on the line) Do: Make shape feature availability reflect the same class and destructor validation used by the query, with a test for a mismatched class.game/crates/api/src/services/world.rs:360: Positive dimensions are checked before conversion to f32, so values too small to represent become zero. (more on the line) Do: Validate the converted f32 dimensions as positive and finite, or impose a documented representable minimum; cover both radius and box extents in tests.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
@fixdoes its part first: Bound or spread the work processed in one physics step if the allowed burst causes a frame-time spike.)@fixcan do L1, L2 and L4.Questions (1) (not confirmed from the code; they don't hold the recommendation)
game/crates/game-core/src/rays.rs:660: Can the builder fail or leave a null holder after initialization, and does the initialized query then own resources that require destruction?Checks: Still running:
PR description / Title and description (pull_request_target).More: does it help, other systems, switches, what was read
Does it help: Unproven across the advertised feature: the author's Windows run reports correct floor distances for all three shapes and player hits for a sphere. Objects, characters, water, a box sweep along a wall, and Linux have not been tested. This is not a performance change; the cited approximately 0.15 ms per shape came from the earlier C version, not a comparison of this head.
Other systems: Shapes share the physics-step queue, per-mod limit, and actor lookup with rays. A mod can request up to 64 casts per frame, so query cost can affect frame pacing; the cost on this implementation has not been measured. No GPU-specific rendering code or saved data changes are apparent.
Switches: None.
Reviewed:
7ba8253220against67a113a710: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, the commit and diff, the changed world service, shape query and related layout and call code, and the world reference. Reviewed the schema and location changes; skimmed the generated modding reference and other documentation changes. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. The full contents of every changed code file were not independently read in full.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no tests, builds, scripts, or game runs were executed. The author reports game-core, API, schema and other checks, with two named failures also occurring on the base.
Overlaps and merge order: Depends on #2662; merge that dependency first and rebase this change. The author identifies #2438 as the older C API version that this replaces.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.
@ -323,0 +357,4 @@"a shape's radius is more than 0 and at most {SHAPE_MAX} m, not {radius}")));}Ok(radius as f32)L2 (should fix): Positive dimensions are checked before conversion to f32, so values too small to represent become zero.
When: A mod can pass a positive radius such as 1e-100, or the same value as a box half extent. Validation accepts it, then the game builder receives zero despite the API requiring a positive dimension.
Do: Validate the converted f32 dimensions as positive and finite, or impose a documented representable minimum; cover both radius and box extents in tests.
@ -224,3 +258,3 @@&& Location::rays_hitsVtable.addr() != 0&& Location::rays_hitsClear.func().is_some();ON | if all { ALL } else { 0 }let shapes = Location::shapes_queryInit.func().is_some()L1 (should fix): The feature bit checks that class slots exist but does not check their contents or destructors, although the query rejects a mismatched class.
When: If a build names the locations but a class slot is null or its destructor differs, has('world.sphereCast') reports true while every affected cast settles null at the class check.
Do: Make shape feature availability reflect the same class and destructor validation used by the query, with a test for a mismatched class.
@fix
Recommendation: Approve. The code is ready: only testing is left. The shape queries have promising in-game results, but the remaining collision cases, Linux behavior and physics-step burst cost are unmeasured. The stacked dependency #2662 also needs to merge first. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
1a3b4e96f8. It was already up to date withmod-api. I edited its description to match the change.Changed
Left for the author
Nothing was built or run: the checks run again on the new head.
Adds sphere, capsule and box casts and overlaps for mods, using the game’s collision queries. This gives mods more world-query options at the cost of work on the physics thread when requested.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
Checks: they run again on this head; a failure shows on the pull request.
More: does it help, other systems, switches, what was read
Does it help: Unproven for the full feature: the author reports successful Windows in-game probes for ground, Link and selected overlaps, but the latest availability and dimension changes have not been run in game. The implementation’s burst cost has no measurement; the reported approximately 0.15 ms per shape is from the C version.
Other systems: The queries run on the physics thread and share ray slots and collision filtering. Windows ground and player cases were reported working; characters, objects, water, a wall sweep and Linux remain untested. Mods that do not request shapes do not run shape queries.
Switches: None added, changed or removed.
Reviewed:
1a3b4e96f8against67a113a710: Read the repository instructions, contribution rules and pull request template, the fix diff, and the relevant shape availability, dimension validation, query and test code. The larger changed files, generated documentation, schemas and site definitions were skimmed; the complete change was not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run the project were executed. The author’s recorded game and check results predate the latest fix; CI has not run on this head.
Overlaps and merge order: Stacked on #2662; merge #2662 first and rebase this change.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
@rebase
I rebased this pull request onto
mod-api(bbfae8e8ef): the new head is2a7d7e9903.Conflicts resolved
Nothing was built or run: read the resolution before merging.
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
1a3b4e96f82a7d7e9903WIP: feat(modapi): world shapes: sphere, capsule and box casts and overlaps through the game's own shape queryto feat(modapi): world shapes: sphere, capsule and box casts and overlaps through the game's own shape queryRecommendation: Approve. The code is ready: only testing is left. The shape queries have shown the basic floor and player cases working on Windows, but the remaining collision cases, Linux behavior, and cost of a request burst are still untested. The change also depends on #2662 merging first. Recommend approval; not approved on the forge.
Adds shape casts and overlaps for mods using the game's collision query. This expands the world API, at the cost of additional physics-step work when mods request shapes.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
Since the last review (on
1a3b4e96f8)Still open: L3 (The shape query still needs its untested collision cases and Linux checked in game.); L4 (The physics-step cost of this implementation is unmeasured at the allowed request rate.)
Checks: Still running:
PR description / Title and description (pull_request_target).More: does it help, other systems, switches, what was read
Does it help: Unproven overall: the author reports successful sphere, capsule, box, player and overlap probes on Windows, but the remaining collision cases and Linux have not been checked. The reported approximately 0.15 ms per shape came from the older C implementation, not a measurement of this implementation.
Other systems: The queries run on the physics-step thread and share slots with rays, so bursts can affect physics timing and other callers. Windows floor and player cases were reported working; character, object, water, wall-sweep and Linux behavior remain untested.
Switches: None.
Reviewed:
2a7d7e9903againstbbfae8e8ef: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the changed generated hash lines, and the shape-query and slot-processing code relevant to the ledger. Skimmed the diff, generated documentation and reported runs; the remaining changed code was not read in full. The referenced Tooling AGENTS.md and docs/review-checklist.md were unavailable.; nothing run (a code review).Checked and fine:
Testing: No commands that build, run tests or execute project code were run. The author reports game and automated checks on Windows; the outstanding in-game cases and burst measurement remain open.
Overlaps and merge order: #2662 supplies the ray API and collector this change depends on; merge #2662 first.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.