Simplify logic and reduce nesting in chunk simulation system

This commit is contained in:
Jarrod Doyle 2024-01-29 15:34:17 +00:00
parent 9e3dc5b3d4
commit b1ea38febe
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 20 additions and 20 deletions

View File

@ -136,24 +136,26 @@ pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {
match element { match element {
Element::Air => {} Element::Air => {}
Element::Sand => { Element::Sand => {
if y != 0 { if y == 0 {
let bottom = chunk.get_cell(x, y - 1).unwrap(); continue;
if *bottom == Element::Air { }
// Bottom
if *chunk.get_cell(x, y - 1).unwrap() == Element::Air {
chunk.swap_cells(x, y, x, y - 1); chunk.swap_cells(x, y, x, y - 1);
continue; continue;
} }
if x != 0 { // Bottom left
let bottom_left = chunk.get_cell(x - 1, y - 1).unwrap(); if x != 0 && *chunk.get_cell(x - 1, y - 1).unwrap() == Element::Air {
if *bottom_left == Element::Air {
chunk.swap_cells(x, y, x - 1, y - 1); chunk.swap_cells(x, y, x - 1, y - 1);
continue; continue;
} }
}
if x != chunk.width - 1 { // Bottom right
let bottom_right = chunk.get_cell(x + 1, y - 1).unwrap(); if x != chunk.width - 1
if *bottom_right == Element::Air { && *chunk.get_cell(x + 1, y - 1).unwrap() == Element::Air
{
chunk.swap_cells(x, y, x + 1, y - 1); chunk.swap_cells(x, y, x + 1, y - 1);
continue; continue;
} }
@ -161,8 +163,6 @@ pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {
} }
} }
} }
}
}
} }
pub fn update_chunk_texture_system( pub fn update_chunk_texture_system(