Disables the AI Pathfinding system for the time being.

This commit is contained in:
Víctor Aguilera Puerto
2020-08-10 03:33:05 +02:00
parent 6a06358012
commit ec75baeede

View File

@@ -37,9 +37,9 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
public IReadOnlyDictionary<GridId, Dictionary<MapIndices, PathfindingChunk>> Graph => _graph; public IReadOnlyDictionary<GridId, Dictionary<MapIndices, PathfindingChunk>> Graph => _graph;
private readonly Dictionary<GridId, Dictionary<MapIndices, PathfindingChunk>> _graph = new Dictionary<GridId, Dictionary<MapIndices, PathfindingChunk>>(); private readonly Dictionary<GridId, Dictionary<MapIndices, PathfindingChunk>> _graph = new Dictionary<GridId, Dictionary<MapIndices, PathfindingChunk>>();
private readonly PathfindingJobQueue _pathfindingQueue = new PathfindingJobQueue(); private readonly PathfindingJobQueue _pathfindingQueue = new PathfindingJobQueue();
// Queued pathfinding graph updates // Queued pathfinding graph updates
private readonly Queue<CollisionChangeMessage> _collidableUpdateQueue = new Queue<CollisionChangeMessage>(); private readonly Queue<CollisionChangeMessage> _collidableUpdateQueue = new Queue<CollisionChangeMessage>();
private readonly Queue<MoveEvent> _moveUpdateQueue = new Queue<MoveEvent>(); private readonly Queue<MoveEvent> _moveUpdateQueue = new Queue<MoveEvent>();
@@ -50,11 +50,11 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
private readonly Dictionary<EntityUid, PathfindingNode> _lastKnownPositions = new Dictionary<EntityUid, PathfindingNode>(); private readonly Dictionary<EntityUid, PathfindingNode> _lastKnownPositions = new Dictionary<EntityUid, PathfindingNode>();
public const int TrackedCollisionLayers = (int) public const int TrackedCollisionLayers = (int)
(CollisionGroup.Impassable | (CollisionGroup.Impassable |
CollisionGroup.MobImpassable | CollisionGroup.MobImpassable |
CollisionGroup.SmallImpassable | CollisionGroup.SmallImpassable |
CollisionGroup.VaultImpassable); CollisionGroup.VaultImpassable);
/// <summary> /// <summary>
/// Ask for the pathfinder to gimme somethin /// Ask for the pathfinder to gimme somethin
/// </summary> /// </summary>
@@ -83,7 +83,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
private void ProcessGraphUpdates() private void ProcessGraphUpdates()
{ {
var totalUpdates = 0; var totalUpdates = 0;
foreach (var update in _collidableUpdateQueue) foreach (var update in _collidableUpdateQueue)
{ {
var entity = _entitymanager.GetEntity(update.Owner); var entity = _entitymanager.GetEntity(update.Owner);
@@ -98,7 +98,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
totalUpdates++; totalUpdates++;
} }
_collidableUpdateQueue.Clear(); _collidableUpdateQueue.Clear();
foreach (var update in _accessReaderUpdateQueue) foreach (var update in _accessReaderUpdateQueue)
@@ -115,7 +115,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
totalUpdates++; totalUpdates++;
} }
_accessReaderUpdateQueue.Clear(); _accessReaderUpdateQueue.Clear();
foreach (var tile in _tileUpdateQueue) foreach (var tile in _tileUpdateQueue)
@@ -123,10 +123,10 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
HandleTileUpdate(tile); HandleTileUpdate(tile);
totalUpdates++; totalUpdates++;
} }
_tileUpdateQueue.Clear(); _tileUpdateQueue.Clear();
var moveUpdateCount = Math.Max(50 - totalUpdates, 0); var moveUpdateCount = Math.Max(50 - totalUpdates, 0);
// Other updates are high priority so for this we'll just defer it if there's a spike (explosion, etc.) // Other updates are high priority so for this we'll just defer it if there's a spike (explosion, etc.)
// If the move updates grow too large then we'll just do it // If the move updates grow too large then we'll just do it
if (_moveUpdateQueue.Count > 100) if (_moveUpdateQueue.Count > 100)
@@ -135,12 +135,12 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
} }
moveUpdateCount = Math.Min(moveUpdateCount, _moveUpdateQueue.Count); moveUpdateCount = Math.Min(moveUpdateCount, _moveUpdateQueue.Count);
for (var i = 0; i < moveUpdateCount; i++) for (var i = 0; i < moveUpdateCount; i++)
{ {
HandleCollidableMove(_moveUpdateQueue.Dequeue()); HandleCollidableMove(_moveUpdateQueue.Dequeue());
} }
DebugTools.Assert(_moveUpdateQueue.Count < 1000); DebugTools.Assert(_moveUpdateQueue.Count < 1000);
} }
@@ -171,10 +171,10 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{ {
_graph.Add(gridId, new Dictionary<MapIndices, PathfindingChunk>()); _graph.Add(gridId, new Dictionary<MapIndices, PathfindingChunk>());
} }
_graph[gridId].Add(indices, newChunk); _graph[gridId].Add(indices, newChunk);
newChunk.Initialize(_mapManager.GetGrid(gridId)); newChunk.Initialize(_mapManager.GetGrid(gridId));
return newChunk; return newChunk;
} }
@@ -204,6 +204,9 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
public override void Initialize() public override void Initialize()
{ {
// TODO: Remove this once the memory leaks are solved.
return;
SubscribeLocalEvent<CollisionChangeMessage>(QueueCollisionChangeMessage); SubscribeLocalEvent<CollisionChangeMessage>(QueueCollisionChangeMessage);
SubscribeLocalEvent<MoveEvent>(QueueMoveEvent); SubscribeLocalEvent<MoveEvent>(QueueMoveEvent);
SubscribeLocalEvent<AccessReaderChangeMessage>(QueueAccessChangeMessage); SubscribeLocalEvent<AccessReaderChangeMessage>(QueueAccessChangeMessage);
@@ -221,12 +224,12 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
UnsubscribeLocalEvent<CollisionChangeMessage>(); UnsubscribeLocalEvent<CollisionChangeMessage>();
UnsubscribeLocalEvent<MoveEvent>(); UnsubscribeLocalEvent<MoveEvent>();
UnsubscribeLocalEvent<AccessReaderChangeMessage>(); UnsubscribeLocalEvent<AccessReaderChangeMessage>();
_mapManager.OnGridRemoved -= HandleGridRemoval; _mapManager.OnGridRemoved -= HandleGridRemoval;
_mapManager.GridChanged -= QueueGridChange; _mapManager.GridChanged -= QueueGridChange;
_mapManager.TileChanged -= QueueTileChange; _mapManager.TileChanged -= QueueTileChange;
} }
private void HandleTileUpdate(TileRef tile) private void HandleTileUpdate(TileRef tile)
{ {
var node = GetNode(tile); var node = GetNode(tile);
@@ -280,7 +283,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{ {
return; return;
} }
var grid = _mapManager.GetGrid(entity.Transform.GridID); var grid = _mapManager.GetGrid(entity.Transform.GridID);
var tileRef = grid.GetTileRef(entity.Transform.GridPosition); var tileRef = grid.GetTileRef(entity.Transform.GridPosition);
@@ -313,7 +316,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
private void HandleCollidableMove(MoveEvent moveEvent) private void HandleCollidableMove(MoveEvent moveEvent)
{ {
var entityUid = moveEvent.Sender.Uid; var entityUid = moveEvent.Sender.Uid;
if (!_lastKnownPositions.TryGetValue(entityUid, out var oldNode)) if (!_lastKnownPositions.TryGetValue(entityUid, out var oldNode))
{ {
return; return;
@@ -326,7 +329,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
HandleEntityRemove(moveEvent.Sender); HandleEntityRemove(moveEvent.Sender);
return; return;
} }
var newTile = _mapManager.GetGrid(moveEvent.NewPosition.GridID).GetTileRef(moveEvent.NewPosition); var newTile = _mapManager.GetGrid(moveEvent.NewPosition.GridID).GetTileRef(moveEvent.NewPosition);
if (oldNode == null || oldNode.TileRef == newTile) if (oldNode == null || oldNode.TileRef == newTile)
@@ -365,7 +368,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
} }
var access = AccessReader.FindAccessTags(entity); var access = AccessReader.FindAccessTags(entity);
foreach (var reader in node.AccessReaders) foreach (var reader in node.AccessReaders)
{ {
if (!reader.IsAllowed(access)) if (!reader.IsAllowed(access))