Files
tbd-station-14/Content.Server/GameObjects/Components/NodeContainer/NodeGroups/INodeGroupManager.cs
DrSmugleaf 5c0cf1b1a0 Use 'new' expression in places where the type is evident for content (#2590)
* Content.Client

* Content.Benchmarks

* Content.IntegrationTests

* Content.Server

* Content.Server.Database

* Content.Shared

* Content.Tests

* Merge fixes

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2020-11-27 21:00:49 +11:00

38 lines
1.1 KiB
C#

using System.Collections.Generic;
namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{
/// <summary>
/// Maintains a set of <see cref="INodeGroup"/>s that need to be remade with <see cref="INodeGroup.RemakeGroup"/>.
/// Defers remaking to reduce recalculations when a group is altered multiple times in a frame.
/// </summary>
public interface INodeGroupManager
{
/// <summary>
/// Queue up an <see cref="INodeGroup"/> to be remade.
/// </summary>
void AddDirtyNodeGroup(INodeGroup nodeGroup);
void Update(float frameTime);
}
public class NodeGroupManager : INodeGroupManager
{
private readonly HashSet<INodeGroup> _dirtyNodeGroups = new();
public void AddDirtyNodeGroup(INodeGroup nodeGroup)
{
_dirtyNodeGroups.Add(nodeGroup);
}
public void Update(float frameTime)
{
foreach (var group in _dirtyNodeGroups)
{
group.RemakeGroup();
}
_dirtyNodeGroups.Clear();
}
}
}