Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Physics fix for "listCheckExists causes dead cells" #765

Open
rdebath opened this issue Jun 19, 2023 · 1 comment
Open

[PATCH] Physics fix for "listCheckExists causes dead cells" #765

rdebath opened this issue Jun 19, 2023 · 1 comment

Comments

@rdebath
Copy link
Contributor

rdebath commented Jun 19, 2023

Multiple instances of explosions and fire can cause cells to ignore physics operations so (for example) a fire block placed in that cell doesn't burn surrounding cells or disappear.

This small change (in the foundInfo function) doesn't prevent cells dying but does cause them to be refreshed (reset?) if someone places a new block in that cell.

This should not measurably impact performance as it only has an effect when a user is placing a block.

diff --git a/MCGalaxy/Levels/Level.Physics.cs b/MCGalaxy/Levels/Level.Physics.cs
index 2d4479814..b1c5f144c 100644
--- a/MCGalaxy/Levels/Level.Physics.cs
+++ b/MCGalaxy/Levels/Level.Physics.cs
@@ -129,12 +129,14 @@ namespace MCGalaxy {
             int index = PosToInt(x, y, z);
             for (int i = 0; i < ListCheck.Count; i++) {
                 Check C = ListCheck.Items[i];
                 if (C.Index != index) continue;
                 return C.data;
             }
+            // Hmmm, it's set, but there's nothing there
+            listCheckExists.Set(x, y, z, false);
             return default(PhysicsArgs);
         }

         void PhysicsTick() {
             lastCheck = ListCheck.Count;
             const uint mask = PhysicsArgs.TypeMask;
@rdebath
Copy link
Contributor Author

rdebath commented Jul 30, 2023

This seems to be a fix for the actual problem.
The problem looks like a classic cellular automata implementation issue where the state of cell (x,y) depends on cell (x-1,y-1) but by the time the (x,y) cell is being calculated the (x-1,y-1) cell has already been updated to the next tick.
I'm correcting this by simply regenerating the bitmap from the queue that it's supposed to be optimising when the queue is scanned for RemoveFromChecks flagged entries. This also has the advantage that the bitmap will be reduced back to a small size after a full map flood has completed.

I suggest the previous update is still also included as IMO it's a cheap and effective fallback.

Subject: [PATCH] Physics fix for listCheckExists causes dead cells

---
 MCGalaxy/Levels/Level.Physics.cs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/MCGalaxy/Levels/Level.Physics.cs b/MCGalaxy/Levels/Level.Physics.cs
index fdb1c5f66..accf3c3b1 100644
--- a/MCGalaxy/Levels/Level.Physics.cs
+++ b/MCGalaxy/Levels/Level.Physics.cs
@@ -307,12 +307,13 @@ namespace MCGalaxy {
             int j = 0, count = ListCheck.Count;
             ushort x, y, z;
             
+            listCheckExists.Clear();
             for (int i = 0; i < count; i++) {
+                IntToPos(items[i].Index, out x, out y, out z);
                 if (items[i].data.Data == PhysicsArgs.RemoveFromChecks) {
-                    IntToPos(items[i].Index, out x, out y, out z);
-                    listCheckExists.Set(x, y, z, false);
                     continue;
                 }
+                listCheckExists.Set(x, y, z, true);
                 items[j] = items[i]; j++;
             }
             ListCheck.Items = items;
-- 
2.20.1

@rdebath rdebath changed the title Workaround for physics dead cells. [PATCH] Physics fix for listCheckExists causes dead cells Jul 30, 2023
@rdebath rdebath changed the title [PATCH] Physics fix for listCheckExists causes dead cells [PATCH] Physics fix for "listCheckExists causes dead cells" Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant