From 4462573267dbbcf2b2ba36168d343aad76a45d71 Mon Sep 17 00:00:00 2001 From: rogo Date: Wed, 30 Apr 2025 23:23:20 +0200 Subject: [PATCH] fixed element leak across chunks --- Scripts/Chunk.cs | 3 +++ Scripts/Elements/Element.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Scripts/Chunk.cs b/Scripts/Chunk.cs index b642d54..d114842 100644 --- a/Scripts/Chunk.cs +++ b/Scripts/Chunk.cs @@ -138,6 +138,9 @@ public class Chunk { if (what.Chunk != swapTo.Chunk) { what.Chunk.RemoveFromChunk(what); swapTo.Chunk.AddToChunk(what); + + swapTo.Chunk.RemoveFromChunk(swapTo); + what.Chunk.AddToChunk(swapTo); } Element temp = new Element(what); diff --git a/Scripts/Elements/Element.cs b/Scripts/Elements/Element.cs index dd264fd..f272ed7 100644 --- a/Scripts/Elements/Element.cs +++ b/Scripts/Elements/Element.cs @@ -88,7 +88,7 @@ public class Element{ else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE)) Chunk.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE); - if (GD.Randi() % MAX_DIFFUSE_SPEED > DiffuseSpeed) return; // ascend slower + if (GD.Randi() % MAX_DIFFUSE_SPEED > DiffuseSpeed) return; // descend slower if (Chunk.Get(Position + randomDirection)?.Density < Density) Chunk.Swap(this, Position + Vector2I.Down);