Support for non-fulltile firelocks!

This commit is contained in:
Víctor Aguilera Puerto
2020-08-30 15:00:40 +02:00
parent c137d1bc16
commit 52e98e29d7
5 changed files with 95 additions and 74 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.GameObjects.Components.Atmos;
using Content.Server.GameObjects.Components.Atmos.Piping; using Content.Server.GameObjects.Components.Atmos.Piping;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Shared.Atmos; using Content.Shared.Atmos;
@@ -48,7 +49,7 @@ namespace Content.Server.Atmos
/// Revalidates indices immediately. /// Revalidates indices immediately.
/// </summary> /// </summary>
/// <param name="indices"></param> /// <param name="indices"></param>
void Revalidate(MapIndices indices); void UpdateAdjacentBits(MapIndices indices);
/// <summary> /// <summary>
/// Adds an active tile so it becomes processed every update until it becomes inactive. /// Adds an active tile so it becomes processed every update until it becomes inactive.
@@ -117,6 +118,7 @@ namespace Content.Server.Atmos
/// Returns a tile. /// Returns a tile.
/// </summary> /// </summary>
/// <param name="indices"></param> /// <param name="indices"></param>
/// <param name="createSpace"></param>
/// <returns></returns> /// <returns></returns>
TileAtmosphere GetTile(MapIndices indices, bool createSpace = true); TileAtmosphere GetTile(MapIndices indices, bool createSpace = true);
@@ -124,17 +126,19 @@ namespace Content.Server.Atmos
/// Returns a tile. /// Returns a tile.
/// </summary> /// </summary>
/// <param name="coordinates"></param> /// <param name="coordinates"></param>
/// <param name="createSpace"></param>
/// <returns></returns> /// <returns></returns>
TileAtmosphere GetTile(GridCoordinates coordinates, bool createSpace = true); TileAtmosphere GetTile(GridCoordinates coordinates, bool createSpace = true);
/// <summary> /// <summary>
/// Returns if the tile in question is air-blocked. /// Returns if the tile in question is air-blocked.
/// This could be due to a wall, an airlock, etc. /// This could be due to a wall, an airlock, etc.
/// Also see AirtightComponent. /// <seealso cref="AirtightComponent"/>
/// </summary> /// </summary>
/// <param name="indices"></param> /// <param name="indices"></param>
/// <param name="direction"></param>
/// <returns></returns> /// <returns></returns>
bool IsAirBlocked(MapIndices indices); bool IsAirBlocked(MapIndices indices, AtmosDirection direction);
/// <summary> /// <summary>
/// Returns if the tile in question is space. /// Returns if the tile in question is space.

View File

@@ -1122,7 +1122,7 @@ namespace Content.Server.Atmos
_adjacentTiles[direction.ToIndex()] = adjacent; _adjacentTiles[direction.ToIndex()] = adjacent;
adjacent?.UpdateAdjacent(direction.GetOpposite()); adjacent?.UpdateAdjacent(direction.GetOpposite());
if (adjacent != null && !_gridAtmosphereComponent.IsAirBlocked(adjacent.GridIndices)) if (adjacent != null && !_gridAtmosphereComponent.IsAirBlocked(adjacent.GridIndices, direction.GetOpposite()))
{ {
_adjacentBits |= direction; _adjacentBits |= direction;
} }

View File

@@ -1,5 +1,6 @@
#nullable enable #nullable enable
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Atmos;
using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.GameObjects.Components.Transform;
@@ -22,6 +23,8 @@ namespace Content.Server.GameObjects.Components.Atmos
public override string Name => "Airtight"; public override string Name => "Airtight";
[ViewVariables]
private int _airBlockedDirection;
private bool _airBlocked = true; private bool _airBlocked = true;
private bool _fixVacuum = false; private bool _fixVacuum = false;
@@ -33,11 +36,19 @@ namespace Content.Server.GameObjects.Components.Atmos
{ {
_airBlocked = value; _airBlocked = value;
if (Owner.TryGetComponent(out SnapGridComponent? snapGrid)) UpdatePosition();
{
EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.GridID)?.Revalidate(snapGrid.Position);
} }
} }
public AtmosDirection AirBlockedDirection
{
get => (AtmosDirection)_airBlockedDirection;
set
{
_airBlockedDirection = (int) value;
UpdatePosition();
}
} }
[ViewVariables] [ViewVariables]
@@ -49,16 +60,16 @@ namespace Content.Server.GameObjects.Components.Atmos
serializer.DataField(ref _airBlocked, "airBlocked", true); serializer.DataField(ref _airBlocked, "airBlocked", true);
serializer.DataField(ref _fixVacuum, "fixVacuum", true); serializer.DataField(ref _fixVacuum, "fixVacuum", true);
serializer.DataField(ref _airBlockedDirection, "airBlockedDirection", (int)AtmosDirection.All, WithFormat.Flags<AtmosDirectionFlags>());
} }
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
// Using the SnapGrid is critical for the performance of the room builder, and thus if // Using the SnapGrid is critical for performance, and thus if it is absent the component
// it is absent the component will not be airtight. A warning is much easier to track // will not be airtight. A warning is much easier to track down than the object magically
// down than the object magically not being airtight, so log one if the SnapGrid component // not being airtight, so log one if the SnapGrid component is missing.
// is missing.
if (!Owner.EnsureComponent(out SnapGridComponent _)) if (!Owner.EnsureComponent(out SnapGridComponent _))
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition.ToString()} didn't have a {nameof(SnapGridComponent)}"); Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition.ToString()} didn't have a {nameof(SnapGridComponent)}");
@@ -87,13 +98,10 @@ namespace Content.Server.GameObjects.Components.Atmos
snapGrid.OnPositionChanged -= OnTransformMove; snapGrid.OnPositionChanged -= OnTransformMove;
} }
if (_fixVacuum) UpdatePosition(_lastPosition.Item1, _lastPosition.Item2);
{
var mapIndices = Owner.Transform.GridPosition.ToMapIndices(_mapManager);
EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.GridID)?.FixVacuum(mapIndices);
}
UpdatePosition(); if (_fixVacuum)
EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(_lastPosition.Item1)?.FixVacuum(_lastPosition.Item2);
} }
private void OnTransformMove() private void OnTransformMove()
@@ -109,13 +117,18 @@ namespace Content.Server.GameObjects.Components.Atmos
private void UpdatePosition() private void UpdatePosition()
{ {
var mapIndices = Owner.Transform.GridPosition.ToMapIndices(_mapManager); if (Owner.TryGetComponent(out SnapGridComponent? snapGrid))
UpdatePosition(Owner.Transform.GridID, mapIndices); UpdatePosition(Owner.Transform.GridID, snapGrid.Position);
} }
private void UpdatePosition(GridId gridId, MapIndices pos) private void UpdatePosition(GridId gridId, MapIndices pos)
{ {
EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId)?.Invalidate(pos); var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
if (gridAtmos == null) return;
gridAtmos.UpdateAdjacentBits(pos);
gridAtmos.Invalidate(pos);
} }
} }
} }

View File

@@ -209,20 +209,11 @@ namespace Content.Server.GameObjects.Components.Atmos
} }
private void Revalidate() private void Revalidate()
{
foreach (var indices in _invalidatedCoords.ToArray())
{
Revalidate(indices);
}
_invalidatedCoords.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Revalidate(MapIndices indices)
{ {
if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return; if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return;
foreach (var indices in _invalidatedCoords.ToArray())
{
var tile = GetTile(indices); var tile = GetTile(indices);
if (tile == null) if (tile == null)
@@ -270,6 +261,15 @@ namespace Content.Server.GameObjects.Components.Atmos
} }
} }
_invalidatedCoords.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void UpdateAdjacentBits(MapIndices indices)
{
GetTile(indices)?.UpdateAdjacent();
}
/// <inheritdoc /> /// <inheritdoc />
public void FixVacuum(MapIndices indices) public void FixVacuum(MapIndices indices)
{ {
@@ -413,10 +413,10 @@ namespace Content.Server.GameObjects.Components.Atmos
} }
/// <inheritdoc /> /// <inheritdoc />
public bool IsAirBlocked(MapIndices indices) public bool IsAirBlocked(MapIndices indices, AtmosDirection direction = AtmosDirection.All)
{ {
var ac = GetObstructingComponent(indices); var ac = GetObstructingComponent(indices);
return ac != null && ac.AirBlocked; return ac != null && ac.AirBlocked && ac.AirBlockedDirection.HasFlag(direction);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -1,13 +1,15 @@
using System; using System;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Serialization;
namespace Content.Shared.Atmos namespace Content.Shared.Atmos
{ {
/// <summary> /// <summary>
/// The reason we use this over <see cref="Direction"/> is that we are going to do some heavy bitflag usage. /// The reason we use this over <see cref="Direction"/> is that we are going to do some heavy bitflag usage.
/// </summary> /// </summary>
[Flags] [Flags, Serializable]
public enum AtmosDirection : byte [FlagsFor(typeof(AtmosDirectionFlags))]
public enum AtmosDirection
{ {
Invalid = 0, Invalid = 0,
North = 1 << 0, North = 1 << 0,
@@ -86,4 +88,6 @@ namespace Content.Shared.Atmos
return direction | other; return direction | other;
} }
} }
public sealed class AtmosDirectionFlags { }
} }