Endless world, still some bugs to figure out

This commit is contained in:
Piotrek
2021-05-14 19:54:46 +02:00
parent e6329d568c
commit 00c518b9c1
9 changed files with 91 additions and 60 deletions
-2
View File
@@ -53,7 +53,6 @@ impl WorldChunk {
}
// Blocks
let timer = Instant::now();
let mut block_bytes = vec![0_u8; num_blocks*block::SIZE_QB];
lz4::decompress(&block_bytes_compressed, &mut block_bytes[0..num_blocks*block::SIZE_QB]).unwrap();
let block_bytes = Arc::new(block_bytes);
@@ -85,7 +84,6 @@ impl WorldChunk {
blocks.sort_by(|a, b| (*a).0.cmp(&(*b).0));
for b in blocks { instance.blocks.push(b.1); }
println!("Blocks: {} ms, {}", timer.elapsed().as_millis(), instance.blocks.len());
instance
}
+12 -3
View File
@@ -42,19 +42,28 @@ impl WorldGen {
* Generate block
*/
pub fn generate(block_pos: &Vector3<i32>, block: &mut WorldBlock) {
if block_pos.z > 32 as i32 { return; }
let mut rng = rand::thread_rng();
let noise = Perlin::new();
// Generate height map
let (map, _max) = WorldGen::gen_height_map(block_pos.x, block_pos.z, &mut rng, &noise);
// Fill
for x in 0..block::SIZE {
for z in 0..block::SIZE {
let h = map[x][z];
let mut h = map[x][z];
let mut t = 2;
if block_pos.x == 8 && block_pos.z == 8 {
h = 32;
t = 3;
}
//let h = 16; // testing
for y in 0..h {
block.set(Vector3{x, y, z}, 2);
block.set(Vector3{x, y, z}, t);
}
}
}
+1
View File
@@ -81,6 +81,7 @@ impl World {
pub fn load_chunk(&mut self, pos: Vector3<i32>) ->bool {
// Abort if chunk is already loaded
if let Some(_) = self.chunks.get(&pos) {
println!("Chunk at {:?} already loaded", pos);
return false;
}