Reduce node resolves (#6435)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -12,11 +12,11 @@ namespace Content.Server.NodeContainer.Nodes
|
||||
/// </summary>
|
||||
public static class NodeHelpers
|
||||
{
|
||||
public static IEnumerable<Node> GetNodesInTile(IEntityManager entMan, IMapGrid grid, Vector2i coords)
|
||||
public static IEnumerable<Node> GetNodesInTile(EntityQuery<NodeContainerComponent> nodeQuery, IMapGrid grid, Vector2i coords)
|
||||
{
|
||||
foreach (var entityUid in grid.GetAnchoredEntities(coords))
|
||||
{
|
||||
if (!entMan.TryGetComponent(entityUid, out NodeContainerComponent? container))
|
||||
if (!nodeQuery.TryGetComponent(entityUid, out var container))
|
||||
continue;
|
||||
|
||||
foreach (var node in container.Nodes.Values)
|
||||
@@ -27,14 +27,14 @@ namespace Content.Server.NodeContainer.Nodes
|
||||
}
|
||||
|
||||
public static IEnumerable<(Direction dir, Node node)> GetCardinalNeighborNodes(
|
||||
IEntityManager entMan,
|
||||
EntityQuery<NodeContainerComponent> nodeQuery,
|
||||
IMapGrid grid,
|
||||
Vector2i coords,
|
||||
bool includeSameTile = true)
|
||||
{
|
||||
foreach (var (dir, entityUid) in GetCardinalNeighborCells(grid, coords, includeSameTile))
|
||||
{
|
||||
if (!entMan.TryGetComponent(entityUid, out NodeContainerComponent? container))
|
||||
if (!nodeQuery.TryGetComponent(entityUid, out var container))
|
||||
continue;
|
||||
|
||||
foreach (var node in container.Nodes.Values)
|
||||
@@ -68,22 +68,5 @@ namespace Content.Server.NodeContainer.Nodes
|
||||
foreach (var uid in grid.GetAnchoredEntities(coords + (-1, 0)))
|
||||
yield return (Direction.West, uid);
|
||||
}
|
||||
|
||||
public static Vector2i TileOffsetForDir(Direction dir)
|
||||
{
|
||||
return dir switch
|
||||
{
|
||||
Direction.Invalid => (0, 0),
|
||||
Direction.South => (0, -1),
|
||||
Direction.SouthEast => (1, -1),
|
||||
Direction.East => (1, 0),
|
||||
Direction.NorthEast => (1, 1),
|
||||
Direction.North => (0, 1),
|
||||
Direction.NorthWest => (-1, 1),
|
||||
Direction.West => (-1, 0),
|
||||
Direction.SouthWest => (-1, -1),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(dir), dir, null)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user