Added stalagtites

This commit is contained in:
Joshua Barretto 2020-07-26 12:41:46 +01:00
parent c547cdd72c
commit c8ae5163b3
2 changed files with 31 additions and 3 deletions

View File

@ -1,10 +1,11 @@
use crate::site::Site;
use common::store::{Id, Store};
use noise::{NoiseFn, Seedable, SuperSimplex};
#[derive(Default)]
pub struct Index {
pub seed: u32,
pub time: f32,
pub noise: Noise,
pub sites: Store<Site>,
}
@ -12,7 +13,21 @@ impl Index {
pub fn new(seed: u32) -> Self {
Self {
seed,
..Self::default()
time: 0.0,
noise: Noise::new(seed),
sites: Store::default(),
}
}
}
pub struct Noise {
pub cave_nz: SuperSimplex,
}
impl Noise {
fn new(seed: u32) -> Self {
Self {
cave_nz: SuperSimplex::new().set_seed(seed),
}
}
}

View File

@ -9,7 +9,8 @@ use common::{
lottery::Lottery,
assets,
};
use std::f32;
use noise::NoiseFn;
use std::{f32, ops::{Sub, Mul}};
use vek::*;
pub fn apply_paths_to<'a>(
@ -138,6 +139,18 @@ pub fn apply_caves_to<'a>(
let _ = vol.set(Vec3::new(offs.x, offs.y, z), Block::empty());
}
// Stalagtites
let stalagtites = index.noise.cave_nz
.get(wpos2d.map(|e| e as f64 * 0.1).into_array())
.sub(0.6)
.max(0.0)
.mul((col_sample.alt - cave_roof as f32 - 5.0).mul(0.15).clamped(0.0, 1.0) as f64)
.mul(40.0) as i32;
for z in cave_roof - stalagtites..cave_roof {
let _ = vol.set(Vec3::new(offs.x, offs.y, z), Block::new(BlockKind::Normal, Rgb::broadcast(200)));
}
// Scatter things in caves
if RandomField::new(index.seed).chance(wpos2d.into(), 0.001) && cave_base < surface_z as i32 - 25 {
let kind = *assets::load_expect::<Lottery<BlockKind>>("common.cave_scatter")