Files
tbd-station-14/Content.Server/GameObjects/Components/Power/PowerNetComponents/IPowerNetManager.cs
collinlunn b51b8cb182 Some Power nullable & ComponentDependency (#3050)
* Power nullability

* AME nullability

* re-adds EnsureComponents

* conflict fix

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* removes duplicate component assignment

Co-authored-by: py01 <pyronetics01@gmail.com>
Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>
2021-02-01 17:19:43 +01:00

40 lines
1.2 KiB
C#

#nullable enable
using System.Collections.Generic;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
{
/// <summary>
/// Maintains a set of <see cref="IPowerNet"/>s that need to be updated with <see cref="IPowerNet.UpdateConsumerReceivedPower"/>.
/// Defers updating to reduce recalculations when a group is altered multiple times in a frame.
/// </summary>
public interface IPowerNetManager
{
/// <summary>
/// Queue up an <see cref="IPowerNet"/> to be updated.
/// </summary>
void AddDirtyPowerNet(IPowerNet powerNet);
void Update(float frameTime);
}
public class PowerNetManager : IPowerNetManager
{
private readonly HashSet<IPowerNet> _dirtyPowerNets = new();
public void AddDirtyPowerNet(IPowerNet powerNet)
{
_dirtyPowerNets.Add(powerNet);
}
public void Update(float frameTime)
{
foreach (var powerNet in _dirtyPowerNets)
{
powerNet.UpdateConsumerReceivedPower();
}
_dirtyPowerNets.Clear();
}
}
}