Fix atmos NaN error (#26441)

* Fix atmos NAN error

* Remove redundant yaml entries
This commit is contained in:
Leon Friedrich
2024-03-26 15:44:56 +11:00
committed by GitHub
parent 51a02c98fa
commit fdb4a61487
16 changed files with 43 additions and 25 deletions

View File

@@ -9,27 +9,53 @@ namespace Content.Server.Atmos.Components
{ {
public (EntityUid Grid, Vector2i Tile) LastPosition { get; set; } public (EntityUid Grid, Vector2i Tile) LastPosition { get; set; }
/// <summary>
/// The directions in which this entity should block airflow, relative to its own reference frame.
/// </summary>
[DataField("airBlockedDirection", customTypeSerializer: typeof(FlagSerializer<AtmosDirectionFlags>))] [DataField("airBlockedDirection", customTypeSerializer: typeof(FlagSerializer<AtmosDirectionFlags>))]
public int InitialAirBlockedDirection { get; set; } = (int) AtmosDirection.All; public int InitialAirBlockedDirection { get; set; } = (int) AtmosDirection.All;
/// <summary>
/// The directions in which the entity is currently blocking airflow, relative to the grid that the entity is on.
/// I.e., this is a variant of <see cref="InitialAirBlockedDirection"/> that takes into account the entity's
/// current rotation.
/// </summary>
[ViewVariables] [ViewVariables]
public int CurrentAirBlockedDirection; public int CurrentAirBlockedDirection;
[DataField("airBlocked")] /// <summary>
/// Whether the airtight entity is currently blocking airflow.
/// </summary>
[DataField]
public bool AirBlocked { get; set; } = true; public bool AirBlocked { get; set; } = true;
[DataField("fixVacuum")] /// <summary>
/// If true, entities on this tile will attempt to draw air from surrounding tiles when they become unblocked
/// and currently have no air. This is generally only required when <see cref="NoAirWhenFullyAirBlocked"/> is
/// true, or if the entity is likely to occupy the same tile as another no-air airtight entity.
/// </summary>
[DataField]
public bool FixVacuum { get; set; } = true; public bool FixVacuum { get; set; } = true;
// I think fixvacuum exists to ensure that repeatedly closing/opening air-blocking doors doesn't end up
// depressurizing a room. However it can also effectively be used as a means of generating gasses for free
// TODO ATMOS Mass conservation. Make it actually push/pull air from adjacent tiles instead of destroying & creating,
// TODO ATMOS Do we need these two fields?
[DataField("rotateAirBlocked")] [DataField("rotateAirBlocked")]
public bool RotateAirBlocked { get; set; } = true; public bool RotateAirBlocked { get; set; } = true;
// TODO ATMOS remove this? What is this even for??
[DataField("fixAirBlockedDirectionInitialize")] [DataField("fixAirBlockedDirectionInitialize")]
public bool FixAirBlockedDirectionInitialize { get; set; } = true; public bool FixAirBlockedDirectionInitialize { get; set; } = true;
[DataField("noAirWhenFullyAirBlocked")] /// <summary>
/// If true, then the tile that this entity is on will have no air at all if all directions are blocked.
/// </summary>
[DataField]
public bool NoAirWhenFullyAirBlocked { get; set; } = true; public bool NoAirWhenFullyAirBlocked { get; set; } = true;
/// <inheritdoc cref="CurrentAirBlockedDirection"/>
[Access(Other = AccessPermissions.ReadWriteExecute)] [Access(Other = AccessPermissions.ReadWriteExecute)]
public AtmosDirection AirBlockedDirection => (AtmosDirection)CurrentAirBlockedDirection; public AtmosDirection AirBlockedDirection => (AtmosDirection)CurrentAirBlockedDirection;
} }

View File

@@ -85,8 +85,6 @@ namespace Content.Server.Atmos.EntitySystems
private bool AirtightMove(Entity<AirtightComponent> ent, ref MoveEvent ev) private bool AirtightMove(Entity<AirtightComponent> ent, ref MoveEvent ev)
{ {
var (owner, airtight) = ent; var (owner, airtight) = ent;
if (!airtight.RotateAirBlocked || airtight.InitialAirBlockedDirection == (int)AtmosDirection.Invalid)
return false;
airtight.CurrentAirBlockedDirection = (int) Rotate((AtmosDirection)airtight.InitialAirBlockedDirection, ev.NewRotation); airtight.CurrentAirBlockedDirection = (int) Rotate((AtmosDirection)airtight.InitialAirBlockedDirection, ev.NewRotation);
var pos = airtight.LastPosition; var pos = airtight.LastPosition;

View File

@@ -399,10 +399,7 @@ public sealed partial class AtmosphereSystem
args.Handled = true; args.Handled = true;
} }
private void GridFixTileVacuum( private void GridFixTileVacuum(TileAtmosphere tile)
Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ent,
TileAtmosphere tile,
float volume)
{ {
DebugTools.AssertNotNull(tile.Air); DebugTools.AssertNotNull(tile.Air);
DebugTools.Assert(tile.Air?.Immutable == false ); DebugTools.Assert(tile.Air?.Immutable == false );
@@ -416,6 +413,9 @@ public sealed partial class AtmosphereSystem
count++; count++;
} }
if (count == 0)
return;
var ratio = 1f / count; var ratio = 1f / count;
var totalTemperature = 0f; var totalTemperature = 0f;

View File

@@ -272,7 +272,7 @@ namespace Content.Server.Atmos.EntitySystems
tile.Air = new GasMixture(volume){Temperature = Atmospherics.T20C}; tile.Air = new GasMixture(volume){Temperature = Atmospherics.T20C};
if (data.FixVacuum) if (data.FixVacuum)
GridFixTileVacuum(ent, tile, volume); GridFixTileVacuum(tile);
} }
private void QueueRunTiles( private void QueueRunTiles(

View File

@@ -78,12 +78,13 @@ public partial class AtmosphereSystem
if (!_airtightQuery.TryGetComponent(ent, out var airtight)) if (!_airtightQuery.TryGetComponent(ent, out var airtight))
continue; continue;
fixVacuum |= airtight.FixVacuum;
if(!airtight.AirBlocked) if(!airtight.AirBlocked)
continue; continue;
blockedDirs |= airtight.AirBlockedDirection; blockedDirs |= airtight.AirBlockedDirection;
noAirWhenBlocked |= airtight.NoAirWhenFullyAirBlocked; noAirWhenBlocked |= airtight.NoAirWhenFullyAirBlocked;
fixVacuum |= airtight.FixVacuum;
if (blockedDirs == AtmosDirection.All && noAirWhenBlocked && fixVacuum) if (blockedDirs == AtmosDirection.All && noAirWhenBlocked && fixVacuum)
break; break;

View File

@@ -62,9 +62,9 @@ namespace Content.Server.Atmos
get => _temperature; get => _temperature;
set set
{ {
DebugTools.Assert(!float.IsNaN(_temperature)); DebugTools.Assert(!float.IsNaN(value));
if (Immutable) return; if (!Immutable)
_temperature = MathF.Min(MathF.Max(value, Atmospherics.TCMB), Atmospherics.Tmax); _temperature = MathF.Min(MathF.Max(value, Atmospherics.TCMB), Atmospherics.Tmax);
} }
} }
@@ -91,6 +91,7 @@ namespace Content.Server.Atmos
if (volume < 0) if (volume < 0)
volume = 0; volume = 0;
DebugTools.Assert(!float.IsNaN(temp));
_temperature = temp; _temperature = temp;
Moles = moles; Moles = moles;
Volume = volume; Volume = volume;

View File

@@ -28,6 +28,9 @@ namespace Content.Server.Atmos
[ViewVariables] [ViewVariables]
public TileAtmosphere? PressureSpecificTarget { get; set; } public TileAtmosphere? PressureSpecificTarget { get; set; }
/// <summary>
/// This is either the pressure difference, or the quantity of moles transferred if monstermos is enabled.
/// </summary>
[ViewVariables] [ViewVariables]
public float PressureDifference { get; set; } public float PressureDifference { get; set; }

View File

@@ -104,7 +104,6 @@
- key: enum.WiresUiKey.Key - key: enum.WiresUiKey.Key
type: WiresBoundUserInterface type: WiresBoundUserInterface
- type: Airtight - type: Airtight
fixVacuum: true
noAirWhenFullyAirBlocked: false noAirWhenFullyAirBlocked: false
- type: RadiationBlocker - type: RadiationBlocker
resistance: 3 resistance: 3

View File

@@ -80,7 +80,6 @@
- key: enum.WiresUiKey.Key - key: enum.WiresUiKey.Key
type: WiresBoundUserInterface type: WiresBoundUserInterface
- type: Airtight - type: Airtight
fixVacuum: true
- type: Occluder - type: Occluder
- type: Damageable - type: Damageable
damageContainer: StructuralInorganic damageContainer: StructuralInorganic

View File

@@ -57,7 +57,6 @@
denySound: denySound:
path: /Audio/Machines/airlock_deny.ogg path: /Audio/Machines/airlock_deny.ogg
- type: Airtight - type: Airtight
fixVacuum: true
noAirWhenFullyAirBlocked: false noAirWhenFullyAirBlocked: false
- type: Tag - type: Tag
tags: tags:

View File

@@ -93,7 +93,6 @@
- type: Physics - type: Physics
canCollide: false canCollide: false
- type: Airtight - type: Airtight
fixVacuum: true
airBlocked: false airBlocked: false
noAirWhenFullyAirBlocked: true noAirWhenFullyAirBlocked: true
- type: RadiationBlocker - type: RadiationBlocker
@@ -158,7 +157,6 @@
sprite: Structures/Doors/edge_door_hazard.rsi sprite: Structures/Doors/edge_door_hazard.rsi
snapCardinals: false snapCardinals: false
- type: Airtight - type: Airtight
fixVacuum: true
airBlocked: false airBlocked: false
noAirWhenFullyAirBlocked: false noAirWhenFullyAirBlocked: false
airBlockedDirection: airBlockedDirection:

View File

@@ -40,7 +40,6 @@
path: /Audio/Effects/stonedoor_openclose.ogg path: /Audio/Effects/stonedoor_openclose.ogg
- type: Appearance - type: Appearance
- type: Airtight - type: Airtight
fixVacuum: true
- type: Damageable - type: Damageable
damageContainer: Inorganic damageContainer: Inorganic
damageModifierSet: Metallic damageModifierSet: Metallic

View File

@@ -38,7 +38,6 @@
- type: Weldable - type: Weldable
time: 2 time: 2
- type: Airtight - type: Airtight
fixVacuum: true
- type: Damageable - type: Damageable
damageContainer: Inorganic damageContainer: Inorganic
damageModifierSet: Metallic damageModifierSet: Metallic

View File

@@ -59,7 +59,6 @@
- key: enum.WiresUiKey.Key - key: enum.WiresUiKey.Key
type: WiresBoundUserInterface type: WiresBoundUserInterface
- type: Airtight - type: Airtight
fixVacuum: true
- type: RadiationBlocker - type: RadiationBlocker
resistance: 2 resistance: 2
- type: Damageable - type: Damageable

View File

@@ -130,7 +130,6 @@
- type: Appearance - type: Appearance
- type: WiresVisuals - type: WiresVisuals
- type: Airtight - type: Airtight
fixVacuum: true
noAirWhenFullyAirBlocked: false noAirWhenFullyAirBlocked: false
airBlockedDirection: airBlockedDirection:
- South - South

View File

@@ -83,7 +83,6 @@
- !type:DoActsBehavior - !type:DoActsBehavior
acts: ["Destruction"] acts: ["Destruction"]
- type: Airtight - type: Airtight
fixVacuum: true
- type: entity - type: entity
id: PlasticFlapsAirtightOpaque id: PlasticFlapsAirtightOpaque
@@ -101,4 +100,3 @@
- !type:DoActsBehavior - !type:DoActsBehavior
acts: ["Destruction"] acts: ["Destruction"]
- type: Airtight - type: Airtight
fixVacuum: true