fixed element leak across chunks

This commit is contained in:
2025-04-30 23:23:20 +02:00
parent 0b97027e00
commit 4462573267
2 changed files with 4 additions and 1 deletions

View File

@@ -138,6 +138,9 @@ public class Chunk {
if (what.Chunk != swapTo.Chunk) { if (what.Chunk != swapTo.Chunk) {
what.Chunk.RemoveFromChunk(what); what.Chunk.RemoveFromChunk(what);
swapTo.Chunk.AddToChunk(what); swapTo.Chunk.AddToChunk(what);
swapTo.Chunk.RemoveFromChunk(swapTo);
what.Chunk.AddToChunk(swapTo);
} }
Element temp = new Element(what); Element temp = new Element(what);

View File

@@ -88,7 +88,7 @@ public class Element{
else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE)) else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE))
Chunk.Swap(this, 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) if (Chunk.Get(Position + randomDirection)?.Density < Density)
Chunk.Swap(this, Position + Vector2I.Down); Chunk.Swap(this, Position + Vector2I.Down);