Simplify logic and reduce nesting in chunk simulation system
This commit is contained in:
parent
9e3dc5b3d4
commit
b1ea38febe
|
@ -136,24 +136,26 @@ pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {
|
|||
match element {
|
||||
Element::Air => {}
|
||||
Element::Sand => {
|
||||
if y != 0 {
|
||||
let bottom = chunk.get_cell(x, y - 1).unwrap();
|
||||
if *bottom == Element::Air {
|
||||
if y == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bottom
|
||||
if *chunk.get_cell(x, y - 1).unwrap() == Element::Air {
|
||||
chunk.swap_cells(x, y, x, y - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if x != 0 {
|
||||
let bottom_left = chunk.get_cell(x - 1, y - 1).unwrap();
|
||||
if *bottom_left == Element::Air {
|
||||
// Bottom left
|
||||
if x != 0 && *chunk.get_cell(x - 1, y - 1).unwrap() == Element::Air {
|
||||
chunk.swap_cells(x, y, x - 1, y - 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if x != chunk.width - 1 {
|
||||
let bottom_right = chunk.get_cell(x + 1, y - 1).unwrap();
|
||||
if *bottom_right == Element::Air {
|
||||
// Bottom right
|
||||
if x != chunk.width - 1
|
||||
&& *chunk.get_cell(x + 1, y - 1).unwrap() == Element::Air
|
||||
{
|
||||
chunk.swap_cells(x, y, x + 1, y - 1);
|
||||
continue;
|
||||
}
|
||||
|
@ -162,8 +164,6 @@ pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_chunk_texture_system(
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
|
|
Loading…
Reference in New Issue