Revert parallel steering (#13085)

This commit is contained in:
metalgearsloth
2022-12-19 18:46:27 +11:00
committed by GitHub
parent 2ba9eb66ff
commit c656e051c2
3 changed files with 8 additions and 12 deletions

View File

@@ -44,8 +44,10 @@ public sealed class NPCSteeringComponent : Component
/// <summary> /// <summary>
/// Last time the NPC steered. /// Last time the NPC steered.
/// </summary> /// </summary>
[ViewVariables]
public TimeSpan LastTimeSteer; public TimeSpan LastTimeSteer;
[ViewVariables]
public Vector2 LastSteer; public Vector2 LastSteer;
/// <summary> /// <summary>

View File

@@ -50,6 +50,7 @@ namespace Content.Server.NPC.Pathfinding
private readonly Dictionary<ICommonSession, PathfindingDebugMode> _subscribedSessions = new(); private readonly Dictionary<ICommonSession, PathfindingDebugMode> _subscribedSessions = new();
[ViewVariables]
private readonly List<PathRequest> _pathRequests = new(PathTickLimit); private readonly List<PathRequest> _pathRequests = new(PathTickLimit);
private static readonly TimeSpan PathTime = TimeSpan.FromMilliseconds(3); private static readonly TimeSpan PathTime = TimeSpan.FromMilliseconds(3);

View File

@@ -134,6 +134,7 @@ namespace Content.Server.NPC.Systems
{ {
// Cancel any active pathfinding jobs as they're irrelevant. // Cancel any active pathfinding jobs as they're irrelevant.
component.PathfindToken?.Cancel(); component.PathfindToken?.Cancel();
component.PathfindToken = null;
} }
/// <summary> /// <summary>
@@ -203,18 +204,12 @@ namespace Content.Server.NPC.Systems
var npcs = EntityQuery<NPCSteeringComponent, ActiveNPCComponent, InputMoverComponent, TransformComponent>() var npcs = EntityQuery<NPCSteeringComponent, ActiveNPCComponent, InputMoverComponent, TransformComponent>()
.ToArray(); .ToArray();
var options = new ParallelOptions
{
MaxDegreeOfParallelism = _parallel.ParallelProcessCount,
};
Parallel.For(0, npcs.Length, options, i => foreach (var (steering, _, mover, xform) in npcs)
{ {
var (steering, _, mover, xform) = npcs[i];
Steer(steering, mover, xform, modifierQuery, bodyQuery, xformQuery, frameTime); Steer(steering, mover, xform, modifierQuery, bodyQuery, xformQuery, frameTime);
steering.LastSteer = mover.CurTickSprintMovement; steering.LastSteer = mover.CurTickSprintMovement;
}); }
if (_subscribedSessions.Count > 0) if (_subscribedSessions.Count > 0)
{ {
@@ -261,8 +256,6 @@ namespace Content.Server.NPC.Systems
EntityQuery<TransformComponent> xformQuery, EntityQuery<TransformComponent> xformQuery,
float frameTime) float frameTime)
{ {
IoCManager.InitThread(_dependencies, replaceExisting: true);
if (Deleted(steering.Coordinates.EntityId)) if (Deleted(steering.Coordinates.EntityId))
{ {
SetDirection(mover, steering, Vector2.Zero); SetDirection(mover, steering, Vector2.Zero);
@@ -400,10 +393,11 @@ namespace Content.Server.NPC.Systems
steering.PathfindToken.Token, steering.PathfindToken.Token,
flags); flags);
steering.PathfindToken = null;
if (result.Result == PathResult.NoPath) if (result.Result == PathResult.NoPath)
{ {
steering.CurrentPath.Clear(); steering.CurrentPath.Clear();
steering.PathfindToken = null;
steering.FailedPathCount++; steering.FailedPathCount++;
if (steering.FailedPathCount >= NPCSteeringComponent.FailedPathLimit) if (steering.FailedPathCount >= NPCSteeringComponent.FailedPathLimit)
@@ -419,7 +413,6 @@ namespace Content.Server.NPC.Systems
PrunePath(ourPos, targetPos.Position - ourPos.Position, result.Path); PrunePath(ourPos, targetPos.Position - ourPos.Position, result.Path);
steering.CurrentPath = result.Path; steering.CurrentPath = result.Path;
steering.PathfindToken = null;
} }
// TODO: Move these to movercontroller // TODO: Move these to movercontroller