MCGalaxy icon indicating copy to clipboard operation
MCGalaxy copied to clipboard

Physics-5 Change Queue doesn't clear

Open rdebath opened this issue 3 years ago • 2 comments

If you have a physics-5 map DoorPhysics.Do is placed as the handler for air blocks. Deleting a block then places an item on the physics check queue, this block doesn't have Type1 set to Custom so it is ignored every tick. The below change (for example) cleans up these items.

diff --git a/MCGalaxy/Blocks/Physics/DoorPhysics.cs b/MCGalaxy/Blocks/Physics/DoorPhysics.cs
index 79fd89bcc..7c64fe078 100644
--- a/MCGalaxy/Blocks/Physics/DoorPhysics.cs
+++ b/MCGalaxy/Blocks/Physics/DoorPhysics.cs
@@ -22,7 +22,11 @@ namespace MCGalaxy.Blocks.Physics {
     public static class DoorPhysics {

         public static void Do(Level lvl, ref PhysInfo C) {
-            if (C.Data.Type1 != PhysicsArgs.Custom) return;
+            if (C.Data.Type1 != PhysicsArgs.Custom) {
+                if (lvl.physics == 5)
+                    C.Data.Data = PhysicsArgs.RemoveFromChecks;
+                return;
+            }
             if (C.Data.Data == 0) {
                 BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock << Block.ExtendedShift));
                 bool tdoor = lvl.Props[block].IsTDoor;

rdebath avatar Apr 17 '21 11:04 rdebath

Probably better off changing HandlePhysics delegate to instead return a bool for whether to remove the PhysicsCheck entry from the checks list or not. Trying to remember to do C.Data.Data = PhysicsArgs.RemoveFromChecks everywhere seems to just be fraught with issues

UnknownShadow200 avatar Apr 20 '21 13:04 UnknownShadow200

Agreed, though, returning a bool would normally be taken as an indication of success not that you want to do it again. To me it doesn't seem to fit exactly.

Personally I thought it should just delete the timed physics task unless explicitly told that it's to be retriggered; do nothing and it's deleted. After all for performance reasons the primary method of triggering physics changes should be via events not a repeated poll.

rdebath avatar Apr 20 '21 15:04 rdebath