Removes AtmosCooldown from TileAtmosphere, fixes various atmos issues (#2297)

* Remove AtmosCooldown

* Fix former space tiles always having an immutable gas mixture

* _tile -> _tiles
This commit is contained in:
Víctor Aguilera Puerto
2020-10-19 14:50:16 +02:00
committed by GitHub
parent 717a375abb
commit 19d32eb4ce
7 changed files with 39 additions and 37 deletions

View File

@@ -12,7 +12,7 @@ namespace Content.Server.Atmos
private bool _disposed = false;
[ViewVariables]
private readonly HashSet<TileAtmosphere> _tile = new HashSet<TileAtmosphere>();
private readonly HashSet<TileAtmosphere> _tiles = new HashSet<TileAtmosphere>();
[ViewVariables]
private GridAtmosphereComponent _gridAtmosphereComponent;
@@ -25,35 +25,41 @@ namespace Content.Server.Atmos
public void AddTile(TileAtmosphere tile)
{
_tile.Add(tile);
_tiles.Add(tile);
tile.ExcitedGroup = this;
ResetCooldowns();
}
public bool RemoveTile(TileAtmosphere tile)
{
tile.ExcitedGroup = null;
return _tiles.Remove(tile);
}
public void MergeGroups(ExcitedGroup other)
{
var ourSize = _tile.Count;
var otherSize = other._tile.Count;
var ourSize = _tiles.Count;
var otherSize = other._tiles.Count;
if (ourSize > otherSize)
{
foreach (var tile in other._tile)
foreach (var tile in other._tiles)
{
tile.ExcitedGroup = this;
_tile.Add(tile);
_tiles.Add(tile);
}
other._tile.Clear();
other._tiles.Clear();
other.Dispose();
ResetCooldowns();
}
else
{
foreach (var tile in _tile)
foreach (var tile in _tiles)
{
tile.ExcitedGroup = other;
other._tile.Add(tile);
other._tiles.Add(tile);
}
_tile.Clear();
_tiles.Clear();
Dispose();
other.ResetCooldowns();
}
@@ -80,7 +86,7 @@ namespace Content.Server.Atmos
{
var combined = new GasMixture(Atmospherics.CellVolume);
var tileSize = _tile.Count;
var tileSize = _tiles.Count;
if (_disposed) return;
@@ -90,7 +96,7 @@ namespace Content.Server.Atmos
return;
}
foreach (var tile in _tile)
foreach (var tile in _tiles)
{
if (tile?.Air == null) continue;
combined.Merge(tile.Air);
@@ -101,11 +107,10 @@ namespace Content.Server.Atmos
combined.Multiply(1 / (float)tileSize);
foreach (var tile in _tile)
foreach (var tile in _tiles)
{
if (tile?.Air == null) continue;
tile.Air.CopyFromMutable(combined);
tile.AtmosCooldown = 0;
tile.UpdateVisuals();
}
@@ -114,7 +119,7 @@ namespace Content.Server.Atmos
public void Dismantle(bool unexcite = true)
{
foreach (var tile in _tile)
foreach (var tile in _tiles)
{
if (tile == null) continue;
tile.ExcitedGroup = null;
@@ -123,7 +128,7 @@ namespace Content.Server.Atmos
_gridAtmosphereComponent.RemoveActiveTile(tile);
}
_tile.Clear();
_tiles.Clear();
}
public void Dispose()

View File

@@ -63,7 +63,7 @@ namespace Content.Server.Atmos
/// Use with caution.
/// </summary>
/// <param name="tile"></param>
void RemoveActiveTile(TileAtmosphere tile);
void RemoveActiveTile(TileAtmosphere tile, bool disposeGroup = true);
/// <summary>
/// Marks a tile as having a hotspot so it can be processed.

View File

@@ -44,9 +44,6 @@ namespace Content.Server.Atmos
[ViewVariables]
private static GasTileOverlaySystem _gasTileOverlaySystem;
[ViewVariables]
public int AtmosCooldown { get; set; } = 0;
[ViewVariables]
public float Temperature {get; private set; } = Atmospherics.T20C;
@@ -647,7 +644,7 @@ namespace Content.Server.Atmos
// Can't process a tile without air
if (Air == null)
{
_gridAtmosphereComponent.RemoveActiveTile(this);
Excited = false;
return;
}
@@ -657,7 +654,6 @@ namespace Content.Server.Atmos
_currentCycle = fireCount;
var adjacentTileLength = 0;
AtmosCooldown++;
for (var i = 0; i < Atmospherics.Directions; i++)
{
var direction = (AtmosDirection) (1 << i);
@@ -738,7 +734,7 @@ namespace Content.Server.Atmos
if (ConsiderSuperconductivity(true))
remove = false;
if((ExcitedGroup == null && remove) || (AtmosCooldown > (Atmospherics.ExcitedGroupsDismantleCycles * 2)))
if(ExcitedGroup == null && remove)
_gridAtmosphereComponent.RemoveActiveTile(this);
}
@@ -1187,11 +1183,9 @@ namespace Content.Server.Atmos
if (lastShare > Atmospherics.MinimumAirToSuspend)
{
ExcitedGroup.ResetCooldowns();
AtmosCooldown = 0;
} else if (lastShare > Atmospherics.MinimumMolesDeltaToMove)
{
ExcitedGroup.DismantleCooldown = 0;
AtmosCooldown = 0;
}
}

View File

@@ -241,6 +241,12 @@ namespace Content.Server.GameObjects.Components.Atmos
FixVacuum(tile.GridIndices);
}
// Tile used to be space, but isn't anymore.
if (tile.Air?.Immutable ?? false)
{
tile.Air = null;
}
tile.Air ??= new GasMixture(GetVolumeForCells(1), AtmosphereSystem){Temperature = Atmospherics.T20C};
}
@@ -300,12 +306,15 @@ namespace Content.Server.GameObjects.Components.Atmos
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void RemoveActiveTile(TileAtmosphere? tile)
public virtual void RemoveActiveTile(TileAtmosphere? tile, bool disposeGroup = true)
{
if (tile == null) return;
_activeTiles.Remove(tile);
tile.Excited = false;
tile.ExcitedGroup?.Dispose();
if(disposeGroup)
tile.ExcitedGroup?.Dispose();
else
tile.ExcitedGroup?.RemoveTile(tile);
}
/// <inheritdoc />

View File

@@ -40,7 +40,7 @@ namespace Content.Server.GameObjects.Components.Atmos
public override void AddActiveTile(TileAtmosphere? tile) { }
public override void RemoveActiveTile(TileAtmosphere? tile) { }
public override void RemoveActiveTile(TileAtmosphere? tile, bool disposeGroup = true) { }
public override void AddHotspotTile(TileAtmosphere? tile) { }

View File

@@ -26,7 +26,6 @@ namespace Content.Server.GameObjects.EntitySystems
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPauseManager _pauseManager = default!;
[Dependency] private IEntityManager _entityManager = default!;
private GasReactionPrototype[] _gasReactions = Array.Empty<GasReactionPrototype>();
@@ -38,11 +37,6 @@ namespace Content.Server.GameObjects.EntitySystems
/// </summary>
public IEnumerable<GasReactionPrototype> GasReactions => _gasReactions!;
/// <summary>
/// EventBus reference for gas reactions.
/// </summary>
public IEventBus EventBus => _entityManager.EventBus;
public GridTileLookupSystem GridTileLookupSystem => _gridTileLookup ??= Get<GridTileLookupSystem>();
public override void Initialize()

View File

@@ -109,8 +109,8 @@
/// <summary>
/// Minimum temperature for starting superconduction.
/// </summary>
public const float MinimumTemperatureStartSuperConduction = (T20C + 200f);
public const float MinimumTemperatureForSuperconduction = (T20C + 10f);
public const float MinimumTemperatureStartSuperConduction = (T20C + 400f);
public const float MinimumTemperatureForSuperconduction = (T20C + 80f);
/// <summary>
/// Minimum heat capacity.
@@ -233,7 +233,7 @@
/// <summary>
/// Gases to Ids. Keep these updated with the prototypes!
/// </summary>
public enum Gas
public enum Gas : sbyte
{
Oxygen = 0,
Nitrogen = 1,