Skip to main content

Algorithm

Trait Algorithm 

Source
pub trait Algorithm<C: Cell = Tile>: Send + Sync {
    // Required methods
    fn generate(&self, grid: &mut Grid<C>, seed: u64);
    fn name(&self) -> &'static str;
}
Expand description

Trait for procedural generation algorithms.

All implementations must be Send + Sync so algorithms can be shared across threads (e.g. in a Pipeline or thread pool).

§Examples

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

let mut grid = Grid::new(40, 30);
let algo = Bsp::default();
algo.generate(&mut grid, 42);
assert!(grid.count(|t| t.is_floor()) > 0);

Required Methods§

Source

fn generate(&self, grid: &mut Grid<C>, seed: u64)

Generate content into the grid using the given seed

Source

fn name(&self) -> &'static str

Algorithm name for identification

Trait Implementations§

Source§

impl<C: Cell> Algorithm<C> for Box<dyn Algorithm<C> + Send + Sync>

Source§

fn generate(&self, grid: &mut Grid<C>, seed: u64)

Generate content into the grid using the given seed
Source§

fn name(&self) -> &'static str

Algorithm name for identification

Implementations on Foreign Types§

Source§

impl<C: Cell> Algorithm<C> for Box<dyn Algorithm<C> + Send + Sync>

Source§

fn generate(&self, grid: &mut Grid<C>, seed: u64)

Source§

fn name(&self) -> &'static str

Implementors§