2019-01-15 15:13:11 +00:00
|
|
|
// Library
|
|
|
|
use vek::*;
|
2019-01-23 20:01:58 +00:00
|
|
|
use noise::{NoiseFn, Perlin};
|
2019-01-15 15:13:11 +00:00
|
|
|
|
|
|
|
// Project
|
|
|
|
use common::{
|
2019-01-23 20:01:58 +00:00
|
|
|
vol::{Vox, SizedVol, WriteVol},
|
2019-01-15 15:13:11 +00:00
|
|
|
terrain::{
|
|
|
|
Block,
|
|
|
|
TerrainChunk,
|
|
|
|
TerrainChunkMeta,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
Other(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct World;
|
|
|
|
|
|
|
|
impl World {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self
|
|
|
|
}
|
|
|
|
|
2019-04-10 23:41:37 +00:00
|
|
|
pub fn generate_chunk(chunk_pos: Vec3<i32>) -> TerrainChunk {
|
2019-01-23 22:21:47 +00:00
|
|
|
// TODO: This is all test code, remove/improve this later
|
|
|
|
|
2019-01-23 20:01:58 +00:00
|
|
|
let mut chunk = TerrainChunk::filled(Block::empty(), TerrainChunkMeta::void());
|
|
|
|
|
|
|
|
let air = Block::empty();
|
|
|
|
let stone = Block::new(1, Rgb::new(200, 220, 255));
|
|
|
|
let grass = Block::new(2, Rgb::new(50, 255, 0));
|
2019-01-30 12:11:34 +00:00
|
|
|
let sand = Block::new(3, Rgb::new(180, 150, 50));
|
2019-01-23 20:01:58 +00:00
|
|
|
|
|
|
|
let perlin_nz = Perlin::new();
|
|
|
|
|
|
|
|
for lpos in chunk.iter_positions() {
|
|
|
|
let wpos = lpos + chunk_pos * chunk.get_size().map(|e| e as i32);
|
|
|
|
let wposf = wpos.map(|e| e as f64);
|
|
|
|
|
2019-04-25 08:53:39 +00:00
|
|
|
let freq = 1.0 / 128.0;
|
|
|
|
let ampl = 32.0;
|
|
|
|
let small_freq = 1.0 / 16.0;
|
|
|
|
let small_ampl = 8.0;
|
|
|
|
let offs = 32.0;
|
|
|
|
let height =
|
|
|
|
perlin_nz.get(Vec2::from(wposf * freq).into_array()) * ampl
|
|
|
|
+ perlin_nz.get(Vec2::from(wposf * small_freq).into_array()) * small_ampl
|
|
|
|
+ offs;
|
2019-01-23 20:01:58 +00:00
|
|
|
|
|
|
|
chunk.set(lpos, if wposf.z < height {
|
|
|
|
if wposf.z < height - 1.0 {
|
|
|
|
stone
|
|
|
|
} else {
|
2019-04-23 22:48:31 +00:00
|
|
|
grass
|
2019-01-23 20:01:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
air
|
2019-01-23 22:21:47 +00:00
|
|
|
}).unwrap();
|
2019-01-23 20:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chunk
|
2019-01-15 15:13:11 +00:00
|
|
|
}
|
|
|
|
}
|