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