Skip to main content

Crate terrain_forge

Crate terrain_forge 

Source
Expand description

§TerrainForge

A modular procedural generation engine for terrain, dungeons, and maps.

§Quick Start

use terrain_forge::{Grid, ops};

let mut grid = Grid::new(80, 60);
ops::generate("bsp", &mut grid, Some(12345), None).unwrap();

println!("Generated {} floor tiles", grid.count(|t| t.is_floor()));

§Quick Start (Direct Instantiation)

use terrain_forge::{Algorithm, Grid};
use terrain_forge::algorithms::{Bsp, BspConfig};

let mut grid = Grid::new(80, 60);
let bsp = Bsp::new(BspConfig {
    min_room_size: 6,
    max_depth: 5,
    room_padding: 1,
});
bsp.generate(&mut grid, 12345);

§Semantic Extraction

Extract semantic information from any generated map:

use terrain_forge::{algorithms, SemanticExtractor, Grid, Rng};

// 1. Generate map using any method
let mut grid = Grid::new(80, 60);
algorithms::get("cellular").unwrap().generate(&mut grid, 12345);

// 2. Extract semantic information
let extractor = SemanticExtractor::for_caves();
let mut rng = Rng::new(12345);
let semantic = extractor.extract(&grid, &mut rng);

// Works with any grid source - pipelines, external tools, etc.

§Algorithms

15 generation algorithms available via algorithms::get:

  • bsp - Binary Space Partitioning for structured rooms
  • cellular - Cellular automata for organic caves
  • drunkard - Random walk for winding corridors
  • maze - Perfect maze generation
  • rooms - Simple rectangular rooms
  • voronoi - Voronoi-based regions
  • dla - Diffusion-limited aggregation
  • wfc - Wave Function Collapse
  • percolation - Connected cluster generation
  • diamond_square - Heightmap terrain
  • noise_fill - Noise-driven threshold fill
  • fractal - Fractal noise terrain
  • agent - Multi-agent carving
  • glass_seam - Region connector
  • room_accretion - Brogue-style organic dungeons

§Composition

Chain algorithms with compose::Pipeline or layer with compose::LayeredGenerator:

use terrain_forge::{Grid, Tile};
use terrain_forge::pipeline::Pipeline;

let mut grid = Grid::new(80, 60);
let mut pipeline = Pipeline::new();
pipeline.add_algorithm("rooms", None, None);
pipeline.add_algorithm("cellular", None, None);
pipeline.execute_seed(&mut grid, 12345).unwrap();

§Effects

Post-process with effects: morphology, connectivity, filters, transforms.

§Noise

noise module provides Perlin, Simplex, Value, Worley with FBM and modifiers.

Re-exports§

pub use ops::CombineMode;
pub use ops::Params;
pub use semantic::ConnectivityGraph;
pub use semantic::Marker;
pub use semantic::Masks;
pub use semantic::Region;
pub use semantic::SemanticConfig;
pub use semantic::SemanticLayers;

Modules§

algorithms
Procedural generation algorithms
analysis
Analysis algorithms for room connectivity and graph theory
compose
Composition system for chaining and layering algorithms.
constraints
Constraint validation utilities and helpers.
effects
Effects and transforms for post-processing generated maps.
noise
Noise generation module with composable generators and modifiers
ops
Unified ops facade: algorithms, effects, and grid combine.
pipeline
Pipeline system for conditional generation and ops orchestration.
semantic
Semantic layers for procedural generation
spatial
Spatial analysis algorithms.

Structs§

Grid
2D grid of cells
Rng
Seeded RNG wrapper for deterministic generation
SemanticExtractor
Standalone semantic extractor that analyzes any grid
VisualizationConfig
Visualization configuration

Enums§

Tile
Basic tile type for dungeon/terrain generation

Traits§

Algorithm
Trait for procedural generation algorithms
Cell
Trait for grid cells

Functions§

extract_semantics
Convenience function for quick semantic extraction
extract_semantics_default
Extract semantics with default configuration
generate_with_requirements
Generate a map that meets specific semantic requirements
generate_with_semanticDeprecated
Generate a map with semantic layers using the new extraction approach
visualize_connectivity_graph
Visualize connectivity graph as text
visualize_masks
Visualize spatial masks
visualize_region_ids
Create region ID visualization (useful for debugging)
visualize_regions
Visualize regions overlaid on the grid
visualize_semantic_layers
Create comprehensive semantic visualization