Fix namespaces and optimize imports (#1651)

* Fix namespaces and optimize imports

* Cleanup fixes

* Merge conflict fixes

* Merge conflict fixes

* Merge conflict fixes
This commit is contained in:
DrSmugleaf
2020-08-13 14:40:27 +02:00
committed by GitHub
parent 05a76d55f7
commit 4a8ed41e3a
500 changed files with 1044 additions and 1557 deletions

View File

@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Pathfinders;
using Content.Server.GameObjects.EntitySystems.Pathfinding;
using Content.Shared.AI;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
@@ -75,7 +73,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
// Plus this way we can check if everything is equal except for vision so an entity with a lower vision radius can use an entity with a higher vision radius' cached result
private Dictionary<ReachableArgs, Dictionary<PathfindingRegion, (TimeSpan CacheTime, HashSet<PathfindingRegion> Regions)>> _cachedAccessible =
new Dictionary<ReachableArgs, Dictionary<PathfindingRegion, (TimeSpan, HashSet<PathfindingRegion>)>>();
private readonly List<PathfindingRegion> _queuedCacheDeletions = new List<PathfindingRegion>();
#if DEBUG
@@ -91,7 +89,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
#endif
_mapmanager.OnGridRemoved += GridRemoved;
}
private void GridRemoved(GridId gridId)
{
_regions.Remove(gridId);
@@ -457,7 +455,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
/// <param name="y">This is already calculated in advance so may as well re-use it</param>
/// <returns></returns>
private PathfindingRegion CalculateNode(
PathfindingNode node,
PathfindingNode node,
Dictionary<PathfindingNode, PathfindingRegion> existingRegions,
HashSet<PathfindingRegion> chunkRegions,
int x, int y)
@@ -497,15 +495,15 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
!leftRegion.IsDoor)
{
// We'll try and connect the left node's region to the bottom region if they're separate (yay merge)
if (bottomNeighbor != null &&
if (bottomNeighbor != null &&
existingRegions.TryGetValue(bottomNeighbor, out bottomRegion) &&
bottomRegion != leftRegion &&
bottomRegion != leftRegion &&
!bottomRegion.IsDoor)
{
bottomRegion.Add(node);
existingRegions.Add(node, bottomRegion);
MergeInto(leftRegion, bottomRegion, existingRegions);
// Cleanup leftRegion
// MergeInto will remove it from the overall region chunk cache while we need to remove it from
// our short-term ones (chunkRegions and existingRegions)
@@ -515,7 +513,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
existingRegions[leftNode] = bottomRegion;
}
return bottomRegion;
}
@@ -549,7 +547,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
/// </summary>
/// <param name="source"></param>
/// <param name="target"></param>
private void MergeInto(PathfindingRegion source, PathfindingRegion target, Dictionary<PathfindingNode, PathfindingRegion> existingRegions = null)
private void MergeInto(PathfindingRegion source, PathfindingRegion target, Dictionary<PathfindingNode, PathfindingRegion> existingRegions = null)
{
DebugTools.AssertNotNull(source);
DebugTools.AssertNotNull(target);
@@ -586,7 +584,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
private void ClearCache(PathfindingRegion region)
{
DebugTools.Assert(region.Deleted);
// Need to forcibly clear cache for ourself and anything that includes us
foreach (var (_, cachedRegions) in _cachedAccessible)
{
@@ -599,7 +597,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
// We could just have GetVisionAccessible remove us if it can tell we're deleted but that
// seems like it could be unreliable
var regionsToClear = new List<PathfindingRegion>();
foreach (var (otherRegion, cache) in cachedRegions)
{
if (cache.Regions.Contains(region))
@@ -613,9 +611,9 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
cachedRegions.Remove(otherRegion);
}
}
#if DEBUG
if (_regions.TryGetValue(region.ParentChunk.GridId, out var chunks) &&
if (_regions.TryGetValue(region.ParentChunk.GridId, out var chunks) &&
chunks.TryGetValue(region.ParentChunk, out var regions))
{
DebugTools.Assert(!regions.Contains(region));
@@ -642,7 +640,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
_queuedCacheDeletions.Add(region);
region.Shutdown();
}
_regions[chunk.GridId].Remove(chunk);
}
@@ -673,7 +671,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
DebugTools.Assert(!region.Deleted);
}
DebugTools.Assert(chunkRegions.Count < Math.Pow(PathfindingChunk.ChunkSize, 2));
SendRegionsDebugMessage(chunk.GridId);
#endif

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Pathfinders;
using Content.Server.GameObjects.EntitySystems.Pathfinding;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Map;
@@ -36,7 +35,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
startNode = pathfindingSystem.GetNode(pathfindingArgs.End);
}
PathfindingNode currentNode;
openTiles.Enqueue(startNode);
@@ -49,13 +48,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
// No distances stored so can just check closed tiles here
if (closedTiles.Contains(neighbor.TileRef)) continue;
closedTiles.Add(currentNode.TileRef);
// So currently tileCost gets the octile distance between the 2 so we'll also use that for our range check
var tileCost = PathfindingHelpers.GetTileCost(pathfindingArgs, startNode, neighbor);
var direction = PathfindingHelpers.RelativeDirection(neighbor, currentNode);
if (tileCost == null ||
tileCost > pathfindingArgs.Proximity ||
if (tileCost == null ||
tileCost > pathfindingArgs.Proximity ||
!PathfindingHelpers.DirectionTraversable(pathfindingArgs.CollisionMask, pathfindingArgs.Access, currentNode, direction))
{
continue;
@@ -67,4 +66,4 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
}
}
}
}
}

View File

@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Content.Server.GameObjects.EntitySystems.Pathfinding;
using Robust.Shared.Utility;
namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
@@ -16,7 +13,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
/// Bottom-left reference node of the region
/// </summary>
public PathfindingNode OriginNode { get; }
// The shape may be anything within the bounds of a chunk, this is just a quick way to do a bounds-check
/// <summary>
@@ -49,13 +46,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
// Tell our neighbors we no longer exist ;-/
var neighbors = new List<PathfindingRegion>(Neighbors);
for (var i = 0; i < neighbors.Count; i++)
{
var neighbor = neighbors[i];
neighbor.Neighbors.Remove(this);
}
_nodes.Clear();
Neighbors.Clear();
@@ -81,7 +78,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
xDistance = Math.Abs(xDistance + otherRegion.Width);
}
if (yDistance > 0)
{
yDistance -= Height;
@@ -90,7 +87,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
yDistance = Math.Abs(yDistance + otherRegion.Height);
}
return PathfindingHelpers.OctileDistance(xDistance, yDistance);
}
@@ -121,10 +118,10 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
Height = yHeight;
}
_nodes.Add(node);
}
// HashSet wasn't working correctly so uhh we got this.
public bool Equals(PathfindingRegion other)
{
@@ -141,4 +138,4 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
return OriginNode.GetHashCode();
}
}
}
}