]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add CVar to disable pow3r parallel processing (#28488)
authorKevin Zheng <kevinz5000@gmail.com>
Tue, 4 Jun 2024 14:54:22 +0000 (06:54 -0800)
committerGitHub <noreply@github.com>
Tue, 4 Jun 2024 14:54:22 +0000 (16:54 +0200)
* Add CVar to disable pow3r parallel processing

* Cache CVar value

* Fix pointyhat

* Move all CVar-ing to Content.Server

Content.Server/Power/EntitySystems/PowerNetSystem.cs
Content.Server/Power/Pow3r/BatteryRampPegSolver.cs
Content.Shared/CCVar/CCVars.cs

index 7bd057951c9b1f6f0d433242f3fba3392a85e166..6c35ba20083ced9036d0f41db7af7892243bc339 100644 (file)
@@ -3,9 +3,11 @@ using Content.Server.NodeContainer.EntitySystems;
 using Content.Server.Power.Components;
 using Content.Server.Power.NodeGroups;
 using Content.Server.Power.Pow3r;
+using Content.Shared.CCVar;
 using Content.Shared.Power;
 using JetBrains.Annotations;
 using Robust.Server.GameObjects;
+using Robust.Shared.Configuration;
 using Robust.Shared.Threading;
 
 namespace Content.Server.Power.EntitySystems
@@ -18,6 +20,7 @@ namespace Content.Server.Power.EntitySystems
     {
         [Dependency] private readonly AppearanceSystem _appearance = default!;
         [Dependency] private readonly PowerNetConnectorSystem _powerNetConnector = default!;
+        [Dependency] private readonly IConfigurationManager _cfg = default!;
         [Dependency] private readonly IParallelManager _parMan = default!;
         [Dependency] private readonly PowerReceiverSystem _powerReceiver = default!;
 
@@ -25,13 +28,14 @@ namespace Content.Server.Power.EntitySystems
         private readonly HashSet<PowerNet> _powerNetReconnectQueue = new();
         private readonly HashSet<ApcNet> _apcNetReconnectQueue = new();
 
-        private readonly BatteryRampPegSolver _solver = new();
+        private BatteryRampPegSolver _solver = new();
 
         public override void Initialize()
         {
             base.Initialize();
 
             UpdatesAfter.Add(typeof(NodeGroupSystem));
+            _solver = new(_cfg.GetCVar(CCVars.DebugPow3rDisableParallel));
 
             SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentInit>(ApcPowerReceiverInit);
             SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentShutdown>(ApcPowerReceiverShutdown);
@@ -53,6 +57,13 @@ namespace Content.Server.Power.EntitySystems
             SubscribeLocalEvent<PowerSupplierComponent, ComponentShutdown>(PowerSupplierShutdown);
             SubscribeLocalEvent<PowerSupplierComponent, EntityPausedEvent>(PowerSupplierPaused);
             SubscribeLocalEvent<PowerSupplierComponent, EntityUnpausedEvent>(PowerSupplierUnpaused);
+
+            Subs.CVar(_cfg, CCVars.DebugPow3rDisableParallel, DebugPow3rDisableParallelChanged);
+        }
+
+        private void DebugPow3rDisableParallelChanged(bool val)
+        {
+            _solver = new(val);
         }
 
         private void ApcPowerReceiverInit(EntityUid uid, ApcPowerReceiverComponent component, ComponentInit args)
index 12118968b70ff6c3443850950f4fe4bba99e55ca..599c55b6ba4bd44bc6f90ab520561cbedd2ef22d 100644 (file)
@@ -9,9 +9,11 @@ namespace Content.Server.Power.Pow3r
     public sealed class BatteryRampPegSolver : IPowerSolver
     {
         private UpdateNetworkJob _networkJob;
+        private bool _disableParallel;
 
-        public BatteryRampPegSolver()
+        public BatteryRampPegSolver(bool disableParallel = false)
         {
+            _disableParallel = disableParallel;
             _networkJob = new()
             {
                 Solver = this,
@@ -56,7 +58,10 @@ namespace Content.Server.Power.Pow3r
                 // suppliers + discharger) Then decide based on total layer size whether its worth parallelizing that
                 // layer?
                 _networkJob.Networks = group;
-                parallel.ProcessNow(_networkJob, group.Count);
+                if (_disableParallel)
+                    parallel.ProcessSerialNow(_networkJob, group.Count);
+                else
+                    parallel.ProcessNow(_networkJob, group.Count);
             }
 
             ClearBatteries(state);
index f41e0a1e6f1026012392f58e99b7c264375a8c97..b3da71fde1a444c77f8734791b12199a0b418688 100644 (file)
@@ -2062,5 +2062,11 @@ namespace Content.Shared.CCVar
         /// </summary>
         public static readonly CVarDef<bool> DebugOptionVisualizerTest =
             CVarDef.Create("debug.option_visualizer_test", false, CVar.CLIENTONLY);
+
+        /// <summary>
+        /// Set to true to disable parallel processing in the pow3r solver.
+        /// </summary>
+        public static readonly CVarDef<bool> DebugPow3rDisableParallel =
+            CVarDef.Create("debug.pow3r_disable_parallel", true, CVar.SERVERONLY);
     }
 }