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
{
[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!;
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);
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)
public sealed class BatteryRampPegSolver : IPowerSolver
{
private UpdateNetworkJob _networkJob;
+ private bool _disableParallel;
- public BatteryRampPegSolver()
+ public BatteryRampPegSolver(bool disableParallel = false)
{
+ _disableParallel = disableParallel;
_networkJob = new()
{
Solver = this,
// 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);
/// </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);
}
}