]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Deload biome entities (#15531)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sun, 7 May 2023 15:03:04 +0000 (01:03 +1000)
committerGitHub <noreply@github.com>
Sun, 7 May 2023 15:03:04 +0000 (01:03 +1000)
Content.Server/Parallax/BiomeSystem.cs
Content.Shared/Parallax/Biomes/BiomeComponent.cs

index a679ab2648e1389a944a1cfdaebd216392a484d8..35bfd7b8ffe4e312c2c18951935f03803b0b6c76 100644 (file)
@@ -432,7 +432,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
         tiles.Clear();
 
         // Now do entities
-        var loadedEntities = new List<EntityUid>();
+        var loadedEntities = new Dictionary<EntityUid, Vector2i>();
         component.LoadedEntities.Add(chunk, loadedEntities);
 
         for (var x = 0; x < ChunkSize; x++)
@@ -460,7 +460,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
                     _transform.AnchorEntity(ent, xform, gridUid, grid, indices);
                 }
 
-                loadedEntities.Add(ent);
+                loadedEntities.Add(ent, indices);
             }
         }
 
@@ -548,11 +548,36 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
         component.LoadedDecals.Remove(chunk);
 
         // Delete entities
-        // This is a TODO
         // Ideally any entities that aren't modified just get deleted and re-generated later
         // This is because if we want to save the map (e.g. persistent server) it makes the file much smaller
         // and also if the map is enormous will make stuff like physics broadphase much faster
-        // For now we'll just leave them because no entity diffs.
+        var xformQuery = GetEntityQuery<TransformComponent>();
+
+        foreach (var (ent, tile) in component.LoadedEntities[chunk])
+        {
+            if (Deleted(ent) || !xformQuery.TryGetComponent(ent, out var xform))
+            {
+                modified.Add(tile);
+                continue;
+            }
+
+            // It's moved
+            var entTile = grid.LocalToTile(xform.Coordinates);
+
+            if (!xform.Anchored || entTile != tile)
+            {
+                modified.Add(tile);
+                continue;
+            }
+
+            if (!EntityManager.IsDefault(ent))
+            {
+                modified.Add(tile);
+                continue;
+            }
+
+            Del(ent);
+        }
 
         component.LoadedEntities.Remove(chunk);
 
index c4ef905835cfc25c3c1baa2ccc8ad2b7c9a007d4..b8c233d407817d172958f724d67b20860eb11d2e 100644 (file)
@@ -48,7 +48,7 @@ public sealed partial class BiomeComponent : Component
     public Dictionary<Vector2i, Dictionary<uint, Vector2i>> LoadedDecals = new();
 
     [DataField("entities")]
-    public Dictionary<Vector2i, List<EntityUid>> LoadedEntities = new();
+    public Dictionary<Vector2i, Dictionary<EntityUid, Vector2i>> LoadedEntities = new();
 
     /// <summary>
     /// Currently active chunks