Atmos device performance improvements (#26493)

* Atmos device performance improvements

* AtmosDirection perf improvements

* Fix errors

* Add GasTileOverlayComponent arguments

* Make excite no longer invalidate a tile
This commit is contained in:
Leon Friedrich
2024-03-30 17:17:53 +13:00
committed by GitHub
parent aa96baeb5f
commit 888a3bda51
51 changed files with 373 additions and 324 deletions

View File

@@ -13,6 +13,7 @@ public sealed class AirFilterSystem : EntitySystem
{ {
[Dependency] private readonly AtmosphereSystem _atmosphere = default!; [Dependency] private readonly AtmosphereSystem _atmosphere = default!;
[Dependency] private readonly IMapManager _map = default!; [Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -31,7 +32,7 @@ public sealed class AirFilterSystem : EntitySystem
if (air.Pressure >= intake.Pressure) if (air.Pressure >= intake.Pressure)
return; return;
var environment = _atmosphere.GetContainingMixture(uid, true, true); var environment = _atmosphere.GetContainingMixture(uid, args.Grid, args.Map, true, true);
// nothing to intake from // nothing to intake from
if (environment == null) if (environment == null)
return; return;
@@ -63,12 +64,11 @@ public sealed class AirFilterSystem : EntitySystem
var oxygen = air.GetMoles(filter.Oxygen) / air.TotalMoles; var oxygen = air.GetMoles(filter.Oxygen) / air.TotalMoles;
var gases = oxygen >= filter.TargetOxygen ? filter.Gases : filter.OverflowGases; var gases = oxygen >= filter.TargetOxygen ? filter.Gases : filter.OverflowGases;
var coordinates = Transform(uid).MapPosition;
GasMixture? destination = null; GasMixture? destination = null;
if (_map.TryFindGridAt(coordinates, out _, out var grid)) if (args.Grid is {} grid)
{ {
var tile = grid.GetTileRef(coordinates); var position = _transform.GetGridTilePositionOrDefault(uid);
destination = _atmosphere.GetTileMixture(tile.GridUid, null, tile.GridIndices, true); destination = _atmosphere.GetTileMixture(grid, args.Map, position, true);
} }
if (destination != null) if (destination != null)

View File

@@ -24,6 +24,8 @@ namespace Content.Server.Atmos.EntitySystems
/// <summary> /// <summary>
/// Event that tries to query the mixture a certain entity is exposed to. /// Event that tries to query the mixture a certain entity is exposed to.
/// This is mainly intended for use with entities inside of containers.
/// This event is not raised for entities that are directly parented to the grid.
/// </summary> /// </summary>
[ByRefEvent] [ByRefEvent]
public struct AtmosExposedGetAirEvent public struct AtmosExposedGetAirEvent
@@ -31,7 +33,7 @@ namespace Content.Server.Atmos.EntitySystems
/// <summary> /// <summary>
/// The entity we want to query this for. /// The entity we want to query this for.
/// </summary> /// </summary>
public readonly EntityUid Entity; public readonly Entity<TransformComponent> Entity;
/// <summary> /// <summary>
/// The mixture that the entity is exposed to. Output parameter. /// The mixture that the entity is exposed to. Output parameter.
@@ -39,9 +41,9 @@ namespace Content.Server.Atmos.EntitySystems
public GasMixture? Gas = null; public GasMixture? Gas = null;
/// <summary> /// <summary>
/// Whether to invalidate the mixture, if possible. /// Whether to excite the mixture, if possible.
/// </summary> /// </summary>
public bool Invalidate = false; public readonly bool Excite = false;
/// <summary> /// <summary>
/// Whether this event has been handled or not. /// Whether this event has been handled or not.
@@ -49,10 +51,10 @@ namespace Content.Server.Atmos.EntitySystems
/// </summary> /// </summary>
public bool Handled = false; public bool Handled = false;
public AtmosExposedGetAirEvent(EntityUid entity, bool invalidate = false) public AtmosExposedGetAirEvent(Entity<TransformComponent> entity, bool excite = false)
{ {
Entity = entity; Entity = entity;
Invalidate = invalidate; Excite = excite;
} }
} }
} }

View File

@@ -4,6 +4,7 @@ using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Reactions; using Content.Server.Atmos.Reactions;
using Content.Server.NodeContainer.NodeGroups; using Content.Server.NodeContainer.NodeGroups;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Atmos.Components;
using Robust.Shared.Map.Components; using Robust.Shared.Map.Components;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -11,41 +12,39 @@ namespace Content.Server.Atmos.EntitySystems;
public partial class AtmosphereSystem public partial class AtmosphereSystem
{ {
public GasMixture? GetContainingMixture(EntityUid uid, bool ignoreExposed = false, bool excite = false, TransformComponent? transform = null) public GasMixture? GetContainingMixture(Entity<TransformComponent?> ent, bool ignoreExposed = false, bool excite = false)
{ {
if (!ignoreExposed) if (!Resolve(ent, ref ent.Comp))
return null;
return GetContainingMixture(ent, ent.Comp.GridUid, ent.Comp.MapUid, ignoreExposed, excite);
}
public GasMixture? GetContainingMixture(
Entity<TransformComponent?> ent,
Entity<GridAtmosphereComponent?, GasTileOverlayComponent?>? grid,
Entity<MapAtmosphereComponent?>? map,
bool ignoreExposed = false,
bool excite = false)
{
if (!Resolve(ent, ref ent.Comp))
return null;
if (!ignoreExposed && !ent.Comp.Anchored)
{ {
// Used for things like disposals/cryo to change which air people are exposed to. // Used for things like disposals/cryo to change which air people are exposed to.
var ev = new AtmosExposedGetAirEvent(uid, excite); var ev = new AtmosExposedGetAirEvent((ent, ent.Comp), excite);
RaiseLocalEvent(ent, ref ev);
// Give the entity itself a chance to handle this.
RaiseLocalEvent(uid, ref ev, false);
if (ev.Handled) if (ev.Handled)
return ev.Gas; return ev.Gas;
// We need to get the parent now, so we need the transform... If the parent is invalid, we can't do much else. // TODO ATMOS: recursively iterate up through parents
if(!Resolve(uid, ref transform) || !transform.ParentUid.IsValid() || transform.MapUid == null) // This really needs recursive InContainer metadata flag for performance
return GetTileMixture(null, null, Vector2i.Zero, excite); // And ideally some fast way to get the innermost airtight container.
// Give the parent entity a chance to handle the event...
RaiseLocalEvent(transform.ParentUid, ref ev, false);
if (ev.Handled)
return ev.Gas;
}
// Oops, we did a little bit of code duplication...
else if(!Resolve(uid, ref transform))
{
return GetTileMixture(null, null, Vector2i.Zero, excite);
} }
var position = _transformSystem.GetGridTilePositionOrDefault((ent, ent.Comp));
var gridUid = transform.GridUid; return GetTileMixture(grid, map, position, excite);
var mapUid = transform.MapUid;
var position = _transformSystem.GetGridOrMapTilePosition(uid, transform);
return GetTileMixture(gridUid, mapUid, position, excite);
} }
public bool HasAtmosphere(EntityUid gridUid) => _atmosQuery.HasComponent(gridUid); public bool HasAtmosphere(EntityUid gridUid) => _atmosQuery.HasComponent(gridUid);
@@ -84,21 +83,28 @@ public partial class AtmosphereSystem
entity.Comp.InvalidatedCoords.Add(tile); entity.Comp.InvalidatedCoords.Add(tile);
} }
public GasMixture?[]? GetTileMixtures(Entity<GridAtmosphereComponent?>? grid, Entity<MapAtmosphereComponent?>? map, List<Vector2i> tiles, bool excite = false) public GasMixture?[]? GetTileMixtures(
Entity<GridAtmosphereComponent?, GasTileOverlayComponent?>? grid,
Entity<MapAtmosphereComponent?>? map,
List<Vector2i> tiles,
bool excite = false)
{ {
GasMixture?[]? mixtures = null; GasMixture?[]? mixtures = null;
var handled = false; var handled = false;
// If we've been passed a grid, try to let it handle it. // If we've been passed a grid, try to let it handle it.
if (grid is {} gridEnt && Resolve(gridEnt, ref gridEnt.Comp)) if (grid is {} gridEnt && Resolve(gridEnt, ref gridEnt.Comp1))
{ {
if (excite)
Resolve(gridEnt, ref gridEnt.Comp2);
handled = true; handled = true;
mixtures = new GasMixture?[tiles.Count]; mixtures = new GasMixture?[tiles.Count];
for (var i = 0; i < tiles.Count; i++) for (var i = 0; i < tiles.Count; i++)
{ {
var tile = tiles[i]; var tile = tiles[i];
if (!gridEnt.Comp.Tiles.TryGetValue(tile, out var atmosTile)) if (!gridEnt.Comp1.Tiles.TryGetValue(tile, out var atmosTile))
{ {
// need to get map atmosphere // need to get map atmosphere
handled = false; handled = false;
@@ -108,7 +114,10 @@ public partial class AtmosphereSystem
mixtures[i] = atmosTile.Air; mixtures[i] = atmosTile.Air;
if (excite) if (excite)
gridEnt.Comp.InvalidatedCoords.Add(tile); {
AddActiveTile(gridEnt.Comp1, atmosTile);
InvalidateVisuals((gridEnt.Owner, gridEnt.Comp2), tile);
}
} }
} }
@@ -146,15 +155,22 @@ public partial class AtmosphereSystem
return GetTileMixture(entity.Comp.GridUid, entity.Comp.MapUid, indices, excite); return GetTileMixture(entity.Comp.GridUid, entity.Comp.MapUid, indices, excite);
} }
public GasMixture? GetTileMixture(Entity<GridAtmosphereComponent?>? grid, Entity<MapAtmosphereComponent?>? map, Vector2i gridTile, bool excite = false) public GasMixture? GetTileMixture(
Entity<GridAtmosphereComponent?, GasTileOverlayComponent?>? grid,
Entity<MapAtmosphereComponent?>? map,
Vector2i gridTile,
bool excite = false)
{ {
// If we've been passed a grid, try to let it handle it. // If we've been passed a grid, try to let it handle it.
if (grid is {} gridEnt if (grid is {} gridEnt
&& Resolve(gridEnt, ref gridEnt.Comp, false) && Resolve(gridEnt, ref gridEnt.Comp1, false)
&& gridEnt.Comp.Tiles.TryGetValue(gridTile, out var tile)) && gridEnt.Comp1.Tiles.TryGetValue(gridTile, out var tile))
{ {
if (excite) if (excite)
gridEnt.Comp.InvalidatedCoords.Add(gridTile); {
AddActiveTile(gridEnt.Comp1, tile);
InvalidateVisuals((grid.Value.Owner, grid.Value.Comp2), gridTile);
}
return tile.Air; return tile.Air;
} }

View File

@@ -1,5 +1,7 @@
using Content.Server.Atmos.Components; using Content.Server.Atmos.Components;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Atmos.Components;
using Robust.Shared.Map.Components;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Server.Atmos.EntitySystems namespace Content.Server.Atmos.EntitySystems
@@ -64,10 +66,12 @@ namespace Content.Server.Atmos.EntitySystems
excitedGroup.DismantleCooldown = 0; excitedGroup.DismantleCooldown = 0;
} }
private void ExcitedGroupSelfBreakdown(GridAtmosphereComponent gridAtmosphere, ExcitedGroup excitedGroup) private void ExcitedGroupSelfBreakdown(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
ExcitedGroup excitedGroup)
{ {
DebugTools.Assert(!excitedGroup.Disposed, "Excited group is disposed!"); DebugTools.Assert(!excitedGroup.Disposed, "Excited group is disposed!");
DebugTools.Assert(gridAtmosphere.ExcitedGroups.Contains(excitedGroup), "Grid Atmosphere does not contain Excited Group!"); DebugTools.Assert(ent.Comp1.ExcitedGroups.Contains(excitedGroup), "Grid Atmosphere does not contain Excited Group!");
var combined = new GasMixture(Atmospherics.CellVolume); var combined = new GasMixture(Atmospherics.CellVolume);
var tileSize = excitedGroup.Tiles.Count; var tileSize = excitedGroup.Tiles.Count;
@@ -77,7 +81,7 @@ namespace Content.Server.Atmos.EntitySystems
if (tileSize == 0) if (tileSize == 0)
{ {
ExcitedGroupDispose(gridAtmosphere, excitedGroup); ExcitedGroupDispose(ent.Comp1, excitedGroup);
return; return;
} }
@@ -103,7 +107,7 @@ namespace Content.Server.Atmos.EntitySystems
continue; continue;
tile.Air.CopyFromMutable(combined); tile.Air.CopyFromMutable(combined);
InvalidateVisuals(tile.GridIndex, tile.GridIndices); InvalidateVisuals(ent, tile);
} }
excitedGroup.BreakdownCooldown = 0; excitedGroup.BreakdownCooldown = 0;

View File

@@ -1,4 +1,3 @@
using System.Linq;
using Content.Server.Atmos.Components; using Content.Server.Atmos.Components;
using Content.Server.Atmos.Reactions; using Content.Server.Atmos.Reactions;
using Content.Shared.Atmos; using Content.Shared.Atmos;
@@ -160,7 +159,7 @@ public sealed partial class AtmosphereSystem
} }
/// <summary> /// <summary>
/// Update array of adjacent tiles and the adjacency flags. Optionally activates all tiles with modified adjacencies. /// Update array of adjacent tiles and the adjacency flags.
/// </summary> /// </summary>
private void UpdateAdjacentTiles( private void UpdateAdjacentTiles(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent, Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
@@ -195,14 +194,16 @@ public sealed partial class AtmosphereSystem
if (activate) if (activate)
AddActiveTile(atmos, adjacent); AddActiveTile(atmos, adjacent);
var oppositeDirection = direction.GetOpposite(); var oppositeIndex = i.ToOppositeIndex();
var oppositeDirection = (AtmosDirection) (1 << oppositeIndex);
if (adjBlockDirs.IsFlagSet(oppositeDirection) || blockedDirs.IsFlagSet(direction)) if (adjBlockDirs.IsFlagSet(oppositeDirection) || blockedDirs.IsFlagSet(direction))
{ {
// Adjacency is blocked by some airtight entity. // Adjacency is blocked by some airtight entity.
tile.AdjacentBits &= ~direction; tile.AdjacentBits &= ~direction;
adjacent.AdjacentBits &= ~oppositeDirection; adjacent.AdjacentBits &= ~oppositeDirection;
tile.AdjacentTiles[i] = null; tile.AdjacentTiles[i] = null;
adjacent.AdjacentTiles[oppositeDirection.ToIndex()] = null; adjacent.AdjacentTiles[oppositeIndex] = null;
} }
else else
{ {
@@ -210,7 +211,7 @@ public sealed partial class AtmosphereSystem
tile.AdjacentBits |= direction; tile.AdjacentBits |= direction;
adjacent.AdjacentBits |= oppositeDirection; adjacent.AdjacentBits |= oppositeDirection;
tile.AdjacentTiles[i] = adjacent; tile.AdjacentTiles[i] = adjacent;
adjacent.AdjacentTiles[oppositeDirection.ToIndex()] = tile; adjacent.AdjacentTiles[oppositeIndex] = tile;
} }
DebugTools.Assert(!(tile.AdjacentBits.IsFlagSet(direction) ^ DebugTools.Assert(!(tile.AdjacentBits.IsFlagSet(direction) ^

View File

@@ -1,10 +1,12 @@
using Content.Server.Atmos.Components; using Content.Server.Atmos.Components;
using Content.Server.Atmos.Reactions; using Content.Server.Atmos.Reactions;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Atmos.Components;
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.Database; using Content.Shared.Database;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Player; using Robust.Shared.Player;
namespace Content.Server.Atmos.EntitySystems namespace Content.Server.Atmos.EntitySystems
@@ -18,18 +20,18 @@ namespace Content.Server.Atmos.EntitySystems
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public string? HotspotSound { get; private set; } = "/Audio/Effects/fire.ogg"; public string? HotspotSound { get; private set; } = "/Audio/Effects/fire.ogg";
private void ProcessHotspot(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile) private void ProcessHotspot(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
TileAtmosphere tile)
{ {
var gridAtmosphere = ent.Comp1;
if (!tile.Hotspot.Valid) if (!tile.Hotspot.Valid)
{ {
gridAtmosphere.HotspotTiles.Remove(tile); gridAtmosphere.HotspotTiles.Remove(tile);
return; return;
} }
if (!tile.Excited)
{
AddActiveTile(gridAtmosphere, tile); AddActiveTile(gridAtmosphere, tile);
}
if (!tile.Hotspot.SkippedFirstProcess) if (!tile.Hotspot.SkippedFirstProcess)
{ {
@@ -44,7 +46,7 @@ namespace Content.Server.Atmos.EntitySystems
|| 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.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.Hotspot = new Hotspot();
InvalidateVisuals(tile.GridIndex, tile.GridIndices); InvalidateVisuals(ent, tile);
return; return;
} }

View File

@@ -1,14 +1,18 @@
using Content.Server.Atmos.Components; using Content.Server.Atmos.Components;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Atmos.Components; using Content.Shared.Atmos.Components;
using Robust.Shared.Map.Components;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Server.Atmos.EntitySystems namespace Content.Server.Atmos.EntitySystems
{ {
public sealed partial class AtmosphereSystem public sealed partial class AtmosphereSystem
{ {
private void ProcessCell(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, int fireCount, GasTileOverlayComponent visuals) private void ProcessCell(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
TileAtmosphere tile, int fireCount)
{ {
var gridAtmosphere = ent.Comp1;
// Can't process a tile without air // Can't process a tile without air
if (tile.Air == null) if (tile.Air == null)
{ {
@@ -51,12 +55,8 @@ namespace Content.Server.Atmos.EntitySystems
shouldShareAir = true; shouldShareAir = true;
} else if (CompareExchange(tile.Air, enemyTile.Air) != GasCompareResult.NoExchange) } else if (CompareExchange(tile.Air, enemyTile.Air) != GasCompareResult.NoExchange)
{
if (!enemyTile.Excited)
{ {
AddActiveTile(gridAtmosphere, enemyTile); AddActiveTile(gridAtmosphere, enemyTile);
}
if (ExcitedGroups) if (ExcitedGroups)
{ {
var excitedGroup = tile.ExcitedGroup; var excitedGroup = tile.ExcitedGroup;
@@ -91,7 +91,7 @@ namespace Content.Server.Atmos.EntitySystems
} }
else else
{ {
ConsiderPressureDifference(gridAtmosphere, enemyTile, direction.GetOpposite(), -difference); ConsiderPressureDifference(gridAtmosphere, enemyTile, i.ToOppositeDir(), -difference);
} }
} }
@@ -102,7 +102,7 @@ namespace Content.Server.Atmos.EntitySystems
if(tile.Air != null) if(tile.Air != null)
React(tile.Air, tile); React(tile.Air, tile);
InvalidateVisuals(tile.GridIndex, tile.GridIndices, visuals); InvalidateVisuals(ent, tile);
var remove = true; var remove = true;
@@ -146,7 +146,7 @@ namespace Content.Server.Atmos.EntitySystems
/// <param name="tile">Tile Atmosphere to be activated.</param> /// <param name="tile">Tile Atmosphere to be activated.</param>
private void AddActiveTile(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile) private void AddActiveTile(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile)
{ {
if (tile.Air == null) if (tile.Air == null || tile.Excited)
return; return;
tile.Excited = true; tile.Excited = true;

View File

@@ -230,7 +230,7 @@ namespace Content.Server.Atmos.EntitySystems
if (otherTile2.MonstermosInfo.LastSlowQueueCycle == queueCycleSlow) continue; if (otherTile2.MonstermosInfo.LastSlowQueueCycle == queueCycleSlow) continue;
_equalizeQueue[queueLength++] = otherTile2; _equalizeQueue[queueLength++] = otherTile2;
otherTile2.MonstermosInfo.LastSlowQueueCycle = queueCycleSlow; otherTile2.MonstermosInfo.LastSlowQueueCycle = queueCycleSlow;
otherTile2.MonstermosInfo.CurrentTransferDirection = direction.GetOpposite(); otherTile2.MonstermosInfo.CurrentTransferDirection = k.ToOppositeDir();
otherTile2.MonstermosInfo.CurrentTransferAmount = 0; otherTile2.MonstermosInfo.CurrentTransferAmount = 0;
if (otherTile2.MonstermosInfo.MoleDelta < 0) if (otherTile2.MonstermosInfo.MoleDelta < 0)
{ {
@@ -296,7 +296,7 @@ namespace Content.Server.Atmos.EntitySystems
if (otherTile2.MonstermosInfo.LastSlowQueueCycle == queueCycleSlow) continue; if (otherTile2.MonstermosInfo.LastSlowQueueCycle == queueCycleSlow) continue;
_equalizeQueue[queueLength++] = otherTile2; _equalizeQueue[queueLength++] = otherTile2;
otherTile2.MonstermosInfo.LastSlowQueueCycle = queueCycleSlow; otherTile2.MonstermosInfo.LastSlowQueueCycle = queueCycleSlow;
otherTile2.MonstermosInfo.CurrentTransferDirection = direction.GetOpposite(); otherTile2.MonstermosInfo.CurrentTransferDirection = k.ToOppositeDir();
otherTile2.MonstermosInfo.CurrentTransferAmount = 0; otherTile2.MonstermosInfo.CurrentTransferAmount = 0;
if (otherTile2.MonstermosInfo.MoleDelta > 0) if (otherTile2.MonstermosInfo.MoleDelta > 0)
@@ -338,7 +338,7 @@ namespace Content.Server.Atmos.EntitySystems
for (var i = 0; i < tileCount; i++) for (var i = 0; i < tileCount; i++)
{ {
var otherTile = _equalizeTiles[i]!; var otherTile = _equalizeTiles[i]!;
FinalizeEq(gridAtmosphere, otherTile, ent); FinalizeEq(ent, otherTile);
} }
for (var i = 0; i < tileCount; i++) for (var i = 0; i < tileCount; i++)
@@ -473,7 +473,7 @@ namespace Content.Server.Atmos.EntitySystems
if(tile2.Space) if(tile2.Space)
continue; continue;
tile2.MonstermosInfo.CurrentTransferDirection = direction.GetOpposite(); tile2.MonstermosInfo.CurrentTransferDirection = j.ToOppositeDir();
tile2.MonstermosInfo.CurrentTransferAmount = 0.0f; tile2.MonstermosInfo.CurrentTransferAmount = 0.0f;
tile2.PressureSpecificTarget = otherTile.PressureSpecificTarget; tile2.PressureSpecificTarget = otherTile.PressureSpecificTarget;
tile2.MonstermosInfo.LastSlowQueueCycle = queueCycleSlow; tile2.MonstermosInfo.LastSlowQueueCycle = queueCycleSlow;
@@ -549,7 +549,7 @@ namespace Content.Server.Atmos.EntitySystems
otherTile.Air.Temperature = Atmospherics.TCMB; otherTile.Air.Temperature = Atmospherics.TCMB;
} }
InvalidateVisuals(otherTile.GridIndex, otherTile.GridIndices, visuals); InvalidateVisuals(ent, otherTile);
HandleDecompressionFloorRip(mapGrid, otherTile, otherTile.MonstermosInfo.CurrentTransferAmount); HandleDecompressionFloorRip(mapGrid, otherTile, otherTile.MonstermosInfo.CurrentTransferAmount);
} }
@@ -598,11 +598,13 @@ namespace Content.Server.Atmos.EntitySystems
UpdateAdjacentTiles(ent, tile); UpdateAdjacentTiles(ent, tile);
UpdateAdjacentTiles(ent, other); UpdateAdjacentTiles(ent, other);
InvalidateVisuals(tile.GridIndex, tile.GridIndices, ent); InvalidateVisuals(ent, tile);
InvalidateVisuals(other.GridIndex, other.GridIndices, ent); InvalidateVisuals(ent, other);
} }
private void FinalizeEq(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, GasTileOverlayComponent? visuals) private void FinalizeEq(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
TileAtmosphere tile)
{ {
Span<float> transferDirections = stackalloc float[Atmospherics.Directions]; Span<float> transferDirections = stackalloc float[Atmospherics.Directions];
var hasTransferDirs = false; var hasTransferDirs = false;
@@ -629,17 +631,19 @@ namespace Content.Server.Atmos.EntitySystems
// Everything that calls this method already ensures that Air will not be null. // Everything that calls this method already ensures that Air will not be null.
if (tile.Air!.TotalMoles < amount) if (tile.Air!.TotalMoles < amount)
FinalizeEqNeighbors(gridAtmosphere, tile, transferDirections, visuals); FinalizeEqNeighbors(ent, tile, transferDirections);
otherTile.MonstermosInfo[direction.GetOpposite()] = 0; otherTile.MonstermosInfo[i.ToOppositeDir()] = 0;
Merge(otherTile.Air, tile.Air.Remove(amount)); Merge(otherTile.Air, tile.Air.Remove(amount));
InvalidateVisuals(tile.GridIndex, tile.GridIndices, visuals); InvalidateVisuals(ent, tile);
InvalidateVisuals(otherTile.GridIndex, otherTile.GridIndices, visuals); InvalidateVisuals(ent, otherTile);
ConsiderPressureDifference(gridAtmosphere, tile, direction, amount); ConsiderPressureDifference(ent, tile, direction, amount);
} }
} }
private void FinalizeEqNeighbors(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile, ReadOnlySpan<float> transferDirs, GasTileOverlayComponent? visuals) private void FinalizeEqNeighbors(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
TileAtmosphere tile, ReadOnlySpan<float> transferDirs)
{ {
for (var i = 0; i < Atmospherics.Directions; i++) for (var i = 0; i < Atmospherics.Directions; i++)
{ {
@@ -647,7 +651,7 @@ namespace Content.Server.Atmos.EntitySystems
var amount = transferDirs[i]; var amount = transferDirs[i];
// Since AdjacentBits is set, AdjacentTiles[i] wouldn't be null, and neither would its air. // Since AdjacentBits is set, AdjacentTiles[i] wouldn't be null, and neither would its air.
if(amount < 0 && tile.AdjacentBits.IsFlagSet(direction)) if(amount < 0 && tile.AdjacentBits.IsFlagSet(direction))
FinalizeEq(gridAtmosphere, tile.AdjacentTiles[i]!, visuals); // A bit of recursion if needed. FinalizeEq(ent, tile.AdjacentTiles[i]!); // A bit of recursion if needed.
} }
} }
@@ -664,7 +668,9 @@ namespace Content.Server.Atmos.EntitySystems
Log.Error($"Encountered null-tile in {nameof(AdjustEqMovement)}. Trace: {Environment.StackTrace}"); Log.Error($"Encountered null-tile in {nameof(AdjustEqMovement)}. Trace: {Environment.StackTrace}");
return; return;
} }
var adj = tile.AdjacentTiles[direction.ToIndex()];
var idx = direction.ToIndex();
var adj = tile.AdjacentTiles[idx];
if (adj == null) if (adj == null)
{ {
var nonNull = tile.AdjacentTiles.Where(x => x != null).Count(); var nonNull = tile.AdjacentTiles.Where(x => x != null).Count();
@@ -673,7 +679,7 @@ namespace Content.Server.Atmos.EntitySystems
} }
tile.MonstermosInfo[direction] += amount; tile.MonstermosInfo[direction] += amount;
adj.MonstermosInfo[direction.GetOpposite()] -= amount; adj.MonstermosInfo[idx.ToOppositeDir()] -= amount;
} }
private void HandleDecompressionFloorRip(MapGridComponent mapGrid, TileAtmosphere tile, float sum) private void HandleDecompressionFloorRip(MapGridComponent mapGrid, TileAtmosphere tile, float sum)

View File

@@ -86,7 +86,7 @@ namespace Content.Server.Atmos.EntitySystems
DebugTools.Assert(atmosphere.Tiles.GetValueOrDefault(tile.GridIndices) == tile); DebugTools.Assert(atmosphere.Tiles.GetValueOrDefault(tile.GridIndices) == tile);
UpdateAdjacentTiles(ent, tile, activate: true); UpdateAdjacentTiles(ent, tile, activate: true);
UpdateTileAir(ent, tile, volume); UpdateTileAir(ent, tile, volume);
InvalidateVisuals(uid, tile.GridIndices, visuals); InvalidateVisuals(ent, tile);
if (number++ < InvalidCoordinatesLagCheckIterations) if (number++ < InvalidCoordinatesLagCheckIterations)
continue; continue;
@@ -313,15 +313,17 @@ namespace Content.Server.Atmos.EntitySystems
return true; return true;
} }
private bool ProcessActiveTiles(GridAtmosphereComponent atmosphere, GasTileOverlayComponent visuals) private bool ProcessActiveTiles(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent)
{ {
var atmosphere = ent.Comp1;
if(!atmosphere.ProcessingPaused) if(!atmosphere.ProcessingPaused)
QueueRunTiles(atmosphere.CurrentRunTiles, atmosphere.ActiveTiles); QueueRunTiles(atmosphere.CurrentRunTiles, atmosphere.ActiveTiles);
var number = 0; var number = 0;
while (atmosphere.CurrentRunTiles.TryDequeue(out var tile)) while (atmosphere.CurrentRunTiles.TryDequeue(out var tile))
{ {
ProcessCell(atmosphere, tile, atmosphere.UpdateCounter, visuals); ProcessCell(ent, tile, atmosphere.UpdateCounter);
if (number++ < LagCheckIterations) if (number++ < LagCheckIterations)
continue; continue;
@@ -337,8 +339,10 @@ namespace Content.Server.Atmos.EntitySystems
return true; return true;
} }
private bool ProcessExcitedGroups(GridAtmosphereComponent gridAtmosphere) private bool ProcessExcitedGroups(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent)
{ {
var gridAtmosphere = ent.Comp1;
if (!gridAtmosphere.ProcessingPaused) if (!gridAtmosphere.ProcessingPaused)
{ {
gridAtmosphere.CurrentRunExcitedGroups.Clear(); gridAtmosphere.CurrentRunExcitedGroups.Clear();
@@ -356,7 +360,7 @@ namespace Content.Server.Atmos.EntitySystems
excitedGroup.DismantleCooldown++; excitedGroup.DismantleCooldown++;
if (excitedGroup.BreakdownCooldown > Atmospherics.ExcitedGroupBreakdownCycles) if (excitedGroup.BreakdownCooldown > Atmospherics.ExcitedGroupBreakdownCycles)
ExcitedGroupSelfBreakdown(gridAtmosphere, excitedGroup); ExcitedGroupSelfBreakdown(ent, excitedGroup);
else if (excitedGroup.DismantleCooldown > Atmospherics.ExcitedGroupsDismantleCycles) else if (excitedGroup.DismantleCooldown > Atmospherics.ExcitedGroupsDismantleCycles)
DeactivateGroupTiles(gridAtmosphere, excitedGroup); DeactivateGroupTiles(gridAtmosphere, excitedGroup);
// TODO ATMOS. What is the point of this? why is this only de-exciting the group? Shouldn't it also dismantle it? // TODO ATMOS. What is the point of this? why is this only de-exciting the group? Shouldn't it also dismantle it?
@@ -411,15 +415,17 @@ namespace Content.Server.Atmos.EntitySystems
return true; return true;
} }
private bool ProcessHotspots(GridAtmosphereComponent atmosphere) private bool ProcessHotspots(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent)
{ {
var atmosphere = ent.Comp1;
if(!atmosphere.ProcessingPaused) if(!atmosphere.ProcessingPaused)
QueueRunTiles(atmosphere.CurrentRunTiles, atmosphere.HotspotTiles); QueueRunTiles(atmosphere.CurrentRunTiles, atmosphere.HotspotTiles);
var number = 0; var number = 0;
while (atmosphere.CurrentRunTiles.TryDequeue(out var hotspot)) while (atmosphere.CurrentRunTiles.TryDequeue(out var hotspot))
{ {
ProcessHotspot(atmosphere, hotspot); ProcessHotspot(ent, hotspot);
if (number++ < LagCheckIterations) if (number++ < LagCheckIterations)
continue; continue;
@@ -507,8 +513,11 @@ namespace Content.Server.Atmos.EntitySystems
return num * AtmosTime; return num * AtmosTime;
} }
private bool ProcessAtmosDevices(GridAtmosphereComponent atmosphere) private bool ProcessAtmosDevices(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
Entity<MapAtmosphereComponent?> map)
{ {
var atmosphere = ent.Comp1;
if (!atmosphere.ProcessingPaused) if (!atmosphere.ProcessingPaused)
{ {
atmosphere.CurrentRunAtmosDevices.Clear(); atmosphere.CurrentRunAtmosDevices.Clear();
@@ -521,7 +530,7 @@ namespace Content.Server.Atmos.EntitySystems
var time = _gameTiming.CurTime; var time = _gameTiming.CurTime;
var number = 0; var number = 0;
var ev = new AtmosDeviceUpdateEvent(RealAtmosTime()); var ev = new AtmosDeviceUpdateEvent(RealAtmosTime(), (ent, ent.Comp1, ent.Comp2), map);
while (atmosphere.CurrentRunAtmosDevices.TryDequeue(out var device)) while (atmosphere.CurrentRunAtmosDevices.TryDequeue(out var device))
{ {
RaiseLocalEvent(device, ref ev); RaiseLocalEvent(device, ref ev);
@@ -565,12 +574,11 @@ namespace Content.Server.Atmos.EntitySystems
var ent = _currentRunAtmosphere[_currentRunAtmosphereIndex]; var ent = _currentRunAtmosphere[_currentRunAtmosphereIndex];
var (owner, atmosphere, visuals, grid, xform) = ent; var (owner, atmosphere, visuals, grid, xform) = ent;
if (!TryComp(owner, out TransformComponent? x) if (xform.MapUid == null
|| x.MapUid == null || TerminatingOrDeleted(xform.MapUid.Value)
|| TerminatingOrDeleted(x.MapUid.Value) || xform.MapID == MapId.Nullspace)
|| x.MapID == MapId.Nullspace)
{ {
Log.Error($"Attempted to process atmos without a map? Entity: {ToPrettyString(owner)}. Map: {ToPrettyString(x?.MapUid)}. MapId: {x?.MapID}"); Log.Error($"Attempted to process atmos without a map? Entity: {ToPrettyString(owner)}. Map: {ToPrettyString(xform?.MapUid)}. MapId: {xform?.MapID}");
continue; continue;
} }
@@ -585,6 +593,8 @@ namespace Content.Server.Atmos.EntitySystems
// We subtract it so it takes lost time into account. // We subtract it so it takes lost time into account.
atmosphere.Timer -= AtmosTime; atmosphere.Timer -= AtmosTime;
var map = new Entity<MapAtmosphereComponent?>(xform.MapUid.Value, _mapAtmosQuery.CompOrNull(xform.MapUid.Value));
switch (atmosphere.State) switch (atmosphere.State)
{ {
case AtmosphereProcessingState.Revalidate: case AtmosphereProcessingState.Revalidate:
@@ -614,7 +624,7 @@ namespace Content.Server.Atmos.EntitySystems
atmosphere.State = AtmosphereProcessingState.ActiveTiles; atmosphere.State = AtmosphereProcessingState.ActiveTiles;
continue; continue;
case AtmosphereProcessingState.ActiveTiles: case AtmosphereProcessingState.ActiveTiles:
if (!ProcessActiveTiles(ent, ent)) if (!ProcessActiveTiles(ent))
{ {
atmosphere.ProcessingPaused = true; atmosphere.ProcessingPaused = true;
return; return;
@@ -625,7 +635,7 @@ namespace Content.Server.Atmos.EntitySystems
atmosphere.State = ExcitedGroups ? AtmosphereProcessingState.ExcitedGroups : AtmosphereProcessingState.HighPressureDelta; atmosphere.State = ExcitedGroups ? AtmosphereProcessingState.ExcitedGroups : AtmosphereProcessingState.HighPressureDelta;
continue; continue;
case AtmosphereProcessingState.ExcitedGroups: case AtmosphereProcessingState.ExcitedGroups:
if (!ProcessExcitedGroups(atmosphere)) if (!ProcessExcitedGroups(ent))
{ {
atmosphere.ProcessingPaused = true; atmosphere.ProcessingPaused = true;
return; return;
@@ -645,7 +655,7 @@ namespace Content.Server.Atmos.EntitySystems
atmosphere.State = AtmosphereProcessingState.Hotspots; atmosphere.State = AtmosphereProcessingState.Hotspots;
continue; continue;
case AtmosphereProcessingState.Hotspots: case AtmosphereProcessingState.Hotspots:
if (!ProcessHotspots(atmosphere)) if (!ProcessHotspots(ent))
{ {
atmosphere.ProcessingPaused = true; atmosphere.ProcessingPaused = true;
return; return;
@@ -680,7 +690,7 @@ namespace Content.Server.Atmos.EntitySystems
atmosphere.State = AtmosphereProcessingState.AtmosDevices; atmosphere.State = AtmosphereProcessingState.AtmosDevices;
continue; continue;
case AtmosphereProcessingState.AtmosDevices: case AtmosphereProcessingState.AtmosDevices:
if (!ProcessAtmosDevices(atmosphere)) if (!ProcessAtmosDevices(ent, map))
{ {
atmosphere.ProcessingPaused = true; atmosphere.ProcessingPaused = true;
return; return;

View File

@@ -16,7 +16,7 @@ namespace Content.Server.Atmos.EntitySystems
if (!directions.IsFlagSet(direction)) if (!directions.IsFlagSet(direction))
continue; continue;
var adjacent = tile.AdjacentTiles[direction.ToIndex()]; var adjacent = tile.AdjacentTiles[i];
// TODO ATMOS handle adjacent being null. // TODO ATMOS handle adjacent being null.
if (adjacent == null || adjacent.ThermalConductivity == 0f) if (adjacent == null || adjacent.ThermalConductivity == 0f)

View File

@@ -36,9 +36,17 @@ public partial class AtmosphereSystem
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void InvalidateVisuals(EntityUid gridUid, Vector2i tile, GasTileOverlayComponent? comp = null) public void InvalidateVisuals(Entity<GasTileOverlayComponent?> grid, Vector2i tile)
{ {
_gasTileOverlaySystem.Invalidate(gridUid, tile, comp); _gasTileOverlaySystem.Invalidate(grid, tile);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void InvalidateVisuals(
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
TileAtmosphere tile)
{
_gasTileOverlaySystem.Invalidate((ent.Owner, ent.Comp2), tile.GridIndices);
} }
/// <summary> /// <summary>

View File

@@ -96,7 +96,7 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
var query = EntityQueryEnumerator<AtmosExposedComponent, TransformComponent>(); var query = EntityQueryEnumerator<AtmosExposedComponent, TransformComponent>();
while (query.MoveNext(out var uid, out _, out var transform)) while (query.MoveNext(out var uid, out _, out var transform))
{ {
var air = GetContainingMixture(uid, transform:transform); var air = GetContainingMixture((uid, transform));
if (air == null) if (air == null)
continue; continue;

View File

@@ -168,7 +168,7 @@ namespace Content.Server.Atmos.EntitySystems
private void ReleaseGas(Entity<GasTankComponent> gasTank) private void ReleaseGas(Entity<GasTankComponent> gasTank)
{ {
var removed = RemoveAirVolume(gasTank, gasTank.Comp.ValveOutputRate * TimerDelay); var removed = RemoveAirVolume(gasTank, gasTank.Comp.ValveOutputRate * TimerDelay);
var environment = _atmosphereSystem.GetContainingMixture(gasTank, false, true); var environment = _atmosphereSystem.GetContainingMixture(gasTank.Owner, false, true);
if (environment != null) if (environment != null)
{ {
_atmosphereSystem.Merge(environment, removed); _atmosphereSystem.Merge(environment, removed);

View File

@@ -60,6 +60,7 @@ namespace Content.Server.Atmos.EntitySystems
private float _updateInterval; private float _updateInterval;
private int _thresholds; private int _thresholds;
private EntityQuery<GasTileOverlayComponent> _query;
public override void Initialize() public override void Initialize()
{ {
@@ -84,6 +85,7 @@ namespace Content.Server.Atmos.EntitySystems
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset); SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
SubscribeLocalEvent<GasTileOverlayComponent, ComponentStartup>(OnStartup); SubscribeLocalEvent<GasTileOverlayComponent, ComponentStartup>(OnStartup);
_query = GetEntityQuery<GasTileOverlayComponent>();
} }
private void OnStartup(EntityUid uid, GasTileOverlayComponent component, ComponentStartup args) private void OnStartup(EntityUid uid, GasTileOverlayComponent component, ComponentStartup args)
@@ -132,10 +134,10 @@ namespace Content.Server.Atmos.EntitySystems
private void UpdateThresholds(int value) => _thresholds = value; private void UpdateThresholds(int value) => _thresholds = value;
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Invalidate(EntityUid grid, Vector2i index, GasTileOverlayComponent? comp = null) public void Invalidate(Entity<GasTileOverlayComponent?> grid, Vector2i index)
{ {
if (Resolve(grid, ref comp)) if (_query.Resolve(grid.Owner, ref grid.Comp))
comp.InvalidTiles.Add(index); grid.Comp.InvalidTiles.Add(index);
} }
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e) private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)

View File

@@ -40,24 +40,16 @@ public sealed class HeatExchangerSystem : EntitySystem
private void OnAtmosUpdate(EntityUid uid, HeatExchangerComponent comp, ref AtmosDeviceUpdateEvent args) private void OnAtmosUpdate(EntityUid uid, HeatExchangerComponent comp, ref AtmosDeviceUpdateEvent args)
{ {
if (!TryComp(uid, out NodeContainerComponent? nodeContainer) // make sure that the tile the device is on isn't blocked by a wall or something similar.
|| !TryComp(uid, out AtmosDeviceComponent? device) if (args.Grid is {} grid
|| !_nodeContainer.TryGetNode(nodeContainer, comp.InletName, out PipeNode? inlet) && _transform.TryGetGridTilePosition(uid, out var tile)
|| !_nodeContainer.TryGetNode(nodeContainer, comp.OutletName, out PipeNode? outlet)) && _atmosphereSystem.IsTileAirBlocked(grid, tile))
{ {
return; return;
} }
// make sure that the tile the device is on isn't blocked by a wall or something similar. if (!_nodeContainer.TryGetNodes(uid, comp.InletName, comp.OutletName, out PipeNode? inlet, out PipeNode? outlet))
var xform = Transform(uid);
if (_transform.TryGetGridTilePosition(uid, out var tile))
{
// TryGetGridTilePosition() already returns false if GridUid is null, but the null checker isn't smart enough yet
if (xform.GridUid != null && _atmosphereSystem.IsTileAirBlocked(xform.GridUid.Value, tile))
{
return; return;
}
}
var dt = args.dt; var dt = args.dt;

View File

@@ -204,11 +204,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
if (!this.IsPowered(uid, EntityManager)) if (!this.IsPowered(uid, EntityManager))
return; return;
// can't hurt if (args.Grid == null)
// (in case something is making AtmosDeviceUpdateEvents
// outside the typical device loop)
if (!TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent)
|| atmosDeviceComponent.JoinedGrid == null)
return; return;
// if we're not monitoring atmos, don't bother // if we're not monitoring atmos, don't bother

View File

@@ -26,11 +26,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
private void OnPassiveGateUpdated(EntityUid uid, GasPassiveGateComponent gate, ref AtmosDeviceUpdateEvent args) private void OnPassiveGateUpdated(EntityUid uid, GasPassiveGateComponent gate, ref AtmosDeviceUpdateEvent args)
{ {
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)) if (!_nodeContainer.TryGetNodes(uid, gate.InletName, gate.OutletName, out PipeNode? inlet, out PipeNode? outlet))
return;
if (!_nodeContainer.TryGetNode(nodeContainer, gate.InletName, out PipeNode? inlet)
|| !_nodeContainer.TryGetNode(nodeContainer, gate.OutletName, out PipeNode? outlet))
return; return;
var n1 = inlet.Air.TotalMoles; var n1 = inlet.Air.TotalMoles;

View File

@@ -66,9 +66,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, ref AtmosDeviceUpdateEvent args) private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, ref AtmosDeviceUpdateEvent args)
{ {
if (!pump.Enabled if (!pump.Enabled
|| !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) || !_nodeContainer.TryGetNodes(uid, pump.InletName, pump.OutletName, out PipeNode? inlet, out PipeNode? outlet))
|| !_nodeContainer.TryGetNode(nodeContainer, pump.InletName, out PipeNode? inlet)
|| !_nodeContainer.TryGetNode(nodeContainer, pump.OutletName, out PipeNode? outlet))
{ {
_ambientSoundSystem.SetAmbience(uid, false); _ambientSoundSystem.SetAmbience(uid, false);
return; return;

View File

@@ -41,12 +41,8 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
if (!EntityManager.GetComponent<TransformComponent>(ent).Anchored || !args.IsInDetailsRange) // Not anchored? Out of range? No status. if (!EntityManager.GetComponent<TransformComponent>(ent).Anchored || !args.IsInDetailsRange) // Not anchored? Out of range? No status.
return; return;
if (!EntityManager.TryGetComponent(ent, out NodeContainerComponent? nodeContainer) if (!_nodeContainer.TryGetNode(ent.Owner, comp.InletName, out PipeNode? inlet))
|| !_nodeContainer.TryGetNode(nodeContainer, comp.InletName, out PipeNode? inlet)
|| !_nodeContainer.TryGetNode(nodeContainer, comp.OutletName, out PipeNode? _))
{
return; return;
}
using (args.PushGroup(nameof(GasRecyclerComponent))) using (args.PushGroup(nameof(GasRecyclerComponent)))
{ {
@@ -72,9 +68,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
private void OnUpdate(Entity<GasRecyclerComponent> ent, ref AtmosDeviceUpdateEvent args) private void OnUpdate(Entity<GasRecyclerComponent> ent, ref AtmosDeviceUpdateEvent args)
{ {
var comp = ent.Comp; var comp = ent.Comp;
if (!EntityManager.TryGetComponent(ent, out NodeContainerComponent? nodeContainer) if (!_nodeContainer.TryGetNodes(ent.Owner, comp.InletName, comp.OutletName, out PipeNode? inlet, out PipeNode? outlet))
|| !_nodeContainer.TryGetNode(nodeContainer, comp.InletName, out PipeNode? inlet)
|| !_nodeContainer.TryGetNode(nodeContainer, comp.OutletName, out PipeNode? outlet))
{ {
_ambientSoundSystem.SetAmbience(ent, false); _ambientSoundSystem.SetAmbience(ent, false);
return; return;

View File

@@ -59,9 +59,8 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
public void Set(EntityUid uid, GasValveComponent component, bool value) public void Set(EntityUid uid, GasValveComponent component, bool value)
{ {
component.Open = value; component.Open = value;
if (TryComp(uid, out NodeContainerComponent? nodeContainer)
&& _nodeContainer.TryGetNode(nodeContainer, component.InletName, out PipeNode? inlet) if (_nodeContainer.TryGetNodes(uid, component.InletName, component.OutletName, out PipeNode? inlet, out PipeNode? outlet))
&& _nodeContainer.TryGetNode(nodeContainer, component.OutletName, out PipeNode? outlet))
{ {
if (TryComp<AppearanceComponent>(uid, out var appearance)) if (TryComp<AppearanceComponent>(uid, out var appearance))
{ {

View File

@@ -71,11 +71,8 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
private void OnVolumePumpUpdated(EntityUid uid, GasVolumePumpComponent pump, ref AtmosDeviceUpdateEvent args) private void OnVolumePumpUpdated(EntityUid uid, GasVolumePumpComponent pump, ref AtmosDeviceUpdateEvent args)
{ {
if (!pump.Enabled if (!pump.Enabled ||
|| !TryComp(uid, out NodeContainerComponent? nodeContainer) !_nodeContainer.TryGetNodes(uid, pump.InletName, pump.OutletName, out PipeNode? inlet, out PipeNode? outlet))
|| !TryComp(uid, out AtmosDeviceComponent? device)
|| !_nodeContainer.TryGetNode(nodeContainer, pump.InletName, out PipeNode? inlet)
|| !_nodeContainer.TryGetNode(nodeContainer, pump.OutletName, out PipeNode? outlet))
{ {
_ambientSoundSystem.SetAmbience(uid, false); _ambientSoundSystem.SetAmbience(uid, false);
return; return;

View File

@@ -1,4 +1,5 @@
using Content.Server.Atmos.Components; using Content.Server.Atmos.Components;
using Content.Shared.Atmos.Components;
namespace Content.Server.Atmos.Piping.Components; namespace Content.Server.Atmos.Piping.Components;
@@ -46,18 +47,25 @@ public sealed partial class AtmosDeviceComponent : Component
/// Use this for atmos devices instead of <see cref="EntitySystem.Update"/>. /// Use this for atmos devices instead of <see cref="EntitySystem.Update"/>.
/// </summary> /// </summary>
[ByRefEvent] [ByRefEvent]
public readonly struct AtmosDeviceUpdateEvent public readonly struct AtmosDeviceUpdateEvent(float dt, Entity<GridAtmosphereComponent, GasTileOverlayComponent>? grid, Entity<MapAtmosphereComponent?>? map)
{ {
/// <summary> /// <summary>
/// Time elapsed since last update, in seconds. Multiply values used in the update handler /// Time elapsed since last update, in seconds. Multiply values used in the update handler
/// by this number to make them tickrate-invariant. Use this number instead of AtmosphereSystem.AtmosTime. /// by this number to make them tickrate-invariant. Use this number instead of AtmosphereSystem.AtmosTime.
/// </summary> /// </summary>
public readonly float dt; public readonly float dt = dt;
public AtmosDeviceUpdateEvent(float dt) /// <summary>
{ /// The grid that this device is currently on.
this.dt = dt; /// </summary>
} public readonly Entity<GridAtmosphereComponent?, GasTileOverlayComponent?>? Grid = grid == null
? null
: (grid.Value, grid.Value, grid.Value);
/// <summary>
/// The map that the device & grid is on.
/// </summary>
public readonly Entity<MapAtmosphereComponent?>? Map = map;
} }
/// <summary> /// <summary>

View File

@@ -129,9 +129,10 @@ namespace Content.Server.Atmos.Piping.EntitySystems
_timer -= _atmosphereSystem.AtmosTime; _timer -= _atmosphereSystem.AtmosTime;
var time = _gameTiming.CurTime; var time = _gameTiming.CurTime;
var ev = new AtmosDeviceUpdateEvent(_atmosphereSystem.AtmosTime); var ev = new AtmosDeviceUpdateEvent(_atmosphereSystem.AtmosTime, null, null);
foreach (var device in _joinedDevices) foreach (var device in _joinedDevices)
{ {
DebugTools.Assert(!HasComp<GridAtmosphereComponent>(Transform(device).GridUid));
RaiseLocalEvent(device, ref ev); RaiseLocalEvent(device, ref ev);
device.Comp.LastProcess = time; device.Comp.LastProcess = time;
} }

View File

@@ -38,9 +38,9 @@ namespace Content.Server.Atmos.Piping.Other.EntitySystems
private bool CheckMinerOperation(Entity<GasMinerComponent> ent, [NotNullWhen(true)] out GasMixture? environment) private bool CheckMinerOperation(Entity<GasMinerComponent> ent, [NotNullWhen(true)] out GasMixture? environment)
{ {
var (uid, miner) = ent; var (uid, miner) = ent;
environment = _atmosphereSystem.GetContainingMixture(uid, true, true);
var transform = Transform(uid); var transform = Transform(uid);
environment = _atmosphereSystem.GetContainingMixture((uid, transform), true, true);
var position = _transformSystem.GetGridOrMapTilePosition(uid, transform); var position = _transformSystem.GetGridOrMapTilePosition(uid, transform);
// Space. // Space.

View File

@@ -53,11 +53,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
private void OnFilterUpdated(EntityUid uid, GasFilterComponent filter, ref AtmosDeviceUpdateEvent args) private void OnFilterUpdated(EntityUid uid, GasFilterComponent filter, ref AtmosDeviceUpdateEvent args)
{ {
if (!filter.Enabled if (!filter.Enabled
|| !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) || !_nodeContainer.TryGetNodes(uid, filter.InletName, filter.OutletName, filter.FilterName, out PipeNode? inletNode, out PipeNode? filterNode, out PipeNode? outletNode)
|| !EntityManager.TryGetComponent(uid, out AtmosDeviceComponent? device)
|| !_nodeContainer.TryGetNode(nodeContainer, filter.InletName, out PipeNode? inletNode)
|| !_nodeContainer.TryGetNode(nodeContainer, filter.FilterName, out PipeNode? filterNode)
|| !_nodeContainer.TryGetNode(nodeContainer, filter.OutletName, out PipeNode? outletNode)
|| outletNode.Air.Pressure >= Atmospherics.MaxOutputPressure) // No need to transfer if target is full. || outletNode.Air.Pressure >= Atmospherics.MaxOutputPressure) // No need to transfer if target is full.
{ {
_ambientSoundSystem.SetAmbience(uid, false); _ambientSoundSystem.SetAmbience(uid, false);
@@ -187,16 +183,15 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)) if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return; return;
var gasMixDict = new Dictionary<string, GasMixture?>(); args.GasMixtures ??= new Dictionary<string, GasMixture?>();
if(_nodeContainer.TryGetNode(nodeContainer, component.InletName, out PipeNode? inlet)) if(_nodeContainer.TryGetNode(nodeContainer, component.InletName, out PipeNode? inlet))
gasMixDict.Add(Loc.GetString("gas-analyzer-window-text-inlet"), inlet.Air); args.GasMixtures.Add(Loc.GetString("gas-analyzer-window-text-inlet"), inlet.Air);
if(_nodeContainer.TryGetNode(nodeContainer, component.FilterName, out PipeNode? filterNode)) if(_nodeContainer.TryGetNode(nodeContainer, component.FilterName, out PipeNode? filterNode))
gasMixDict.Add(Loc.GetString("gas-analyzer-window-text-filter"), filterNode.Air); args.GasMixtures.Add(Loc.GetString("gas-analyzer-window-text-filter"), filterNode.Air);
if(_nodeContainer.TryGetNode(nodeContainer, component.OutletName, out PipeNode? outlet)) if(_nodeContainer.TryGetNode(nodeContainer, component.OutletName, out PipeNode? outlet))
gasMixDict.Add(Loc.GetString("gas-analyzer-window-text-outlet"), outlet.Air); args.GasMixtures.Add(Loc.GetString("gas-analyzer-window-text-outlet"), outlet.Air);
args.GasMixtures = gasMixDict;
args.DeviceFlipped = inlet != null && filterNode != null && inlet.CurrentPipeDirection.ToDirection() == filterNode.CurrentPipeDirection.ToDirection().GetClockwise90Degrees(); args.DeviceFlipped = inlet != null && filterNode != null && inlet.CurrentPipeDirection.ToDirection() == filterNode.CurrentPipeDirection.ToDirection().GetClockwise90Degrees();
} }
} }

View File

@@ -54,18 +54,8 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
{ {
// TODO ATMOS: Cache total moles since it's expensive. // TODO ATMOS: Cache total moles since it's expensive.
if (!mixer.Enabled) if (!mixer.Enabled
{ || !_nodeContainer.TryGetNodes(uid, mixer.InletOneName, mixer.InletTwoName, mixer.OutletName, out PipeNode? inletOne, out PipeNode? inletTwo, out PipeNode? outlet))
_ambientSoundSystem.SetAmbience(uid, false);
return;
}
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return;
if (!_nodeContainer.TryGetNode(nodeContainer, mixer.InletOneName, out PipeNode? inletOne)
|| !_nodeContainer.TryGetNode(nodeContainer, mixer.InletTwoName, out PipeNode? inletTwo)
|| !_nodeContainer.TryGetNode(nodeContainer, mixer.OutletName, out PipeNode? outlet))
{ {
_ambientSoundSystem.SetAmbience(uid, false); _ambientSoundSystem.SetAmbience(uid, false);
return; return;

View File

@@ -33,11 +33,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
private void OnUpdate(EntityUid uid, PressureControlledValveComponent comp, ref AtmosDeviceUpdateEvent args) private void OnUpdate(EntityUid uid, PressureControlledValveComponent comp, ref AtmosDeviceUpdateEvent args)
{ {
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) if (!_nodeContainer.TryGetNodes(uid, comp.InletName, comp.ControlName, comp.OutletName, out PipeNode? inletNode, out PipeNode? controlNode, out PipeNode? outletNode))
|| !EntityManager.TryGetComponent(uid, out AtmosDeviceComponent? device)
|| !_nodeContainer.TryGetNode(nodeContainer, comp.InletName, out PipeNode? inletNode)
|| !_nodeContainer.TryGetNode(nodeContainer, comp.ControlName, out PipeNode? controlNode)
|| !_nodeContainer.TryGetNode(nodeContainer, comp.OutletName, out PipeNode? outletNode))
{ {
_ambientSoundSystem.SetAmbience(uid, false); _ambientSoundSystem.SetAmbience(uid, false);
comp.Enabled = false; comp.Enabled = false;

View File

@@ -60,7 +60,7 @@ public sealed class GasCanisterSystem : EntitySystem
if (!Resolve(uid, ref canister, ref transform)) if (!Resolve(uid, ref canister, ref transform))
return; return;
var environment = _atmos.GetContainingMixture(uid, false, true); var environment = _atmos.GetContainingMixture((uid, transform), false, true);
if (environment is not null) if (environment is not null)
_atmos.Merge(environment, canister.Air); _atmos.Merge(environment, canister.Air);
@@ -168,7 +168,7 @@ public sealed class GasCanisterSystem : EntitySystem
} }
else else
{ {
var environment = _atmos.GetContainingMixture(uid, false, true); var environment = _atmos.GetContainingMixture(uid, args.Grid, args.Map, false, true);
_atmos.ReleaseGasTo(canister.Air, environment, canister.ReleasePressure); _atmos.ReleaseGasTo(canister.Air, environment, canister.ReleasePressure);
} }
} }

View File

@@ -30,9 +30,8 @@ public sealed class GasCondenserSystem : EntitySystem
private void OnCondenserUpdated(Entity<GasCondenserComponent> entity, ref AtmosDeviceUpdateEvent args) private void OnCondenserUpdated(Entity<GasCondenserComponent> entity, ref AtmosDeviceUpdateEvent args)
{ {
if (!(_power.IsPowered(entity) && TryComp<ApcPowerReceiverComponent>(entity, out var receiver)) if (!(TryComp<ApcPowerReceiverComponent>(entity, out var receiver) && _power.IsPowered(entity, receiver))
|| !TryComp<NodeContainerComponent>(entity, out var nodeContainer) || !_nodeContainer.TryGetNode(entity.Owner, entity.Comp.Inlet, out PipeNode? inlet)
|| !_nodeContainer.TryGetNode(nodeContainer, entity.Comp.Inlet, out PipeNode? inlet)
|| !_solution.ResolveSolution(entity.Owner, entity.Comp.SolutionId, ref entity.Comp.Solution, out var solution)) || !_solution.ResolveSolution(entity.Owner, entity.Comp.SolutionId, ref entity.Comp.Solution, out var solution))
{ {
return; return;

View File

@@ -50,16 +50,10 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (!injector.Enabled) if (!injector.Enabled)
return; return;
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)) if (!_nodeContainer.TryGetNode(uid, injector.InletName, out PipeNode? inlet))
return; return;
if (!TryComp(uid, out AtmosDeviceComponent? device)) var environment = _atmosphereSystem.GetContainingMixture(uid, args.Grid, args.Map, true, true);
return;
if (!_nodeContainer.TryGetNode(nodeContainer, injector.InletName, out PipeNode? inlet))
return;
var environment = _atmosphereSystem.GetContainingMixture(uid, true, true);
if (environment == null) if (environment == null)
return; return;

View File

@@ -24,15 +24,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnPassiveVentUpdated(EntityUid uid, GasPassiveVentComponent vent, ref AtmosDeviceUpdateEvent args) private void OnPassiveVentUpdated(EntityUid uid, GasPassiveVentComponent vent, ref AtmosDeviceUpdateEvent args)
{ {
var environment = _atmosphereSystem.GetContainingMixture(uid, true, true); var environment = _atmosphereSystem.GetContainingMixture(uid, args.Grid, args.Map, true, true);
if (environment == null) if (environment == null)
return; return;
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)) if (!_nodeContainer.TryGetNode(uid, vent.InletName, out PipeNode? inlet))
return;
if (!_nodeContainer.TryGetNode(nodeContainer, vent.InletName, out PipeNode? inlet))
return; return;
var inletAir = inlet.Air.RemoveRatio(1f); var inletAir = inlet.Air.RemoveRatio(1f);

View File

@@ -39,10 +39,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnAnchorChanged(EntityUid uid, GasPortableComponent portable, ref AnchorStateChangedEvent args) private void OnAnchorChanged(EntityUid uid, GasPortableComponent portable, ref AnchorStateChangedEvent args)
{ {
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)) if (!_nodeContainer.TryGetNode(uid, portable.PortName, out PipeNode? portableNode))
return;
if (!_nodeContainer.TryGetNode(nodeContainer, portable.PortName, out PipeNode? portableNode))
return; return;
portableNode.ConnectionsEnabled = args.Anchored; portableNode.ConnectionsEnabled = args.Anchored;

View File

@@ -110,7 +110,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
_atmosphereSystem.AddHeat(heatExchangeGasMixture, dQPipe); _atmosphereSystem.AddHeat(heatExchangeGasMixture, dQPipe);
thermoMachine.LastEnergyDelta = dQPipe; thermoMachine.LastEnergyDelta = dQPipe;
if (dQLeak != 0f && _atmosphereSystem.GetContainingMixture(uid, excite: true) is { } containingMixture) if (dQLeak != 0f && _atmosphereSystem.GetContainingMixture(uid, args.Grid, args.Map, excite: true) is { } containingMixture)
_atmosphereSystem.AddHeat(containingMixture, dQLeak); _atmosphereSystem.AddHeat(containingMixture, dQLeak);
} }
@@ -130,8 +130,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
} }
else else
{ {
if (!TryComp<NodeContainerComponent>(uid, out var nodeContainer) if (!_nodeContainer.TryGetNode(uid, thermoMachine.InletName, out PipeNode? inlet))
|| !_nodeContainer.TryGetNode(nodeContainer, thermoMachine.InletName, out PipeNode? inlet))
return; return;
heatExchangeGasMixture = inlet.Air; heatExchangeGasMixture = inlet.Air;
} }

View File

@@ -67,15 +67,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
_ => throw new ArgumentOutOfRangeException() _ => throw new ArgumentOutOfRangeException()
}; };
if (!vent.Enabled if (!vent.Enabled || !_nodeContainer.TryGetNode(uid, nodeName, out PipeNode? pipe))
|| !TryComp(uid, out AtmosDeviceComponent? device)
|| !TryComp(uid, out NodeContainerComponent? nodeContainer)
|| !_nodeContainer.TryGetNode(nodeContainer, nodeName, out PipeNode? pipe))
{ {
return; return;
} }
var environment = _atmosphereSystem.GetContainingMixture(uid, true, true); var environment = _atmosphereSystem.GetContainingMixture(uid, args.Grid, args.Map, true, true);
// We're in an air-blocked tile... Do nothing. // We're in an air-blocked tile... Do nothing.
if (environment == null) if (environment == null)
@@ -295,9 +292,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
/// </summary> /// </summary>
private void OnAnalyzed(EntityUid uid, GasVentPumpComponent component, GasAnalyzerScanEvent args) private void OnAnalyzed(EntityUid uid, GasVentPumpComponent component, GasAnalyzerScanEvent args)
{ {
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return;
var gasMixDict = new Dictionary<string, GasMixture?>(); var gasMixDict = new Dictionary<string, GasMixture?>();
// these are both called pipe, above it switches using this so I duplicated that...? // these are both called pipe, above it switches using this so I duplicated that...?
@@ -307,7 +301,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
VentPumpDirection.Siphoning => component.Outlet, VentPumpDirection.Siphoning => component.Outlet,
_ => throw new ArgumentOutOfRangeException() _ => throw new ArgumentOutOfRangeException()
}; };
if (_nodeContainer.TryGetNode(nodeContainer, nodeName, out PipeNode? pipe)) if (_nodeContainer.TryGetNode(uid, nodeName, out PipeNode? pipe))
gasMixDict.Add(nodeName, pipe.Air); gasMixDict.Add(nodeName, pipe.Air);
args.GasMixtures = gasMixDict; args.GasMixtures = gasMixDict;

View File

@@ -49,27 +49,18 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnVentScrubberUpdated(EntityUid uid, GasVentScrubberComponent scrubber, ref AtmosDeviceUpdateEvent args) private void OnVentScrubberUpdated(EntityUid uid, GasVentScrubberComponent scrubber, ref AtmosDeviceUpdateEvent args)
{ {
if (_weldable.IsWelded(uid)) if (_weldable.IsWelded(uid))
{
return;
}
if (!TryComp(uid, out AtmosDeviceComponent? device))
return; return;
var timeDelta = args.dt; var timeDelta = args.dt;
if (!scrubber.Enabled if (!scrubber.Enabled || !_nodeContainer.TryGetNode(uid, scrubber.OutletName, out PipeNode? outlet))
|| !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !_nodeContainer.TryGetNode(nodeContainer, scrubber.OutletName, out PipeNode? outlet))
return; return;
var xform = Transform(uid); if (args.Grid is not {} grid)
if (xform.GridUid == null)
return; return;
var position = _transformSystem.GetGridTilePositionOrDefault((uid,xform)); var position = _transformSystem.GetGridTilePositionOrDefault(uid);
var environment = _atmosphereSystem.GetTileMixture(xform.GridUid, xform.MapUid, position, true); var environment = _atmosphereSystem.GetTileMixture(grid, args.Map, position, true);
Scrub(timeDelta, scrubber, environment, outlet); Scrub(timeDelta, scrubber, environment, outlet);
@@ -77,7 +68,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
return; return;
// Scrub adjacent tiles too. // Scrub adjacent tiles too.
var enumerator = _atmosphereSystem.GetAdjacentTileMixtures(xform.GridUid.Value, position, false, true); var enumerator = _atmosphereSystem.GetAdjacentTileMixtures(grid, position, false, true);
while (enumerator.MoveNext(out var adjacent)) while (enumerator.MoveNext(out var adjacent))
{ {
Scrub(timeDelta, scrubber, adjacent, outlet); Scrub(timeDelta, scrubber, adjacent, outlet);

View File

@@ -47,17 +47,13 @@ namespace Content.Server.Atmos.Portable
private void OnDeviceUpdated(EntityUid uid, PortableScrubberComponent component, ref AtmosDeviceUpdateEvent args) private void OnDeviceUpdated(EntityUid uid, PortableScrubberComponent component, ref AtmosDeviceUpdateEvent args)
{ {
if (!TryComp(uid, out AtmosDeviceComponent? device))
return;
var timeDelta = args.dt; var timeDelta = args.dt;
if (!component.Enabled) if (!component.Enabled)
return; return;
// If we are on top of a connector port, empty into it. // If we are on top of a connector port, empty into it.
if (TryComp<NodeContainerComponent>(uid, out var nodeContainer) if (_nodeContainer.TryGetNode(uid, component.PortName, out PortablePipeNode? portableNode)
&& _nodeContainer.TryGetNode(nodeContainer, component.PortName, out PortablePipeNode? portableNode)
&& portableNode.ConnectionsEnabled) && portableNode.ConnectionsEnabled)
{ {
_atmosphereSystem.React(component.Air, portableNode); _atmosphereSystem.React(component.Air, portableNode);
@@ -71,13 +67,11 @@ namespace Content.Server.Atmos.Portable
return; return;
} }
var xform = Transform(uid); if (args.Grid is not {} grid)
if (xform.GridUid == null)
return; return;
var position = _transformSystem.GetGridTilePositionOrDefault((uid,xform)); var position = _transformSystem.GetGridTilePositionOrDefault(uid);
var environment = _atmosphereSystem.GetTileMixture(xform.GridUid, xform.MapUid, position, true); var environment = _atmosphereSystem.GetTileMixture(grid, args.Map, position, true);
var running = Scrub(timeDelta, component, environment); var running = Scrub(timeDelta, component, environment);
@@ -85,8 +79,9 @@ namespace Content.Server.Atmos.Portable
// We scrub once to see if we can and set the animation // We scrub once to see if we can and set the animation
if (!running) if (!running)
return; return;
// widenet // widenet
var enumerator = _atmosphereSystem.GetAdjacentTileMixtures(xform.GridUid.Value, position, false, true); var enumerator = _atmosphereSystem.GetAdjacentTileMixtures(grid, position, false, true);
while (enumerator.MoveNext(out var adjacent)) while (enumerator.MoveNext(out var adjacent))
{ {
Scrub(timeDelta, component, adjacent); Scrub(timeDelta, component, adjacent);
@@ -98,10 +93,7 @@ namespace Content.Server.Atmos.Portable
/// </summary> /// </summary>
private void OnAnchorChanged(EntityUid uid, PortableScrubberComponent component, ref AnchorStateChangedEvent args) private void OnAnchorChanged(EntityUid uid, PortableScrubberComponent component, ref AnchorStateChangedEvent args)
{ {
if (!TryComp(uid, out NodeContainerComponent? nodeContainer)) if (!_nodeContainer.TryGetNode(uid, component.PortName, out PipeNode? portableNode))
return;
if (!_nodeContainer.TryGetNode(nodeContainer, component.PortName, out PipeNode? portableNode))
return; return;
portableNode.ConnectionsEnabled = (args.Anchored && _gasPortableSystem.FindGasPortIn(Transform(uid).GridUid, Transform(uid).Coordinates, out _)); portableNode.ConnectionsEnabled = (args.Anchored && _gasPortableSystem.FindGasPortIn(Transform(uid).GridUid, Transform(uid).Coordinates, out _));
@@ -159,14 +151,10 @@ namespace Content.Server.Atmos.Portable
/// </summary> /// </summary>
private void OnScrubberAnalyzed(EntityUid uid, PortableScrubberComponent component, GasAnalyzerScanEvent args) private void OnScrubberAnalyzed(EntityUid uid, PortableScrubberComponent component, GasAnalyzerScanEvent args)
{ {
var gasMixDict = new Dictionary<string, GasMixture?> { { Name(uid), component.Air } }; args.GasMixtures ??= new Dictionary<string, GasMixture?> { { Name(uid), component.Air } };
// If it's connected to a port, include the port side // If it's connected to a port, include the port side
if (TryComp(uid, out NodeContainerComponent? nodeContainer)) if (_nodeContainer.TryGetNode(uid, component.PortName, out PipeNode? port))
{ args.GasMixtures.Add(component.PortName, port.Air);
if (_nodeContainer.TryGetNode(nodeContainer, component.PortName, out PipeNode? port))
gasMixDict.Add(component.PortName, port.Air);
}
args.GasMixtures = gasMixDict;
} }
} }
} }

View File

@@ -71,7 +71,7 @@ public sealed class SpaceHeaterSystem : EntitySystem
// If in automatic temperature mode, check if we need to adjust the heat exchange direction // If in automatic temperature mode, check if we need to adjust the heat exchange direction
if (spaceHeater.Mode == SpaceHeaterMode.Auto) if (spaceHeater.Mode == SpaceHeaterMode.Auto)
{ {
var environment = _atmosphereSystem.GetContainingMixture(uid); var environment = _atmosphereSystem.GetContainingMixture(uid, args.Grid, args.Map);
if (environment == null) if (environment == null)
return; return;

View File

@@ -9,7 +9,7 @@ namespace Content.Server.Electrocution
public sealed partial class ElectrocutionNode : Node public sealed partial class ElectrocutionNode : Node
{ {
[DataField("cable")] [DataField("cable")]
public EntityUid CableEntity; public EntityUid? CableEntity;
[DataField("node")] [DataField("node")]
public string? NodeName; public string? NodeName;
@@ -19,12 +19,11 @@ namespace Content.Server.Electrocution
MapGridComponent? grid, MapGridComponent? grid,
IEntityManager entMan) IEntityManager entMan)
{ {
var _nodeContainer = entMan.System<NodeContainerSystem>(); if (CableEntity == null || NodeName == null)
if (!nodeQuery.TryGetComponent(CableEntity, out var nodeContainer))
yield break; yield break;
if (_nodeContainer.TryGetNode(nodeContainer, NodeName, out Node? node)) var _nodeContainer = entMan.System<NodeContainerSystem>();
if (_nodeContainer.TryGetNode(CableEntity.Value, NodeName, out Node? node))
yield return node; yield return node;
} }
} }

View File

@@ -271,7 +271,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
var direction = (AtmosDirection) (1 << i); var direction = (AtmosDirection) (1 << i);
if (ignoreTileBlockers || !blockedDirections.IsFlagSet(direction)) if (ignoreTileBlockers || !blockedDirections.IsFlagSet(direction))
{ {
ProcessNewTile(iteration, tile.Offset(direction), direction.GetOpposite()); ProcessNewTile(iteration, tile.Offset(direction), i.ToOppositeDir());
} }
} }
@@ -300,7 +300,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
var direction = (AtmosDirection) (1 << i); var direction = (AtmosDirection) (1 << i);
if (blockedDirections.IsFlagSet(direction)) if (blockedDirections.IsFlagSet(direction))
{ {
list.Add((tile.Offset(direction), direction.GetOpposite())); list.Add((tile.Offset(direction), i.ToOppositeDir()));
} }
} }
} }

View File

@@ -97,7 +97,7 @@ public sealed class ExplosionSpaceTileFlood : ExplosionTileFlood
if (!unblockedDirections.IsFlagSet(direction)) if (!unblockedDirections.IsFlagSet(direction))
continue; // explosion cannot propagate in this direction. Ever. continue; // explosion cannot propagate in this direction. Ever.
ProcessNewTile(iteration, tile.Offset(direction), direction.GetOpposite()); ProcessNewTile(iteration, tile.Offset(direction), i.ToOppositeDir());
} }
} }
} }

View File

@@ -404,14 +404,17 @@ public sealed partial class MechSystem : SharedMechSystem
if (args.Handled) if (args.Handled)
return; return;
if (!TryComp<MechComponent>(component.Mech, out var mech) || if (!TryComp(component.Mech, out MechComponent? mech))
!TryComp<MechAirComponent>(component.Mech, out var mechAir)) return;
if (mech.Airtight && TryComp(component.Mech, out MechAirComponent? air))
{ {
args.Handled = true;
args.Gas = air.Air;
return; return;
} }
args.Gas = mech.Airtight ? mechAir.Air : _atmosphere.GetContainingMixture(component.Mech); args.Gas = _atmosphere.GetContainingMixture(component.Mech, excite: args.Excite);
args.Handled = true; args.Handled = true;
} }

View File

@@ -257,10 +257,7 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
private void OnCryoPodUpdateAtmosphere(Entity<CryoPodComponent> entity, ref AtmosDeviceUpdateEvent args) private void OnCryoPodUpdateAtmosphere(Entity<CryoPodComponent> entity, ref AtmosDeviceUpdateEvent args)
{ {
if (!TryComp(entity, out NodeContainerComponent? nodeContainer)) if (!_nodeContainer.TryGetNode(entity.Owner, entity.Comp.PortName, out PortablePipeNode? portNode))
return;
if (!_nodeContainer.TryGetNode(nodeContainer, entity.Comp.PortName, out PortablePipeNode? portNode))
return; return;
if (!TryComp(entity, out CryoPodAirComponent? cryoPodAir)) if (!TryComp(entity, out CryoPodAirComponent? cryoPodAir))
@@ -279,14 +276,10 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
if (!TryComp(entity, out CryoPodAirComponent? cryoPodAir)) if (!TryComp(entity, out CryoPodAirComponent? cryoPodAir))
return; return;
var gasMixDict = new Dictionary<string, GasMixture?> { { Name(entity.Owner), cryoPodAir.Air } }; args.GasMixtures ??= new Dictionary<string, GasMixture?> { { Name(entity.Owner), cryoPodAir.Air } };
// If it's connected to a port, include the port side // If it's connected to a port, include the port side
if (TryComp(entity, out NodeContainerComponent? nodeContainer)) if (_nodeContainer.TryGetNode(entity.Owner, entity.Comp.PortName, out PipeNode? port))
{ args.GasMixtures.Add(entity.Comp.PortName, port.Air);
if (_nodeContainer.TryGetNode(nodeContainer, entity.Comp.PortName, out PipeNode? port))
gasMixDict.Add(entity.Comp.PortName, port.Air);
}
args.GasMixtures = gasMixDict;
} }
private void OnEjected(Entity<CryoPodComponent> cryoPod, ref EntRemovedFromContainerMessage args) private void OnEjected(Entity<CryoPodComponent> cryoPod, ref EntRemovedFromContainerMessage args)

View File

@@ -14,6 +14,7 @@ namespace Content.Server.NodeContainer.EntitySystems
public sealed class NodeContainerSystem : EntitySystem public sealed class NodeContainerSystem : EntitySystem
{ {
[Dependency] private readonly NodeGroupSystem _nodeGroupSystem = default!; [Dependency] private readonly NodeGroupSystem _nodeGroupSystem = default!;
private EntityQuery<NodeContainerComponent> _query;
public override void Initialize() public override void Initialize()
{ {
@@ -26,6 +27,8 @@ namespace Content.Server.NodeContainer.EntitySystems
SubscribeLocalEvent<NodeContainerComponent, ReAnchorEvent>(OnReAnchor); SubscribeLocalEvent<NodeContainerComponent, ReAnchorEvent>(OnReAnchor);
SubscribeLocalEvent<NodeContainerComponent, MoveEvent>(OnMoveEvent); SubscribeLocalEvent<NodeContainerComponent, MoveEvent>(OnMoveEvent);
SubscribeLocalEvent<NodeContainerComponent, ExaminedEvent>(OnExamine); SubscribeLocalEvent<NodeContainerComponent, ExaminedEvent>(OnExamine);
_query = GetEntityQuery<NodeContainerComponent>();
} }
public bool TryGetNode<T>(NodeContainerComponent component, string? identifier, [NotNullWhen(true)] out T? node) where T : Node public bool TryGetNode<T>(NodeContainerComponent component, string? identifier, [NotNullWhen(true)] out T? node) where T : Node
@@ -46,6 +49,77 @@ namespace Content.Server.NodeContainer.EntitySystems
return false; return false;
} }
public bool TryGetNode<T>(Entity<NodeContainerComponent?> ent, string identifier, [NotNullWhen(true)] out T? node) where T : Node
{
if (_query.Resolve(ent, ref ent.Comp, false)
&& ent.Comp.Nodes.TryGetValue(identifier, out var n)
&& n is T t)
{
node = t;
return true;
}
node = null;
return false;
}
public bool TryGetNodes<T1, T2>(
Entity<NodeContainerComponent?> ent,
string id1,
string id2,
[NotNullWhen(true)] out T1? node1,
[NotNullWhen(true)] out T2? node2)
where T1 : Node
where T2 : Node
{
if (_query.Resolve(ent, ref ent.Comp, false)
&& ent.Comp.Nodes.TryGetValue(id1, out var n1)
&& n1 is T1 t1
&& ent.Comp.Nodes.TryGetValue(id2, out var n2)
&& n2 is T2 t2)
{
node1 = t1;
node2 = t2;
return true;
}
node1 = null;
node2 = null;
return false;
}
public bool TryGetNodes<T1, T2, T3>(
Entity<NodeContainerComponent?> ent,
string id1,
string id2,
string id3,
[NotNullWhen(true)] out T1? node1,
[NotNullWhen(true)] out T2? node2,
[NotNullWhen(true)] out T3? node3)
where T1 : Node
where T2 : Node
where T3 : Node
{
if (_query.Resolve(ent, ref ent.Comp, false)
&& ent.Comp.Nodes.TryGetValue(id1, out var n1)
&& n1 is T1 t1
&& ent.Comp.Nodes.TryGetValue(id2, out var n2)
&& n2 is T2 t2
&& ent.Comp.Nodes.TryGetValue(id3, out var n3)
&& n2 is T3 t3)
{
node1 = t1;
node2 = t2;
node3 = t3;
return true;
}
node1 = null;
node2 = null;
node3 = null;
return false;
}
private void OnInitEvent(EntityUid uid, NodeContainerComponent component, ComponentInit args) private void OnInitEvent(EntityUid uid, NodeContainerComponent component, ComponentInit args)
{ {
foreach (var (key, node) in component.Nodes) foreach (var (key, node) in component.Nodes)

View File

@@ -94,7 +94,7 @@ public sealed class PneumaticCannonSystem : SharedPneumaticCannonSystem
return; return;
// this should always be possible, as we'll eject the gas tank when it no longer is // this should always be possible, as we'll eject the gas tank when it no longer is
var environment = _atmos.GetContainingMixture(cannon, false, true); var environment = _atmos.GetContainingMixture(cannon.Owner, false, true);
var removed = _gasTank.RemoveAir(gas.Value, component.GasUsage); var removed = _gasTank.RemoveAir(gas.Value, component.GasUsage);
if (environment != null && removed != null) if (environment != null && removed != null)
{ {

View File

@@ -4,7 +4,7 @@
public sealed partial class CableVisComponent : Component public sealed partial class CableVisComponent : Component
{ {
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("node")] [DataField("node", required:true)]
public string? Node; public string Node;
} }
} }

View File

@@ -23,10 +23,7 @@ namespace Content.Server.Power.EntitySystems
private void UpdateAppearance(EntityUid uid, CableVisComponent cableVis, ref NodeGroupsRebuilt args) private void UpdateAppearance(EntityUid uid, CableVisComponent cableVis, ref NodeGroupsRebuilt args)
{ {
if (!TryComp(uid, out NodeContainerComponent? nodeContainer) || !TryComp(uid, out AppearanceComponent? appearance)) if (!_nodeContainer.TryGetNode(uid, cableVis.Node, out CableNode? node))
return;
if (!_nodeContainer.TryGetNode<CableNode>(nodeContainer, cableVis.Node, out var node))
return; return;
var transform = Transform(uid); var transform = Transform(uid);
@@ -55,7 +52,7 @@ namespace Content.Server.Power.EntitySystems
}; };
} }
_appearance.SetData(uid, WireVisVisuals.ConnectedMask, mask, appearance); _appearance.SetData(uid, WireVisVisuals.ConnectedMask, mask);
} }
} }
} }

View File

@@ -26,12 +26,8 @@ public sealed class GasPowerReceiverSystem : EntitySystem
{ {
var timeDelta = args.dt; var timeDelta = args.dt;
if (!HasComp<AtmosDeviceComponent>(uid) if (!_nodeContainer.TryGetNode(uid, "pipe", out PipeNode? pipe))
|| !TryComp<NodeContainerComponent>(uid, out var nodeContainer)
|| !_nodeContainer.TryGetNode<PipeNode>(nodeContainer, "pipe", out var pipe))
{
return; return;
}
// if we're below the max temperature, then we are simply consuming our target gas // if we're below the max temperature, then we are simply consuming our target gas
if (pipe.Air.Temperature <= component.MaxTemperature) if (pipe.Air.Temperature <= component.MaxTemperature)
@@ -57,7 +53,7 @@ public sealed class GasPowerReceiverSystem : EntitySystem
if (component.OffVentGas) if (component.OffVentGas)
{ {
// eject the gas into the atmosphere // eject the gas into the atmosphere
var mix = _atmosphereSystem.GetContainingMixture(uid, false, true); var mix = _atmosphereSystem.GetContainingMixture(uid, args.Grid, args.Map, false, true);
if (mix is not null) if (mix is not null)
_atmosphereSystem.Merge(res, mix); _atmosphereSystem.Merge(res, mix);
} }

View File

@@ -231,10 +231,9 @@ public sealed class SpreaderSystem : EntitySystem
// Add the normal neighbors. // Add the normal neighbors.
for (var i = 0; i < 4; i++) for (var i = 0; i < 4; i++)
{ {
var direction = (Direction) (i * 2); var atmosDir = (AtmosDirection) (1 << i);
var atmosDir = direction.ToAtmosDirection(); var neighborPos = tile.Offset(atmosDir);
var neighborPos = SharedMapSystem.GetDirection(tile, direction); neighborTiles.Add((comp.GridUid.Value, grid, neighborPos, atmosDir, i.ToOppositeDir()));
neighborTiles.Add((comp.GridUid.Value, grid, neighborPos, atmosDir, atmosDir.GetOpposite()));
} }
foreach (var (neighborEnt, neighborGrid, neighborPos, ourAtmosDir, otherAtmosDir) in neighborTiles) foreach (var (neighborEnt, neighborGrid, neighborPos, ourAtmosDir, otherAtmosDir) in neighborTiles)

View File

@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices; using System.Numerics;
using System.Runtime.CompilerServices;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Shared.Atmos namespace Content.Shared.Atmos
@@ -15,6 +16,8 @@ namespace Content.Shared.Atmos
South = 1 << 1, // 2 South = 1 << 1, // 2
East = 1 << 2, // 4 East = 1 << 2, // 4
West = 1 << 3, // 8 West = 1 << 3, // 8
// If more directions are added, note that AtmosDirectionHelpers.ToOppositeIndex() expects opposite directions
// to come in pairs
NorthEast = North | East, // 5 NorthEast = North | East, // 5
SouthEast = South | East, // 6 SouthEast = South | East, // 6
@@ -42,6 +45,22 @@ namespace Content.Shared.Atmos
}; };
} }
/// <summary>
/// This returns the index that corresponds to the opposite direction of some other direction index.
/// I.e., <c>1&lt;&lt;OppositeIndex(i) == (1&lt;&lt;i).GetOpposite()</c>
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ToOppositeIndex(this int index)
{
return index ^ 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static AtmosDirection ToOppositeDir(this int index)
{
return (AtmosDirection) (1 << (index ^ 1));
}
public static Direction ToDirection(this AtmosDirection direction) public static Direction ToDirection(this AtmosDirection direction)
{ {
return direction switch return direction switch
@@ -119,10 +138,11 @@ namespace Content.Shared.Atmos
return angle.GetDir().ToAtmosDirection(); return angle.GetDir().ToAtmosDirection();
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ToIndex(this AtmosDirection direction) public static int ToIndex(this AtmosDirection direction)
{ {
// This will throw if you pass an invalid direction. Not this method's fault, but yours! // This will throw if you pass an invalid direction. Not this method's fault, but yours!
return (int) Math.Log2((int) direction); return BitOperations.Log2((uint)direction);
} }
public static AtmosDirection WithFlag(this AtmosDirection direction, AtmosDirection other) public static AtmosDirection WithFlag(this AtmosDirection direction, AtmosDirection other)

View File

@@ -15,14 +15,7 @@ public sealed class WeldableSystem : EntitySystem
[Dependency] private readonly SharedToolSystem _toolSystem = default!; [Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!;
private EntityQuery<WeldableComponent> _query;
public bool IsWelded(EntityUid uid, WeldableComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return false;
return component.IsWelded;
}
public override void Initialize() public override void Initialize()
{ {
@@ -31,6 +24,13 @@ public sealed class WeldableSystem : EntitySystem
SubscribeLocalEvent<WeldableComponent, WeldFinishedEvent>(OnWeldFinished); SubscribeLocalEvent<WeldableComponent, WeldFinishedEvent>(OnWeldFinished);
SubscribeLocalEvent<LayerChangeOnWeldComponent, WeldableChangedEvent>(OnWeldChanged); SubscribeLocalEvent<LayerChangeOnWeldComponent, WeldableChangedEvent>(OnWeldChanged);
SubscribeLocalEvent<WeldableComponent, ExaminedEvent>(OnExamine); SubscribeLocalEvent<WeldableComponent, ExaminedEvent>(OnExamine);
_query = GetEntityQuery<WeldableComponent>();
}
public bool IsWelded(EntityUid uid, WeldableComponent? component = null)
{
return _query.Resolve(uid, ref component, false) && component.IsWelded;
} }
private void OnExamine(EntityUid uid, WeldableComponent component, ExaminedEvent args) private void OnExamine(EntityUid uid, WeldableComponent component, ExaminedEvent args)
@@ -49,7 +49,7 @@ public sealed class WeldableSystem : EntitySystem
private bool CanWeld(EntityUid uid, EntityUid tool, EntityUid user, WeldableComponent? component = null) private bool CanWeld(EntityUid uid, EntityUid tool, EntityUid user, WeldableComponent? component = null)
{ {
if (!Resolve(uid, ref component)) if (!_query.Resolve(uid, ref component))
return false; return false;
// Other component systems // Other component systems
@@ -63,7 +63,7 @@ public sealed class WeldableSystem : EntitySystem
private bool TryWeld(EntityUid uid, EntityUid tool, EntityUid user, WeldableComponent? component = null) private bool TryWeld(EntityUid uid, EntityUid tool, EntityUid user, WeldableComponent? component = null)
{ {
if (!Resolve(uid, ref component)) if (!_query.Resolve(uid, ref component))
return false; return false;
if (!CanWeld(uid, tool, user, component)) if (!CanWeld(uid, tool, user, component))
@@ -115,17 +115,13 @@ public sealed class WeldableSystem : EntitySystem
private void UpdateAppearance(EntityUid uid, WeldableComponent? component = null) private void UpdateAppearance(EntityUid uid, WeldableComponent? component = null)
{ {
if (!Resolve(uid, ref component)) if (_query.Resolve(uid, ref component))
return; _appearance.SetData(uid, WeldableVisuals.IsWelded, component.IsWelded);
if (!TryComp(uid, out AppearanceComponent? appearance))
return;
_appearance.SetData(uid, WeldableVisuals.IsWelded, component.IsWelded, appearance);
} }
public void SetWeldedState(EntityUid uid, bool state, WeldableComponent? component = null) public void SetWeldedState(EntityUid uid, bool state, WeldableComponent? component = null)
{ {
if (!Resolve(uid, ref component)) if (!_query.Resolve(uid, ref component))
return; return;
if (component.IsWelded == state) if (component.IsWelded == state)
@@ -141,7 +137,7 @@ public sealed class WeldableSystem : EntitySystem
public void SetWeldingTime(EntityUid uid, TimeSpan time, WeldableComponent? component = null) public void SetWeldingTime(EntityUid uid, TimeSpan time, WeldableComponent? component = null)
{ {
if (!Resolve(uid, ref component)) if (!_query.Resolve(uid, ref component))
return; return;
if (component.WeldingTime.Equals(time)) if (component.WeldingTime.Equals(time))

View File

@@ -1,7 +1,7 @@
# Special entity used to attach to power networks as load when somebody gets electrocuted. # Special entity used to attach to power networks as load when somebody gets electrocuted.
- type: entity - type: entity
id: VirtualElectrocutionLoadBase id: VirtualElectrocutionLoadBase
noSpawn: true abstract: true
components: components:
- type: Electrocution - type: Electrocution
- type: Icon - type: Icon