Class ProceduralMapPostProcessor
Post-processing utilities for procedurally generated maps. Provides connectivity repair, dead-end removal, room detection, door placement, region grid construction, and spawn point selection. All methods operate in-place on existing grids or are non-destructive queries, and can be called independently after any ProceduralMapGenerator algorithm or combined automatically via the flags in MapGenSettings.
Inherited Members
Namespace: Scylla.Core.Util.ProceduralMapGen
Assembly: ScyllaCore.dll
Syntax
public static class ProceduralMapPostProcessor
Remarks
Overloads are provided for square (ScyllaSquareGrid<TCell>) and hex (ScyllaHexGrid<TCell>) grids. Triangle grids have limited support (component counting only) because their 3-neighbor topology makes connectivity repair and dead-end removal ill-defined.
Methods that accept both floorValue and corridorValue treat both
as passable cells. This allows the same post-processing steps to be applied
regardless of whether the caller distinguishes room floors from corridor cells.
All BFS-based methods (connectivity repair, spawn-point search, flood fill) allocate intermediate HashSet<T> and Queue<T> structures internally. For hot-path scenarios where allocation matters, consider caching and reusing the grid between generation and post-processing calls.
Methods
BuildRegionGrid(ScyllaHexGrid<int>, MapGenResult<HexCoord>, int, int)
Builds a region grid that maps each passable cell to a region ID based on the rooms and corridors from a generation result. Wall cells get ID 0. Room cells get IDs 1..N (room.ID + 1), tracked corridor cells get IDs N+1..M. Untracked passable cells (e.g. corridors carved by connectivity repair) receive additional sequential IDs starting at M+1, grouped by connected component. Room cells take priority over corridor cells (corridors don't overwrite rooms).
Declaration
public static ScyllaHexGrid<int> BuildRegionGrid(ScyllaHexGrid<int> grid, MapGenResult<HexCoord> result, int floorValue, int corridorValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The source grid (read to identify untracked passable cells). |
| MapGenResult<HexCoord> | result | The generation result containing rooms and corridors with cell lists. |
| int | floorValue | The cell value that represents room floor. |
| int | corridorValue | The cell value that represents corridor. |
Returns
| Type | Description |
|---|---|
| ScyllaHexGrid<int> | A new grid of the same dimensions where each cell contains its region ID (0 = wall/void). |
BuildRegionGrid(ScyllaSquareGrid<int>, MapGenResult<SquareCoord>, int, int)
Builds a region grid that maps each passable cell to a region ID based on the rooms and corridors from a generation result. Wall cells get ID 0. Room cells get IDs 1..N (room.ID + 1), tracked corridor cells get IDs N+1..M. Untracked passable cells (e.g. corridors carved by connectivity repair) receive additional sequential IDs starting at M+1, grouped by connected component. Room cells take priority over corridor cells (corridors don't overwrite rooms).
Declaration
public static ScyllaSquareGrid<int> BuildRegionGrid(ScyllaSquareGrid<int> grid, MapGenResult<SquareCoord> result, int floorValue, int corridorValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The source grid (read to identify untracked passable cells). |
| MapGenResult<SquareCoord> | result | The generation result containing rooms and corridors with cell lists. |
| int | floorValue | The cell value that represents room floor. |
| int | corridorValue | The cell value that represents corridor. |
Returns
| Type | Description |
|---|---|
| ScyllaSquareGrid<int> | A new grid of the same dimensions where each cell contains its region ID (0 = wall/void). |
CountConnectedComponents(ScyllaHexGrid<int>, int, int)
Counts the number of connected passable components in a hex grid.
Both floorValue and corridorValue cells are
treated as passable and may belong to the same connected component.
Uses 6-neighbor adjacency inherent to hex grids.
Declaration
public static int CountConnectedComponents(ScyllaHexGrid<int> grid, int floorValue, int corridorValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to analyze. |
| int | floorValue | The cell value that represents passable floor. |
| int | corridorValue | The cell value that represents passable corridor. |
Returns
| Type | Description |
|---|---|
| int | The number of distinct connected passable regions. |
CountConnectedComponents(ScyllaSquareGrid<int>, int, int, SquareAdjacency)
Counts the number of connected passable components in a square grid.
Both floorValue and corridorValue cells are
treated as passable and may belong to the same connected component.
Declaration
public static int CountConnectedComponents(ScyllaSquareGrid<int> grid, int floorValue, int corridorValue, SquareAdjacency adjacency = SquareAdjacency.VonNeumann)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to analyze. |
| int | floorValue | The cell value that represents passable floor. |
| int | corridorValue | The cell value that represents passable corridor. |
| SquareAdjacency | adjacency | The adjacency model: VonNeumann (4-neighbor) or Moore (8-neighbor). |
Returns
| Type | Description |
|---|---|
| int | The number of distinct connected passable regions. |
DetectRooms(ScyllaHexGrid<int>, int)
Detects rooms in a hex grid by flood-filling contiguous floor regions.
Declaration
public static List<MapRoom<HexCoord>> DetectRooms(ScyllaHexGrid<int> grid, int floorValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to analyze. |
| int | floorValue | The cell value that represents room floor. |
Returns
| Type | Description |
|---|---|
| List<MapRoom<HexCoord>> | A list of detected rooms. |
DetectRooms(ScyllaSquareGrid<int>, int, SquareAdjacency)
Detects rooms in a square grid by flood-filling contiguous floor regions.
Each contiguous region of cells matching floorValue becomes a room.
Declaration
public static List<MapRoom<SquareCoord>> DetectRooms(ScyllaSquareGrid<int> grid, int floorValue, SquareAdjacency adjacency = SquareAdjacency.VonNeumann)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to analyze. |
| int | floorValue | The cell value that represents room floor. |
| SquareAdjacency | adjacency | The adjacency model. |
Returns
| Type | Description |
|---|---|
| List<MapRoom<SquareCoord>> | A list of detected rooms. |
EnsureConnectivity(ScyllaHexGrid<int>, int, int)
Ensures all passable regions in a hex grid are connected by carving straight hex-line corridors between disconnected components. Components are found by flood fill, then connected in order using a greedy nearest-pair search: each unconnected component is linked to the already-connected group via the shortest DrawLine(SquareCoord, SquareCoord, Span<SquareCoord>) path between sampled cell pairs.
Declaration
public static int EnsureConnectivity(ScyllaHexGrid<int> grid, int floorValue, int corridorValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to modify. |
| int | floorValue | The cell value that represents passable floor. |
| int | corridorValue | The cell value to write for newly carved corridor cells. |
Returns
| Type | Description |
|---|---|
| int | The number of corridor segments carved to connect all components. |
Remarks
The cell-pair search is capped at 256 samples per component to bound worst-case runtime for large grids. Uses 6-neighbor adjacency inherent to hex grids.
EnsureConnectivity(ScyllaSquareGrid<int>, int, int, SquareAdjacency)
Ensures all passable regions in a square grid are connected by carving straight-line corridors between disconnected components. Components are found by flood fill, then connected in order using a greedy nearest-pair search: each unconnected component is linked to the already-connected group via the shortest Bresenham line between sampled cell pairs.
Declaration
public static int EnsureConnectivity(ScyllaSquareGrid<int> grid, int floorValue, int corridorValue, SquareAdjacency adjacency = SquareAdjacency.VonNeumann)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify. |
| int | floorValue | The cell value that represents passable floor. |
| int | corridorValue | The cell value to write for newly carved corridor cells. |
| SquareAdjacency | adjacency | The adjacency model used for flood fill. |
Returns
| Type | Description |
|---|---|
| int | The number of corridor segments carved to connect all components. |
Remarks
The cell-pair search is capped at 256 samples per component to bound worst-case runtime for large grids. This may produce slightly longer corridors than an exhaustive search on components with more than 256 cells.
FindSpawnPoints(ScyllaHexGrid<int>, int, int, int)
Finds spawn points in a hex grid by selecting passable cells maximally distant from the grid center. Performs a BFS starting from the nearest passable cell to the grid center and returns cells sampled evenly from the end of the BFS traversal order, giving preference to cells far from the starting point.
Declaration
public static List<HexCoord> FindSpawnPoints(ScyllaHexGrid<int> grid, int floorValue, int corridorValue, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to analyze. |
| int | floorValue | The cell value that represents passable floor. |
| int | corridorValue | The cell value that represents passable corridor. |
| int | count | The number of spawn points to find. Returns an empty list when |
Returns
| Type | Description |
|---|---|
| List<HexCoord> | A list of up to |
FindSpawnPoints(ScyllaSquareGrid<int>, int, int, int, SquareAdjacency)
Finds spawn points in a square grid by selecting floor cells maximally distant from the grid center. Uses BFS from the center outward.
Declaration
public static List<SquareCoord> FindSpawnPoints(ScyllaSquareGrid<int> grid, int floorValue, int corridorValue, int count, SquareAdjacency adjacency = SquareAdjacency.VonNeumann)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to analyze. |
| int | floorValue | The cell value that represents passable floor. |
| int | corridorValue | The cell value that represents passable corridor. |
| int | count | The number of spawn points to find. |
| SquareAdjacency | adjacency | The adjacency model. |
Returns
| Type | Description |
|---|---|
| List<SquareCoord> | A list of spawn point coordinates, ordered from most to least distant from center. |
PlaceDoors(ScyllaHexGrid<int>, MapGenResult<HexCoord>, DoorPlacementSettings, int, int, IRandomSource)
Places door cells at room boundary positions in a hex grid. A cell qualifies as a door candidate if it is a passable non-room cell adjacent to a room cell and has walls on opposing hex neighbor pairs (directions 0+3, 1+4, or 2+5).
Declaration
public static int PlaceDoors(ScyllaHexGrid<int> grid, MapGenResult<HexCoord> result, DoorPlacementSettings settings, int doorValue, int wallValue, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to modify (doors are written in-place). |
| MapGenResult<HexCoord> | result | The generation result containing rooms with cell lists. |
| DoorPlacementSettings | settings | Door placement settings controlling probability, limits, and spacing. |
| int | doorValue | The cell value to write for placed doors. |
| int | wallValue | The cell value that represents impassable wall. |
| IRandomSource | rng | Random source for probabilistic placement. |
Returns
| Type | Description |
|---|---|
| int | The total number of doors placed. |
PlaceDoors(ScyllaSquareGrid<int>, MapGenResult<SquareCoord>, DoorPlacementSettings, int, int, IRandomSource)
Places door cells at room-corridor boundary positions in a square grid. A cell qualifies as a door candidate if it is a passable non-room cell adjacent to a room cell and has walls on opposing sides (left+right or top+bottom).
Declaration
public static int PlaceDoors(ScyllaSquareGrid<int> grid, MapGenResult<SquareCoord> result, DoorPlacementSettings settings, int doorValue, int wallValue, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify (doors are written in-place). |
| MapGenResult<SquareCoord> | result | The generation result containing rooms with cell lists. |
| DoorPlacementSettings | settings | Door placement settings controlling probability, limits, and spacing. |
| int | doorValue | The cell value to write for placed doors. |
| int | wallValue | The cell value that represents impassable wall. |
| IRandomSource | rng | Random source for probabilistic placement. |
Returns
| Type | Description |
|---|---|
| int | The total number of doors placed. |
RemoveDeadEnds(ScyllaHexGrid<int>, int, int, int)
Iteratively removes dead-end cells from a hex grid. Returns the number of cells filled.
Declaration
public static int RemoveDeadEnds(ScyllaHexGrid<int> grid, int wallValue, int floorValue, int corridorValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to modify. |
| int | wallValue | The cell value to write when filling dead ends. |
| int | floorValue | The cell value that represents passable floor. |
| int | corridorValue | The cell value that represents passable corridor. |
Returns
| Type | Description |
|---|---|
| int | The total number of cells converted to wall. |
RemoveDeadEnds(ScyllaSquareGrid<int>, int, int, int, SquareAdjacency)
Iteratively removes dead-end cells (floor cells with only one passable neighbor) from a square grid. Returns the number of cells filled.
Declaration
public static int RemoveDeadEnds(ScyllaSquareGrid<int> grid, int wallValue, int floorValue, int corridorValue, SquareAdjacency adjacency = SquareAdjacency.VonNeumann)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify. |
| int | wallValue | The cell value to write when filling dead ends. |
| int | floorValue | The cell value that represents passable floor. |
| int | corridorValue | The cell value that represents passable corridor. |
| SquareAdjacency | adjacency | The adjacency model. |
Returns
| Type | Description |
|---|---|
| int | The total number of cells converted from floor/corridor to wall. |