Skip to content

feat(spatial): adopt nearest queries in starburst and rts2d - #2725

Open
houko wants to merge 3 commits into
mainfrom
feat/issue-1515-spatial-target-adoption
Open

houko wants to merge 3 commits into
mainfrom
feat/issue-1515-spatial-target-adoption

Conversation

@houko

@houko houko commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Issue #1515's spatial queries landed in two earlier PRs, but its final acceptance item — Starburst and the rts2d template actually using the new queries — was still open. Starburst's auto-aim scanned every enemy and kept a separate intrusive 16×9 collision grid; the RTS template's nearestEnemy scanned every entity for each fighter. This change replaces the Starburst grid with one spatial.Hash[uint64], rebuilt once after enemy movement and shared by the bullets' QueryCircle broad-phase probes and the auto-aim Nearest query, with stable enemy ids and a slot map kept current through compaction. The rts2d template indexes entities by pointer in a spatial.Hash[*entity] rebuilt once per step on the first fighter query, with team, alive and fog-visibility checks in the Nearest accept callback. Ties keep the old preference for the first entity in spawn order, and distances follow the package contract of measuring to entry bounds.

Related issue

Fixes #1515

Verification

  • gofmt -l . produces no output
  • go tool nsgo test ./... passes from the repository root — not run as a whole; the scoped runs below passed
  • go tool nsgo check -target macos,windows,linux,android,web passes from the repository root — go tool nsgo check (default targets) passed
  • go tool nsgo check -target ios,ios_simulator passes (if on macOS with Xcode) — not run
  • bun run build passes (for docs/ or website/ changes) — no docs or website change
  • Both docs/en/ and docs/zh/ updated (when applicable) — not applicable; the queries are already documented equivalently in docs/en/spatial.md and docs/zh/spatial.md

Tests and checks that passed:

  • go tool nsgo check (catalogs and vet)
  • go tool nsgo test ./examples/starburst — 26 passed, 1 skipped, including the steady-state 1000-sprite zero-allocation step
  • go tool nsgo test ./template/rts2d/... — 33 passed, including the deterministic skirmish and both playthroughs
  • go tool nsgo test ./pkg/spatial — 15 passed
  • go run ./tools/changelog check and bun run verify-notes

Screenshots

None: no visible UI change. The template's targeting is the only behavior that moved, and no view code changed.

Starburst replaces its intrusive collision grid with one spatial.Hash shared by bullet circle queries and auto-aim nearest-target queries, and the rts2d template's fighters find sighted enemies through a lazily rebuilt spatial.Hash instead of scanning every entity. Both keep the old insertion-order tie preference now that the spatial package provides the queries.

Fixes #1515
@github-actions github-actions Bot added enhancement New feature or request size/M documentation Improvements or additions to documentation area/examples area/template area/agents labels Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Perf: nearest, k-nearest and radius queries on SpatialHash and Quadtree, with deterministic ties

2 participants