feat(modapi): nav.closest, the closest point on the game's navmesh, made after its navmesh update #2745
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!2745
Loading…
Reference in a new issue
No description provided.
Delete branch "ChloeNow/Longshot:feat/modapi-nav-closest"
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?
feat(modapi): nav.closest, the closest point on the game's navmesh, made after its navmesh update
Summary
A first
longshot/navmodule:nav.closest(position, { radius })settles with the point on the game's own navmeshclosest to a position (and its distance), or null. A mod can now put a spawned actor where a character could stand,
check that a spot is walkable, or snap a marker to the ground, as the game's AI does (its
QueryGetClosestNavMeshPoint). It is the first of the navmesh calls: paths, line of sight along the navmesh and a mod'sown cuts come next, on the same site (
docs/dev/reference/nav.md, "What comes next").game-core:nav(new) asks the game's closest-point call (nav.closest,f_80542dc0). The request is built on the gueststack, as the game's callers build it (
layout::nav), for the map's first character type, with the defaultfilter and no navmesh object of the asker's own.
nav.manager,0x84eaedb0); 0 means no navmesh now.raysdoes.nav.updated, the return of the navmesh manager's update job (f_80781b00, which holds the manager'slock exclusively while it steps the Havok AI world). Queries are made there, on that job's thread, once every lock is
released.
on jobs the main thread runs, which is the reason
world.rayis cast after the physics step.api:services::nav(new). It allows at most 64 queries a frame for a mod, and nulls a query that has waited 4frames (a pause, a load). Answers settle at the next serial point. It needs
state.read.has("nav.closest").nav.toml, plusNavPointandNavOptionsintypes.toml.docs/modding/nav.md, the guide.docs/dev/reference/nav.md: what was read of the game, the request's layout, the threading, and the run.Read first:
game/crates/game-core/src/nav.rs, thenav.updatedsite ingame/sites/sites.toml, andgame/crates/api/src/services/nav.rs.Testing
Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24, build
e0f3ccfa.Game-free tests:
game-corenav: 6 new tests, run withhost_sys::fake.apiservices::nav: 2 new tests (a point read as aNavPointwith its distance, and the radius rules). The settlingand the limit are covered by the in-game run.
game-core(all),game-sites, and the builder'ssites(the new site's owner line) pass.schema-gen --check,tests/test_doc_anchors.py, andcargo check --workspaceare clean.In the game: a probe mod's in-game test,
dev.py game-tests, sandboxed and headless. Link starts in Kokiri Forestat (-46.09, 118.44, 15.39).
has("nav.closest")is true.the walkable ground.
LimitErrorat the call.ok - test/nav.test.ts: the closest navmesh point is under Link, found from above, and none 30 m up, 1passed, exit 0.
mod-api(eaf4a48b9), with the builder confining thegame: the same numbers, and the test passed (exit 0). It was merged locally with #2726 and #2747, which a sandboxed
test run on the new
mod-apineeds; that merge was not pushed. The first runs were on the earliermod-api, beforethe rebase and BeanBot's batch-bounding commit.
Still to test:
dev.py game-testsof a mod callingnav.closestat Link in Kokiri Forest.The 118 checks that fail on Windows on mod-api (`
eaf4a48b9`) tootest_antilag.py,test_astc_decoder_gpu.py,test_async_safe_frees.py,test_audio_output_devices.py,test_audio_source_load.py,test_auto_handheld.py,test_bc_copy_layer_pitch.py,test_builder_channel.py,test_builtin_compute_unoptimized.py,test_capture_dimensions.py,test_capture_readback_visibility.py,test_capture_resources.py,test_coopmat_probe_failures.py,test_crash_record.py,test_desc_counts.py,test_dev_ab.py,test_dev_build.py,test_dev_migrate.py,test_dev_packs.py,test_dev_update.py,test_device_policy.py,test_draw_binds.py,test_draw_stream_visibility.py,test_drs.py,test_dummy_views.py,test_dump_readback.py,test_fallback_pipeline_state.py,test_float_add_subgroup.py,test_framegen_resources.py,test_framelog_sink.py,test_fsr3_release_frees.py,test_fsr3fi_hud_mask.py,test_fsr4_bind_dispatch.py,test_fsr4_tune.py,test_fsr_image_retirement.py,test_fsr_uniform_ownership.py,test_game_menu_mouse_buttons.py,test_gcn_mesh_shared_warp.py,test_image_view_retry.py,test_import_buffer_binding.py,test_import_log.py,test_import_reach.py,test_inline_write_order.py,test_input_background.py,test_input_movie.py,test_job_queue.py,test_lifter.py,test_linux_pressure.py,test_loaded_modules_drop.py,test_longshot_builder.py,test_longshot_ctl.py,test_lost_wait_said.py,test_low_vram_texture_mips.py,test_menu_hooks.py,test_mesh_fallback_strict_fmul.py,test_mesh_first_types.py,test_pads_after_menu.py,test_parity_gates.py,test_pass_barrier.py,test_pass_hazard.py,test_pcache_header_read.py,test_pipeline_key_values.py,test_pipeline_state_portable.py,test_pipeline_states.py,test_present_probe.py,test_present_queue_default.py,test_present_sites.py,test_present_source_crop.py,test_program_answer_domains.py,test_program_cache_cleanup.py,test_program_cache_one_variant.py,test_push_state.py,test_queue_priority.py,test_recorder_own_idle.py,test_recorder_parts.py,test_recorder_sync.py,test_recording_admission.py,test_replay_write_order.py,test_reshade_fx.py,test_run_all_mingw.py,test_same_draw.py,test_same_dyn.py,test_sampler_admission.py,test_seed_reader.py,test_shader_store.py,test_sparse_bind_failure.py,test_sparse_bind_ranges.py,test_split_ub_flush.py,test_staging_burst.py,test_taau_typed_dispatch.py,test_table_track.py,test_target_layouts.py,test_target_reuse_memory.py,test_temporal_present_bandwidth.py,test_texel_buffer_ownership.py,test_texture_init_barrier.py,test_texture_staging_publication.py,test_ub_snapshot_default.py,test_ub_update_batch.py,test_ui_record.py,test_ui_texture_upload.py,test_vcore_video_acquire.py,test_vendor_fixes.py,test_vertex_bind.py,test_vertex_bind_range.py,test_video_catchup.py,test_video_hold_early.py,test_video_input_limit.py,test_vk_occlusion_queries.py,test_vulkan_clear_mip.py,test_vulkan_copy_span.py,test_vulkan_copy_span_gpu_compile.py,test_wb_diff_observations_gpu.py,test_widen_alpha.py,test_windows_on_linux.py,test_windows_stop.py,test_wmma16_zero_c_kchain.py,test_xinput_thread.pyMeasurements
Nothing to measure: the site is off while no mod asks, and a query is one call of the game's own on its navmesh job's thread.
Risks
own readers take the same lock shared from their threads. The call is a reader too.
game's own, fully written and zeroed. The site's signature pins the build.
Checklist
Ready for review
mod-api; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named): Windows, this branch: 669 passed, 120 failed, 47 skipped. The same 118 fail on mod-api; the other two (test_host_alloc_wait,test_mesh_args_cleanup) pass on rerun, flaky under the full run.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
A new module, longshot/nav, and its first call: nav.closest(position, { radius }) settles with the point on the game's navmesh closest to a position (a NavPoint: the point and its distance), or null (none within the radius, no navmesh now, or not made in 4 frames), as the game's AI asks it (QueryGetClosestNavMeshPoint). - game_core::nav: the game's call (f_80542dc0: the navmesh manager, the request as the AI node and the movement code build it, the point out) made on the navmesh manager's update job's thread, at the update's return (the site nav.updated, f_80781b00's), never from the main thread: the call takes the manager's reader/writer lock shared, and the update holds it exclusively while it steps the navmesh world. The hand-over is the rays' slots, no lock; with nothing asked the site is off. A mod's request: the map's first character type, the game's default face filter, no navmesh object of its own, no flags. - api::services::nav: at most 64 queries a frame a mod, a radius more than 0 and at most 50 m (2 by default); a stopped mod's queries let go. has("nav.closest") is the call, the manager's variable and the site found in this build. - sites.toml: the locations nav.closest and nav.manager, the site nav.updated (its signature the update's step call). Co-Authored-By: Claude Opus 5.5 <[email protected]>Tested in game: Windows 11, RTX 4060 Laptop, sandboxed dev.py game-tests of a probe mod in Kokiri Forest on this head (with #2726 and #2742 merged locally): the closest point under Link, the ground found from 1.5 m above, null 30 m up, 40 queries in a frame all settled, the 65th to 70th in a frame a LimitError; 1 passed, exit 0.
Possibly related, for context:
@review
Recommendation: Approve. The change leaves the update hook active after the last querying mod stops. The recorded Windows run shows the basic query working, but load behavior, Linux, and the cost of queries remain untested. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
Adds an asynchronous mod API for finding a nearby navmesh point, with per-mod limits and a timeout. It gives mods a useful placement primitive, at the cost of work on the navmesh update thread and a fixed shared query pool.
Should fix (1): not blocking, but worth doing before merging.
game/crates/api/src/services/nav.rs:91: Stopping the last mod with pending queries cancels its slots but never disables the update site. (more on the line) Do: Call nav::idle after removing the last query, and cover stopping a mod with a pending query.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
game/sites/sites.toml:2227: The worker-thread call and its timeout have only been exercised in one area on Windows. (more on the line) Do: Run the query on Linux, on a tiled map and a map without a navmesh, and across a load; check the returned points, nulls and timeout.game/crates/game-core/src/nav.rs:179: The cost of processing a batch on the navmesh update thread is unknown. (more on the line) Do: Compare frame times and update-job duration with and without representative and maximum query batches, using repeated runs in a demanding scene. (@fixdoes its part first: Bound or spread the number of queries processed by one update.)@fixcan do L1 and L3.More: does it help, other systems, switches, what was read
Does it help: Yes for the basic feature: the reported Windows run found ground below Link, returned null for a distant query, and settled 40 queries. It does not establish behavior across loads, on tiled or absent navmeshes, or on Linux; query costs were not measured.
Other systems: The hook runs on the game’s navmesh worker and can affect its update timing when mods query it. The recorded run covers one Windows NVIDIA system in Kokiri Forest; Linux, tiled and absent navmeshes, and queries across loads remain untested. Saves are not written, and no renderer interface changes.
Switches: None.
Reviewed:
d6ccb5ba51against5c1cd9f5b1: Read the repository rules and PR template, commit log, changed nav service and game-core implementation, layouts, call binding, schema and site change, and traced frame and shutdown paths, site registration and guest-memory access. Read the integration diffs and skimmed generated documentation and the recorded run. The sibling Tooling checkout and docs/review-checklist.md were absent. Larger surrounding files and unrelated existing site definitions were skimmed, not read in full.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no code or tests were run. The author reports game-free checks and one in-game Windows run, with two other PRs merged locally.
Overlaps and merge order: The reported test included local merges of #2726 and #2742; their merge status and overlap could not be verified offline.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -0,0 +88,4 @@}/// A stopped mod's queries let go.pub(crate) fn nav_gone(&self, main: &MainThread, id: &ModId) {L1 (should fix): Stopping the last mod with pending queries cancels its slots but never disables the update site.
When: When nav_gone removes the final query, subsequent nav_step calls return immediately because the query list is empty, so nav::idle is never called and the hook stays active for the rest of the session.
Do: Call nav::idle after removing the last query, and cover stopping a mod with a pending query.
@ -0,0 +176,4 @@return;}for slot in &self.slots {if slot.state.compare_exchange(ASKED, QUERYING, Ordering::AcqRel, Ordering::Acquire).is_err() {L3 (should fix): The cost of processing a batch on the navmesh update thread is unknown.
When: A mod can request 64 queries in a frame, and multiple mods can fill the shared pool; those game calls execute serially before the update job returns.
Do: Compare frame times and update-job duration with and without representative and maximum query batches, using repeated runs in a demanding scene.
@ -2224,2 +2224,4 @@builds.e0f3ccfa = { fn = "f_838d0080", offset = 0xa4 }[[site]]name = "nav.updated"L2 (should fix): The worker-thread call and its timeout have only been exercised in one area on Windows.
When: Queries during a map load, on a tiled navmesh, or on Linux can take different lifecycle and scheduling paths from the recorded Kokiri Forest run.
Do: Run the query on Linux, on a tiled map and a map without a navmesh, and across a load; check the returned points, nulls and timeout.
@fix
Recommendation: Approve. The code is ready: only testing is left. The query batch is bounded, but its cost on the navmesh update thread remains unmeasured, and the platform and game-state runs are still missing. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
861ff40e24. It was already up to date withmod-api. I edited its description to match the change.Changed
Changed in part (the rest is for the author)
Nothing was built or run: the checks run again on the new head.
Adds a mod API for finding the closest point on the game’s navmesh. The follow-up limits work to 32 queries per update and disables the site after the last mod’s queries are cancelled; the cost is delayed or timed-out queries under backlog.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
game/sites/sites.toml:2227: The worker-thread call and its timeout have only been exercised in one area on Windows. When: Queries during a map load, on a tiled navmesh, or on Linux can take different lifecycle and scheduling paths from the recorded Kokiri Forest run. Do: Run the query on Linux, on a tiled map and a map without a navmesh, and across a load; check the returned points, nulls and timeout.game/crates/game-core/src/nav.rs:179: The cost of the new 32-query batch on the navmesh update thread remains unknown. When: A mod submits a full batch while the game is running; the added work can delay the navmesh update, but its duration and effect on frame times are unmeasured. Do: Measure batch duration and frame times in game with and without sustained 32-query batches on representative hardware.Checks: they run again on this head; a failure shows on the pull request.
Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven on the current head. A Windows in-game run before the follow-up found points and enforced the per-mod limit, but the bounded-batch and shutdown changes have not been run in game.
Other systems: The query executes on a game worker thread and depends on the navmesh manager and update site. Linux, tiled and absent navmeshes, and a load-spanning timeout remain untested.
Switches: None.
Reviewed:
861ff40e24against5c1cd9f5b1: Read AGENTS.md, CONTRIBUTING.md, the fix diff, the nav service and core query implementation, and the changed service wiring and site definition. Skimmed the overall diff statistics and commits; did not read every changed file in full.; nothing run (a code review).Checked and fine:
Testing: No commands that run project code or tests were executed. The supplied Windows in-game and game-free results predate the follow-up; CI has not run on this head.
Overlaps and merge order: #2726 and #2742 were merged locally for the reported sandboxed run; their current merge status is not supplied.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
861ff40e24b31f6fee96Rebased onto the squashed mod-api (
eaf4a48b9): only this PR's 4 commits now, BeanBot's batch-bounding fix kept, the generated docs made again. game-core nav (7), api nav (4), the site owners and schema-gen pass. An in-game run on the new mod-api (the builder now starts the game) is next; this comes out of WIP once that passes.WIP: feat(modapi): nav.closest, the closest point on the game's navmesh, made after its navmesh updateto feat(modapi): nav.closest, the closest point on the game's navmesh, made after its navmesh updateView command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
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.