Skip to content

Commit

Permalink
Cherry-Pick PR #27113 (Simple-Station#803)
Browse files Browse the repository at this point in the history
# Description

This is a cherry-pick of
space-wizards/space-station-14#27113
Which fixes a bug that has been reported here where the FixGridAtmos
command does not work.

# Changelog

:cl:
- fix: Fixed the FixGridAtmos command.

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
  • Loading branch information
VMSolidus and ElectroJr authored Aug 26, 2024
1 parent ec11eed commit 5118c60
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 29 deletions.
81 changes: 55 additions & 26 deletions Content.Server/Atmos/EntitySystems/AtmosphereSystem.Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -84,44 +85,72 @@ private void FixGridAtmosCommand(IConsoleShell shell, string argstr, string[] ar
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ public sealed partial class AtmosphereSystem
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;
Expand Down Expand Up @@ -68,7 +70,7 @@ private bool ProcessRevalidate(Entity<GridAtmosphereComponent, GasTileOverlayCom
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.
Expand Down

0 comments on commit 5118c60

Please sign in to comment.