small fixes
This commit is contained in:
@@ -31,7 +31,7 @@ impl WorldGen {
|
|||||||
for lx in 0..BLOCK_SIZE {
|
for lx in 0..BLOCK_SIZE {
|
||||||
for lz 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 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;
|
h += (rand.gen::<f32>() * 2.0) as usize;
|
||||||
if h > max { max = h; }
|
if h > max { max = h; }
|
||||||
map[lx][lz] = h;
|
map[lx][lz] = h;
|
||||||
@@ -47,11 +47,12 @@ impl WorldGen {
|
|||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let mut dirty: Vec<usize> = Vec::new();
|
let mut dirty: Vec<usize> = Vec::new();
|
||||||
|
|
||||||
for bx in 0..48 {
|
for bx in 0..16 {
|
||||||
for bz in 0..48 {
|
for bz in 0..16 {
|
||||||
// Generate height map
|
// Generate height map
|
||||||
let (map, max) = WorldGen::gen_height_map(bx, bz, &mut rng, noise);
|
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
|
// Generate blocks
|
||||||
for by in 0..bh {
|
for by in 0..bh {
|
||||||
// Get
|
// Get
|
||||||
@@ -63,8 +64,7 @@ impl WorldGen {
|
|||||||
// TODO
|
// TODO
|
||||||
let h = map[x][z];
|
let h = map[x][z];
|
||||||
for y in 0..h {
|
for y in 0..h {
|
||||||
let val = if y+1 == h { 2 } else { 1 };
|
b.set(Point3{x, y, z}, 2);
|
||||||
b.set(Point3{x, y, z}, val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ impl Blocks {
|
|||||||
// Data
|
// Data
|
||||||
let mut blocks = vec![Block::new(); BLOCK_ARR_LEN].into_boxed_slice();
|
let mut blocks = vec![Block::new(); BLOCK_ARR_LEN].into_boxed_slice();
|
||||||
for (i, b) in blocks.iter_mut().enumerate() { b.id = i; }
|
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
|
// Done
|
||||||
Self { blocks, texture, bind_layout, bind_group, free_block: 0 }
|
Self { blocks, texture, bind_layout, bind_group, free_block: 0 }
|
||||||
@@ -148,7 +148,7 @@ impl Blocks {
|
|||||||
*/
|
*/
|
||||||
pub fn alloc(&mut self) -> &mut Block {
|
pub fn alloc(&mut self) -> &mut Block {
|
||||||
// Make sure we still have some free blocks
|
// 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;
|
self.free_block += 1;
|
||||||
&mut self.blocks[self.free_block - 1]
|
&mut self.blocks[self.free_block - 1]
|
||||||
|
|||||||
@@ -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 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_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
|
pub const BLOCK_TEX_LEN: usize = BLOCK_TEX_SIZE*BLOCK_TEX_SIZE * BLOCK_LEN; // Number of u8 in block texture
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user