[Proc Gen] BSP.adjacency - Room connectivity graph #210
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Depends on
#202 [Proc Gen] BSP - Core class with splitting
john/McRogueFace
#204 [Proc Gen] BSP - Iteration (leaves, traverse)
john/McRogueFace
Reference
john/McRogueFace#210
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Parent Issue: #192
Depends On: #202 (BSP core), #203 (BSPNode), #204 (BSP iteration)
Priority: Lower - Nice to have for 7DRL, not blocking
Overview
Add leaf adjacency graph to BSP, enabling room connectivity analysis for corridor generation, critical path detection, and spatial reasoning.
Design Decisions (Settled)
1. Adjacency-Only API (no find_path)
Exposing the adjacency graph is more flexible than providing a specific pathfinding algorithm. Users can implement BFS (shortest), DFS with backtracking (longer paths), or domain-specific heuristics. "Longest path" is NP-hard anyway, and a "probably pretty long" path via simple heuristics is more fun than an optimal zig-zag.
2. Geometric Wall Segment Detection
Two leaves are adjacent if they share a wall segment (not just a corner). This is determined geometrically:
a.x + a.w == b.xAND y-ranges overlap (max(a.y, b.y) < min(a.y+a.h, b.y+b.h))a.y + a.h == b.yAND x-ranges overlap3. Lazy Computation with Caching
The adjacency graph is computed on first access and cached. Cache is invalidated when generation changes (after
clear()orsplit_recursive()). The O(n²) cost is acceptable for typical BSP sizes (depth 4-6 = 16-64 leaves) and happens during level generation where loading time is expected.4. Leaf Indexing
Leaves are assigned stable indices 0..n-1 based on level-order traversal. These indices are used consistently across
bsp.adjacencyandnode.adjacent_tiles. Modifying the tree invalidates the cache and may change indices - this is an acceptable tradeoff for the uncommon "iterative refinement" workflow.API Specification
BSP.adjacency (property)
Returns a sequence-like object where
adjacency[i]gives the tuple of leaf indices adjacent to leafi.BSPNode.leaf_index (property)
Returns this node's index in the leaf enumeration, or
Noneif not a leaf.BSPNode.adjacent_tiles (property)
Returns a dict-like object where
adjacent_tiles[neighbor_index]gives the tuple of Vector coordinates representing wall tiles shared with that neighbor.Example Use Case
Implementation Notes
C++ Data Structures
Wall Tile Calculation
For two adjacent leaves A and B:
Cache Invalidation
The existing
generationfield handles this. When adjacency is accessed:Acceptance Criteria
BSP.adjacencyproperty returns sequence of neighbor tuplesBSPNode.leaf_indexreturns stable index (0..n-1) or NoneBSPNode.adjacent_tiles[i]returns wall tile Vectorsclear()/split_recursive()adjacent_tiles[Proc Gen] BSP.find_path - Room connectivity graphto [Proc Gen] BSP.adjacency - Room connectivity graph