ECS Atmos Part 5: Moves all logic from GridAtmosphereComponent to AtmosphereSystem. (#4331)

This commit is contained in:
Vera Aguilera Puerto
2021-07-23 11:09:01 +02:00
committed by GitHub
parent 354ef6daf3
commit 4112847142
23 changed files with 1242 additions and 1355 deletions

View File

@@ -127,6 +127,7 @@ namespace Content.Server.Atmos.EntitySystems
AccumulatedFrameTime -= _updateCooldown;
var currentTick = _gameTiming.CurTick;
var atmosphereSystem = Get<AtmosphereSystem>();
// Now we'll go through each player, then through each chunk in range of that player checking if the player is still in range
// If they are, check if they need the new data to send (i.e. if there's an overlay for the gas).
@@ -156,7 +157,7 @@ namespace Content.Server.Atmos.EntitySystems
for (var x = 0; x < LocalViewRange; x++)
{
var Vector2i = new Vector2i(baseTile.X + x, baseTile.Y + y);
debugOverlayContent[index++] = ConvertTileToData(gam.GetTile(Vector2i));
debugOverlayContent[index++] = ConvertTileToData(atmosphereSystem.GetTileAtmosphereOrCreateSpace(grid, gam, Vector2i));
}
}

View File

@@ -1,9 +1,13 @@
using Content.Shared.CCVar;
using Robust.Shared.Configuration;
using Robust.Shared.IoC;
namespace Content.Server.Atmos.EntitySystems
{
public partial class AtmosphereSystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
public bool SpaceWind { get; private set; }
public string? SpaceWindSound { get; private set; }
public bool MonstermosEqualization { get; private set; }

View File

@@ -0,0 +1,137 @@
using Content.Server.Atmos.Components;
using Content.Shared.Atmos;
using Robust.Shared.Utility;
namespace Content.Server.Atmos.EntitySystems
{
public partial class AtmosphereSystem
{
private void ExcitedGroupAddTile(ExcitedGroup excitedGroup, TileAtmosphere tile)
{
DebugTools.Assert(!excitedGroup.Disposed, "Excited group is disposed!");
DebugTools.Assert(tile.ExcitedGroup == null, "Tried to add a tile to an excited group when it's already in another one!");
excitedGroup.Tiles.Add(tile);
tile.ExcitedGroup = excitedGroup;
ExcitedGroupResetCooldowns(excitedGroup);
}
private void ExcitedGroupRemoveTile(ExcitedGroup excitedGroup, TileAtmosphere tile)
{
DebugTools.Assert(!excitedGroup.Disposed, "Excited group is disposed!");
DebugTools.Assert(tile.ExcitedGroup == excitedGroup, "Tried to remove a tile from an excited group it's not present in!");
tile.ExcitedGroup = null;
excitedGroup.Tiles.Remove(tile);
}
private void ExcitedGroupMerge(GridAtmosphereComponent gridAtmosphere, ExcitedGroup ourGroup, ExcitedGroup otherGroup)
{
DebugTools.Assert(!ourGroup.Disposed, "Excited group is disposed!");
DebugTools.Assert(!otherGroup.Disposed, "Excited group is disposed!");
DebugTools.Assert(gridAtmosphere.ExcitedGroups.Contains(ourGroup), "Grid Atmosphere does not contain Excited Group!");
DebugTools.Assert(gridAtmosphere.ExcitedGroups.Contains(otherGroup), "Grid Atmosphere does not contain Excited Group!");
var ourSize = ourGroup.Tiles.Count;
var otherSize = otherGroup.Tiles.Count;
ExcitedGroup winner;
ExcitedGroup loser;
if (ourSize > otherSize)
{
winner = ourGroup;
loser = otherGroup;
}
else
{
winner = otherGroup;
loser = ourGroup;
}
foreach (var tile in loser.Tiles)
{
tile.ExcitedGroup = winner;
winner.Tiles.Add(tile);
}
loser.Tiles.Clear();
ExcitedGroupDispose(gridAtmosphere, loser);
ExcitedGroupResetCooldowns(winner);
}
private void ExcitedGroupResetCooldowns(ExcitedGroup excitedGroup)
{
DebugTools.Assert(!excitedGroup.Disposed, "Excited group is disposed!");
excitedGroup.BreakdownCooldown = 0;
excitedGroup.DismantleCooldown = 0;
}
private void ExcitedGroupSelfBreakdown(GridAtmosphereComponent gridAtmosphere, ExcitedGroup excitedGroup, bool spaceIsAllConsuming = false)
{
DebugTools.Assert(!excitedGroup.Disposed, "Excited group is disposed!");
DebugTools.Assert(gridAtmosphere.ExcitedGroups.Contains(excitedGroup), "Grid Atmosphere does not contain Excited Group!");
var combined = new GasMixture(Atmospherics.CellVolume);
var tileSize = excitedGroup.Tiles.Count;
if (excitedGroup.Disposed) return;
if (tileSize == 0)
{
ExcitedGroupDispose(gridAtmosphere, excitedGroup);
return;
}
foreach (var tile in excitedGroup.Tiles)
{
if (tile?.Air == null)
continue;
Merge(combined, tile.Air);
if (!spaceIsAllConsuming || !tile.Air.Immutable)
continue;
combined.Clear();
break;
}
combined.Multiply(1 / (float)tileSize);
foreach (var tile in excitedGroup.Tiles)
{
if (tile?.Air == null) continue;
tile.Air.CopyFromMutable(combined);
InvalidateVisuals(tile.GridIndex, tile.GridIndices);
}
excitedGroup.BreakdownCooldown = 0;
}
private void ExcitedGroupDismantle(GridAtmosphereComponent gridAtmosphere, ExcitedGroup excitedGroup, bool unexcite = true)
{
foreach (var tile in excitedGroup.Tiles)
{
tile.ExcitedGroup = null;
if (!unexcite)
continue;
RemoveActiveTile(gridAtmosphere, tile);
}
excitedGroup.Tiles.Clear();
}
private void ExcitedGroupDispose(GridAtmosphereComponent gridAtmosphere, ExcitedGroup excitedGroup)
{
if (excitedGroup.Disposed)
return;
DebugTools.Assert(gridAtmosphere.ExcitedGroups.Contains(excitedGroup), "Grid Atmosphere does not contain Excited Group!");
excitedGroup.Disposed = true;
gridAtmosphere.ExcitedGroups.Remove(excitedGroup);
ExcitedGroupDismantle(gridAtmosphere, excitedGroup, false);
}
}
}

View File

@@ -4,12 +4,16 @@ using System.Linq;
using Content.Server.Atmos.Reactions;
using Content.Server.Interfaces;
using Content.Shared.Atmos;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Server.Atmos.EntitySystems
{
public partial class AtmosphereSystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
private GasReactionPrototype[] _gasReactions = Array.Empty<GasReactionPrototype>();
private float[] _gasSpecificHeats = new float[Atmospherics.TotalNumberOfGases];
@@ -51,16 +55,23 @@ namespace Content.Server.Atmos.EntitySystems
return mixture.Temperature * GetHeatCapacity(mixture);
}
public float GetThermalEnergy(GasMixture mixture, float cachedHeatCapacity)
{
return mixture.Temperature * cachedHeatCapacity;
}
public void Merge(GasMixture receiver, GasMixture giver)
{
if (receiver.Immutable) return;
if (MathF.Abs(receiver.Temperature - giver.Temperature) > Atmospherics.MinimumTemperatureDeltaToConsider)
{
var combinedHeatCapacity = GetHeatCapacity(receiver) + GetHeatCapacity(giver);
var receiverHeatCapacity = GetHeatCapacity(receiver);
var giverHeatCapacity = GetHeatCapacity(giver);
var combinedHeatCapacity = receiverHeatCapacity + giverHeatCapacity;
if (combinedHeatCapacity > 0f)
{
receiver.Temperature = (GetThermalEnergy(giver) + GetThermalEnergy(receiver)) / combinedHeatCapacity;
receiver.Temperature = (GetThermalEnergy(giver, giverHeatCapacity) + GetThermalEnergy(receiver, receiverHeatCapacity)) / combinedHeatCapacity;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -58,7 +58,7 @@ namespace Content.Server.Atmos.EntitySystems
private void ConsiderPressureDifference(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, TileAtmosphere other, float difference)
{
gridAtmosphere.AddHighPressureDelta(tile);
gridAtmosphere.HighPressureDelta.Add(tile);
if (difference > tile.PressureDifference)
{
tile.PressureDifference = difference;

View File

@@ -4,8 +4,8 @@ using Content.Server.Atmos.Components;
using Content.Server.Atmos.Reactions;
using Content.Server.Coordinates.Helpers;
using Content.Shared.Atmos;
using Content.Shared.GameTicking;
using Content.Shared.Maps;
using Robust.Shared.Map;
namespace Content.Server.Atmos.EntitySystems
{
@@ -15,13 +15,13 @@ namespace Content.Server.Atmos.EntitySystems
{
if (!tile.Hotspot.Valid)
{
gridAtmosphere.RemoveHotspotTile(tile);
gridAtmosphere.HotspotTiles.Remove(tile);
return;
}
if (!tile.Excited)
{
gridAtmosphere.AddActiveTile(tile);
AddActiveTile(gridAtmosphere, tile);
}
if (!tile.Hotspot.SkippedFirstProcess)
@@ -30,13 +30,14 @@ namespace Content.Server.Atmos.EntitySystems
return;
}
tile.ExcitedGroup?.ResetCooldowns();
if(tile.ExcitedGroup != null)
ExcitedGroupResetCooldowns(tile.ExcitedGroup);
if ((tile.Hotspot.Temperature < Atmospherics.FireMinimumTemperatureToExist) || (tile.Hotspot.Volume <= 1f)
|| tile.Air == null || tile.Air.GetMoles(Gas.Oxygen) < 0.5f || (tile.Air.GetMoles(Gas.Plasma) < 0.5f && tile.Air.GetMoles(Gas.Tritium) < 0.5f))
{
tile.Hotspot = new Hotspot();
tile.UpdateVisuals();
InvalidateVisuals(tile.GridIndex, tile.GridIndices);
return;
}
@@ -45,13 +46,17 @@ namespace Content.Server.Atmos.EntitySystems
if (tile.Hotspot.Bypassing)
{
tile.Hotspot.State = 3;
gridAtmosphere.BurnTile(tile.GridIndices);
// TODO ATMOS: Burn tile here
if (tile.Air.Temperature > Atmospherics.FireMinimumTemperatureToSpread)
{
var radiatedTemperature = tile.Air.Temperature * Atmospherics.FireSpreadRadiosityScale;
foreach (var otherTile in tile.AdjacentTiles)
{
// TODO ATMOS: This is sus. Suss this out.
if (otherTile == null)
continue;
if(!otherTile.Hotspot.Valid)
HotspotExpose(gridAtmosphere, otherTile, radiatedTemperature, Atmospherics.CellVolume/4);
}
@@ -108,8 +113,8 @@ namespace Content.Server.Atmos.EntitySystems
tile.Hotspot.Start();
gridAtmosphere.AddActiveTile(tile);
gridAtmosphere.AddHotspotTile(tile);
AddActiveTile(gridAtmosphere, tile);
gridAtmosphere.HotspotTiles.Add(tile);
}
}
@@ -128,11 +133,11 @@ namespace Content.Server.Atmos.EntitySystems
{
var affected = tile.Air.RemoveRatio(tile.Hotspot.Volume / tile.Air.Volume);
affected.Temperature = tile.Hotspot.Temperature;
gridAtmosphere.AtmosphereSystem.React(affected, tile);
React(affected, tile);
tile.Hotspot.Temperature = affected.Temperature;
tile.Hotspot.Volume = affected.ReactionResults[GasReaction.Fire] * Atmospherics.FireGrowthRate;
Merge(tile.Air, affected);
gridAtmosphere.Invalidate(tile.GridIndices);
gridAtmosphere.InvalidatedCoords.Add(tile.GridIndices);
}
var tileRef = tile.GridIndices.GetTileRef(tile.GridIndex);

View File

@@ -12,7 +12,7 @@ namespace Content.Server.Atmos.EntitySystems
// Can't process a tile without air
if (tile.Air == null)
{
gridAtmosphere.RemoveActiveTile(tile);
RemoveActiveTile(gridAtmosphere, tile);
return;
}
@@ -46,7 +46,7 @@ namespace Content.Server.Atmos.EntitySystems
{
if (tile.ExcitedGroup != enemyTile.ExcitedGroup)
{
tile.ExcitedGroup.MergeGroups(enemyTile.ExcitedGroup);
ExcitedGroupMerge(gridAtmosphere, tile.ExcitedGroup, enemyTile.ExcitedGroup);
}
shouldShareAir = true;
@@ -54,7 +54,7 @@ namespace Content.Server.Atmos.EntitySystems
{
if (!enemyTile.Excited)
{
gridAtmosphere.AddActiveTile(enemyTile);
AddActiveTile(gridAtmosphere, enemyTile);
}
var excitedGroup = tile.ExcitedGroup;
@@ -63,14 +63,14 @@ namespace Content.Server.Atmos.EntitySystems
if (excitedGroup == null)
{
excitedGroup = new ExcitedGroup();
excitedGroup.Initialize(gridAtmosphere);
gridAtmosphere.ExcitedGroups.Add(excitedGroup);
}
if (tile.ExcitedGroup == null)
excitedGroup.AddTile(tile);
ExcitedGroupAddTile(excitedGroup, tile);
if(enemyTile.ExcitedGroup == null)
excitedGroup.AddTile(enemyTile);
ExcitedGroupAddTile(excitedGroup, enemyTile);
shouldShareAir = true;
}
@@ -97,7 +97,8 @@ namespace Content.Server.Atmos.EntitySystems
if(tile.Air != null)
React(tile.Air, tile);
tile.UpdateVisuals();
InvalidateVisuals(tile.GridIndex, tile.GridIndices);
var remove = true;
@@ -106,7 +107,7 @@ namespace Content.Server.Atmos.EntitySystems
remove = false;
if(tile.ExcitedGroup == null && remove)
gridAtmosphere.RemoveActiveTile(tile);
RemoveActiveTile(gridAtmosphere, tile);
}
private void Archive(TileAtmosphere tile, int fireCount)
@@ -124,7 +125,7 @@ namespace Content.Server.Atmos.EntitySystems
switch (tile.Air.LastShare)
{
case > Atmospherics.MinimumAirToSuspend:
tile.ExcitedGroup.ResetCooldowns();
ExcitedGroupResetCooldowns(tile.ExcitedGroup);
break;
case > Atmospherics.MinimumMolesDeltaToMove:
tile.ExcitedGroup.DismantleCooldown = 0;

View File

@@ -7,6 +7,7 @@ using Content.Server.Atmos.Components;
using Content.Server.Coordinates.Helpers;
using Content.Shared.Atmos;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Random;
@@ -18,7 +19,7 @@ namespace Content.Server.Atmos.EntitySystems
private readonly TileAtmosphereComparer _monstermosComparer = new();
public void EqualizePressureInZone(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, int cycleNum)
public void EqualizePressureInZone(IMapGrid mapGrid, GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, int cycleNum)
{
if (tile.Air == null || (tile.MonstermosInfo.LastCycle >= cycleNum))
return; // Already done.
@@ -80,7 +81,8 @@ namespace Content.Server.Atmos.EntitySystems
if (adj.Air.Immutable)
{
// Looks like someone opened an airlock to space!
ExplosivelyDepressurize(gridAtmosphere, tile, cycleNum);
ExplosivelyDepressurize(mapGrid, gridAtmosphere, tile, cycleNum);
return;
}
}
@@ -339,7 +341,7 @@ namespace Content.Server.Atmos.EntitySystems
if (!otherTile.AdjacentBits.IsFlagSet(direction)) continue;
var otherTile2 = otherTile.AdjacentTiles[j];
if (otherTile2?.Air?.Compare(tile.Air) == GasMixture.GasCompareResult.NoExchange) continue;
gridAtmosphere.AddActiveTile(otherTile2);
AddActiveTile(gridAtmosphere, otherTile2);
break;
}
}
@@ -349,7 +351,7 @@ namespace Content.Server.Atmos.EntitySystems
ArrayPool<TileAtmosphere>.Shared.Return(takerTiles);
}
public void ExplosivelyDepressurize(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, int cycleNum)
public void ExplosivelyDepressurize(IMapGrid mapGrid, GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, int cycleNum)
{
// Check if explosive depressurization is enabled and if the tile is valid.
if (!MonstermosDepressurization || tile.Air == null)
@@ -389,7 +391,7 @@ namespace Content.Server.Atmos.EntitySystems
if (otherTile2.Air == null) continue;
if (otherTile2.MonstermosInfo.LastQueueCycle == queueCycle) continue;
ConsiderFirelocks(otherTile, otherTile2);
ConsiderFirelocks(gridAtmosphere, otherTile, otherTile2);
// The firelocks might have closed on us.
if (!otherTile.AdjacentBits.IsFlagSet(direction)) continue;
@@ -438,8 +440,8 @@ namespace Content.Server.Atmos.EntitySystems
{
var otherTile = progressionOrder[i];
if (otherTile.MonstermosInfo.CurrentTransferDirection == AtmosDirection.Invalid) continue;
gridAtmosphere.AddHighPressureDelta(otherTile);
gridAtmosphere.AddActiveTile(otherTile);
gridAtmosphere.HighPressureDelta.Add(otherTile);
AddActiveTile(gridAtmosphere, otherTile);
var otherTile2 = otherTile.AdjacentTiles[otherTile.MonstermosInfo.CurrentTransferDirection.ToIndex()];
if (otherTile2?.Air == null) continue;
var sum = otherTile2.Air.TotalMoles;
@@ -455,9 +457,9 @@ namespace Content.Server.Atmos.EntitySystems
otherTile2.PressureDirection = otherTile.MonstermosInfo.CurrentTransferDirection;
}
otherTile.Air.Clear();
otherTile.UpdateVisuals();
HandleDecompressionFloorRip(gridAtmosphere, otherTile, sum);
otherTile.Air?.Clear();
InvalidateVisuals(otherTile.GridIndex, otherTile.GridIndices);
HandleDecompressionFloorRip(mapGrid, otherTile, sum);
}
ArrayPool<TileAtmosphere>.Shared.Return(tiles);
@@ -465,7 +467,7 @@ namespace Content.Server.Atmos.EntitySystems
ArrayPool<TileAtmosphere>.Shared.Return(progressionOrder);
}
private void ConsiderFirelocks(TileAtmosphere tile, TileAtmosphere other)
private void ConsiderFirelocks(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, TileAtmosphere other)
{
if (!_mapManager.TryGetGrid(tile.GridIndex, out var mapGrid))
return;
@@ -491,8 +493,10 @@ namespace Content.Server.Atmos.EntitySystems
if (!reconsiderAdjacent)
return;
tile.UpdateAdjacent();
other.UpdateAdjacent();
UpdateAdjacent(mapGrid, gridAtmosphere, tile);
UpdateAdjacent(mapGrid, gridAtmosphere, other);
InvalidateVisuals(tile.GridIndex, tile.GridIndices);
InvalidateVisuals(other.GridIndex, other.GridIndices);
}
public void FinalizeEq(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile)
@@ -524,8 +528,8 @@ namespace Content.Server.Atmos.EntitySystems
otherTile.MonstermosInfo[direction.GetOpposite()] = 0;
Merge(otherTile.Air, tile.Air.Remove(amount));
tile.UpdateVisuals();
otherTile.UpdateVisuals();
InvalidateVisuals(tile.GridIndex, tile.GridIndices);
InvalidateVisuals(otherTile.GridIndex, otherTile.GridIndices);
ConsiderPressureDifference(gridAtmosphere, tile, otherTile, amount);
}
}
@@ -548,12 +552,12 @@ namespace Content.Server.Atmos.EntitySystems
tile.AdjacentTiles[direction.ToIndex()].MonstermosInfo[direction.GetOpposite()] -= amount;
}
private void HandleDecompressionFloorRip(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, float sum)
private void HandleDecompressionFloorRip(IMapGrid mapGrid, TileAtmosphere tile, float sum)
{
var chance = MathHelper.Clamp(sum / 500, 0.005f, 0.5f);
if (sum > 20 && _robustRandom.Prob(chance))
gridAtmosphere.PryTile(tile.GridIndices);
PryTile(mapGrid, tile.GridIndices);
}
private class TileAtmosphereComparer : IComparer<TileAtmosphere>

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.Piping.Components;
@@ -20,6 +21,11 @@ namespace Content.Server.Atmos.EntitySystems
/// </summary>
private const int LagCheckIterations = 30;
/// <summary>
/// Check current execution time every n instances processed.
/// </summary>
private const int InvalidCoordinatesLagCheckIterations = 50;
private int _currentRunAtmosphereIndex = 0;
private bool _simulationPaused = false;
@@ -30,10 +36,13 @@ namespace Content.Server.Atmos.EntitySystems
if(!atmosphere.ProcessingPaused)
atmosphere.CurrentRunTiles = new Queue<TileAtmosphere>(atmosphere.ActiveTiles);
if (!TryGetMapGrid(atmosphere, out var mapGrid))
throw new Exception("Tried to process a grid atmosphere on an entity that isn't a grid!");
var number = 0;
while (atmosphere.CurrentRunTiles.TryDequeue(out var tile))
{
EqualizePressureInZone(atmosphere, tile, atmosphere.UpdateCounter);
EqualizePressureInZone(mapGrid, atmosphere, tile, atmosphere.UpdateCounter);
if (number++ < LagCheckIterations) continue;
number = 0;
@@ -69,22 +78,22 @@ namespace Content.Server.Atmos.EntitySystems
return true;
}
private bool ProcessExcitedGroups(GridAtmosphereComponent atmosphere)
private bool ProcessExcitedGroups(GridAtmosphereComponent gridAtmosphere)
{
if(!atmosphere.ProcessingPaused)
atmosphere.CurrentRunExcitedGroups = new Queue<ExcitedGroup>(atmosphere.ExcitedGroups);
if(!gridAtmosphere.ProcessingPaused)
gridAtmosphere.CurrentRunExcitedGroups = new Queue<ExcitedGroup>(gridAtmosphere.ExcitedGroups);
var number = 0;
while (atmosphere.CurrentRunExcitedGroups.TryDequeue(out var excitedGroup))
while (gridAtmosphere.CurrentRunExcitedGroups.TryDequeue(out var excitedGroup))
{
excitedGroup.BreakdownCooldown++;
excitedGroup.DismantleCooldown++;
if(excitedGroup.BreakdownCooldown > Atmospherics.ExcitedGroupBreakdownCycles)
excitedGroup.SelfBreakdown(this, ExcitedGroupsSpaceIsAllConsuming);
ExcitedGroupSelfBreakdown(gridAtmosphere, excitedGroup, ExcitedGroupsSpaceIsAllConsuming);
else if(excitedGroup.DismantleCooldown > Atmospherics.ExcitedGroupsDismantleCycles)
excitedGroup.Dismantle();
ExcitedGroupDismantle(gridAtmosphere, excitedGroup);
if (number++ < LagCheckIterations) continue;
number = 0;
@@ -195,7 +204,7 @@ namespace Content.Server.Atmos.EntitySystems
atmosphere.CurrentRunAtmosDevices = new Queue<AtmosDeviceComponent>(atmosphere.AtmosDevices);
var time = _gameTiming.CurTime;
var updateEvent = new AtmosDeviceUpdateEvent(atmosphere);
var updateEvent = new AtmosDeviceUpdateEvent();
var number = 0;
while (atmosphere.CurrentRunAtmosDevices.TryDequeue(out var device))
{
@@ -237,8 +246,14 @@ namespace Content.Server.Atmos.EntitySystems
atmosphere.Timer += frameTime;
if (atmosphere.InvalidatedCoords.Count != 0)
atmosphere.Revalidate();
if ((atmosphere.InvalidatedCoords.Count != 0 || atmosphere.RevalidatePaused) && TryGetMapGrid(atmosphere, out var mapGrid))
if (!GridRevalidate(mapGrid, atmosphere))
{
atmosphere.RevalidatePaused = true;
return;
}
atmosphere.RevalidatePaused = false;
if (atmosphere.Timer < AtmosTime)
continue;

View File

@@ -48,21 +48,24 @@ namespace Content.Server.Atmos.EntitySystems
public bool ConsiderSuperconductivity(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile)
{
if (tile.ThermalConductivity == 0f)
if (tile.ThermalConductivity == 0f || !Superconduction)
return false;
gridAtmosphere.AddSuperconductivityTile(tile);
gridAtmosphere.SuperconductivityTiles.Add(tile);
return true;
}
public bool ConsiderSuperconductivity(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, bool starting)
{
if (!Superconduction)
return false;
if (tile.Air == null || tile.Air.Temperature < (starting
? Atmospherics.MinimumTemperatureStartSuperConduction
: Atmospherics.MinimumTemperatureForSuperconduction))
return false;
return !(gridAtmosphere.AtmosphereSystem.GetHeatCapacity(tile.Air) < Atmospherics.MCellWithRatio)
return !(GetHeatCapacity(tile.Air) < Atmospherics.MCellWithRatio)
&& ConsiderSuperconductivity(gridAtmosphere, tile);
}
@@ -82,7 +85,7 @@ namespace Content.Server.Atmos.EntitySystems
// Make sure it's still hot enough to continue conducting.
if (temperature < Atmospherics.MinimumTemperatureForSuperconduction)
{
gridAtmosphere.RemoveSuperconductivityTile(tile);
gridAtmosphere.SuperconductivityTiles.Remove(tile);
}
}
@@ -112,7 +115,7 @@ namespace Content.Server.Atmos.EntitySystems
TemperatureShareOpenToSolid(tile, other);
}
gridAtmosphere.AddActiveTile(tile);
AddActiveTile(gridAtmosphere, tile);
}
private void TemperatureShareOpenToSolid(TileAtmosphere tile, TileAtmosphere other)

View File

@@ -3,19 +3,15 @@ using Content.Server.NodeContainer.EntitySystems;
using Content.Shared.Atmos.EntitySystems;
using Content.Shared.Maps;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Server.Atmos.EntitySystems
{
[UsedImplicitly]
public partial class AtmosphereSystem : SharedAtmosphereSystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
private const float ExposedUpdateDelay = 1f;
private float _exposedTimer = 0f;
@@ -28,6 +24,7 @@ namespace Content.Server.Atmos.EntitySystems
InitializeGases();
InitializeCVars();
InitializeGrid();
#region Events
@@ -57,7 +54,7 @@ namespace Content.Server.Atmos.EntitySystems
return;
}
GetGridAtmosphere(eventArgs.NewTile.GridIndex)?.Invalidate(eventArgs.NewTile.GridIndices);
InvalidateTile(eventArgs.NewTile.GridIndex, eventArgs.NewTile.GridIndices);
}
private void OnMapCreated(object? sender, MapEventArgs e)
@@ -84,8 +81,7 @@ namespace Content.Server.Atmos.EntitySystems
foreach (var exposed in EntityManager.ComponentManager.EntityQuery<AtmosExposedComponent>())
{
// TODO ATMOS: Kill this with fire.
var atmos = GetGridAtmosphere(exposed.Owner.Transform.Coordinates);
var tile = atmos.GetTile(exposed.Owner.Transform.Coordinates);
var tile = GetTileAtmosphereOrCreateSpace(exposed.Owner.Transform.Coordinates);
if (tile == null) continue;
exposed.Update(tile, _exposedTimer, this);
}

View File

@@ -144,14 +144,14 @@ namespace Content.Server.Atmos.EntitySystems
/// <summary>
/// Checks whether the overlay-relevant data for a gas tile has been updated.
/// </summary>
/// <param name="gam"></param>
/// <param name="grid"></param>
/// <param name="oldTile"></param>
/// <param name="indices"></param>
/// <param name="overlayData"></param>
/// <returns>true if updated</returns>
private bool TryRefreshTile(GridAtmosphereComponent gam, GasOverlayData oldTile, Vector2i indices, out GasOverlayData overlayData)
private bool TryRefreshTile(GridId grid, GasOverlayData oldTile, Vector2i indices, out GasOverlayData overlayData)
{
var tile = gam.GetTile(indices);
var tile = _atmosphereSystem.GetTileAtmosphereOrCreateSpace(grid, indices);
if (tile == null)
{
@@ -287,7 +287,7 @@ namespace Content.Server.Atmos.EntitySystems
{
var chunk = GetOrCreateChunk(gridId, invalid);
if (!TryRefreshTile(gam, chunk.GetData(invalid), invalid, out var data)) continue;
if (!TryRefreshTile(grid.Index, chunk.GetData(invalid), invalid, out var data)) continue;
if (!updatedTiles.TryGetValue(chunk, out var tiles))
{