2020-01-22 03:12:17 +00:00
|
|
|
use common::{
|
2020-01-25 02:15:15 +00:00
|
|
|
generation::{ChunkSupplement, EntityInfo, EntityKind},
|
2020-01-22 03:12:17 +00:00
|
|
|
terrain::{Block, BlockKind, TerrainChunk, TerrainChunkMeta, TerrainChunkSize},
|
|
|
|
vol::{ReadVol, RectVolSize, Vox, WriteVol},
|
|
|
|
};
|
|
|
|
use rand::{prelude::*, rngs::SmallRng};
|
|
|
|
use std::time::Duration;
|
|
|
|
use vek::*;
|
|
|
|
|
2020-01-24 10:40:52 +00:00
|
|
|
pub const WORLD_SIZE: Vec2<usize> = Vec2 { x: 1, y: 1 };
|
2020-01-23 14:10:49 +00:00
|
|
|
|
2020-01-22 03:12:17 +00:00
|
|
|
pub struct World;
|
|
|
|
|
|
|
|
impl World {
|
|
|
|
pub fn generate(_seed: u32) -> Self {
|
|
|
|
Self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tick(&self, dt: Duration) {}
|
|
|
|
|
|
|
|
pub fn generate_chunk(
|
|
|
|
&self,
|
|
|
|
chunk_pos: Vec2<i32>,
|
|
|
|
_should_continue: impl FnMut() -> bool,
|
|
|
|
) -> Result<(TerrainChunk, ChunkSupplement), ()> {
|
|
|
|
let (x, y) = chunk_pos.map(|e| e.to_le_bytes()).into_tuple();
|
|
|
|
let mut rng = SmallRng::from_seed([
|
|
|
|
x[0], x[1], x[2], x[3], y[0], y[1], y[2], y[3], x[0], x[1], x[2], x[3], y[0], y[1],
|
|
|
|
y[2], y[3],
|
|
|
|
]);
|
|
|
|
let height = rng.gen::<i32>() % 8;
|
|
|
|
|
2020-01-25 12:27:36 +00:00
|
|
|
let mut supplement = ChunkSupplement::default();
|
|
|
|
|
2020-01-25 18:49:47 +00:00
|
|
|
if chunk_pos.map(|e| e % 8 == 0).reduce_and() {
|
2020-01-25 12:27:36 +00:00
|
|
|
supplement = supplement.with_entity(EntityInfo {
|
|
|
|
pos: Vec3::<f32>::from(chunk_pos.map(|e| e as f32 * 32.0)) + Vec3::unit_z() * 256.0,
|
|
|
|
kind: EntityKind::Waypoint,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-22 03:12:17 +00:00
|
|
|
Ok((
|
|
|
|
TerrainChunk::new(
|
|
|
|
256 + if rng.gen::<u8>() < 64 { height } else { 0 },
|
|
|
|
Block::new(BlockKind::Dense, Rgb::new(200, 220, 255)),
|
|
|
|
Block::empty(),
|
|
|
|
TerrainChunkMeta::void(),
|
|
|
|
),
|
2020-01-25 12:27:36 +00:00
|
|
|
supplement,
|
2020-01-22 03:12:17 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|