small fixes

This commit is contained in:
Piotrek
2021-04-29 16:40:53 +02:00
parent ddf0c42784
commit 78d3a43deb
3 changed files with 9 additions and 9 deletions
+6 -6
View File
@@ -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::<f32>() * 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<usize> = 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);
}
}
}
+2 -2
View File
@@ -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]
+1 -1
View File
@@ -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