BSP: add room adjacency graph for corridor generation (closes #210)

New features:
- bsp.adjacency[i] returns tuple of neighbor leaf indices
- bsp.get_leaf(index) returns BSPNode by leaf index (O(1) lookup)
- node.leaf_index returns this leaf's index (0..n-1) or None
- node.adjacent_tiles[j] returns tuple of Vector wall tiles bordering neighbor j

Implementation details:
- Lazy-computed adjacency cache with generation-based invalidation
- O(n²) pairwise adjacency check on first access
- Wall tiles computed per-direction (not symmetric) for correct perspective
- Supports 'in' operator: `5 in leaf.adjacent_tiles`

Code review fixes applied:
- split_once now increments generation to invalidate cache
- Wall tile cache uses (self, neighbor) key, not symmetric
- Added sq_contains for 'in' operator support
- Documented wall tile semantics (tiles on THIS leaf's boundary)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-01-12 23:43:57 -05:00
commit 8628ac164b
4 changed files with 1058 additions and 2 deletions

View file

@ -441,6 +441,8 @@ PyObject* PyInit_mcrfpy()
/*BSP internal types - returned by BSP methods but not directly instantiable*/
&mcrfpydef::PyBSPNodeType,
&mcrfpydef::PyBSPIterType,
&mcrfpydef::PyBSPAdjacencyType, // #210: BSP.adjacency wrapper
&mcrfpydef::PyBSPAdjacentTilesType, // #210: BSPNode.adjacent_tiles wrapper
nullptr};