Parallelize BatteryRampPegSolver (#12351)

This commit is contained in:
Leon Friedrich
2022-11-09 14:43:45 +13:00
committed by GitHub
parent 4a68db4eb2
commit eebb31493c
11 changed files with 546 additions and 250 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using ImGuiNET;
using Robust.Shared.Maths;
@@ -52,6 +52,7 @@ namespace Pow3r
{
var network = new Network();
_state.Networks.Allocate(out network.Id) = network;
_state.GroupedNets = null;
_displayNetworks.Add(network.Id, new DisplayNetwork());
}
@@ -60,6 +61,7 @@ namespace Pow3r
var battery = new Battery();
_state.Batteries.Allocate(out battery.Id) = battery;
_displayBatteries.Add(battery.Id, new DisplayBattery());
_state.GroupedNets = null;
}
Checkbox("Paused", ref _paused);
@@ -270,7 +272,8 @@ namespace Pow3r
{
if (battery.LinkedNetworkCharging == default && Button("Link as load"))
{
_linking.BatteriesCharging.Add(battery.Id);
_linking.BatteryLoads.Add(battery.Id);
_state.GroupedNets = null;
_linking = null;
RefreshLinks();
}
@@ -279,7 +282,8 @@ namespace Pow3r
SameLine();
if (battery.LinkedNetworkDischarging == default && Button("Link as supply"))
{
_linking.BatteriesDischarging.Add(battery.Id);
_linking.BatterySupplies.Add(battery.Id);
_state.GroupedNets = null;
_linking = null;
RefreshLinks();
}
@@ -290,7 +294,8 @@ namespace Pow3r
if (battery.LinkedNetworkCharging != default && Button("Unlink loading"))
{
var net = _state.Networks[battery.LinkedNetworkCharging];
net.BatteriesCharging.Remove(battery.Id);
net.BatteryLoads.Remove(battery.Id);
_state.GroupedNets = null;
battery.LinkedNetworkCharging = default;
}
else
@@ -299,7 +304,8 @@ namespace Pow3r
if (battery.LinkedNetworkDischarging != default && Button("Unlink supplying"))
{
var net = _state.Networks[battery.LinkedNetworkDischarging];
net.BatteriesDischarging.Remove(battery.Id);
net.BatterySupplies.Remove(battery.Id);
_state.GroupedNets = null;
battery.LinkedNetworkDischarging = default;
}
}
@@ -331,13 +337,13 @@ namespace Pow3r
DrawArrowLine(bgDrawList, load.CurrentWindowPos, displayNet.CurrentWindowPos, Color.Red);
}
foreach (var batteryId in network.BatteriesCharging)
foreach (var batteryId in network.BatteryLoads)
{
var battery = _displayBatteries[batteryId];
DrawArrowLine(bgDrawList, battery.CurrentWindowPos, displayNet.CurrentWindowPos, Color.Purple);
}
foreach (var batteryId in network.BatteriesDischarging)
foreach (var batteryId in network.BatterySupplies)
{
var battery = _displayBatteries[batteryId];
DrawArrowLine(bgDrawList, displayNet.CurrentWindowPos, battery.CurrentWindowPos, Color.Cyan);
@@ -357,6 +363,7 @@ namespace Pow3r
case Network n:
_state.Networks.Free(n.Id);
_displayNetworks.Remove(n.Id);
_state.GroupedNets = null;
reLink = true;
break;
@@ -374,9 +381,10 @@ namespace Pow3r
case Battery b:
_state.Batteries.Free(b.Id);
_state.Networks.Values.ForEach(n => n.BatteriesCharging.Remove(b.Id));
_state.Networks.Values.ForEach(n => n.BatteriesDischarging.Remove(b.Id));
_state.Networks.Values.ForEach(n => n.BatteryLoads.Remove(b.Id));
_state.Networks.Values.ForEach(n => n.BatterySupplies.Remove(b.Id));
_displayBatteries.Remove(b.Id);
_state.GroupedNets = null;
break;
}
}