Remove INodeGroupManager, moves logic into NodeGroupSystem.

It was an absolutely redundant IoC service.
This commit is contained in:
Vera Aguilera Puerto
2021-06-01 11:34:01 +02:00
parent 95a4c17952
commit 59a26102c5
4 changed files with 19 additions and 45 deletions

View File

@@ -1,6 +1,8 @@
#nullable enable
using System.Collections.Generic;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.ViewVariables;
@@ -61,7 +63,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{
_nodes.Remove(node);
OnRemoveNode(node);
IoCManager.Resolve<INodeGroupManager>().AddDirtyNodeGroup(this);
EntitySystem.Get<NodeGroupSystem>().AddDirtyNodeGroup(this);
}
public void CombineGroup(INodeGroup newGroup)

View File

@@ -1,38 +0,0 @@
#nullable enable
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();
}
}
}

View File

@@ -1,19 +1,30 @@
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using System.Collections.Generic;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class NodeGroupSystem : EntitySystem
{
[Dependency] private readonly INodeGroupManager _groupManager = default!;
private readonly HashSet<INodeGroup> _dirtyNodeGroups = new();
public void AddDirtyNodeGroup(INodeGroup nodeGroup)
{
_dirtyNodeGroups.Add(nodeGroup);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
_groupManager.Update(frameTime);
foreach (var group in _dirtyNodeGroups)
{
group.RemakeGroup();
}
_dirtyNodeGroups.Clear();
}
}
}

View File

@@ -49,7 +49,6 @@ namespace Content.Server
IoCManager.Register<ActionManager, ActionManager>();
IoCManager.Register<IPDAUplinkManager,PDAUplinkManager>();
IoCManager.Register<INodeGroupFactory, NodeGroupFactory>();
IoCManager.Register<INodeGroupManager, NodeGroupManager>();
IoCManager.Register<IPowerNetManager, PowerNetManager>();
IoCManager.Register<BlackboardManager, BlackboardManager>();
IoCManager.Register<ConsiderationsManager, ConsiderationsManager>();