Skip to content

Commit df6ce7f

Browse files
Fix Atmospherics dP not trolling partially airtight entities (space-wizards#40435)
* Fix dP not trolling partially airtight entities * Assumptions in atmospherics are the root of all evil
1 parent 1a5be55 commit df6ce7f

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

‎Content.IntegrationTests/Tests/Atmos/DeltaPressureTest.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public sealed class DeltaPressureTest
9393

9494
private readonly ResPath _testMap = new("Maps/Test/Atmospherics/DeltaPressure/deltapressuretest.yml");
9595

96+
// TODO ATMOS TESTS
97+
// - Check for directional windows (partial airtight ents) properly computing pressure differences
98+
// - Check for multi-tick damage (window with n damage threshold should take n ticks to destroy)
99+
// - Check that all maps do not explode into a million pieces on load due to dP
100+
// - Ensure that all tests work for a map that has an origin at a non zero coordinate
101+
96102
/// <summary>
97103
/// Asserts that an entity with a DeltaPressureComponent with autoJoinProcessingList
98104
/// set to true is automatically added to the DeltaPressure processing list

‎Content.Server/Atmos/Components/DeltaPressureComponent.cs‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,13 @@ public sealed partial class DeltaPressureComponent : Component
3434
[Access(typeof(DeltaPressureSystem), typeof(AtmosphereSystem))]
3535
public bool IsTakingDamage;
3636

37-
/// <summary>
38-
/// The current cached position of this entity on the grid.
39-
/// Updated via MoveEvent.
40-
/// </summary>
41-
[DataField(readOnly: true)]
42-
public Vector2i CurrentPosition = Vector2i.Zero;
43-
4437
/// <summary>
4538
/// The grid this entity is currently joined to for processing.
4639
/// Required for proper deletion, as we cannot reference the grid
4740
/// for removal while the entity is being deleted.
4841
/// </summary>
42+
/// <remarks>Note that while <see cref="AirtightComponent"/> already stores the grid,
43+
/// we cannot trust it to be available on init or when the entity is being deleted. Tragic.</remarks>
4944
[DataField]
5045
public EntityUid? GridUid;
5146

‎Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,6 @@ public bool TryAddDeltaPressureEntity(Entity<GridAtmosphereComponent?> grid, Ent
355355
grid.Comp.DeltaPressureEntityLookup[ent.Owner] = grid.Comp.DeltaPressureEntities.Count;
356356
grid.Comp.DeltaPressureEntities.Add(ent);
357357

358-
ent.Comp.CurrentPosition = _map.CoordinatesToTile(grid,
359-
Comp<MapGridComponent>(grid),
360-
xform.Coordinates);
361-
362358
ent.Comp.GridUid = grid.Owner;
363359
ent.Comp.InProcessingList = true;
364360

‎Content.Server/Atmos/EntitySystems/AtmosphereSystem.DeltaPressure.cs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,35 @@ in the NumericsHelpers class.
3939
so simple vector operations like min/max/abs can be performed on them.
4040
*/
4141

42+
var airtightComp = _airtightQuery.Comp(ent);
43+
var currentPos = airtightComp.LastPosition.Tile;
4244
var tiles = new TileAtmosphere?[Atmospherics.Directions];
4345
for (var i = 0; i < Atmospherics.Directions; i++)
4446
{
4547
var direction = (AtmosDirection)(1 << i);
46-
var offset = ent.Comp.CurrentPosition.Offset(direction);
48+
var offset = currentPos.Offset(direction);
4749
tiles[i] = gridAtmosComp.Tiles.GetValueOrDefault(offset);
4850
}
4951

5052
Span<float> pressures = stackalloc float[Atmospherics.Directions];
5153

5254
GetBulkTileAtmospherePressures(tiles, pressures);
5355

56+
// This entity could be airtight but still be able to contain air on the tile it's on (ex. directional windows).
57+
// As such, substitute the pressure of the pressure on top of the entity for the directions that it can accept air from.
58+
// (Or rather, don't do so for directions that it blocks air from.)
59+
if (!airtightComp.NoAirWhenFullyAirBlocked)
60+
{
61+
for (var i = 0; i < Atmospherics.Directions; i++)
62+
{
63+
var direction = (AtmosDirection)(1 << i);
64+
if (!airtightComp.AirBlockedDirection.HasFlag(direction))
65+
{
66+
pressures[i] = gridAtmosComp.Tiles.GetValueOrDefault(currentPos)?.Air?.Pressure ?? 0f;
67+
}
68+
}
69+
}
70+
5471
Span<float> opposingGroupA = stackalloc float[DeltaPressurePairCount];
5572
Span<float> opposingGroupB = stackalloc float[DeltaPressurePairCount];
5673
Span<float> opposingGroupMax = stackalloc float[DeltaPressurePairCount];

‎Content.Server/Atmos/EntitySystems/DeltaPressureSystem.cs‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace Content.Server.Atmos.EntitySystems;
1717
public sealed class DeltaPressureSystem : EntitySystem
1818
{
1919
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
20-
[Dependency] private readonly SharedMapSystem _map = default!;
2120

2221
public override void Initialize()
2322
{
@@ -26,29 +25,17 @@ public override void Initialize()
2625
SubscribeLocalEvent<DeltaPressureComponent, ComponentInit>(OnComponentInit);
2726
SubscribeLocalEvent<DeltaPressureComponent, ComponentShutdown>(OnComponentShutdown);
2827
SubscribeLocalEvent<DeltaPressureComponent, ExaminedEvent>(OnExamined);
29-
SubscribeLocalEvent<DeltaPressureComponent, MoveEvent>(OnMoveEvent);
3028

3129
SubscribeLocalEvent<DeltaPressureComponent, GridUidChangedEvent>(OnGridChanged);
3230
}
3331

34-
private void OnMoveEvent(Entity<DeltaPressureComponent> ent, ref MoveEvent args)
35-
{
36-
var xform = Transform(ent);
37-
// May move off-grid, so, might as well protect against that.
38-
if (!TryComp<MapGridComponent>(xform.GridUid, out var mapGridComponent))
39-
{
40-
return;
41-
}
42-
43-
ent.Comp.CurrentPosition = _map.CoordinatesToTile(xform.GridUid.Value, mapGridComponent, args.NewPosition);
44-
}
45-
4632
private void OnComponentInit(Entity<DeltaPressureComponent> ent, ref ComponentInit args)
4733
{
4834
var xform = Transform(ent);
4935
if (xform.GridUid == null)
5036
return;
5137

38+
EnsureComp<AirtightComponent>(ent);
5239
_atmosphereSystem.TryAddDeltaPressureEntity(xform.GridUid.Value, ent);
5340
}
5441

0 commit comments

Comments
 (0)