]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add atmos time compression (#21954)
authorKevin Zheng <kevinz5000@gmail.com>
Mon, 11 Dec 2023 23:59:47 +0000 (15:59 -0800)
committerGitHub <noreply@github.com>
Mon, 11 Dec 2023 23:59:47 +0000 (15:59 -0800)
Add atmos.speedup which is effectively a atmos-only time compression
CVar. This adjusts heat capacities and transfer rates to effectively
globally speed up the time constants of atmos.

This allows faster response to heating/cooling changes and faster
cleanups (by buffing scrubbers, pumps, and everything else) that is
tunable through one global time compression CVar.

It also achieves this without any thermodynamic unsoundness.

16 files changed:
Content.Server/Atmos/EntitySystems/AirFilterSystem.cs
Content.Server/Atmos/EntitySystems/AtmosphereSystem.CVars.cs
Content.Server/Atmos/EntitySystems/AtmosphereSystem.Gases.cs
Content.Server/Atmos/Piping/Binary/EntitySystems/GasRecyclerSystem.cs
Content.Server/Atmos/Piping/Binary/EntitySystems/GasVolumePumpSystem.cs
Content.Server/Atmos/Piping/Trinary/EntitySystems/GasFilterSystem.cs
Content.Server/Atmos/Piping/Trinary/EntitySystems/PressureControlledValveSystem.cs
Content.Server/Atmos/Piping/Unary/EntitySystems/GasOutletInjectorSystem.cs
Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs
Content.Server/Atmos/Portable/PortableScrubberSystem.cs
Content.Server/Atmos/Reactions/FrezonCoolantReaction.cs
Content.Server/Atmos/Reactions/PlasmaFireReaction.cs
Content.Server/Atmos/Reactions/TritiumFireReaction.cs
Content.Shared/CCVar/CCVars.cs
Resources/Prototypes/Entities/Structures/Piping/Atmospherics/unary.yml
Resources/Prototypes/Entities/Structures/Power/Generation/teg.yml

index a7404c08f4538af8ff7dde7fa05ab03cdd9f4ef6..6230a184d7d502d7a0380ccc2fb7278e2e20708c 100644 (file)
@@ -56,7 +56,7 @@ public sealed class AirFilterSystem : EntitySystem
         if (!GetAir(uid, out var air))
             return;
 
-        var ratio = MathF.Min(1f, args.dt * filter.TransferRate);
+        var ratio = MathF.Min(1f, args.dt * filter.TransferRate * _atmosphere.PumpSpeedup());
         var removed = air.RemoveRatio(ratio);
         // nothing left to remove from the volume
         if (MathHelper.CloseToPercent(removed.TotalMoles, 0f))
index 60e215204d455261f7712e47d41ac6e140648a3d..1da90545059ecb63f1329a0683658a75535c9b17 100644 (file)
@@ -24,6 +24,7 @@ namespace Content.Server.Atmos.EntitySystems
         public bool ExcitedGroupsSpaceIsAllConsuming { get; private set; }
         public float AtmosMaxProcessTime { get; private set; }
         public float AtmosTickRate { get; private set; }
+        public float Speedup { get; private set; }
 
         /// <summary>
         /// Time between each atmos sub-update.  If you are writing an atmos device, use AtmosDeviceUpdateEvent.dt
@@ -49,6 +50,7 @@ namespace Content.Server.Atmos.EntitySystems
             _cfg.OnValueChanged(CCVars.Superconduction, value => Superconduction = value, true);
             _cfg.OnValueChanged(CCVars.AtmosMaxProcessTime, value => AtmosMaxProcessTime = value, true);
             _cfg.OnValueChanged(CCVars.AtmosTickRate, value => AtmosTickRate = value, true);
+            _cfg.OnValueChanged(CCVars.AtmosSpeedup, value => Speedup = value, true);
             _cfg.OnValueChanged(CCVars.ExcitedGroups, value => ExcitedGroups = value, true);
             _cfg.OnValueChanged(CCVars.ExcitedGroupsSpaceIsAllConsuming, value => ExcitedGroupsSpaceIsAllConsuming = value, true);
         }
index 0726606ae043f18aa9502e2ae223262236b8a546..afed8e223c0e46fd4dca6e66cda231289a3a3487 100644 (file)
@@ -59,7 +59,17 @@ namespace Content.Server.Atmos.EntitySystems
 
             Span<float> tmp = stackalloc float[moles.Length];
             NumericsHelpers.Multiply(moles, GasSpecificHeats, tmp);
-            return MathF.Max(NumericsHelpers.HorizontalAdd(tmp), Atmospherics.MinimumHeatCapacity);
+            // Adjust heat capacity by speedup, because this is primarily what
+            // determines how quickly gases heat up/cool.
+            return MathF.Max(NumericsHelpers.HorizontalAdd(tmp), Atmospherics.MinimumHeatCapacity) / Speedup;
+        }
+
+        /// <summary>
+        ///     Return speedup factor for pumped or flow-based devices that depend on MaxTransferRate.
+        /// </summary>
+        public float PumpSpeedup()
+        {
+            return MathF.Sqrt(Speedup);
         }
 
         /// <summary>
index 359123aabf216244d37a77565097284ca1de6ea0..5ee239936c934bf2000e478d13227b4ecc434509 100644 (file)
@@ -105,7 +105,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
                 return 0;
             }
             float overPressConst = 300; // pressure difference (in atm) to get 200 L/sec transfer rate
-            float alpha = Atmospherics.MaxTransferRate / (float)Math.Sqrt(overPressConst*Atmospherics.OneAtmosphere);
+            float alpha = Atmospherics.MaxTransferRate * _atmosphereSystem.PumpSpeedup() / (float)Math.Sqrt(overPressConst*Atmospherics.OneAtmosphere);
             return alpha * (float)Math.Sqrt(inlet.Pressure - outlet.Pressure);
         }
 
index 3cfbda27af329e4db4a4c34d4c9d6dde7ab8f041..eb4fcf183e33228a498ad2166c15e6557be6c835 100644 (file)
@@ -105,7 +105,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
                 return;
 
             // We multiply the transfer rate in L/s by the seconds passed since the last process to get the liters.
-            var removed = inlet.Air.RemoveVolume(pump.TransferRate * args.dt);
+            var removed = inlet.Air.RemoveVolume(pump.TransferRate * _atmosphereSystem.PumpSpeedup() * args.dt);
 
             // Some of the gas from the mixture leaks when overclocked.
             if (pump.Overclocked)
index 7032e7fe0e969a5ca58ef95b15e28e3455b3c00a..62df033f9324ecb3d702ea8f53990ef594d581a3 100644 (file)
@@ -65,7 +65,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
             }
 
             // We multiply the transfer rate in L/s by the seconds passed since the last process to get the liters.
-            var transferVol = filter.TransferRate * args.dt;
+            var transferVol = filter.TransferRate * _atmosphereSystem.PumpSpeedup() * args.dt;
 
             if (transferVol <= 0)
             {
index ceea449a31212c4475ec46ebb5ec3a0cbbad9cdc..e805a4d0aedac8d79f0b2604e7a26dfb34345486 100644 (file)
@@ -62,7 +62,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
             else
             {
                 comp.Enabled = true;
-                transferRate = Math.Min(control * comp.Gain, comp.MaxTransferRate);
+                transferRate = Math.Min(control * comp.Gain, comp.MaxTransferRate * _atmosphereSystem.PumpSpeedup());
             }
             UpdateAppearance(uid, comp);
 
index adde584cc3907860901defe096d85dbc01ac81a2..45771b49d3c5c950c2cf0e8d3ead02d541baa41a 100644 (file)
@@ -73,7 +73,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
             var timeDelta = args.dt;
 
             // TODO adjust ratio so that environment does not go above MaxPressure?
-            var ratio = MathF.Min(1f, timeDelta * injector.TransferRate / inlet.Air.Volume);
+            var ratio = MathF.Min(1f, timeDelta * injector.TransferRate * _atmosphereSystem.PumpSpeedup() / inlet.Air.Volume);
             var removed = inlet.Air.RemoveRatio(ratio);
 
             _atmosphereSystem.Merge(environment, removed);
index d63b521a35f8777de6cef594f036b7ccc73c1b38..37c8358a6f1962b1ce1a333e2d87e4cda93f11f6 100644 (file)
@@ -90,7 +90,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
 
         private void Scrub(float timeDelta, GasVentScrubberComponent scrubber, GasMixture? tile, PipeNode outlet)
         {
-            Scrub(timeDelta, scrubber.TransferRate, scrubber.PumpDirection, scrubber.FilterGases, tile, outlet.Air);
+            Scrub(timeDelta, scrubber.TransferRate*_atmosphereSystem.PumpSpeedup(), scrubber.PumpDirection, scrubber.FilterGases, tile, outlet.Air);
         }
 
         /// <summary>
index 17e2ae591f9422bd9c586e6fe1d14081f709b030..3e72b75f14f6ed8b192bd0b5832ba6b21afb5c1b 100644 (file)
@@ -145,7 +145,7 @@ namespace Content.Server.Atmos.Portable
 
         private bool Scrub(float timeDelta, PortableScrubberComponent scrubber, GasMixture? tile)
         {
-            return _scrubberSystem.Scrub(timeDelta, scrubber.TransferRate, ScrubberPumpDirection.Scrubbing, scrubber.FilterGases, tile, scrubber.Air);
+            return _scrubberSystem.Scrub(timeDelta, scrubber.TransferRate * _atmosphereSystem.PumpSpeedup(), ScrubberPumpDirection.Scrubbing, scrubber.FilterGases, tile, scrubber.Air);
         }
 
         private void UpdateAppearance(EntityUid uid, bool isFull, bool isRunning)
index 36a0f28686a80a7522ac2828632edf17065460f4..ce134126be9a71bf4f43f5a5a99c0c4c0d009e5a 100644 (file)
@@ -45,6 +45,7 @@ public sealed partial class FrezonCoolantReaction : IGasReactionEffect
             energyReleased = burnRate * Atmospherics.FrezonCoolEnergyReleased * energyModifier;
         }
 
+        energyReleased /= atmosphereSystem.Speedup; // adjust energy to make sure speedup doesn't cause mega temperature rise
         if (energyReleased >= 0f)
             return ReactionResult.NoReaction;
 
index 6aae69b2f25d03c36b0ec2ffdfea21fd8bfeb0a4..9553b5ebfbed5cd3e0244b82b21096cca04a5743 100644 (file)
@@ -56,6 +56,7 @@ namespace Content.Server.Atmos.Reactions
                     mixture.AdjustMoles(Gas.CarbonDioxide, plasmaBurnRate * (1.0f - supersaturation));
 
                     energyReleased += Atmospherics.FirePlasmaEnergyReleased * plasmaBurnRate;
+                    energyReleased /= atmosphereSystem.Speedup; // adjust energy to make sure speedup doesn't cause mega temperature rise
                     mixture.ReactionResults[GasReaction.Fire] += plasmaBurnRate * (1 + oxygenBurnRate);
                 }
             }
index cc58f0cf7de4e90e425bc983f10fcb77c182b29c..78a149aa25ddc86ef53e9a82f1738c01f4e6f308 100644 (file)
@@ -47,6 +47,7 @@ namespace Content.Server.Atmos.Reactions
                 mixture.ReactionResults[GasReaction.Fire] += burnedFuel;
             }
 
+            energyReleased /= atmosphereSystem.Speedup; // adjust energy to make sure speedup doesn't cause mega temperature rise
             if (energyReleased > 0)
             {
                 var newHeatCapacity = atmosphereSystem.GetHeatCapacity(mixture);
index dc35ee4368b6b431d142a72432d505f376d06e30..3014bbce0be86906099096a5be0dc3ad969980be 100644 (file)
@@ -1044,6 +1044,15 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<float> AtmosTickRate =
             CVarDef.Create("atmos.tickrate", 15f, CVar.SERVERONLY);
 
+        /// <summary>
+        ///     Scale factor for how fast things happen in our atmosphere
+        ///     simulation compared to real life. 1x means that a room takes as
+        ///     long to heat up in game as real life. Players typically expect
+        ///     things to happen faster in-game.
+        /// </summary>
+        public static readonly CVarDef<float> AtmosSpeedup =
+            CVarDef.Create("atmos.speedup", 64f, CVar.SERVERONLY);
+
         /*
          * MIDI instruments
          */
index 1d08bd8c6e57e5fe154e0dc48bf66c1796615424..0fdad5d9670108be91fe8fc76c8e72ba48d29fc3 100644 (file)
             True: { state: freezerOn }
             False: { state: freezerOff }
     - type: GasThermoMachine
-      coefficientOfPerformance: -64
+      coefficientOfPerformance: -3.9
     - type: ApcPowerReceiver
       powerDisabled: true #starts off
     - type: Machine
             True: { state: heaterOn }
             False: { state: heaterOff }
     - type: GasThermoMachine
-      coefficientOfPerformance: 32
+      coefficientOfPerformance: 0.95
     - type: ApcPowerReceiver
       powerDisabled: true #starts off
     - type: Machine
index 090a015d9737edf580040be57f540d16bdbcb437..723a1480de1b2e9e70b59a96b430cd376fbc3fcc 100644 (file)
@@ -57,7 +57,6 @@
     # It fires processing on behalf of its connected circulators.
     - type: AtmosDevice
     - type: TegGenerator
-      powerFactor: 0.025
 
     - type: DeviceNetwork
       deviceNetId: AtmosDevices