From 00fd077642627b7c4618d23031eb67d2ed008cc2 Mon Sep 17 00:00:00 2001 From: Piotrek Date: Sat, 24 Apr 2021 17:17:09 +0200 Subject: [PATCH] grass? testing --- src/app/mod.rs | 20 +++++++++++++++++--- src/renderer/buffers/brick_buffer.rs | 4 ++++ src/renderer/mod.rs | 8 ++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index c284826..8d52d52 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -3,6 +3,7 @@ use winit::{ window::Window }; use std::sync::Arc; +use rand::Rng; mod camera_controller; use camera_controller::CameraController; mod world_gen; use world_gen::WorldGen; @@ -37,9 +38,11 @@ impl App { // println!("Generated in {}ms", start.elapsed().as_millis()); + let mut rng = rand::thread_rng(); + let start = std::time::Instant::now(); - for bx in 0..4 { - for bz in 0..4 { + for bx in 0..32 { + for bz in 0..32 { let brick_id = renderer.brick_get_id(bx, 0, bz); renderer.brick_mark_changed(brick_id); @@ -53,7 +56,18 @@ impl App { renderer.brick_set_voxel(brick_id, x, 31, z, 2); } } - + + let brick_id = renderer.brick_get_id(bx, 1, bz); + renderer.brick_mark_changed(brick_id); + for x in 0..32 { + for z in 0..32 { + // Dirt + let h = (rng.gen::() * 16.0) as usize; + for y in 0..h { + renderer.brick_set_voxel(brick_id, x, y, z, 2); + } + } + } } } println!("Generated in {}ms", start.elapsed().as_millis()); diff --git a/src/renderer/buffers/brick_buffer.rs b/src/renderer/buffers/brick_buffer.rs index bdba9ea..4ee2955 100644 --- a/src/renderer/buffers/brick_buffer.rs +++ b/src/renderer/buffers/brick_buffer.rs @@ -101,6 +101,10 @@ impl BrickBuffer { ); } + /* + * Get id of next free brick + * Later: reusing old bricks + */ pub fn next_brick(&mut self) -> usize { if self.free_brick >= self.bricks.len() { panic!("No more free bricks! we should consider reusing bricks..."); diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index fb26e3b..6ba9f4b 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -166,6 +166,8 @@ impl Renderer { for node in &self.changed_bricks { self.brick_buffer.write(&self.queue, *node); } + + println!("Changed: {}", self.changed_bricks.len()); self.changed_bricks.clear(); } @@ -213,8 +215,7 @@ impl Renderer { * Create or update brick at given location */ #[allow(dead_code)] - pub fn set_voxel(&mut self, x: usize, y: usize, z:usize, value: u8) - { + pub fn set_voxel(&mut self, x: usize, y: usize, z:usize, value: u8) { let brick_id = self.brick_get_id(x/32, y/32, z/32 ); self.brick_set_voxel(brick_id, x%32, y%32, z%32, value); self.brick_mark_changed(brick_id); @@ -223,8 +224,7 @@ impl Renderer { /* * Create or update brick at given location */ - pub fn brick_set_voxel(&mut self, brick_id:usize, x: usize, y: usize, z:usize, value: u8) - { + pub fn brick_set_voxel(&mut self, brick_id:usize, x: usize, y: usize, z:usize, value: u8) { let voxel_id = x + buffers::BRICK_SIZE * (y + buffers::BRICK_SIZE * z); let brick_offset = brick_id * buffers::BRICK_LEN; self.brick_buffer.bricks[brick_offset + voxel_id] = value;