diff --git a/Content.Server/Parallax/BiomeSystem.cs b/Content.Server/Parallax/BiomeSystem.cs index a679ab2648..35bfd7b8ff 100644 --- a/Content.Server/Parallax/BiomeSystem.cs +++ b/Content.Server/Parallax/BiomeSystem.cs @@ -432,7 +432,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem tiles.Clear(); // Now do entities - var loadedEntities = new List(); + var loadedEntities = new Dictionary(); 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(); + + 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); diff --git a/Content.Shared/Parallax/Biomes/BiomeComponent.cs b/Content.Shared/Parallax/Biomes/BiomeComponent.cs index c4ef905835..b8c233d407 100644 --- a/Content.Shared/Parallax/Biomes/BiomeComponent.cs +++ b/Content.Shared/Parallax/Biomes/BiomeComponent.cs @@ -48,7 +48,7 @@ public sealed partial class BiomeComponent : Component public Dictionary> LoadedDecals = new(); [DataField("entities")] - public Dictionary> LoadedEntities = new(); + public Dictionary> LoadedEntities = new(); /// /// Currently active chunks