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