aboutsummaryrefslogtreecommitdiff
path: root/src/sandbox.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2025-05-18 10:56:57 -0700
committerrtk0c <[email protected]>2025-05-18 11:09:22 -0700
commit3af71b8aa4976d2eb6ed9eb61e9e8ac5bd6d309a (patch)
tree7f0a9368f030b63599d5924498714c75c86f1ac8 /src/sandbox.cpp
parentf7455f44518d36cc688f915e5d6cc046eaa65896 (diff)
Fix unupdated sand
Just grow the dirty rect by 1 on each side, update neighbors of any updated sand.
Diffstat (limited to 'src/sandbox.cpp')
-rw-r--r--src/sandbox.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/sandbox.cpp b/src/sandbox.cpp
index c6d0294..2c09d77 100644
--- a/src/sandbox.cpp
+++ b/src/sandbox.cpp
@@ -102,17 +102,24 @@ void Sandbox::simulate_step() {
dirty_writeto = {};
const auto [x0, y0] = dirty_curr.bl;
const auto [x1, y1] = dirty_curr.tr;
+
// Clear update bit for this cycle
for (_y = y0; _y <= y1; ++_y) {
for (_x = x0; _x <= x1; ++_x) {
gs(_x, _y).updated = false;
}
}
+
+ // Update
for (_y = y0; _y <= y1; ++_y) {
for (_x = x0; _x <= x1; ++_x) {
simulate_sand_tile(*this, _x, _y);
}
}
+ dirty_writeto.bl -= Pt(1, 1);
+ dirty_writeto.tr += Pt(1, 1);
+ dirty_writeto = rect_intersect(dirty_writeto, Rect(0, 0, width - 1, height - 1));
+
++ncycle;
}