From 78d3a43deb470e210a0e518cf12eeac4582c77fc Mon Sep 17 00:00:00 2001 From: Piotrek Date: Thu, 29 Apr 2021 16:40:53 +0200 Subject: [PATCH] small fixes --- src/app/world_gen.rs | 12 ++++++------ src/renderer/buffers/blocks.rs | 4 ++-- src/renderer/buffers/mod.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/world_gen.rs b/src/app/world_gen.rs index e315980..ef44f80 100644 --- a/src/app/world_gen.rs +++ b/src/app/world_gen.rs @@ -31,7 +31,7 @@ impl WorldGen { for lx in 0..BLOCK_SIZE { for lz in 0..BLOCK_SIZE { let value = (noise.get([(x + lx) as f64 / SCALE, (z + lz) as f64 /SCALE]) + 1.0) / 2.0; - let mut h = (value * 30.0) as usize + 1; + let mut h = (value * 30.0) as usize; h += (rand.gen::() * 2.0) as usize; if h > max { max = h; } map[lx][lz] = h; @@ -47,11 +47,12 @@ impl WorldGen { let mut rng = rand::thread_rng(); let mut dirty: Vec = Vec::new(); - for bx in 0..48 { - for bz in 0..48 { + for bx in 0..16 { + for bz in 0..16 { // Generate height map let (map, max) = WorldGen::gen_height_map(bx, bz, &mut rng, noise); - let bh = max % BLOCK_SIZE; + let bh = (max / BLOCK_SIZE) + 1; + // Generate blocks for by in 0..bh { // Get @@ -63,8 +64,7 @@ impl WorldGen { // TODO let h = map[x][z]; for y in 0..h { - let val = if y+1 == h { 2 } else { 1 }; - b.set(Point3{x, y, z}, val); + b.set(Point3{x, y, z}, 2); } } } diff --git a/src/renderer/buffers/blocks.rs b/src/renderer/buffers/blocks.rs index 1e3ed60..5a155f3 100644 --- a/src/renderer/buffers/blocks.rs +++ b/src/renderer/buffers/blocks.rs @@ -92,7 +92,7 @@ impl Blocks { // Data let mut blocks = vec![Block::new(); BLOCK_ARR_LEN].into_boxed_slice(); for (i, b) in blocks.iter_mut().enumerate() { b.id = i; } - println!("block buffer size: {} MB", BLOCK_TEX_LEN as f32 / 1024.0 / 1024.0); + println!("Blocks size: {} MB, max: {}", BLOCK_TEX_LEN as f32 / 1024.0 / 1024.0, BLOCK_ARR_LEN); // Done Self { blocks, texture, bind_layout, bind_group, free_block: 0 } @@ -148,7 +148,7 @@ impl Blocks { */ pub fn alloc(&mut self) -> &mut Block { // Make sure we still have some free blocks - if self.free_block >= self.blocks.len() { panic!("No more free blocks! we should consider reusing blocks..."); } + if self.free_block >= BLOCK_ARR_LEN { panic!("No more free blocks! we should consider reusing blocks..."); } self.free_block += 1; &mut self.blocks[self.free_block - 1] diff --git a/src/renderer/buffers/mod.rs b/src/renderer/buffers/mod.rs index 115566f..67716a9 100644 --- a/src/renderer/buffers/mod.rs +++ b/src/renderer/buffers/mod.rs @@ -8,7 +8,7 @@ pub const NODE_TEX_SIZE: usize = 48; // 32x32x32 nodes in texture pub const NODE_TEX_LEN: usize = NODE_TEX_SIZE*NODE_TEX_SIZE*NODE_TEX_SIZE; // Number of u32 in node texture pub const BLOCK_LEN : usize = BLOCK_SIZE*BLOCK_SIZE*BLOCK_SIZE; // Number of u8 in one block -pub const BLOCK_ARR_LEN: usize = NODE_TEX_SIZE*NODE_TEX_SIZE; // Number of blocks in texture +pub const BLOCK_ARR_LEN: usize = BLOCK_TEX_SIZE*BLOCK_TEX_SIZE; // Number of blocks in texture pub const BLOCK_TEX_LEN: usize = BLOCK_TEX_SIZE*BLOCK_TEX_SIZE * BLOCK_LEN; // Number of u8 in block texture