grass? testing
This commit is contained in:
+16
-2
@@ -3,6 +3,7 @@ use winit::{
|
|||||||
window::Window
|
window::Window
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
mod camera_controller; use camera_controller::CameraController;
|
mod camera_controller; use camera_controller::CameraController;
|
||||||
mod world_gen; use world_gen::WorldGen;
|
mod world_gen; use world_gen::WorldGen;
|
||||||
@@ -37,9 +38,11 @@ impl App {
|
|||||||
// println!("Generated in {}ms", start.elapsed().as_millis());
|
// println!("Generated in {}ms", start.elapsed().as_millis());
|
||||||
|
|
||||||
|
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
let start = std::time::Instant::now();
|
let start = std::time::Instant::now();
|
||||||
for bx in 0..4 {
|
for bx in 0..32 {
|
||||||
for bz in 0..4 {
|
for bz in 0..32 {
|
||||||
|
|
||||||
let brick_id = renderer.brick_get_id(bx, 0, bz);
|
let brick_id = renderer.brick_get_id(bx, 0, bz);
|
||||||
renderer.brick_mark_changed(brick_id);
|
renderer.brick_mark_changed(brick_id);
|
||||||
@@ -54,6 +57,17 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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::<f32>() * 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());
|
println!("Generated in {}ms", start.elapsed().as_millis());
|
||||||
|
|||||||
@@ -101,6 +101,10 @@ impl BrickBuffer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get id of next free brick
|
||||||
|
* Later: reusing old bricks
|
||||||
|
*/
|
||||||
pub fn next_brick(&mut self) -> usize {
|
pub fn next_brick(&mut self) -> usize {
|
||||||
if self.free_brick >= self.bricks.len() {
|
if self.free_brick >= self.bricks.len() {
|
||||||
panic!("No more free bricks! we should consider reusing bricks...");
|
panic!("No more free bricks! we should consider reusing bricks...");
|
||||||
|
|||||||
+4
-4
@@ -166,6 +166,8 @@ impl Renderer {
|
|||||||
for node in &self.changed_bricks {
|
for node in &self.changed_bricks {
|
||||||
self.brick_buffer.write(&self.queue, *node);
|
self.brick_buffer.write(&self.queue, *node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Changed: {}", self.changed_bricks.len());
|
||||||
self.changed_bricks.clear();
|
self.changed_bricks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,8 +215,7 @@ impl Renderer {
|
|||||||
* Create or update brick at given location
|
* Create or update brick at given location
|
||||||
*/
|
*/
|
||||||
#[allow(dead_code)]
|
#[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 );
|
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_set_voxel(brick_id, x%32, y%32, z%32, value);
|
||||||
self.brick_mark_changed(brick_id);
|
self.brick_mark_changed(brick_id);
|
||||||
@@ -223,8 +224,7 @@ impl Renderer {
|
|||||||
/*
|
/*
|
||||||
* Create or update brick at given location
|
* 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 voxel_id = x + buffers::BRICK_SIZE * (y + buffers::BRICK_SIZE * z);
|
||||||
let brick_offset = brick_id * buffers::BRICK_LEN;
|
let brick_offset = brick_id * buffers::BRICK_LEN;
|
||||||
self.brick_buffer.bricks[brick_offset + voxel_id] = value;
|
self.brick_buffer.bricks[brick_offset + voxel_id] = value;
|
||||||
|
|||||||
Reference in New Issue
Block a user