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

@@ -1,7 +1,5 @@
#nullable disable warnings
#nullable enable annotations
using System.Runtime.CompilerServices;
using Content.Server.Atmos.Components;
using Content.Server.Interfaces;
using Content.Shared.Atmos;
using Content.Shared.Maps;
@@ -11,6 +9,9 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.Atmos
{
/// <summary>
/// Internal Atmos class that stores data about the atmosphere in a grid.
/// </summary>
public class TileAtmosphere : IGasMixtureHolder
{
[ViewVariables]
@@ -40,9 +41,6 @@ namespace Content.Server.Atmos
[ViewVariables]
public bool Excited { get; set; }
[ViewVariables]
private readonly GridAtmosphereComponent _gridAtmosphereComponent;
/// <summary>
/// Adjacent tiles in the same order as <see cref="AtmosDirection"/>. (NSEW)
/// </summary>
@@ -86,9 +84,8 @@ namespace Content.Server.Atmos
[ViewVariables]
public AtmosDirection BlockedAirflow { get; set; } = AtmosDirection.Invalid;
public TileAtmosphere(GridAtmosphereComponent atmosphereComponent, GridId gridIndex, Vector2i gridIndices, GasMixture? mixture = null, bool immutable = false)
public TileAtmosphere(GridId gridIndex, Vector2i gridIndices, GasMixture? mixture = null, bool immutable = false)
{
_gridAtmosphereComponent = atmosphereComponent;
GridIndex = gridIndex;
GridIndices = gridIndices;
Air = mixture;
@@ -96,47 +93,5 @@ namespace Content.Server.Atmos
if(immutable)
Air?.MarkImmutable();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void UpdateVisuals()
{
if (Air == null) return;
_gridAtmosphereComponent.GasTileOverlaySystem.Invalidate(GridIndex, GridIndices);
}
public void UpdateAdjacent()
{
for (var i = 0; i < Atmospherics.Directions; i++)
{
var direction = (AtmosDirection) (1 << i);
var otherIndices = GridIndices.Offset(direction.ToDirection());
var isSpace = _gridAtmosphereComponent.IsSpace(GridIndices);
var adjacent = _gridAtmosphereComponent.GetTile(otherIndices, !isSpace);
AdjacentTiles[direction.ToIndex()] = adjacent;
adjacent?.UpdateAdjacent(direction.GetOpposite());
if (adjacent != null && !BlockedAirflow.IsFlagSet(direction) && !_gridAtmosphereComponent.IsAirBlocked(adjacent.GridIndices, direction.GetOpposite()))
{
AdjacentBits |= direction;
}
}
}
private void UpdateAdjacent(AtmosDirection direction)
{
AdjacentTiles[direction.ToIndex()] = _gridAtmosphereComponent.GetTile(GridIndices.Offset(direction.ToDirection()));
if (!BlockedAirflow.IsFlagSet(direction) && !_gridAtmosphereComponent.IsAirBlocked(GridIndices.Offset(direction.ToDirection()), direction.GetOpposite()))
{
AdjacentBits |= direction;
}
else
{
AdjacentBits &= ~direction;
}
}
}
}