ECS Atmos Part 2: Moves a lot of Gas Mixture methods to AtmosphereSystem. (#4218)

This commit is contained in:
Vera Aguilera Puerto
2021-06-23 11:35:30 +02:00
committed by GitHub
parent e16c23a747
commit 263c9ef974
34 changed files with 461 additions and 464 deletions

View File

@@ -1,4 +1,5 @@
#nullable enable
using Content.Server.Atmos.EntitySystems;
using Content.Server.Temperature.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.ViewVariables;
@@ -23,14 +24,15 @@ namespace Content.Server.Atmos.Components
[ViewVariables]
[ComponentDependency] private readonly FlammableComponent? _flammableComponent = null;
public void Update(TileAtmosphere tile, float frameDelta)
public void Update(TileAtmosphere tile, float frameDelta, AtmosphereSystem atmosphereSystem)
{
if (_temperatureComponent != null)
{
if (tile.Air != null)
{
var temperatureDelta = tile.Air.Temperature - _temperatureComponent.CurrentTemperature;
var heat = temperatureDelta * (tile.Air.HeatCapacity * _temperatureComponent.HeatCapacity / (tile.Air.HeatCapacity + _temperatureComponent.HeatCapacity));
var tileHeatCapacity = atmosphereSystem.GetHeatCapacity(tile.Air);
var heat = temperatureDelta * (tileHeatCapacity * _temperatureComponent.HeatCapacity / (tileHeatCapacity + _temperatureComponent.HeatCapacity));
_temperatureComponent.ReceiveHeat(heat);
}
_temperatureComponent.Update();

View File

@@ -204,9 +204,9 @@ namespace Content.Server.Atmos.Components
{
var gas = atmosSystem.GetGas(i);
if (tile.Gases[i] <= Atmospherics.GasMinMoles) continue;
if (tile.Moles[i] <= Atmospherics.GasMinMoles) continue;
gases.Add(new GasEntry(gas.Name, tile.Gases[i], gas.Color));
gases.Add(new GasEntry(gas.Name, tile.Moles[i], gas.Color));
}
UserInterface.SetState(

View File

@@ -1,6 +1,7 @@
#nullable enable
#nullable disable warnings
using System;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Respiratory;
using Content.Server.Explosion;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
@@ -155,13 +156,6 @@ namespace Content.Server.Atmos.Components
DisconnectFromInternals();
}
public void Update()
{
Air?.React(this);
CheckStatus();
UpdateUserInterface();
}
public GasMixture? RemoveAir(float amount)
{
var gas = Air?.Remove(amount);
@@ -223,7 +217,7 @@ namespace Content.Server.Atmos.Components
UpdateUserInterface();
}
private void UpdateUserInterface(bool initialUpdate = false)
public void UpdateUserInterface(bool initialUpdate = false)
{
var internals = GetInternalsComponent();
_userInterface?.SetState(
@@ -279,15 +273,17 @@ namespace Content.Server.Atmos.Components
public void AssumeAir(GasMixture giver)
{
Air?.Merge(giver);
EntitySystem.Get<AtmosphereSystem>().Merge(Air, giver);
CheckStatus();
}
private void CheckStatus()
public void CheckStatus()
{
if (Air == null)
return;
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var pressure = Air.Pressure;
if (pressure > TankFragmentPressure)
@@ -295,7 +291,7 @@ namespace Content.Server.Atmos.Components
// Give the gas a chance to build up more pressure.
for (var i = 0; i < 3; i++)
{
Air.React(this);
atmosphereSystem.React(Air, this);
}
pressure = Air.Pressure;

View File

@@ -7,6 +7,7 @@ using System.Linq;
using System.Runtime.CompilerServices;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Piping.Components;
using Content.Server.CPUJob.JobQueues.Queues;
using Content.Server.NodeContainer.NodeGroups;
using Content.Shared.Atmos;
using Content.Shared.Maps;
@@ -204,7 +205,7 @@ namespace Content.Server.Atmos.Components
foreach (var tile in mapGrid.Grid.GetAllTiles())
{
if(!Tiles.ContainsKey(tile.GridIndices))
Tiles.Add(tile.GridIndices, new TileAtmosphere(this, tile.GridIndex, tile.GridIndices, new GasMixture(GetVolumeForCells(1), AtmosphereSystem){Temperature = Atmospherics.T20C}));
Tiles.Add(tile.GridIndices, new TileAtmosphere(this, tile.GridIndex, tile.GridIndices, new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C}));
Invalidate(tile.GridIndices);
}
@@ -230,7 +231,7 @@ namespace Content.Server.Atmos.Components
if (tile == null)
{
tile = new TileAtmosphere(this, _gridId, indices, new GasMixture(GetVolumeForCells(1), AtmosphereSystem){Temperature = Atmospherics.T20C});
tile = new TileAtmosphere(this, _gridId, indices, new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C});
Tiles[indices] = tile;
}
@@ -238,7 +239,7 @@ namespace Content.Server.Atmos.Components
if (IsSpace(indices) && !isAirBlocked)
{
tile.Air = new GasMixture(GetVolumeForCells(1), AtmosphereSystem);
tile.Air = new GasMixture(GetVolumeForCells(1));
tile.Air.MarkImmutable();
Tiles[indices] = tile;
@@ -271,7 +272,7 @@ namespace Content.Server.Atmos.Components
tile.Air = null;
}
tile.Air ??= new GasMixture(GetVolumeForCells(1), AtmosphereSystem){Temperature = Atmospherics.T20C};
tile.Air ??= new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C};
}
// By removing the active tile, we effectively remove its excited group, if any.
@@ -312,7 +313,7 @@ namespace Content.Server.Atmos.Components
if (tile?.GridIndex != _gridId) return;
// includeAirBlocked is false, therefore all tiles in this have Air != null.
var adjacent = GetAdjacentTiles(indices);
tile.Air = new GasMixture(GetVolumeForCells(1), AtmosphereSystem){Temperature = Atmospherics.T20C};
tile.Air = new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.T20C};
Tiles[indices] = tile;
var ratio = 1f / adjacent.Count;
@@ -320,8 +321,8 @@ namespace Content.Server.Atmos.Components
foreach (var (_, adj) in adjacent)
{
var mix = adj.Air!.RemoveRatio(ratio);
tile.Air.Merge(mix);
adj.Air.Merge(mix);
AtmosphereSystem.Merge(tile.Air, mix);
AtmosphereSystem.Merge(adj.Air, mix);
}
}
@@ -435,7 +436,7 @@ namespace Content.Server.Atmos.Components
// We don't have that tile!
if (IsSpace(indices) && createSpace)
{
return new TileAtmosphere(this, _gridId, indices, new GasMixture(GetVolumeForCells(1), AtmosphereSystem){Temperature = Atmospherics.TCMB}, true);
return new TileAtmosphere(this, _gridId, indices, new GasMixture(GetVolumeForCells(1)){Temperature = Atmospherics.TCMB}, true);
}
return null;

View File

@@ -1,6 +1,7 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using Content.Shared.Atmos;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -22,7 +23,7 @@ namespace Content.Server.Atmos.Components
public override TileAtmosphere GetTile(Vector2i indices, bool createSpace = true)
{
return new(this, GridId.Invalid, indices, new GasMixture(2500, AtmosphereSystem), true);
return new(this, GridId.Invalid, indices, new GasMixture(Atmospherics.CellVolume), true);
}
protected override IEnumerable<AirtightComponent> GetObstructingComponents(Vector2i indices)