Optimise air + cable shutdowns for grid deletion (#5847)

Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
metalgearsloth
2021-12-21 17:17:21 +11:00
committed by GitHub
parent 7d041db06d
commit caf28d09b3
2 changed files with 49 additions and 19 deletions

View File

@@ -44,7 +44,15 @@ namespace Content.Server.Atmos.EntitySystems
private void OnAirtightShutdown(EntityUid uid, AirtightComponent airtight, ComponentShutdown args)
{
SetAirblocked(airtight, false);
var xform = Transform(uid);
// If the grid is deleting no point updating atmos.
if (_mapManager.TryGetGrid(xform.GridID, out var grid))
{
if (MetaData(grid.GridEntityId).EntityLifeStage > EntityLifeStage.MapInitialized) return;
}
SetAirblocked(airtight, false, xform);
InvalidatePosition(airtight.LastPosition.Item1, airtight.LastPosition.Item2, airtight.FixVacuum);
RaiseLocalEvent(new AirtightChanged(airtight));
@@ -79,16 +87,18 @@ namespace Content.Server.Atmos.EntitySystems
RaiseLocalEvent(uid, new AirtightChanged(airtight));
}
public void SetAirblocked(AirtightComponent airtight, bool airblocked)
public void SetAirblocked(AirtightComponent airtight, bool airblocked, TransformComponent? xform = null)
{
if (!Resolve(airtight.Owner, ref xform)) return;
airtight.AirBlocked = airblocked;
UpdatePosition(airtight);
RaiseLocalEvent((airtight).Owner, new AirtightChanged(airtight));
UpdatePosition(airtight, xform);
RaiseLocalEvent(airtight.Owner, new AirtightChanged(airtight));
}
public void UpdatePosition(AirtightComponent airtight)
public void UpdatePosition(AirtightComponent airtight, TransformComponent? xform = null)
{
var xform = EntityManager.GetComponent<TransformComponent>(airtight.Owner);
if (!Resolve(airtight.Owner, ref xform)) return;
if (!xform.Anchored || !xform.GridID.IsValid())
return;