Gas moles may never be below the minimum amount of moles again.

A few atmos tweaks and fixes. Should(?) fix the NaN issue that can't be replicated.
This commit is contained in:
Víctor Aguilera Puerto 2020-11-26 12:39:13 +01:00
parent e21356ad93
commit 4b77f27e77
2 changed files with 31 additions and 11 deletions

View File

@ -120,8 +120,8 @@ namespace Content.Server.Atmos
public GasMixture(AtmosphereSystem? atmosphereSystem)
{
_atmosphereSystem = atmosphereSystem ?? EntitySystem.Get<AtmosphereSystem>();
_moles = new float[MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4)];
_molesArchived = new float[_moles.Length];
_moles = new float[Atmospherics.AdjustedNumberOfGases];
_molesArchived = new float[Atmospherics.AdjustedNumberOfGases];
}
public GasMixture(float volume, AtmosphereSystem? atmosphereSystem = null): this(atmosphereSystem)
@ -222,6 +222,15 @@ namespace Content.Server.Atmos
if (!Immutable)
NumericsHelpers.Sub(_moles, removed._moles);
for (var i = 0; i < _moles.Length; i++)
{
if (_moles[i] < Atmospherics.GasMinMoles)
_moles[i] = 0;
if (removed._moles[i] < Atmospherics.GasMinMoles)
removed._moles[i] = 0;
}
return removed;
}
@ -508,19 +517,17 @@ namespace Content.Server.Atmos
public void ExposeData(ObjectSerializer serializer)
{
var length = MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4);
serializer.DataField(this, x => Immutable, "immutable", false);
serializer.DataField(this, x => Volume, "volume", 0f);
serializer.DataField(this, x => LastShare, "lastShare", 0f);
serializer.DataField(this, x => TemperatureArchived, "temperatureArchived", 0f);
serializer.DataField(ref _moles, "moles", new float[length]);
serializer.DataField(ref _molesArchived, "molesArchived", new float[length]);
serializer.DataField(ref _moles, "moles", new float[Atmospherics.AdjustedNumberOfGases]);
serializer.DataField(ref _molesArchived, "molesArchived", new float[Atmospherics.AdjustedNumberOfGases]);
serializer.DataField(ref _temperature, "temperature", Atmospherics.TCMB);
// The arrays MUST have a specific length.
Array.Resize(ref _moles, length);
Array.Resize(ref _molesArchived, length);
Array.Resize(ref _moles, Atmospherics.AdjustedNumberOfGases);
Array.Resize(ref _molesArchived, Atmospherics.AdjustedNumberOfGases);
}
public override bool Equals(object? obj)

View File

@ -1,10 +1,17 @@
namespace Content.Shared.Atmos
using Robust.Shared.Maths;
namespace Content.Shared.Atmos
{
/// <summary>
/// Class to store atmos constants.
/// </summary>
public class Atmospherics
public static class Atmospherics
{
static Atmospherics()
{
AdjustedNumberOfGases = MathHelper.NextMultipleOf(TotalNumberOfGases, 4);
}
#region ATMOS
/// <summary>
/// The universal gas constant, in kPa*L/(K*mol)
@ -144,7 +151,13 @@
/// <summary>
/// Total number of gases. Increase this if you want to add more!
/// </summary>
public const byte TotalNumberOfGases = 6;
public const int TotalNumberOfGases = 6;
/// <summary>
/// This is the actual length of the gases arrays in mixtures.
/// Set to the closest multiple of 4 relative to <see cref="TotalNumberOfGases"/> for SIMD reasons.
/// </summary>
public static readonly int AdjustedNumberOfGases;
/// <summary>
/// Amount of heat released per mole of burnt hydrogen or tritium (hydrogen isotope)