summaryrefslogtreecommitdiff
path: root/src/sim/cell/materials/liquid.rs
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-22 13:54:00 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-22 13:54:00 -0700
commit6350e4ffca8ce1e46465284ef3d7559e0f40229b (patch)
tree597bd17cc5c86d7271fea5abba4495fb58b4d7c2 /src/sim/cell/materials/liquid.rs
parent21f6ee0be48f83db3a0052269cfc47ac73dc64f9 (diff)
fixes and refactors
Diffstat (limited to 'src/sim/cell/materials/liquid.rs')
-rw-r--r--src/sim/cell/materials/liquid.rs25
1 files changed, 12 insertions, 13 deletions
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 {