Fix fixgridatmos command (#27113)
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Server.Administration;
|
|||||||
using Content.Server.Atmos.Components;
|
using Content.Server.Atmos.Components;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
|
using Content.Shared.Atmos.Components;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Map.Components;
|
using Robust.Shared.Map.Components;
|
||||||
@@ -84,44 +85,72 @@ public sealed partial class AtmosphereSystem
|
|||||||
continue;
|
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)
|
RebuildGridTiles(grid);
|
||||||
|
|
||||||
|
var query = GetEntityQuery<AtmosFixMarkerComponent>();
|
||||||
|
foreach (var (indices, tile) in gridAtmosphere.Tiles.ToArray())
|
||||||
{
|
{
|
||||||
var tile = tileMain.Air;
|
if (tile.Air is not {Immutable: false} air)
|
||||||
if (tile == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!_mapSystem.TryGetTile(gridComp, indices, out var gTile) || gTile.IsEmpty)
|
air.Clear();
|
||||||
{
|
|
||||||
gridAtmosphere.Tiles.Remove(indices);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tile.Immutable && !IsTileSpace(euid, transform.MapUid, indices))
|
|
||||||
{
|
|
||||||
tile = new GasMixture(tile.Volume) { Temperature = tile.Temperature };
|
|
||||||
tileMain.Air = tile;
|
|
||||||
}
|
|
||||||
|
|
||||||
tile.Clear();
|
|
||||||
var mixtureId = 0;
|
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))
|
if (query.TryComp(entUid, out var marker))
|
||||||
continue;
|
mixtureId = marker.Mode;
|
||||||
mixtureId = afm.Mode;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
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)
|
private CompletionResult FixGridAtmosCommandCompletions(IConsoleShell shell, string[] args)
|
||||||
{
|
{
|
||||||
MapId? playerMap = null;
|
MapId? playerMap = null;
|
||||||
|
|||||||
@@ -30,13 +30,15 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
private int _currentRunAtmosphereIndex;
|
private int _currentRunAtmosphereIndex;
|
||||||
private bool _simulationPaused;
|
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);
|
var tile = atmosphere.Tiles.GetOrNew(index, out var existing);
|
||||||
if (existing)
|
if (existing)
|
||||||
return tile;
|
return tile;
|
||||||
|
|
||||||
|
if (invalidateNew)
|
||||||
atmosphere.InvalidatedCoords.Add(index);
|
atmosphere.InvalidatedCoords.Add(index);
|
||||||
|
|
||||||
tile.GridIndex = owner;
|
tile.GridIndex = owner;
|
||||||
tile.GridIndices = index;
|
tile.GridIndices = index;
|
||||||
return tile;
|
return tile;
|
||||||
@@ -68,7 +70,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
atmosphere.CurrentRunInvalidatedTiles.EnsureCapacity(atmosphere.InvalidatedCoords.Count);
|
atmosphere.CurrentRunInvalidatedTiles.EnsureCapacity(atmosphere.InvalidatedCoords.Count);
|
||||||
foreach (var indices in atmosphere.InvalidatedCoords)
|
foreach (var indices in atmosphere.InvalidatedCoords)
|
||||||
{
|
{
|
||||||
var tile = GetOrNewTile(uid, atmosphere, indices);
|
var tile = GetOrNewTile(uid, atmosphere, indices, invalidateNew: false);
|
||||||
atmosphere.CurrentRunInvalidatedTiles.Enqueue(tile);
|
atmosphere.CurrentRunInvalidatedTiles.Enqueue(tile);
|
||||||
|
|
||||||
// Update tile.IsSpace and tile.MapAtmosphere, and tile.AirtightData.
|
// Update tile.IsSpace and tile.MapAtmosphere, and tile.AirtightData.
|
||||||
|
|||||||
Reference in New Issue
Block a user