Skip to content

Spatial Indexing: Page-Backed Wide R-Tree with ECS Integration - #193

Merged
nockawa merged 14 commits into
mainfrom
feature/183-spatial-indexing
Mar 29, 2026
Merged

nockawa merged 14 commits into
mainfrom
feature/183-spatial-indexing

Conversation

@nockawa

@nockawa nockawa commented Mar 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Complete spatial indexing implementation for Typhon — a page-backed wide R-Tree with SOA node layout, fully integrated with the ECS architecture.

v1 Core (Phases 0–4)

  • Foundation types: SpatialNodeDescriptor, [SpatialIndex] attribute, geometry helpers, 4 variants (2D/3D × f32/f64)
  • R-Tree core: SOA insert/remove/split with R*-overlap-minimizing heuristic, OLC concurrency, AABB query
  • ECS integration: Back-pointers, fat AABBs, SpatialMaintainer (spawn/update/destroy hooks), SpatialIndexState, schema registration, SV tick fence + Versioned commit paths
  • Extended queries: Radius, ray (front-to-back), frustum (coherent culling), kNN (iterative radius expansion), zero-allocation ref struct enumerators
  • Layer 1 + telemetry: HashMap occupancy filter, BSphere→AABB conversion, escape rate metrics

v2 Game Features (F1–F6)

  • F1 Category Filtering: 32-bit per-entry mask + internal union mask, subtree pruning
  • F2 Static/Dynamic Separation: Two R-Trees per component, STR bulk-load for static
  • F3 Trigger Volumes: Enter/leave/stay events, per-region frequency control, static cache
  • F4 Interest Management: Inverted dirty-set on DirtyBitmap ring buffer, O(dirty × observers)
  • F5 Count Queries: CountInAABB/CountInRadius with subtree counting shortcut (sign-bit DFS encoding)
  • F6 Compound Queries: Two-pass pattern validated, ComponentChunkId exposed in SpatialQueryResult

Code Review Fixes

  • Interlocked counters for thread-safe metadata (B1)
  • OLC validation in RefitAncestorsBottomUp (B2)
  • Missing RefitInternalUnionMask in RemoveEmptyLeaf (B3)
  • kNN partial result return on iteration exhaustion (B4)
  • Incremental MBR expand on insert — O(CoordCount) vs O(N×CoordCount) (M1)
  • ArrayPool for trigger/interest scratch arrays (M3)
  • Debug assertions on DFS stack overflow (E1)
  • Fixed pinning in Frustum/Ray enumerators eliminating per-MoveNext stackalloc+copy (M4)

Stats

~12,500 LOC added across 56 files. 2,621 tests passing, 0 regressions.

Closes #183, #190, #191

Test plan

  • dotnet test — 2,621/2,621 pass
  • Benchmarks: count vs query (3.6–11x speedup), compound query post-filter (16µs, under 50µs threshold)
  • All 4 variants (R2Df32, R3Df32, R2Df64, R3Df64) covered by parametrized tests

@nockawa
nockawa merged commit f44468b into main Mar 29, 2026
5 checks passed
@nockawa
nockawa deleted the feature/183-spatial-indexing branch March 29, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spatial Indexing: Page-Backed Wide R-Tree with ECS Integration

1 participant