Reduce node resolves (#6435)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.NodeContainer;
|
||||
using Content.Server.NodeContainer.Nodes;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -12,21 +12,23 @@ namespace Content.Server.Power.Nodes
|
||||
[DataDefinition]
|
||||
public class CableNode : Node
|
||||
{
|
||||
public override IEnumerable<Node> GetReachableNodes()
|
||||
public override IEnumerable<Node> GetReachableNodes(TransformComponent xform,
|
||||
EntityQuery<NodeContainerComponent> nodeQuery,
|
||||
EntityQuery<TransformComponent> xformQuery,
|
||||
IMapGrid? grid,
|
||||
IEntityManager entMan)
|
||||
{
|
||||
if (!Anchored)
|
||||
if (!xform.Anchored || grid == null)
|
||||
yield break;
|
||||
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
var grid = IoCManager.Resolve<IMapManager>().GetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).GridID);
|
||||
var gridIndex = grid.TileIndicesFor(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
var gridIndex = grid.TileIndicesFor(xform.Coordinates);
|
||||
|
||||
// While we go over adjacent nodes, we build a list of blocked directions due to
|
||||
// incoming or outgoing wire terminals.
|
||||
var terminalDirs = 0;
|
||||
List<(Direction, Node)> nodeDirs = new();
|
||||
|
||||
foreach (var (dir, node) in NodeHelpers.GetCardinalNeighborNodes(entMan, grid, gridIndex))
|
||||
foreach (var (dir, node) in NodeHelpers.GetCardinalNeighborNodes(nodeQuery, grid, gridIndex))
|
||||
{
|
||||
if (node is CableNode && node != this)
|
||||
{
|
||||
@@ -44,11 +46,11 @@ namespace Content.Server.Power.Nodes
|
||||
if (dir == Direction.Invalid)
|
||||
{
|
||||
// On own tile, block direction it faces
|
||||
terminalDirs |= 1 << (int) IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(node.Owner).LocalRotation.GetCardinalDir();
|
||||
terminalDirs |= 1 << (int) xformQuery.GetComponent(node.Owner).LocalRotation.GetCardinalDir();
|
||||
}
|
||||
else
|
||||
{
|
||||
var terminalDir = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(node.Owner).LocalRotation.GetCardinalDir();
|
||||
var terminalDir = xformQuery.GetComponent(node.Owner).LocalRotation.GetCardinalDir();
|
||||
if (terminalDir.GetOpposite() == dir)
|
||||
{
|
||||
// Target tile has a terminal towards us, block the direction.
|
||||
|
||||
Reference in New Issue
Block a user