Reduce unnecessary `ComponentInit` work for airtight entities (#42390)

Refactor AirtightSystem to skip rotation checks for omnidirectional blocks on init

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
This commit is contained in:
TriviaSolari 2026-01-14 21:31:05 -05:00 committed by BarryNorfolk
parent 2a3fb80998
commit 88bba6790b
2 changed files with 6 additions and 19 deletions

View File

@ -44,20 +44,6 @@ namespace Content.Server.Atmos.Components
[DataField("rotateAirBlocked")] [DataField("rotateAirBlocked")]
public bool RotateAirBlocked { get; set; } = true; public bool RotateAirBlocked { get; set; } = true;
/// <summary>
/// Whether to fix the <see cref="CurrentAirBlockedDirection"/> on initialization
/// to the entity's current rotation.
/// </summary>
/// <remarks>This is an optimization routine for initializing airtight components.
/// If this entity doesn't have unique airtight directions
/// (ex. not all directions are blocked but some are), we can skip
/// a lot of event/transform business during initialization.
/// This field marks whether this is skipped or not.</remarks>
/// <example>If your entity only blocks air in one direction,
/// and that can depend on rotation, this needs to be set to true.</example>
[DataField]
public bool FixAirBlockedDirectionInitialize = true;
/// <summary> /// <summary>
/// If true, then the tile that this entity is on will have no air at all if all directions are blocked. /// If true, then the tile that this entity is on will have no air at all if all directions are blocked.
/// </summary> /// </summary>

View File

@ -25,16 +25,17 @@ namespace Content.Server.Atmos.EntitySystems
private void OnAirtightInit(Entity<AirtightComponent> airtight, ref ComponentInit args) private void OnAirtightInit(Entity<AirtightComponent> airtight, ref ComponentInit args)
{ {
// If this entity has unique airtight directions that are affected by rotation, // If this entity blocks air in all directions (e.g. full tile walls, doors, and windows)
// we need to fix up the current airtight directions based on its rotation. // we can skip some expensive logic.
// Otherwise, we can skip all of that logic (stuff adds up when you're initing if (airtight.Comp.InitialAirBlockedDirection == (int)AtmosDirection.All)
// a morbillion walls).
if (!airtight.Comp.FixAirBlockedDirectionInitialize)
{ {
airtight.Comp.CurrentAirBlockedDirection = airtight.Comp.InitialAirBlockedDirection;
UpdatePosition(airtight); UpdatePosition(airtight);
return; return;
} }
// Otherwise we need to determine its current blocked air directions based on rotation
// and check if it's still airtight.
var xform = Transform(airtight); var xform = Transform(airtight);
airtight.Comp.CurrentAirBlockedDirection = airtight.Comp.CurrentAirBlockedDirection =
(int) Rotate((AtmosDirection) airtight.Comp.InitialAirBlockedDirection, xform.LocalRotation); (int) Rotate((AtmosDirection) airtight.Comp.InitialAirBlockedDirection, xform.LocalRotation);