From 6350e4ffca8ce1e46465284ef3d7559e0f40229b Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sat, 22 Aug 2026 13:54:00 -0700 Subject: fixes and refactors --- src/sim/cell/materials/liquid.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/sim/cell/materials/liquid.rs') diff --git a/src/sim/cell/materials/liquid.rs b/src/sim/cell/materials/liquid.rs index 4b848fb..bff0ac0 100644 --- a/src/sim/cell/materials/liquid.rs +++ b/src/sim/cell/materials/liquid.rs @@ -1,14 +1,15 @@ -use crate::sim::cell_sim::sim::UpdateCtx; +use crate::sim::cell_sim::sim::{PostUpdateAction, UpdateCtx}; #[inline] -pub fn sim_update(ctx: &mut UpdateCtx) { +pub fn sim_update(ctx: &mut UpdateCtx) -> PostUpdateAction { // if the water can fall, do so - if ctx.candidates_swap(&[ + if ctx.swap_or_settle(&[ (0, 1), (-1 + 2 * ctx.seqno_parity as i32, 1), (1 - 2 * ctx.seqno_parity as i32, 1), - ]) { - return; + ]) == PostUpdateAction::None + { + return PostUpdateAction::None; } // if the water can't fall, check if we can move left or right @@ -22,18 +23,16 @@ pub fn sim_update(ctx: &mut UpdateCtx) { // we can't move down or to other side, so we're stuck if !can_move_left && !can_move_right { - return; + return PostUpdateAction::Settle; } // if we can't move left, just move right if !can_move_left { - ctx.candidates_swap(&[(1, 0)]); - return; + return ctx.swap_or_settle(&[(1, 0)]); } // and vice versa if !can_move_right { - ctx.candidates_swap(&[(-1, 0)]); - return; + return ctx.swap_or_settle(&[(-1, 0)]); } // find the closest hole within 20 pixels (TODO optimize) @@ -54,12 +53,12 @@ pub fn sim_update(ctx: &mut UpdateCtx) { { // we identified a hole and we know that the space on this side is open // move toward the hole - // new_target.flags = new_target.flags ^ 0b1; - ctx.candidates_swap(&[(side, 0)]); - return; + return ctx.swap_or_settle(&[(side, 0)]); } } + return PostUpdateAction::Settle; + // we didn't find a hole, so just move "randomly" on the same surface // TODO when to settle? // let target_x = if !can_move_left { -- cgit v1.3.1