Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry Pick WizDen PR #28488 #1194

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Content.Server/Power/EntitySystems/PowerNetSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
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
Expand All @@ -18,19 +20,21 @@ public sealed class PowerNetSystem : EntitySystem
{
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly PowerNetConnectorSystem _powerNetConnector = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IParallelManager _parMan = default!;

private readonly PowerState _powerState = new();
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);
Expand All @@ -52,6 +56,13 @@ public override void Initialize()
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)
Expand Down
9 changes: 7 additions & 2 deletions Content.Server/Power/Pow3r/BatteryRampPegSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,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,
Expand Down Expand Up @@ -54,7 +56,10 @@ public void Tick(float frameTime, PowerState state, IParallelManager parallel)
// 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);
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2634,5 +2634,11 @@ public static readonly CVarDef<float>
CVarDef.Create("ghost.allow_same_character", false, CVar.SERVERONLY);

#endregion

/// <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);
}
}
Loading