diff --git a/world/src/block/mod.rs b/world/src/block/mod.rs index c0a2283620..4205fd060d 100644 --- a/world/src/block/mod.rs +++ b/world/src/block/mod.rs @@ -2,6 +2,7 @@ mod natural; use crate::{ column::{ColumnGen, ColumnSample, StructureData}, + generator::TownGen, util::{HashCache, RandomField, Sampler, SamplerMut}, World, CONFIG, }; @@ -155,6 +156,8 @@ impl<'a> BlockGen<'a> { cliff_hill, close_cliffs, temp, + + chunk, .. } = &z_cache?.sample; @@ -352,6 +355,15 @@ impl<'a> BlockGen<'a> { } }); + // Structures (like towns) + let block = block.or_else(|| { + chunk + .structures + .town + .as_ref() + .and_then(|town| TownGen.get((town, wpos))) + }); + let block = structures .iter() .find_map(|st| { diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index 5240bdb713..d5bd54560b 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -514,6 +514,8 @@ impl<'a> Sampler<'a> for ColumnGen<'a> { temp, spawn_rate, location: sim_chunk.location.as_ref(), + + chunk: sim_chunk, }) } } @@ -541,6 +543,8 @@ pub struct ColumnSample<'a> { pub temp: f32, pub spawn_rate: f32, pub location: Option<&'a LocationInfo>, + + pub chunk: &'a SimChunk, } #[derive(Copy, Clone)] diff --git a/world/src/generator/mod.rs b/world/src/generator/mod.rs index 021235916a..8097b7b8e3 100644 --- a/world/src/generator/mod.rs +++ b/world/src/generator/mod.rs @@ -1,10 +1,13 @@ mod town; // Reexports -pub use self::town::TownGen; +pub use self::town::{TownGen, TownState}; use crate::util::Sampler; use common::terrain::Block; use vek::*; -pub trait Generator<'a, T: 'a>: Sampler<'a, Index = (&'a T, Vec3), Sample = Block> {} +pub trait Generator<'a, T: 'a>: + Sampler<'a, Index = (&'a T, Vec3), Sample = Option> +{ +} diff --git a/world/src/generator/town.rs b/world/src/generator/town.rs index effe803c4b..39c8dac312 100644 --- a/world/src/generator/town.rs +++ b/world/src/generator/town.rs @@ -1,18 +1,23 @@ use super::Generator; use crate::util::Sampler; -use common::terrain::Block; +use common::terrain::{Block, BlockKind}; use vek::*; +#[derive(Clone)] pub struct TownState; pub struct TownGen; impl<'a> Sampler<'a> for TownGen { type Index = (&'a TownState, Vec3); - type Sample = Block; + type Sample = Option; fn get(&self, (town, pos): Self::Index) -> Self::Sample { - unimplemented!() + if pos.z < 150 { + Some(Block::new(BlockKind::Normal, Rgb::broadcast(255))) + } else { + None + } } } diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 938ddc1783..b894f992bb 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -11,6 +11,7 @@ use self::util::{ use crate::{ all::ForestKind, + generator::TownState, util::{seed_expan, Sampler, StructureGen2d}, CONFIG, }; @@ -26,6 +27,7 @@ use rand_chacha::ChaChaRng; use std::{ f32, ops::{Add, Div, Mul, Neg, Sub}, + sync::Arc, }; use vek::*; @@ -499,6 +501,8 @@ pub struct SimChunk { pub forest_kind: ForestKind, pub spawn_rate: f32, pub location: Option, + + pub structures: Structures, } #[derive(Copy, Clone)] @@ -515,6 +519,11 @@ pub struct LocationInfo { pub near: Vec, } +#[derive(Clone)] +pub struct Structures { + pub town: Option>, +} + impl SimChunk { fn generate(posi: usize, gen_ctx: &mut GenCtx, gen_cdf: &GenCdf) -> Self { let pos = uniform_idx_as_vec2(posi); @@ -657,6 +666,8 @@ impl SimChunk { }, spawn_rate: 1.0, location: None, + + structures: Structures { town: None }, } }