TerrainForge
A modular procedural generation engine for terrain, dungeons, and maps in Rust.
🚀 Now with Spatial Analysis & Quality of Life Features in v0.4.0!
Features
🎯 v0.4.0 - Spatial Analysis & Quality of Life
- 📐 Spatial Analysis: Distance transforms, advanced pathfinding, morphological operations
- 🧠 Enhanced Wave Function Collapse: Pattern learning, backtracking, constraint propagation
- 🔗 Delaunay Triangulation: Natural room connections using triangulation and MST algorithms
- 🏗️ Advanced Prefab System: JSON/TOML support, weighted selection, rotation/mirroring
- 📊 Graph Analysis: Connectivity analysis, shortest paths, clustering coefficients
🎯 Core Features
- Semantic Layers: Game-agnostic metadata for entity spawning and region analysis
- 15 Generation Algorithms: BSP, Cellular Automata, DLA, Drunkard Walk, Maze, Rooms, Voronoi, WFC, Percolation, Diamond Square, Fractal, Agent-based, Glass Seam, Room Accretion, Enhanced WFC
- 🔗 Advanced Connectivity: Region-aware connectors with spanning tree analysis
- 🎨 Enhanced Demo Framework: Semantic visualization with color-coded markers
- Noise Generation: Perlin, Simplex, Value, Worley with FBM, Ridged, and modifiers
- Effects: Morphology, spatial analysis, filters, connectivity
- Composition: Pipeline chaining and layered generation
- Prefab System: JSON/TOML support with rotation, mirroring, and weighted selection
- Deterministic: Seeded RNG for reproducible results
- Generic: Works with custom cell types via traits
Quick Start
Basic Generation
use ;
NEW: Enhanced Wave Function Collapse
use ;
NEW: Delaunay Triangulation
use ;
NEW: Advanced Prefab System
use ;
use serde_json;
NEW: Spatial Analysis
use ;
Semantic Generation
use ;
use Bsp;
Installation
[]
= "0.4"
Algorithms
| Algorithm | Description | Semantic Support |
|---|---|---|
bsp |
Binary Space Partitioning - structured rooms | ✅ for_rooms() |
cellular |
Cellular Automata - organic caves | ✅ for_caves() |
drunkard |
Drunkard's Walk - winding corridors | ✅ default() |
maze |
Perfect maze generation | ✅ for_mazes() |
rooms |
Simple rectangular rooms | ✅ for_rooms() |
voronoi |
Voronoi-based regions | ✅ default() |
dla |
Diffusion-Limited Aggregation | ✅ default() |
wfc |
Wave Function Collapse | ✅ default() |
enhanced_wfc |
NEW: Enhanced WFC with pattern learning | ✅ default() |
percolation |
Connected cluster generation | ✅ default() |
diamond_square |
Heightmap terrain | ✅ default() |
fractal |
Fractal terrain | ✅ default() |
agent |
Multi-agent carving | ✅ default() |
glass_seam |
Region connector | ✅ default() |
room_accretion |
Brogue-style organic dungeons | ✅ for_rooms() |
Note: All algorithms support semantic analysis through SemanticExtractor. Algorithm-specific extractors (for_caves(), for_rooms(), for_mazes()) provide optimized analysis, while default() works with any terrain type.
Usage
Registry API
use ;
let mut grid = new;
// Get by name
let algo = get.unwrap;
algo.generate;
// List all
for name in list
Direct Instantiation
use ;
use ;
let config = BspConfig ;
let mut grid = new;
new.generate;
Noise
use ;
let noise = new;
let value = noise.get; // -1.0 to 1.0
let fbm = new;
let layered = fbm.get;
Semantic Layers
Generate game-agnostic metadata for entity spawning and region analysis:
use ;
use ;
// Different algorithms provide different semantic insights
let mut grid = new;
let mut rng = new;
// Cave system analysis
let cellular = default;
cellular.generate;
let semantic = for_caves.extract;
// Maze structure analysis
let maze = default;
maze.generate;
let semantic = for_mazes.extract;
// Entity spawning works the same across all algorithms
for in &semantic.markers
// Algorithm-specific region analysis
match semantic.regions.first.map
Constraints
use constraints;
let connectivity = validate_connectivity;
let density = validate_density;
let border_ok = validate_border;
Custom Cell Types
use ;
let grid = new;
CLI Tool
The demo framework provides visualization and testing:
# Generate single algorithm
# NEW: Enhanced WFC with pattern learning
# NEW: Delaunay triangulation connections
# NEW: Advanced prefab system
# Generate with semantic layers
# Room accretion (Brogue-style)
# Pipeline composition
# Layer composition
# Run config file
# NEW: Semantic configuration files
# Compare algorithms
# List available algorithms
What's New
v0.4.0 - Spatial Analysis & Quality of Life
- 📐 Spatial Analysis Module: Distance transforms (Euclidean, Manhattan, Chebyshev), advanced pathfinding with Dijkstra maps and flow fields, morphological operations (erosion, dilation, opening, closing)
- 🧠 Enhanced Wave Function Collapse: Pattern learning from example maps, backtracking support for constraint satisfaction, improved constraint propagation
- 🔗 Delaunay Triangulation: Natural room connections using Bowyer-Watson algorithm and minimum spanning tree generation for optimal dungeon layouts
- 🏗️ Advanced Prefab System: JSON/TOML serialization support, weighted prefab selection, rotation and mirroring transformations, persistent prefab libraries
- 📊 Graph Analysis: Connectivity analysis, shortest path algorithms, clustering coefficients, diameter calculations for level design metrics
v0.3.0 - Semantic Layers
- 🎯 Semantic Layers: Game-agnostic metadata system for entity spawning and region analysis
- 🏗️ Room Accretion Algorithm: Enhanced with semantic support for diverse marker types
- 🎨 Enhanced Demo Framework: Semantic visualization with color-coded markers and PNG output
- 🔗 Connectivity Analysis: Advanced region connectivity with spanning tree generation
- 📊 Spatial Analysis: Automated detection of rooms, corridors, junctions, and chokepoints
v0.2.0 - Advanced Features
- Room Accretion Algorithm: Brogue-style organic dungeon generation with sliding room placement
- Advanced Connectivity:
connect_regions_spanning()with loop control for better dungeon flow - Prefab Rotation: 90°/180°/270° rotation support for prefabs
- Public Region Analysis:
label_regions()for custom connectivity logic
Documentation
See docs/API.md for full API reference. See docs/ROGUELIKE_GENERATION_ANALYSIS.md for advanced techniques.
License
MIT