using System.Runtime.CompilerServices; using Content.Shared.Atmos.Prototypes; namespace Content.Shared.Atmos.EntitySystems; public abstract partial class SharedAtmosphereSystem { /* Partial class for operations involving GasMixtures. Sometimes methods here are abstract because they need different client/server implementations due to sandboxing. */ /// /// Cached array of gas specific heats. /// public float[] GasSpecificHeats => _gasSpecificHeats; private float[] _gasSpecificHeats = new float[Atmospherics.TotalNumberOfGases]; public string?[] GasReagents = new string[Atmospherics.TotalNumberOfGases]; protected readonly GasPrototype[] GasPrototypes = new GasPrototype[Atmospherics.TotalNumberOfGases]; public virtual void InitializeGases() { foreach (var gas in Enum.GetValues()) { var idx = (int)gas; // Log an error if the corresponding prototype isn't found if (!_prototypeManager.TryIndex(gas.ToString(), out var gasPrototype)) { Log.Error($"Failed to find corresponding {nameof(GasPrototype)} for gas ID {(int)gas} ({gas}) with expected ID \"{gas.ToString()}\". Is your prototype named correctly?"); continue; } GasPrototypes[idx] = gasPrototype; GasReagents[idx] = gasPrototype.Reagent; } Array.Resize(ref _gasSpecificHeats, MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4)); for (var i = 0; i < GasPrototypes.Length; i++) { _gasSpecificHeats[i] = GasPrototypes[i].SpecificHeat / HeatScale; } } /// /// Calculates the heat capacity for a gas mixture. /// /// The mixture whose heat capacity should be calculated /// Whether the internal heat capacity scaling should be applied. This should not be /// used outside of atmospheric related heat transfer. /// public float GetHeatCapacity(GasMixture mixture, bool applyScaling) { var scale = GetHeatCapacityCalculation(mixture.Moles, mixture.Immutable); // By default GetHeatCapacityCalculation() has the heat-scale divisor pre-applied. // So if we want the un-scaled heat capacity, we have to multiply by the scale. return applyScaling ? scale : scale * HeatScale; } protected float GetHeatCapacity(GasMixture mixture) { return GetHeatCapacityCalculation(mixture.Moles, mixture.Immutable); } /// /// Gets the heat capacity for a . /// /// The moles array of the /// Whether this represents space, /// and thus experiences space-specific mechanics (we cheat and make it a bit cooler). /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected abstract float GetHeatCapacityCalculation(float[] moles, bool space); }