Class ProceduralMapGenerator
Main public API for procedural grid-based map generation. Provides eight distinct algorithms that operate in-place on ScyllaSquareGrid<TCell>, ScyllaHexGrid<TCell>, or ScyllaTriGrid<TCell> instances and return a MapGenResult<TCoord> containing rooms, corridors, connected-component counts, and suggested spawn points.
Inherited Members
Namespace: Scylla.Core.Util.ProceduralMapGen
Assembly: ScyllaCore.dll
Syntax
public static class ProceduralMapGenerator
Remarks
All algorithms require a pre-created, correctly sized grid passed by reference. Each method fills the grid with WallValue before carving, so prior grid contents are always discarded.
Available algorithms:
- DrunkardWalk(ScyllaSquareGrid<int>, DrunkardWalkSettings, MapGenSettings, IRandomSource) - random-walker cave carving with configurable multi-walker dynamics and chunk carving. Supports square and hex grids.
- CellularAutomata(ScyllaSquareGrid<int>, CellularAutomataSettings, MapGenSettings, IRandomSource) - randomized initial fill followed by iterative birth/death rules producing organic cave shapes. Supports square and hex grids.
- BSP(ScyllaSquareGrid<int>, BSPSettings, MapGenSettings, IRandomSource) - Binary Space Partitioning that recursively splits the grid, places one room per leaf partition, and connects sibling rooms with L-shaped or winding corridors. Square grids only.
- RoomAndCorridor(ScyllaSquareGrid<int>, RoomCorridorSettings, MapGenSettings, IRandomSource) - random room scatter with MST-based corridor connectivity and optional extra loop edges. Supports square and hex grids.
- NoiseThreshold(ScyllaSquareGrid<int>, NoiseThresholdSettings, MapGenSettings, IRandomSource) - coherent noise evaluation thresholded to binary wall/floor output. Supports square, hex, and triangle grids.
- Maze(ScyllaSquareGrid<int>, MazeSettings, MapGenSettings, IRandomSource) - randomized DFS (Recursive Backtracker) perfect maze with optional loop creation and dead-end removal. Square grids only.
- MazeWithRooms(ScyllaSquareGrid<int>, MazeRoomSettings, MapGenSettings, IRandomSource) - maze generation followed by rectangular room carving; multiple RoomGroup entries allow mixing room sizes. Square grids only.
- VoronoiRegions(ScyllaSquareGrid<int>, VoronoiRegionSettings, MapGenSettings, IRandomSource) - Poisson-disk-sampled seed points used to partition the grid into Voronoi regions; floor is carved within a configurable fraction of each region's radius. Supports square, hex, and triangle grids.
- Floorplan(ScyllaSquareGrid<int>, FloorplanSettings, MapGenSettings, IRandomSource) - Squarified Treemap building floorplan generator; packs tightly-filled rooms covering the entire interior with no large voids, connected by door openings and minimal corridors. Square grids only.
Post-processing (connectivity repair, dead-end removal, room detection, spawn-point selection) is controlled by MapGenSettings flags and is automatically applied at the end of each algorithm. For finer control, the ProceduralMapPostProcessor methods can be called independently after generation.
All algorithms are fully deterministic when the same IRandomSource seed is used. The grid is never heap-allocated inside these methods; callers own both the grid and the returned MapGenResult<TCoord>.
Methods
BSP(ScyllaSquareGrid<int>, BSPSettings, MapGenSettings, IRandomSource)
Generates a map using Binary Space Partitioning on a square grid. Iteratively splits the grid into partitions, places rooms in leaf partitions, and carves L-shaped corridors between sibling rooms. Square grids only.
Declaration
public static MapGenResult<SquareCoord> BSP(ScyllaSquareGrid<int> grid, BSPSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify in-place. |
| BSPSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings. |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<SquareCoord> | Generation result metadata. |
CellularAutomata(ScyllaHexGrid<int>, CellularAutomataSettings, MapGenSettings, IRandomSource)
Generates a map using the Cellular Automata algorithm on a hex grid. Random initial fill followed by iterative birth/death rules produces organic cave-like shapes. Uses 6-neighbor adjacency and double-buffering to prevent evaluation-order artifacts.
Declaration
public static MapGenResult<HexCoord> CellularAutomata(ScyllaHexGrid<int> grid, CellularAutomataSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to modify in-place. |
| CellularAutomataSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<HexCoord> | Generation result with detected rooms, corridors, components, and spawn points. |
Remarks
Cells with fewer than six in-bounds neighbors are treated as border cells and are permanently set to WallValue. The UseVonNeumann flag is ignored for hex grids because hex grids always use 6-neighbor adjacency.
CellularAutomata(ScyllaSquareGrid<int>, CellularAutomataSettings, MapGenSettings, IRandomSource)
Generates a map using the Cellular Automata algorithm on a square grid. Random initial fill followed by iterative birth/death rules produces organic cave-like shapes. Uses double-buffering to prevent evaluation-order artifacts.
Declaration
public static MapGenResult<SquareCoord> CellularAutomata(ScyllaSquareGrid<int> grid, CellularAutomataSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify in-place. |
| CellularAutomataSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings. |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<SquareCoord> | Generation result metadata. |
DrunkardWalk(ScyllaHexGrid<int>, DrunkardWalkSettings, MapGenSettings, IRandomSource)
Generates a map using the Drunkard's Walk algorithm on a hex grid. Multiple walkers carve floor cells with optional hex-radius chunk carving and forward bias.
Declaration
public static MapGenResult<HexCoord> DrunkardWalk(ScyllaHexGrid<int> grid, DrunkardWalkSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to modify in-place. Will be filled with walls first. |
| DrunkardWalkSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<HexCoord> | Generation result with detected rooms, corridors, components, and spawn points. |
Remarks
The target floor cell count is computed from the grid's rectangular bounding area
(Width * Height), which slightly overcounts valid hex cells. As a result,
the algorithm may terminate before reaching the exact TargetFillRatio
for non-rectangular hex layouts. Walkers that move out of bounds attempt one random fallback
direction before skipping their step for that iteration.
DrunkardWalk(ScyllaSquareGrid<int>, DrunkardWalkSettings, MapGenSettings, IRandomSource)
Generates a map using the Drunkard's Walk algorithm on a square grid. Multiple walkers carve floor cells with optional chunk carving and forward bias.
Declaration
public static MapGenResult<SquareCoord> DrunkardWalk(ScyllaSquareGrid<int> grid, DrunkardWalkSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify in-place. Will be filled with walls first. |
| DrunkardWalkSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<SquareCoord> | Generation result with detected rooms, corridors, components, and spawn points. |
Floorplan(ScyllaSquareGrid<int>, FloorplanSettings, MapGenSettings, IRandomSource)
Generates a building-style floorplan map on a square grid using the Squarified Treemap technique. Rooms are packed tightly to fill the entire interior with no large voids, separated by thin 1-2 cell shared walls and connected by door openings. Short L-shaped corridors are carved only when two rooms are not wall-adjacent. Square grids only.
Declaration
public static MapGenResult<SquareCoord> Floorplan(ScyllaSquareGrid<int> grid, FloorplanSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify in-place. Will be filled with walls first. |
| FloorplanSettings | settings | Algorithm-specific floorplan settings. |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<SquareCoord> | Generation result with detected rooms, corridors, components, and spawn points. |
Remarks
The algorithm runs in three phases:
- A list of target room areas is generated with a deliberate large/medium/small size mix (governed by LargeRoomWeight, MediumRoomWeight, SmallRoomWeight) summing to the total interior area so every cell is assigned to a room.
- The squarify heuristic packs those areas into the interior rectangle as sub-rectangles, choosing row/column splits to keep aspect ratios close to AspectRatioTarget. The result tiles the interior with no wasted space.
- Each rectangle is inset by WallThickness on its top and left edges; its right and bottom edges receive an additional 1-cell inset with probability ThickWallChance, producing a mix of 1-cell and 2-cell shared walls. An MST over wall-adjacent room pairs guarantees full connectivity via door openings that span the actual gap width. DoorLoopRatio adds extra connections for loops.
Maze(ScyllaSquareGrid<int>, MazeSettings, MapGenSettings, IRandomSource)
Generates a perfect maze using the Recursive Backtracker (randomized DFS) algorithm on a square grid. Uses a 2-cell stride pattern: odd-indexed cells are passages, even-indexed cells are walls. Optionally removes dead ends and creates loops for an imperfect maze. Square grids only.
Declaration
public static MapGenResult<SquareCoord> Maze(ScyllaSquareGrid<int> grid, MazeSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify in-place. Should ideally have odd dimensions for clean results. |
| MazeSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings. |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<SquareCoord> | Generation result metadata. |
MazeWithRooms(ScyllaSquareGrid<int>, MazeRoomSettings, MapGenSettings, IRandomSource)
Generates a maze and then carves rectangular rooms into it. The maze is generated first using recursive backtracking, then rooms are placed at random non-overlapping positions by carving floor cells over the maze structure. Multiple RoomGroup entries allow mixing different room sizes; all groups share the same overlap-check list so rooms never overlap. Post-processing ensures all rooms are connected to the maze network. Square grids only. Grid dimensions should be odd for clean maze structure.
Declaration
public static MapGenResult<SquareCoord> MazeWithRooms(ScyllaSquareGrid<int> grid, MazeRoomSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify in-place. Will be filled with walls first. |
| MazeRoomSettings | settings | Settings controlling maze parameters and room placement. |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<SquareCoord> | Generation result with detected rooms, corridors, components, and spawn points. |
NoiseThreshold(ScyllaHexGrid<int>, NoiseThresholdSettings, MapGenSettings, IRandomSource)
Generates a map by thresholding coherent noise values on a hex grid. Evaluates noise at each cell's world-space position using Fractal2D(float, float, NoiseSettings) when a fractal type is configured, or Evaluate2D(float, float, NoiseAlgorithm) otherwise.
Declaration
public static MapGenResult<HexCoord> NoiseThreshold(ScyllaHexGrid<int> grid, NoiseThresholdSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to modify in-place. |
| NoiseThresholdSettings | settings | Algorithm-specific settings (noise config, threshold, invert). |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output (used to derive noise seed). |
Returns
| Type | Description |
|---|---|
| MapGenResult<HexCoord> | Generation result with detected rooms, corridors, components, and spawn points. |
NoiseThreshold(ScyllaSquareGrid<int>, NoiseThresholdSettings, MapGenSettings, IRandomSource)
Generates a map by thresholding coherent noise values on a square grid. Delegates to Fill2D(float[], int, int, NoiseSettings, float, float) and converts the resulting float array to binary wall/floor output based on the threshold. Supports all noise algorithms and fractal types via NoiseSettings.
Declaration
public static MapGenResult<SquareCoord> NoiseThreshold(ScyllaSquareGrid<int> grid, NoiseThresholdSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify in-place. |
| NoiseThresholdSettings | settings | Algorithm-specific settings (noise config, threshold, invert). |
| MapGenSettings | genSettings | Common generation settings. |
| IRandomSource | rng | Random source for deterministic output (used to derive noise seed). |
Returns
| Type | Description |
|---|---|
| MapGenResult<SquareCoord> | Generation result metadata. |
NoiseThreshold(ScyllaTriGrid<int>, NoiseThresholdSettings, MapGenSettings, IRandomSource)
Generates a map by thresholding coherent noise values on a triangle grid. Evaluates noise at each triangle cell's world-space centroid position. Each grid cell contains two triangles (downward and upward orientation) that are evaluated and classified independently.
Declaration
public static MapGenResult<TriCoord> NoiseThreshold(ScyllaTriGrid<int> grid, NoiseThresholdSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaTriGrid<int> | grid | The grid to modify in-place. |
| NoiseThresholdSettings | settings | Algorithm-specific settings (noise config, threshold, invert). |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output (used to derive noise seed). |
Returns
| Type | Description |
|---|---|
| MapGenResult<TriCoord> | Generation result with component count. Triangle grids have limited post-processing: connectivity repair, dead-end removal, room detection, and spawn-point search are not performed. Only the connected-component count is populated via manual flood fill. |
RoomAndCorridor(ScyllaHexGrid<int>, RoomCorridorSettings, MapGenSettings, IRandomSource)
Generates a map using random room placement and MST-based corridor connectivity on a hex grid. Places hex-circle rooms at random positions, computes a minimum spanning tree for guaranteed connectivity, optionally adds extra loop edges, and carves straight hex-line corridors.
Declaration
public static MapGenResult<HexCoord> RoomAndCorridor(ScyllaHexGrid<int> grid, RoomCorridorSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to modify in-place. |
| RoomCorridorSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<HexCoord> | Generation result with detected rooms, corridors, components, and spawn points. |
Remarks
Room shapes are hex-radius circles rather than rectangles. The radius is derived from MinRoomWidth / MinRoomHeight and MaxRoomWidth / MaxRoomHeight (minimum of the width/height pair is used for each bound). Corridor widening uses hex-range expansion rather than L-shaped segments. The CorridorStyle setting from RoomCorridorSettings has no effect on hex grids; corridors are always straight hex lines.
RoomAndCorridor(ScyllaSquareGrid<int>, RoomCorridorSettings, MapGenSettings, IRandomSource)
Generates a map using random room placement and MST-based corridor connectivity on a square grid. Places rooms at random positions, computes a minimum spanning tree for guaranteed connectivity, optionally adds extra edges for loops, and carves L-shaped corridors.
Declaration
public static MapGenResult<SquareCoord> RoomAndCorridor(ScyllaSquareGrid<int> grid, RoomCorridorSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify in-place. |
| RoomCorridorSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings. |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<SquareCoord> | Generation result metadata. |
VoronoiRegions(ScyllaHexGrid<int>, VoronoiRegionSettings, MapGenSettings, IRandomSource)
Generates a map using Voronoi region partitioning on a hex grid. Uses PoissonDiskSampler to place evenly-spaced seed points, assigns each hex cell to its nearest seed using hex distance, and carves floor within a configurable fraction of each region's radius. Optionally connects all regions via an MST of straight hex-line corridors.
Declaration
public static MapGenResult<HexCoord> VoronoiRegions(ScyllaHexGrid<int> grid, VoronoiRegionSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaHexGrid<int> | grid | The grid to modify in-place. |
| VoronoiRegionSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<HexCoord> | Generation result with detected rooms, corridors, components, and spawn points. |
VoronoiRegions(ScyllaSquareGrid<int>, VoronoiRegionSettings, MapGenSettings, IRandomSource)
Generates a map using Voronoi region partitioning on a square grid. Uses PoissonDiskSampler to place evenly-spaced seed points, assigns each cell to its nearest seed, and carves floor within a configurable fraction of each region's radius. Optionally connects all regions.
Declaration
public static MapGenResult<SquareCoord> VoronoiRegions(ScyllaSquareGrid<int> grid, VoronoiRegionSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaSquareGrid<int> | grid | The grid to modify in-place. |
| VoronoiRegionSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings. |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<SquareCoord> | Generation result metadata. |
VoronoiRegions(ScyllaTriGrid<int>, VoronoiRegionSettings, MapGenSettings, IRandomSource)
Generates a map using Voronoi region partitioning on a triangle grid. Evaluates the nearest Poisson-disk-sampled seed point at each triangle cell's world-space centroid using Euclidean distance, and carves floor within a configurable fraction of each region's maximum radius.
Declaration
public static MapGenResult<TriCoord> VoronoiRegions(ScyllaTriGrid<int> grid, VoronoiRegionSettings settings, MapGenSettings genSettings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaTriGrid<int> | grid | The grid to modify in-place. |
| VoronoiRegionSettings | settings | Algorithm-specific settings. |
| MapGenSettings | genSettings | Common generation settings (cell values, post-processing flags). |
| IRandomSource | rng | Random source for deterministic output. |
Returns
| Type | Description |
|---|---|
| MapGenResult<TriCoord> | Generation result with component count. Triangle grids have limited post-processing: connectivity repair, dead-end removal, room detection, and spawn-point search are not performed. Only the connected-component count is populated via manual flood fill. |