WIP: feat(modapi): world shapes: sphere, capsule and box casts and overlaps through the game's own shape query #2438
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2438
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/modapi-world-shapes"
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
#2422 gives mods rays. 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(sphereCastAlland so on): everything it touches on the way, nearest first, each thingonce, 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).
are not offered (the game's query has a rotation; a later change can expose it).
How it's built, in short: the game has its own shape query. Its AI builds one on the stack for checks like
QueryPhysicsCastShapeEntitySphere(f_82ac68d0), and about 90 other places do the same. The host builds it the sameway: 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), which puts a Havokconvex shape in the query's own arena, so nothing goes on the heap. It runs with
f_805efbc0(Havok'scastShape, orits closest points for an overlap) under the world's lock, taken exactly as for a ray (#2422). Every hit comes from the
one query's collector: no extra queries per hit. A hit's kind is the hit body's own collision layer, so shapes need no
second query to classify, unlike rays. An actor with several bodies (Link has two) is one hit, by the collision group
its bodies share.
game_call_moregains float arguments (s0tos3) for the builders' radius.Read first: the shapes block of
host/game/world.h(what was read of the game), thenshape_queryandshape_castinhost/game/world.c, then the new "Shapes" section of docs/dev/reference/world.md.Testing
Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24, the save
kokiri-start, throughdev.py game-tests, on #2422's branch with this change (and the other open mod-api PRs, which loading a save needs):1.8 m tall) stops 0.90 m above it, a box (half height 0.2 m) 0.20 m above it.
player: true, Link is hit first, once, named by his key; withignoreset to his key the sweep passesthrough him to the floor.
Alls give Link, the floor and the ground under the house, each at its own distance, nearest first.player: true); in the air, nothing; a capsulewhere he stands, nothing; the same capsule sunk 0.3 m, the floor; a box at his feet, the floor.
characterwith its key; an overlap on it gives it;characters: falseleaves it out.tests/game-features/world: the new fake tests pass (a sphere onto the ground, an overlap atLink's feet,
has()false without the shapes); the new game test (a sphere onto the floor at Link's feet) is in thefile.
tests/game-features/in the fake game (19 areas);tests/test_game_call.py(the new float arguments);tests/test_mod_host_features.py(the nine features answer);modapi/generate.py --check.The validation mod ran on this code with a temporary trace of the raw query (removed before the commit, along with a
per-call timer). The final code was built, but the game wasn't run again: the removed lines only logged.
Still to test:
tests/game-features/worldthroughdev.py game-tests(not yet run on its own).mise run test, includingtests/test_modrt.py(its stand-in'sgame_world_shape_castover the floor,water and character planes; new checks for each shape onto the floor, a miss, the
Alls, the overlaps, sizes out ofrange refused, and a build without the shapes). Not run here: the fixture links the POSIX way (by hand, or CI).
Measurements
Verdict: a shape costs about 140 µs on the main thread on average, a little more than a ray; nothing runs when no
mod casts.
Setup: Windows 11, RTX 4060 Laptop GPU, driver 621.24;
HOS_RAY_TRACE=1's counts over the validation run (600requests, most of them the 20-a-frame sphere casts), and a per-call timer in the run before the commit.
The schema's doc for
sphereCasttells mod authors the cost (about 0.15 ms each; ten a frame is about 1.5 ms).Risks
builders, the collector's contact. Each was confirmed in the runs (a raw dump of the query and its contacts, since
removed), and the build-specific functions are checked before use (
game_world_shape_ready: the ray's checks, plusthe shape query's functions in the lift; each class's destructor against the build's). Any other build keeps
has("world.sphereCast")and the rest false.HOS_WORLD_RAY=0turns them off with the rays.f_804ea3e0) nests on the host'shold the same way the ray executor's does.
below it. The game's own callers keep the same object on their stacks.
(
f_80aeb9e0,f_805fd650) for it.Two actors sharing a group would show as one hit; none was seen.
files.*,content.changeintest_mod_host_features.py), andon Windows
tests/test_mod_tools.py(5 path and symlink tests) and thelink-hudexample's input test, which failsthe same on
76da61dd.Checklist
Ready for review
mod-api(stacked on #2422); the title is a Conventional Commit.mise run testpasses (any failure that also fails onmod-apiis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def; its default ships on. (no new switch:HOS_WORLD_RAYandHOS_RAY_TRACEcover the shapes)tests/that reads changed source is updated, not weakened. (tests/modrt_test.c's stand-in,test_mod_host_features.py,game_call_test.c, the fake game)Assisted-by:/Co-Authored-By:trailers.Ready to merge
mod-api.main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
longshot/world's ray was in the schema with no game build answering it. It now casts through the game's own synchronous ray query (f_80e86730), built as the game builds its own inline (f_80e865e0's layout), under the physics world's reader/writer lock taken as the game's own reader would take it but never with a wait that could hang: a compare-and-swap while others read, or under nn::os TryLockMutex from 0; busy, 50 us of retries, then once a frame a 1 ms sleep with the core given up (no CPU of the mod's), then null. The game's own unlock lets the hold go. What a ray hits is chosen by kind (RayOptions: ground, objects, characters, player, water), the game's collision layers read from the binary and checked one bit at a time in runs; by default everything but Link, so a ray cast from him does not stop on him. ignore passes through an actor's collision group (f_803f2dd0, f_80e86ac0). A hit says its kind (the same ray against one kind at a time), the key of the actor whose body it is (a rigid body's handle, [[body+0x78]+8], matched to the listed actors' bodies; for a mod with actors.read) and whether the ray started inside it. rayAll gives every hit along the ray, each body once. The game's invisible walls are no kind: no ray query meets them (a run swept every layer, sub-layer and ray layer in both of the manager's worlds). has("world.ray") and has("world.rayAll") are true in build e0f3ccfa; HOS_WORLD_RAY=0 turns them off. In the game (more than 100,000 casts across map changes): no stall; about 60 us a cast, 80 to 100 us a ray with its kind; busy about once in 500 requests, slept on 4 times in 8,400, one null. The checks: the ground at Link's feet, Link hit and named, passed through with ignore, a spawned Keese hit and named, passed with characters off, rayAll through it, a door an object with its key, Lake Hylia's surface water and the bed under it with water off. docs/dev/reference/world.md has the lock, the layers, the runs and what is not offered (shape casts, the walls). The fake game (mod-tools) filters a test's hits by the options as the game does, and has rayAll. The generator now emits the list type for a nullable list result (list<RayHit>?). Tests: test_modrt.py's world checks over the stand-in's floor, water and a character (kinds, keys, ignore, rayAll, a mod without actors.read); test_mod_host_features.py no longer lists world.ray as absent and gets the hos_game_is_mkw stub services_game.c already called; the world feature suite's game test checks the floor at Link's feet, its fake tests the kinds and rayAll. Co-Authored-By: Claude Opus 5.5 <[email protected]>Superseded by #2663: sphere, capsule and box casts and overlaps, made again on the Rust mod API's step-thread rays (stacked on #2662). Closing this C one.
Pull request closed