TerrainForge
A modular procedural generation engine for terrain, dungeons, and maps in Rust.
🎯 Now with Semantic Layers in v0.3.0!
Features
- 🎯 Semantic Layers: Game-agnostic metadata for entity spawning and region analysis
- 14 Generation Algorithms: BSP, Cellular Automata, DLA, Drunkard Walk, Maze, Rooms, Voronoi, WFC, Percolation, Diamond Square, Fractal, Agent-based, Glass Seam, Room Accretion
- 🔗 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: Rotatable prefabs with 90°/180°/270° variants
- Deterministic: Seeded RNG for reproducible results
- Generic: Works with custom cell types via traits
Quick Start
use ;
NEW: Semantic Generation
use ;
use Bsp;
Installation
[]
= "0.3"
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() |
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 |
NEW: 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: Generate with semantic layers
# NEW: Room accretion (Brogue-style)
# Pipeline composition
# Layer composition
# Run config file
# NEW: Semantic configuration files
# Compare algorithms
# List available algorithms
What's New
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