veloren/world/src/generator/mod.rs

62 lines
1.3 KiB
Rust
Raw Normal View History

2020-02-06 22:32:26 +00:00
pub mod settlement;
mod town;
// Reexports
pub use self::{
settlement::Settlement,
town::{TownGen, TownState},
};
2019-08-24 13:23:42 +00:00
use crate::{column::ColumnSample, util::Sampler};
use common::terrain::Block;
use std::sync::Arc;
use vek::*;
#[derive(Clone)]
pub enum Site {
Settlement(Arc<Settlement>),
}
impl Site {
pub fn get_surface(&self, wpos: Vec2<i32>) -> Option<Block> {
match self {
Site::Settlement(settlement) => settlement.get_surface(wpos),
}
}
}
impl From<Settlement> for Site {
fn from(settlement: Settlement) -> Self { Site::Settlement(Arc::new(settlement)) }
}
2019-08-28 18:32:44 +00:00
#[derive(Copy, Clone, Debug)]
pub struct SpawnRules {
pub trees: bool,
2019-09-25 12:00:00 +00:00
pub cliffs: bool,
2019-08-28 18:32:44 +00:00
}
impl Default for SpawnRules {
fn default() -> Self {
2019-09-25 12:00:00 +00:00
Self {
trees: true,
cliffs: true,
}
2019-08-28 18:32:44 +00:00
}
}
impl SpawnRules {
pub fn and(self, other: Self) -> Self {
Self {
trees: self.trees && other.trees,
2019-09-25 12:00:00 +00:00
cliffs: self.cliffs && other.cliffs,
2019-08-28 18:32:44 +00:00
}
}
}
2019-08-23 21:33:14 +00:00
pub trait Generator<'a, T: 'a>:
2019-08-24 22:57:55 +00:00
Sampler<'a, Index = (&'a T, Vec3<i32>, &'a ColumnSample<'a>, f32), Sample = Option<Block>>
2019-08-23 21:33:14 +00:00
{
2019-08-24 13:23:42 +00:00
fn get_z_limits(&self, state: &'a T, wpos: Vec2<i32>, sample: &ColumnSample) -> (f32, f32);
2019-08-28 18:32:44 +00:00
fn spawn_rules(&self, town: &'a TownState, wpos: Vec2<i32>) -> SpawnRules;
2019-08-23 21:33:14 +00:00
}