2019-05-25 05:54:47 +00:00
|
|
|
use crate::{structure::StructureGen2d, Cache};
|
2019-05-24 11:08:38 +00:00
|
|
|
use common::{
|
2019-05-24 12:25:31 +00:00
|
|
|
assets,
|
2019-05-25 05:54:47 +00:00
|
|
|
terrain::{Block, Structure, TerrainChunkSize},
|
|
|
|
vol::{ReadVol, VolSize, Vox},
|
2019-05-24 11:08:38 +00:00
|
|
|
};
|
2019-05-25 05:54:47 +00:00
|
|
|
use lazy_static::lazy_static;
|
2019-05-21 22:31:38 +00:00
|
|
|
use noise::{
|
|
|
|
BasicMulti, HybridMulti, MultiFractal, NoiseFn, OpenSimplex, RidgedMulti, Seedable,
|
|
|
|
SuperSimplex,
|
|
|
|
};
|
2019-05-20 02:53:04 +00:00
|
|
|
use std::{
|
|
|
|
f32,
|
2019-05-21 22:31:38 +00:00
|
|
|
ops::{Add, Div, Mul, Neg, Sub},
|
2019-05-24 12:25:31 +00:00
|
|
|
sync::Arc,
|
2019-05-20 02:53:04 +00:00
|
|
|
};
|
2019-05-16 17:40:32 +00:00
|
|
|
use vek::*;
|
2019-05-20 02:53:04 +00:00
|
|
|
|
|
|
|
pub const WORLD_SIZE: Vec2<usize> = Vec2 { x: 1024, y: 1024 };
|
2019-05-18 08:59:58 +00:00
|
|
|
|
2019-05-29 13:49:27 +00:00
|
|
|
struct GenCtx {
|
|
|
|
turb_x_nz: BasicMulti,
|
|
|
|
turb_y_nz: BasicMulti,
|
|
|
|
chaos_nz: RidgedMulti,
|
|
|
|
alt_nz: HybridMulti,
|
|
|
|
hill_nz: SuperSimplex,
|
|
|
|
temp_nz: SuperSimplex,
|
|
|
|
small_nz: BasicMulti,
|
|
|
|
rock_nz: HybridMulti,
|
|
|
|
warp_nz: BasicMulti,
|
|
|
|
tree_nz: BasicMulti,
|
|
|
|
|
2019-06-01 12:44:21 +00:00
|
|
|
cave_0_nz: SuperSimplex,
|
2019-05-31 15:16:26 +00:00
|
|
|
cave_1_nz: SuperSimplex,
|
2019-05-29 13:49:27 +00:00
|
|
|
}
|
|
|
|
|
2019-05-18 08:59:58 +00:00
|
|
|
pub struct WorldSim {
|
2019-05-20 02:53:04 +00:00
|
|
|
pub seed: u32,
|
2019-05-18 08:59:58 +00:00
|
|
|
chunks: Vec<SimChunk>,
|
2019-05-21 00:57:16 +00:00
|
|
|
gen_ctx: GenCtx,
|
2019-05-23 20:41:01 +00:00
|
|
|
tree_gen: StructureGen2d,
|
2019-05-18 08:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl WorldSim {
|
|
|
|
pub fn generate(seed: u32) -> Self {
|
|
|
|
let mut gen_ctx = GenCtx {
|
2019-05-21 22:31:38 +00:00
|
|
|
turb_x_nz: BasicMulti::new().set_seed(seed + 0),
|
|
|
|
turb_y_nz: BasicMulti::new().set_seed(seed + 1),
|
|
|
|
chaos_nz: RidgedMulti::new().set_octaves(7).set_seed(seed + 2),
|
|
|
|
hill_nz: SuperSimplex::new().set_seed(seed + 3),
|
2019-05-21 00:57:16 +00:00
|
|
|
alt_nz: HybridMulti::new()
|
|
|
|
.set_octaves(7)
|
|
|
|
.set_persistence(0.1)
|
|
|
|
.set_seed(seed + 4),
|
2019-05-21 22:31:38 +00:00
|
|
|
temp_nz: SuperSimplex::new().set_seed(seed + 5),
|
|
|
|
small_nz: BasicMulti::new().set_octaves(2).set_seed(seed + 6),
|
|
|
|
rock_nz: HybridMulti::new().set_persistence(0.3).set_seed(seed + 7),
|
2019-05-24 11:08:38 +00:00
|
|
|
warp_nz: BasicMulti::new().set_octaves(3).set_seed(seed + 8),
|
2019-05-25 07:36:11 +00:00
|
|
|
tree_nz: BasicMulti::new()
|
|
|
|
.set_octaves(8)
|
|
|
|
.set_persistence(0.75)
|
|
|
|
.set_seed(seed + 9),
|
2019-06-01 12:44:21 +00:00
|
|
|
cave_0_nz: SuperSimplex::new().set_seed(seed + 10),
|
2019-05-31 15:16:26 +00:00
|
|
|
cave_1_nz: SuperSimplex::new().set_seed(seed + 11),
|
2019-05-18 08:59:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut chunks = Vec::new();
|
2019-05-16 17:40:32 +00:00
|
|
|
for x in 0..WORLD_SIZE.x as u32 {
|
|
|
|
for y in 0..WORLD_SIZE.y as u32 {
|
|
|
|
chunks.push(SimChunk::generate(Vec2::new(x, y), &mut gen_ctx));
|
2019-05-18 08:59:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Self {
|
|
|
|
seed,
|
|
|
|
chunks,
|
2019-05-21 00:57:16 +00:00
|
|
|
gen_ctx,
|
2019-05-29 13:49:27 +00:00
|
|
|
tree_gen: StructureGen2d::new(seed, 32, 28),
|
2019-05-18 08:59:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-16 17:40:32 +00:00
|
|
|
|
|
|
|
pub fn get(&self, chunk_pos: Vec2<u32>) -> Option<&SimChunk> {
|
2019-05-21 22:31:38 +00:00
|
|
|
if chunk_pos
|
|
|
|
.map2(WORLD_SIZE, |e, sz| e < sz as u32)
|
|
|
|
.reduce_and()
|
|
|
|
{
|
2019-05-16 17:40:32 +00:00
|
|
|
Some(&self.chunks[chunk_pos.y as usize * WORLD_SIZE.x + chunk_pos.x as usize])
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2019-05-20 02:53:04 +00:00
|
|
|
|
|
|
|
pub fn get_base_z(&self, chunk_pos: Vec2<u32>) -> Option<f32> {
|
2019-05-21 22:31:38 +00:00
|
|
|
self.get(chunk_pos).and_then(|_| {
|
|
|
|
(0..2)
|
|
|
|
.map(|i| (0..2).map(move |j| (i, j)))
|
2019-05-20 02:53:04 +00:00
|
|
|
.flatten()
|
2019-05-21 22:31:38 +00:00
|
|
|
.map(|(i, j)| {
|
|
|
|
self.get(chunk_pos + Vec2::new(i, j))
|
|
|
|
.map(|c| c.get_base_z())
|
|
|
|
})
|
2019-05-20 02:53:04 +00:00
|
|
|
.flatten()
|
2019-05-21 22:31:38 +00:00
|
|
|
.fold(None, |a: Option<f32>, x| a.map(|a| a.min(x)).or(Some(x)))
|
|
|
|
})
|
2019-05-20 02:53:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 15:01:27 +00:00
|
|
|
pub fn get_interpolated<T, F>(&self, pos: Vec2<i32>, mut f: F) -> Option<T>
|
2019-05-21 22:31:38 +00:00
|
|
|
where
|
|
|
|
T: Copy + Default + Add<Output = T> + Mul<f32, Output = T>,
|
|
|
|
F: FnMut(&SimChunk) -> T,
|
2019-05-20 15:01:27 +00:00
|
|
|
{
|
2019-05-21 22:31:38 +00:00
|
|
|
let pos = pos.map2(TerrainChunkSize::SIZE.into(), |e, sz: u32| {
|
|
|
|
e as f64 / sz as f64
|
|
|
|
});
|
2019-05-20 02:53:04 +00:00
|
|
|
|
2019-05-20 15:01:27 +00:00
|
|
|
let cubic = |a: T, b: T, c: T, d: T, x: f32| -> T {
|
2019-05-20 02:53:04 +00:00
|
|
|
let x2 = x * x;
|
|
|
|
|
|
|
|
// Catmull-Rom splines
|
2019-05-20 15:01:27 +00:00
|
|
|
let co0 = a * -0.5 + b * 1.5 + c * -1.5 + d * 0.5;
|
|
|
|
let co1 = a + b * -2.5 + c * 2.0 + d * -0.5;
|
|
|
|
let co2 = a * -0.5 + c * 0.5;
|
2019-05-20 02:53:04 +00:00
|
|
|
let co3 = b;
|
|
|
|
|
|
|
|
co0 * x2 * x + co1 * x2 + co2 * x + co3
|
2019-05-20 15:01:27 +00:00
|
|
|
};
|
2019-05-20 02:53:04 +00:00
|
|
|
|
2019-05-22 09:42:19 +00:00
|
|
|
let mut x = [T::default(); 4];
|
2019-05-20 02:53:04 +00:00
|
|
|
|
2019-05-22 09:42:19 +00:00
|
|
|
for (x_idx, j) in (-1..3).enumerate() {
|
2019-05-25 05:54:47 +00:00
|
|
|
let y0 =
|
|
|
|
f(self.get(pos.map2(Vec2::new(j, -1), |e, q| (e.max(0.0) as i32 + q) as u32))?);
|
|
|
|
let y1 = f(self.get(pos.map2(Vec2::new(j, 0), |e, q| (e.max(0.0) as i32 + q) as u32))?);
|
|
|
|
let y2 = f(self.get(pos.map2(Vec2::new(j, 1), |e, q| (e.max(0.0) as i32 + q) as u32))?);
|
|
|
|
let y3 = f(self.get(pos.map2(Vec2::new(j, 2), |e, q| (e.max(0.0) as i32 + q) as u32))?);
|
2019-05-20 02:53:04 +00:00
|
|
|
|
2019-05-22 09:42:19 +00:00
|
|
|
x[x_idx] = cubic(y0, y1, y2, y3, pos.y.fract() as f32);
|
2019-05-20 02:53:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 09:42:19 +00:00
|
|
|
Some(cubic(x[0], x[1], x[2], x[3], pos.x.fract() as f32))
|
2019-05-20 02:53:04 +00:00
|
|
|
}
|
2019-05-21 00:57:16 +00:00
|
|
|
|
2019-05-23 20:41:01 +00:00
|
|
|
pub fn sampler(&self) -> Sampler {
|
|
|
|
Sampler {
|
|
|
|
sim: self,
|
2019-05-24 11:08:38 +00:00
|
|
|
sample2d_cache: Cache::with_capacity(1024),
|
2019-05-23 20:41:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Sampler<'a> {
|
|
|
|
sim: &'a WorldSim,
|
2019-05-24 11:08:38 +00:00
|
|
|
sample2d_cache: Cache<Vec2<i32>, Option<Sample2d>>,
|
2019-05-23 20:41:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Sampler<'a> {
|
2019-05-24 11:08:38 +00:00
|
|
|
fn sample_2d_impl(sim: &WorldSim, wpos: Vec2<i32>) -> Option<Sample2d> {
|
2019-05-23 20:41:01 +00:00
|
|
|
let wposf = wpos.map(|e| e as f64);
|
2019-05-21 00:57:16 +00:00
|
|
|
|
2019-05-24 11:08:38 +00:00
|
|
|
let alt_base = sim.get_interpolated(wpos, |chunk| chunk.alt_base)?;
|
|
|
|
let chaos = sim.get_interpolated(wpos, |chunk| chunk.chaos)?;
|
|
|
|
let temp = sim.get_interpolated(wpos, |chunk| chunk.temp)?;
|
|
|
|
let rockiness = sim.get_interpolated(wpos, |chunk| chunk.rockiness)?;
|
2019-05-25 05:38:40 +00:00
|
|
|
let tree_density = sim.get_interpolated(wpos, |chunk| chunk.tree_density)?;
|
2019-05-21 12:28:53 +00:00
|
|
|
|
2019-05-24 11:08:38 +00:00
|
|
|
let rock = (sim.gen_ctx.small_nz.get((wposf.div(100.0)).into_array()) as f32)
|
2019-05-21 12:28:53 +00:00
|
|
|
.mul(rockiness)
|
2019-05-21 21:50:12 +00:00
|
|
|
.sub(0.2)
|
2019-05-21 12:28:53 +00:00
|
|
|
.max(0.0)
|
2019-05-21 21:50:12 +00:00
|
|
|
.mul(2.0);
|
2019-05-21 00:57:16 +00:00
|
|
|
|
2019-05-24 11:08:38 +00:00
|
|
|
let alt = sim.get_interpolated(wpos, |chunk| chunk.alt)?
|
2019-05-24 14:32:37 +00:00
|
|
|
+ sim.gen_ctx.small_nz.get((wposf.div(256.0)).into_array()) as f32
|
|
|
|
* chaos.max(0.2)
|
|
|
|
* 64.0
|
2019-05-21 21:50:12 +00:00
|
|
|
+ rock * 15.0;
|
2019-05-21 00:57:16 +00:00
|
|
|
|
2019-05-22 09:42:19 +00:00
|
|
|
let wposf3d = Vec3::new(wposf.x, wposf.y, alt as f64);
|
|
|
|
|
2019-05-29 21:24:47 +00:00
|
|
|
let marble = (sim.gen_ctx.hill_nz.get((wposf3d.div(48.0)).into_array()) as f32)
|
2019-05-25 05:54:47 +00:00
|
|
|
.add(1.0)
|
|
|
|
.mul(0.5);
|
2019-05-22 09:42:19 +00:00
|
|
|
|
2019-05-21 00:57:16 +00:00
|
|
|
// Colours
|
2019-06-03 21:35:03 +00:00
|
|
|
let cold_grass = Rgb::new(0.1, 0.6, 0.3);
|
|
|
|
let warm_grass = Rgb::new(0.25, 0.8, 0.05);
|
2019-05-29 21:24:47 +00:00
|
|
|
let cold_stone = Rgb::new(0.55, 0.7, 0.75);
|
|
|
|
let warm_stone = Rgb::new(0.65, 0.65, 0.35);
|
|
|
|
let beach_sand = Rgb::new(0.93, 0.84, 0.33);
|
|
|
|
let desert_sand = Rgb::new(0.97, 0.84, 0.23);
|
2019-05-22 16:24:08 +00:00
|
|
|
let snow = Rgb::broadcast(1.0);
|
2019-05-21 12:28:53 +00:00
|
|
|
|
2019-05-29 21:24:47 +00:00
|
|
|
let grass = Rgb::lerp(cold_grass, warm_grass, marble);
|
|
|
|
let grassland = Rgb::lerp(grass, warm_stone, rock.mul(5.0).min(0.8));
|
2019-05-22 09:42:19 +00:00
|
|
|
let cliff = Rgb::lerp(cold_stone, warm_stone, marble);
|
2019-05-21 00:57:16 +00:00
|
|
|
|
2019-05-29 21:24:47 +00:00
|
|
|
let ground = Rgb::lerp(
|
2019-05-31 23:07:09 +00:00
|
|
|
Rgb::lerp(snow, grassland, temp.add(0.4).mul(32.0).sub(0.4)),
|
2019-05-29 21:24:47 +00:00
|
|
|
desert_sand,
|
2019-05-31 23:07:09 +00:00
|
|
|
temp.sub(0.4).mul(32.0).add(0.4),
|
2019-05-29 21:24:47 +00:00
|
|
|
);
|
|
|
|
|
2019-05-31 15:16:26 +00:00
|
|
|
// Caves
|
2019-06-01 12:44:21 +00:00
|
|
|
let cave_at = |wposf: Vec2<f64>| {
|
|
|
|
(sim.gen_ctx.cave_0_nz.get(
|
|
|
|
Vec3::new(wposf.x, wposf.y, alt as f64 * 8.0)
|
|
|
|
.div(1000.0)
|
|
|
|
.into_array(),
|
|
|
|
) as f32)
|
|
|
|
.powf(2.0)
|
|
|
|
.neg()
|
|
|
|
.add(1.0)
|
|
|
|
.mul((1.15 - chaos).min(1.0))
|
|
|
|
};
|
2019-05-31 23:58:59 +00:00
|
|
|
let cave_xy = cave_at(wposf);
|
2019-05-31 21:27:34 +00:00
|
|
|
let cave_alt = alt - 32.0
|
2019-06-01 12:44:21 +00:00
|
|
|
+ (sim
|
|
|
|
.gen_ctx
|
|
|
|
.cave_1_nz
|
|
|
|
.get(Vec2::new(wposf.x, wposf.y).div(48.0).into_array()) as f32)
|
|
|
|
* 8.0
|
|
|
|
+ (sim
|
|
|
|
.gen_ctx
|
|
|
|
.cave_1_nz
|
|
|
|
.get(Vec2::new(wposf.x, wposf.y).div(300.0).into_array()) as f32)
|
|
|
|
.add(1.0)
|
|
|
|
.mul(0.5)
|
|
|
|
.powf(8.0)
|
|
|
|
.mul(256.0);
|
2019-05-31 15:16:26 +00:00
|
|
|
|
2019-05-24 11:08:38 +00:00
|
|
|
Some(Sample2d {
|
2019-05-21 00:57:16 +00:00
|
|
|
alt,
|
2019-05-21 21:50:12 +00:00
|
|
|
chaos,
|
|
|
|
surface_color: Rgb::lerp(
|
2019-05-29 21:24:47 +00:00
|
|
|
beach_sand,
|
2019-05-21 21:50:12 +00:00
|
|
|
// Land
|
2019-05-22 16:24:08 +00:00
|
|
|
Rgb::lerp(
|
|
|
|
ground,
|
|
|
|
// Mountain
|
|
|
|
Rgb::lerp(
|
|
|
|
cliff,
|
|
|
|
snow,
|
2019-05-24 23:00:44 +00:00
|
|
|
(alt - SEA_LEVEL - 350.0 - alt_base - temp * 48.0) / 12.0,
|
2019-05-22 16:24:08 +00:00
|
|
|
),
|
2019-05-25 05:54:47 +00:00
|
|
|
(alt - SEA_LEVEL - 150.0) / 180.0,
|
2019-05-22 16:24:08 +00:00
|
|
|
),
|
2019-05-21 21:50:12 +00:00
|
|
|
// Beach
|
|
|
|
(alt - SEA_LEVEL - 2.0) / 5.0,
|
|
|
|
),
|
2019-05-25 05:38:40 +00:00
|
|
|
tree_density,
|
2019-05-24 11:08:38 +00:00
|
|
|
close_trees: sim.tree_gen.sample(wpos),
|
2019-05-31 15:16:26 +00:00
|
|
|
cave_xy,
|
|
|
|
cave_alt,
|
2019-05-24 11:08:38 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sample_2d(&mut self, wpos2d: Vec2<i32>) -> Option<&Sample2d> {
|
|
|
|
let sim = &self.sim;
|
2019-05-25 05:54:47 +00:00
|
|
|
self.sample2d_cache
|
|
|
|
.get(wpos2d, |wpos2d| Self::sample_2d_impl(sim, wpos2d))
|
|
|
|
.as_ref()
|
2019-05-24 11:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sample_3d(&mut self, wpos: Vec3<i32>) -> Option<Sample3d> {
|
|
|
|
let wpos2d = Vec2::from(wpos);
|
|
|
|
let wposf = wpos.map(|e| e as f64);
|
|
|
|
|
|
|
|
// Sample 2D terrain attributes
|
|
|
|
|
|
|
|
let Sample2d {
|
|
|
|
alt,
|
|
|
|
chaos,
|
|
|
|
surface_color,
|
2019-05-25 05:38:40 +00:00
|
|
|
tree_density,
|
2019-05-24 11:08:38 +00:00
|
|
|
close_trees,
|
2019-05-31 15:16:26 +00:00
|
|
|
cave_xy,
|
|
|
|
cave_alt,
|
2019-05-24 12:25:31 +00:00
|
|
|
} = *self.sample_2d(wpos2d)?;
|
2019-05-24 11:08:38 +00:00
|
|
|
|
|
|
|
// Apply warping
|
|
|
|
|
2019-05-25 05:54:47 +00:00
|
|
|
let warp = (self
|
|
|
|
.sim
|
|
|
|
.gen_ctx
|
|
|
|
.warp_nz
|
2019-05-24 11:08:38 +00:00
|
|
|
.get((wposf.div(Vec3::new(120.0, 120.0, 150.0))).into_array())
|
|
|
|
as f32)
|
|
|
|
.mul((chaos - 0.1).max(0.0))
|
2019-05-31 21:27:34 +00:00
|
|
|
.mul(110.0);
|
2019-05-24 11:08:38 +00:00
|
|
|
|
|
|
|
let height = alt + warp;
|
|
|
|
let temp = 0.0;
|
|
|
|
|
|
|
|
// Sample blocks
|
|
|
|
|
|
|
|
let air = Block::empty();
|
2019-05-31 20:37:11 +00:00
|
|
|
let stone = Block::new(2, Rgb::new(200, 220, 255));
|
|
|
|
let dirt = Block::new(1, Rgb::new(128, 90, 0));
|
|
|
|
let sand = Block::new(1, Rgb::new(180, 150, 50));
|
|
|
|
let water = Block::new(1, Rgb::new(100, 150, 255));
|
2019-05-24 11:08:38 +00:00
|
|
|
|
2019-05-30 20:05:28 +00:00
|
|
|
let ground_block = if (wposf.z as f32) < height - 4.0 {
|
|
|
|
// Underground
|
2019-05-29 13:49:27 +00:00
|
|
|
Some(stone)
|
2019-05-30 20:05:28 +00:00
|
|
|
} else if (wposf.z as f32) < height {
|
|
|
|
// Surface
|
2019-05-29 13:49:27 +00:00
|
|
|
Some(Block::new(1, surface_color.map(|e| (e * 255.0) as u8)))
|
2019-05-30 20:05:28 +00:00
|
|
|
} else if (wposf.z as f32) < SEA_LEVEL {
|
|
|
|
// Ocean
|
2019-05-29 13:49:27 +00:00
|
|
|
Some(water)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2019-06-01 12:44:21 +00:00
|
|
|
let ground_block = if let Some(block) = ground_block {
|
|
|
|
// Underground
|
|
|
|
let cave = cave_xy.powf(2.0)
|
|
|
|
* (wposf.z as f32 - cave_alt)
|
|
|
|
.div(40.0)
|
|
|
|
.powf(4.0)
|
|
|
|
.neg()
|
|
|
|
.add(1.0)
|
|
|
|
> 0.9993;
|
2019-05-29 21:24:47 +00:00
|
|
|
|
|
|
|
if cave {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(block)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2019-05-29 13:49:27 +00:00
|
|
|
let block = match ground_block {
|
|
|
|
Some(block) => block,
|
|
|
|
None => (&close_trees)
|
2019-05-25 05:54:47 +00:00
|
|
|
.iter()
|
|
|
|
.fold(air, |block, (tree_pos, tree_seed)| {
|
|
|
|
match self.sample_2d(*tree_pos) {
|
2019-05-25 07:36:11 +00:00
|
|
|
Some(tree_sample)
|
|
|
|
if tree_sample.tree_density
|
|
|
|
> 0.5 + (*tree_seed as f32 / 1000.0).fract() * 0.2 =>
|
|
|
|
{
|
2019-05-25 05:54:47 +00:00
|
|
|
let tree_pos3d =
|
|
|
|
Vec3::new(tree_pos.x, tree_pos.y, tree_sample.alt as i32);
|
|
|
|
block.or(TREES[*tree_seed as usize % TREES.len()]
|
|
|
|
.get(wpos - tree_pos3d)
|
|
|
|
.map(|b| b.clone())
|
|
|
|
.unwrap_or(Block::empty()))
|
|
|
|
}
|
|
|
|
_ => block,
|
|
|
|
}
|
2019-05-29 13:49:27 +00:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
Some(Sample3d { block })
|
2019-05-21 00:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 12:25:31 +00:00
|
|
|
lazy_static! {
|
2019-05-30 20:05:28 +00:00
|
|
|
static ref TREES: [Arc<Structure>; 61] = [
|
2019-05-30 14:19:40 +00:00
|
|
|
// green oaks
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/oak_green/1.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(15, 18, 14)))
|
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/oak_green/2.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(15, 18, 14)))
|
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/oak_green/3.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(16, 20, 14)))
|
2019-05-25 05:54:47 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/oak_green/4.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(18, 21, 14)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/oak_green/5.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(18, 18, 14)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/oak_green/6.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(16, 21, 14)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/oak_green/7.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(20, 19, 14)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/oak_green/8.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(22, 20, 14)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/oak_green/9.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(26, 26, 14)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
|
|
|
// green pines
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/pine_green/1.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(15, 15, 14)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green/2.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(15, 15, 14)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green/3.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(17, 15, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green/4.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 8, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green/5.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 12, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green/6.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(11, 10, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green/7.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(16, 15, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green/8.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 10, 12)))
|
|
|
|
.unwrap(),
|
2019-05-30 19:41:10 +00:00
|
|
|
// green pines 2
|
|
|
|
assets::load_map("world/tree/pine_green_2/1.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(15, 15, 14)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green_2/2.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(15, 15, 14)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green_2/3.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(17, 15, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green_2/4.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 8, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green_2/5.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 12, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green_2/6.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(11, 10, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green_2/7.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(16, 15, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/pine_green_2/8.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 10, 12)))
|
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
// blue pines
|
|
|
|
assets::load_map("world/tree/pine_blue/1.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(15, 15, 14)))
|
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/pine_blue/2.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(15, 15, 14)))
|
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/pine_blue/3.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(17, 15, 12)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/pine_blue/4.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 8, 12)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/pine_blue/5.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 12, 12)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/pine_blue/6.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(11, 10, 12)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/pine_blue/7.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(16, 15, 12)))
|
2019-05-30 14:19:40 +00:00
|
|
|
.unwrap(),
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/pine_blue/8.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 10, 12)))
|
2019-05-25 05:54:47 +00:00
|
|
|
.unwrap(),
|
2019-05-30 14:19:40 +00:00
|
|
|
// temperate small
|
|
|
|
assets::load_map("world/tree/temperate_small/1.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(4, 4, 7)))
|
|
|
|
.unwrap(),
|
2019-05-30 14:19:40 +00:00
|
|
|
assets::load_map("world/tree/temperate_small/2.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(4, 4, 7)))
|
|
|
|
.unwrap(),
|
2019-05-30 14:19:40 +00:00
|
|
|
assets::load_map("world/tree/temperate_small/3.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(4, 4, 7)))
|
|
|
|
.unwrap(),
|
2019-05-30 14:19:40 +00:00
|
|
|
assets::load_map("world/tree/temperate_small/4.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(4, 4, 7)))
|
|
|
|
.unwrap(),
|
2019-05-30 14:19:40 +00:00
|
|
|
assets::load_map("world/tree/temperate_small/5.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(4, 4, 7)))
|
|
|
|
.unwrap(),
|
2019-05-30 14:19:40 +00:00
|
|
|
assets::load_map("world/tree/temperate_small/6.vox", |s: Structure| s
|
2019-05-25 05:54:47 +00:00
|
|
|
.with_center(Vec3::new(4, 4, 7)))
|
|
|
|
.unwrap(),
|
2019-05-30 20:05:28 +00:00
|
|
|
// birch
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/birch/1.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(12, 9, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/2.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(11, 10, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/3.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 10, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/4.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 10, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/5.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 11, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/6.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 9, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/7.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(10, 10, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/8.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 9, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/9.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 10, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/10.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(10, 9, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/11.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 10, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/birch/12.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(10, 9, 5)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
2019-05-30 20:05:28 +00:00
|
|
|
// poplar
|
2019-05-30 15:53:43 +00:00
|
|
|
assets::load_map("world/tree/poplar/1.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(6, 6, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/poplar/2.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(6, 6, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/poplar/3.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(6, 6, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/poplar/4.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(6, 6, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/poplar/5.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(6, 6, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/poplar/6.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(6, 6, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/poplar/7.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(6, 6, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/poplar/8.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(6, 6, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/poplar/9.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(6, 6, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/poplar/10.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(7, 7, 10)))
|
2019-05-30 15:53:43 +00:00
|
|
|
.unwrap(),
|
2019-05-30 19:39:51 +00:00
|
|
|
// palm trees
|
|
|
|
/*assets::load_map("world/tree/desert_palm/1.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 12, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/desert_palm/2.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 10, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/desert_palm/3.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 12, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/desert_palm/4.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 10, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/desert_palm/5.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 10, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/desert_palm/6.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 10, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/desert_palm/7.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 10, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/desert_palm/8.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 10, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/desert_palm/9.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 10, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/desert_palm/10.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 10, 10)))
|
|
|
|
.unwrap(),
|
|
|
|
// snow pines
|
|
|
|
assets::load_map("world/tree/snow_pine/1.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(15, 15, 14)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_pine/2.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(15, 15, 14)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_pine/3.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(17, 15, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_pine/4.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(10, 8, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_pine/5.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 12, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_pine/6.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(11, 10, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_pine/7.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(16, 15, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_pine/8.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(12, 10, 12)))
|
|
|
|
.unwrap(),
|
|
|
|
// snow birches -> need roots!
|
|
|
|
assets::load_map("world/tree/snow_birch/1.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(12, 9, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/2.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(11, 10, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/3.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 10, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/4.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 10, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/5.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 11, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/6.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 9, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/7.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(10, 10, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/8.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 9, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/9.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 10, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/10.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(10, 9, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/11.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(9, 10, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/snow_birch/12.vox", |s: Structure| s
|
2019-05-30 20:05:28 +00:00
|
|
|
.with_center(Vec3::new(10, 9, 4)))
|
2019-05-30 19:39:51 +00:00
|
|
|
.unwrap(),
|
|
|
|
// willows
|
|
|
|
assets::load_map("world/tree/willow/1.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(15, 14, 1)))
|
|
|
|
.unwrap(),
|
|
|
|
assets::load_map("world/tree/willow/2.vox", |s: Structure| s
|
|
|
|
.with_center(Vec3::new(11, 12, 1)))
|
|
|
|
.unwrap(),
|
|
|
|
*/
|
|
|
|
|
2019-05-25 05:38:40 +00:00
|
|
|
];
|
2019-05-24 12:25:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 11:08:38 +00:00
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct Sample2d {
|
2019-05-21 00:57:16 +00:00
|
|
|
pub alt: f32,
|
2019-05-21 21:50:12 +00:00
|
|
|
pub chaos: f32,
|
2019-05-21 00:57:16 +00:00
|
|
|
pub surface_color: Rgb<f32>,
|
2019-05-25 05:38:40 +00:00
|
|
|
pub tree_density: f32,
|
|
|
|
pub close_trees: [(Vec2<i32>, u32); 9],
|
2019-05-31 15:16:26 +00:00
|
|
|
pub cave_xy: f32,
|
|
|
|
pub cave_alt: f32,
|
2019-05-18 08:59:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 12:25:31 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2019-05-24 11:08:38 +00:00
|
|
|
pub struct Sample3d {
|
|
|
|
pub block: Block,
|
|
|
|
}
|
|
|
|
|
2019-05-30 15:53:43 +00:00
|
|
|
const Z_TOLERANCE: (f32, f32) = (126.0, 94.0);
|
2019-05-24 14:32:37 +00:00
|
|
|
pub const SEA_LEVEL: f32 = 128.0;
|
2019-05-20 15:01:27 +00:00
|
|
|
|
2019-05-16 17:40:32 +00:00
|
|
|
pub struct SimChunk {
|
2019-05-20 02:53:04 +00:00
|
|
|
pub chaos: f32,
|
2019-05-23 08:19:19 +00:00
|
|
|
pub alt_base: f32,
|
2019-05-16 17:40:32 +00:00
|
|
|
pub alt: f32,
|
2019-05-21 12:28:53 +00:00
|
|
|
pub temp: f32,
|
|
|
|
pub rockiness: f32,
|
2019-05-25 05:38:40 +00:00
|
|
|
pub tree_density: f32,
|
2019-05-18 08:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SimChunk {
|
2019-05-16 17:40:32 +00:00
|
|
|
fn generate(pos: Vec2<u32>, gen_ctx: &mut GenCtx) -> Self {
|
|
|
|
let wposf = (pos * Vec2::from(TerrainChunkSize::SIZE)).map(|e| e as f64);
|
|
|
|
|
2019-05-24 14:32:37 +00:00
|
|
|
let hill = (0.0
|
2019-05-25 05:54:47 +00:00
|
|
|
+ gen_ctx
|
|
|
|
.hill_nz
|
|
|
|
.get((wposf.div(3_500.0)).into_array())
|
|
|
|
.mul(1.0) as f32
|
|
|
|
+ gen_ctx
|
|
|
|
.hill_nz
|
|
|
|
.get((wposf.div(1_000.0)).into_array())
|
|
|
|
.mul(0.3) as f32)
|
|
|
|
.add(0.3)
|
|
|
|
.max(0.0);
|
2019-05-21 12:28:53 +00:00
|
|
|
|
2019-05-24 14:32:37 +00:00
|
|
|
let chaos = (gen_ctx.chaos_nz.get((wposf.div(4_000.0)).into_array()) as f32)
|
2019-05-21 22:31:38 +00:00
|
|
|
.add(1.0)
|
|
|
|
.mul(0.5)
|
2019-05-31 23:07:09 +00:00
|
|
|
.powf(1.5)
|
|
|
|
.add(0.1 * hill);
|
2019-05-21 00:57:16 +00:00
|
|
|
|
2019-05-24 14:32:37 +00:00
|
|
|
let chaos = chaos + chaos.mul(16.0).sin().mul(0.02);
|
2019-05-20 02:53:04 +00:00
|
|
|
|
2019-05-24 14:32:37 +00:00
|
|
|
let alt_base = gen_ctx.alt_nz.get((wposf.div(6_000.0)).into_array()) as f32;
|
2019-05-23 08:19:19 +00:00
|
|
|
let alt_base = alt_base
|
|
|
|
.mul(0.4)
|
2019-05-24 23:00:44 +00:00
|
|
|
.add(alt_base.mul(128.0).sin().mul(0.004))
|
2019-05-24 14:32:37 +00:00
|
|
|
.mul(600.0);
|
2019-05-21 21:50:12 +00:00
|
|
|
|
2019-05-24 12:54:21 +00:00
|
|
|
let alt_main = gen_ctx.alt_nz.get((wposf.div(1_500.0)).into_array()) as f32;
|
2019-05-21 12:28:53 +00:00
|
|
|
|
2019-05-25 07:36:11 +00:00
|
|
|
let alt = SEA_LEVEL
|
|
|
|
+ alt_base
|
|
|
|
+ (0.0
|
|
|
|
+ alt_main
|
|
|
|
+ gen_ctx.small_nz.get((wposf.div(300.0)).into_array()) as f32
|
|
|
|
* alt_main.max(0.05)
|
|
|
|
* chaos
|
|
|
|
* 1.3)
|
|
|
|
.add(1.0)
|
|
|
|
.mul(0.5)
|
|
|
|
.mul(chaos)
|
|
|
|
.mul(1200.0);
|
|
|
|
|
2019-05-18 08:59:58 +00:00
|
|
|
Self {
|
2019-05-20 02:53:04 +00:00
|
|
|
chaos,
|
2019-05-23 08:19:19 +00:00
|
|
|
alt_base,
|
2019-05-25 07:36:11 +00:00
|
|
|
alt,
|
2019-05-29 21:24:47 +00:00
|
|
|
temp: (gen_ctx.temp_nz.get((wposf.div(8192.0)).into_array()) as f32),
|
2019-05-21 12:28:53 +00:00
|
|
|
rockiness: (gen_ctx.rock_nz.get((wposf.div(1024.0)).into_array()) as f32)
|
|
|
|
.sub(0.1)
|
|
|
|
.mul(1.2)
|
|
|
|
.max(0.0),
|
2019-05-25 05:38:40 +00:00
|
|
|
tree_density: (gen_ctx.tree_nz.get((wposf.div(1024.0)).into_array()) as f32)
|
|
|
|
.add(1.0)
|
|
|
|
.mul(0.5)
|
2019-05-29 21:24:47 +00:00
|
|
|
.mul(1.0 - chaos * 0.85)
|
2019-05-25 07:36:11 +00:00
|
|
|
.add(0.1)
|
|
|
|
.mul(if alt > SEA_LEVEL + 3.0 { 1.0 } else { 0.0 }),
|
2019-05-18 08:59:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-20 02:53:04 +00:00
|
|
|
|
|
|
|
pub fn get_base_z(&self) -> f32 {
|
2019-06-04 12:45:41 +00:00
|
|
|
self.alt - 8.0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_min_z(&self) -> f32 {
|
2019-05-31 15:16:26 +00:00
|
|
|
self.alt - Z_TOLERANCE.0 * (self.chaos + 0.3)
|
2019-05-20 15:01:27 +00:00
|
|
|
}
|
2019-05-20 02:53:04 +00:00
|
|
|
|
2019-05-20 15:01:27 +00:00
|
|
|
pub fn get_max_z(&self) -> f32 {
|
2019-06-04 12:45:41 +00:00
|
|
|
(self.alt + Z_TOLERANCE.1).max(SEA_LEVEL)
|
2019-05-21 12:28:53 +00:00
|
|
|
}
|
|
|
|
}
|