Reduce power allocations

It was the 2nd and 3rd highest traffic for memory allocs.
This commit is contained in:
Metal Gear Sloth
2020-09-03 19:35:09 +10:00
parent 0a1d41d53a
commit 363bfb595f

View File

@@ -35,8 +35,6 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
[ViewVariables] [ViewVariables]
private int TotalReceivers => _providerReceivers.SelectMany(kvp => kvp.Value).Count(); private int TotalReceivers => _providerReceivers.SelectMany(kvp => kvp.Value).Count();
private IEnumerable<BatteryComponent> AvailableBatteries => _apcBatteries.Where(kvp => kvp.Key.MainBreakerEnabled).Select(kvp => kvp.Value);
public static readonly IApcNet NullNet = new NullApcNet(); public static readonly IApcNet NullNet = new NullApcNet();
#region IApcNet Methods #region IApcNet Methods
@@ -88,8 +86,11 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{ {
var totalCharge = 0.0; var totalCharge = 0.0;
var totalMaxCharge = 0; var totalMaxCharge = 0;
foreach (var battery in AvailableBatteries) foreach (var (apc, battery) in _apcBatteries)
{ {
if (!apc.MainBreakerEnabled)
continue;
totalCharge += battery.CurrentCharge; totalCharge += battery.CurrentCharge;
totalMaxCharge += battery.MaxCharge; totalMaxCharge += battery.MaxCharge;
} }
@@ -102,8 +103,11 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
private bool TryUsePower(float neededCharge) private bool TryUsePower(float neededCharge)
{ {
foreach (var battery in AvailableBatteries) foreach (var (apc, battery) in _apcBatteries)
{ {
if (!apc.MainBreakerEnabled)
continue;
if (battery.TryUseCharge(neededCharge)) //simplification - all power needed must come from one battery if (battery.TryUseCharge(neededCharge)) //simplification - all power needed must come from one battery
{ {
return true; return true;