]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix fixgridatmos command (#27113)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Fri, 19 Apr 2024 02:39:38 +0000 (14:39 +1200)
committerGitHub <noreply@github.com>
Fri, 19 Apr 2024 02:39:38 +0000 (19:39 -0700)
Content.Server/Atmos/EntitySystems/AtmosphereSystem.Commands.cs
Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs

index a5e37398c6a4baa41b24fcad256705971402e33c..f711b235af6f12bd466915b886dd7c837bafbd97 100644 (file)
@@ -3,6 +3,7 @@ using Content.Server.Administration;
 using Content.Server.Atmos.Components;
 using Content.Shared.Administration;
 using Content.Shared.Atmos;
+using Content.Shared.Atmos.Components;
 using Robust.Shared.Console;
 using Robust.Shared.Map;
 using Robust.Shared.Map.Components;
@@ -84,44 +85,72 @@ public sealed partial class AtmosphereSystem
                continue;
            }
 
-           var transform = Transform(euid.Value);
+           // Force Invalidate & update air on all tiles
+           Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> grid =
+               new(euid.Value, gridAtmosphere, Comp<GasTileOverlayComponent>(euid.Value), gridComp, Transform(euid.Value));
 
-           foreach (var (indices, tileMain) in gridAtmosphere.Tiles)
-           {
-               var tile = tileMain.Air;
-               if (tile == null)
-                   continue;
+           RebuildGridTiles(grid);
 
-               if (!_mapSystem.TryGetTile(gridComp, indices, out var gTile) || gTile.IsEmpty)
-               {
-                   gridAtmosphere.Tiles.Remove(indices);
+           var query = GetEntityQuery<AtmosFixMarkerComponent>();
+           foreach (var (indices, tile) in gridAtmosphere.Tiles.ToArray())
+           {
+               if (tile.Air is not {Immutable: false} air)
                    continue;
-               }
 
-               if (tile.Immutable && !IsTileSpace(euid, transform.MapUid, indices))
-               {
-                   tile = new GasMixture(tile.Volume) { Temperature = tile.Temperature };
-                   tileMain.Air = tile;
-               }
-
-               tile.Clear();
+               air.Clear();
                var mixtureId = 0;
-               foreach (var entUid in gridComp.GetAnchoredEntities(indices))
+               var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(grid, grid, indices);
+               while (enumerator.MoveNext(out var entUid))
                {
-                   if (!TryComp(entUid, out AtmosFixMarkerComponent? afm))
-                       continue;
-                   mixtureId = afm.Mode;
-                   break;
+                   if (query.TryComp(entUid, out var marker))
+                       mixtureId = marker.Mode;
                }
-               var mixture = mixtures[mixtureId];
-               Merge(tile, mixture);
-               tile.Temperature = mixture.Temperature;
 
-               gridAtmosphere.InvalidatedCoords.Add(indices);
+               var mixture = mixtures[mixtureId];
+               Merge(air, mixture);
+               air.Temperature = mixture.Temperature;
            }
        }
     }
 
+    /// <summary>
+    /// Clears & re-creates all references to <see cref="TileAtmosphere"/>s stored on a grid.
+    /// </summary>
+    private void RebuildGridTiles(
+        Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent)
+    {
+        foreach (var indices in ent.Comp1.Tiles.Keys)
+        {
+            InvalidateVisuals((ent, ent), indices);
+        }
+
+        var atmos = ent.Comp1;
+        atmos.MapTiles.Clear();
+        atmos.ActiveTiles.Clear();
+        atmos.ExcitedGroups.Clear();
+        atmos.HotspotTiles.Clear();
+        atmos.SuperconductivityTiles.Clear();
+        atmos.HighPressureDelta.Clear();
+        atmos.CurrentRunTiles.Clear();
+        atmos.CurrentRunExcitedGroups.Clear();
+        atmos.InvalidatedCoords.Clear();
+        atmos.CurrentRunInvalidatedTiles.Clear();
+        atmos.PossiblyDisconnectedTiles.Clear();
+        atmos.Tiles.Clear();
+
+        var volume = GetVolumeForTiles(ent);
+        TryComp(ent.Comp4.MapUid, out MapAtmosphereComponent? mapAtmos);
+
+        var enumerator = _map.GetAllTilesEnumerator(ent, ent);
+        while (enumerator.MoveNext(out var tileRef))
+        {
+            var tile = GetOrNewTile(ent, ent, tileRef.Value.GridIndices);
+            UpdateTileData(ent, mapAtmos, tile);
+            UpdateAdjacentTiles(ent, tile, activate: true);
+            UpdateTileAir(ent, tile, volume);
+        }
+    }
+
     private CompletionResult FixGridAtmosCommandCompletions(IConsoleShell shell, string[] args)
     {
         MapId? playerMap = null;
index bd023e8574a4de7bfc5625b589d72e82f3118886..85b1a93e20f7e9874befe2e4eb38ebdaa13d50ec 100644 (file)
@@ -30,13 +30,15 @@ namespace Content.Server.Atmos.EntitySystems
         private int _currentRunAtmosphereIndex;
         private bool _simulationPaused;
 
-        private TileAtmosphere GetOrNewTile(EntityUid owner, GridAtmosphereComponent atmosphere, Vector2i index)
+        private TileAtmosphere GetOrNewTile(EntityUid owner, GridAtmosphereComponent atmosphere, Vector2i index, bool invalidateNew = true)
         {
             var tile = atmosphere.Tiles.GetOrNew(index, out var existing);
             if (existing)
                 return tile;
 
-            atmosphere.InvalidatedCoords.Add(index);
+            if (invalidateNew)
+                atmosphere.InvalidatedCoords.Add(index);
+
             tile.GridIndex = owner;
             tile.GridIndices = index;
             return tile;
@@ -68,7 +70,7 @@ namespace Content.Server.Atmos.EntitySystems
                 atmosphere.CurrentRunInvalidatedTiles.EnsureCapacity(atmosphere.InvalidatedCoords.Count);
                 foreach (var indices in atmosphere.InvalidatedCoords)
                 {
-                    var tile = GetOrNewTile(uid, atmosphere, indices);
+                    var tile = GetOrNewTile(uid, atmosphere, indices, invalidateNew: false);
                     atmosphere.CurrentRunInvalidatedTiles.Enqueue(tile);
 
                     // Update tile.IsSpace and tile.MapAtmosphere, and tile.AirtightData.