This commit is contained in:
Piotrek
2021-05-06 15:38:51 +02:00
parent 5b1ca38d75
commit 45362afbf4
7 changed files with 26 additions and 30 deletions
+1
View File
@@ -28,6 +28,7 @@ impl App {
let block = app.world.gen_block(pos);
content.write(pos, block);
println!("App initialized");
app
}
+11 -22
View File
@@ -39,33 +39,22 @@ impl WorldGen {
/*
* Generate block
*/
pub fn generate(block: &mut WorldBlock) {
pub fn generate(block_pos: &Point3<u32>, block: &mut WorldBlock) {
let mut rng = rand::thread_rng();
let mut noise = Perlin::new();
let mut dirty: Vec<usize> = Vec::new();
let noise = Perlin::new();
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) + 1;
// Generate height map
let (map, max) = WorldGen::gen_height_map(block_pos.x as usize, block_pos.z as usize, &mut rng, &noise);
// Generate blocks
for by in 0..bh {
// Fill
for x in 0..block::SIZE {
for z in 0..block::SIZE {
// TODO
let h = map[x][z];
for y in 0..h {
block.set(Point3{x, y, z}, 2);
}
}
}
// Fill
for x in 0..block::SIZE {
for z in 0..block::SIZE {
//let h = map[x][z];
let h = 16; // testing
for y in 0..h {
block.set(Point3{x, y, z}, 2);
}
}
}
// loop end
}
}
+2 -1
View File
@@ -32,10 +32,11 @@ impl World {
// Generate block for chunk
let chunk = self.chunks.get_mut(block_pos).unwrap();
let block = chunk.get_block(&bl_pos);
WorldGen::generate(block);
WorldGen::generate(&bl_pos, block);
block
}
#[allow(unused)]
pub fn get_block(&mut self, block_pos: &Point3<u32>) -> Option<&WorldBlock> {
// Split world space to chunk and block space
let ch_pos = block_pos / chunk::SIZE;
+9 -4
View File
@@ -89,18 +89,23 @@ impl Content {
// Allocate new block
if value == 0 {
value = self.block_freeidx;
value = self.block_freeidx + 1;
self.node_buffer[index] = value as u32;
self.block_freeidx += 1;
self.block_freeidx = value;
//println!("Alloc: {}", value);
}
//println!("Index: {} Value: {}", index, value);
// Calculate position in block texture
let y = (value % BLOCK_TEX_SIZE * BLOCK_SIZE) as u32;
let z = (value / BLOCK_TEX_SIZE * BLOCK_SIZE) as u32;
let y = ((value-1) % BLOCK_TEX_SIZE * BLOCK_SIZE) as u32;
let z = ((value-1) / BLOCK_TEX_SIZE * BLOCK_SIZE) as u32;
let block_origin = wgpu::Origin3d{ x:0, y, z };
let block_size = wgpu::Extent3d{ width: BLOCK_SIZE as u32, height: BLOCK_SIZE as u32, depth: BLOCK_SIZE as u32 };
let block_bytes : [u8;BLOCK_SIZE*BLOCK_SIZE*BLOCK_SIZE] = block.materials.try_into().unwrap();
//println!("Y: {} Z: {}", y, z);
// Write block
queue.write_texture(
wgpu::TextureCopyView { texture: &self.block_texture, mip_level: 0, origin: block_origin }, &block_bytes,
+1 -1
View File
@@ -79,7 +79,7 @@ impl Renderer {
// Other
let start = std::time::Instant::now();
println!("Initialized");
println!("Renderer initialized");
Self { surface, device, queue, swapchain_desc, swapchain, texture, raytrace_pass, postprocess_pass, buffers, camera, start }
}
Binary file not shown.
+2 -2
View File
@@ -15,8 +15,8 @@ layout(set=0, binding=0) uniform Uniform {
float _Time;
};
layout(set=1, binding=0) uniform usampler3D _NodesTexture;
layout(set=2, binding=0) uniform usampler3D _BricksTexture;
layout(set=3, binding=0) uniform Materials { Material _Materials[256]; };
layout(set=1, binding=1) uniform usampler3D _BricksTexture;
layout(set=2, binding=0) uniform Materials { Material _Materials[256]; };
// Defines
#define EPSILON 0.00000001