Pathfinder parallel change (#18736)

This commit is contained in:
metalgearsloth
2023-08-06 14:41:57 +10:00
committed by GitHub
parent 1d0160d158
commit cc5d83fe21
3 changed files with 11 additions and 11 deletions

View File

@@ -84,7 +84,7 @@ public sealed partial class PathfindingSystem
component.Chunks.Clear(); component.Chunks.Clear();
} }
private void UpdateGrid() private void UpdateGrid(ParallelOptions options)
{ {
if (PauseUpdating) if (PauseUpdating)
return; return;
@@ -94,10 +94,6 @@ public sealed partial class PathfindingSystem
var updateCount = 0; var updateCount = 0;
#endif #endif
_stopwatch.Restart(); _stopwatch.Restart();
var options = new ParallelOptions()
{
MaxDegreeOfParallelism = 1,
};
// We defer chunk updates because rebuilding a navmesh is hella costly // We defer chunk updates because rebuilding a navmesh is hella costly
// Still run even when paused. // Still run even when paused.
@@ -157,10 +153,9 @@ public sealed partial class PathfindingSystem
var doorQuery = GetEntityQuery<DoorComponent>(); var doorQuery = GetEntityQuery<DoorComponent>();
var climbableQuery = GetEntityQuery<ClimbableComponent>(); var climbableQuery = GetEntityQuery<ClimbableComponent>();
var fixturesQuery = GetEntityQuery<FixturesComponent>(); var fixturesQuery = GetEntityQuery<FixturesComponent>();
var physicsQuery = GetEntityQuery<PhysicsComponent>();
var xformQuery = GetEntityQuery<TransformComponent>(); var xformQuery = GetEntityQuery<TransformComponent>();
BuildBreadcrumbs(dirt[i], mapGridComp, accessQuery, destructibleQuery, doorQuery, climbableQuery, BuildBreadcrumbs(dirt[i], mapGridComp, accessQuery, destructibleQuery, doorQuery, climbableQuery,
fixturesQuery, physicsQuery, xformQuery); fixturesQuery, xformQuery);
}); });
const int Division = 4; const int Division = 4;
@@ -427,7 +422,6 @@ public sealed partial class PathfindingSystem
EntityQuery<DoorComponent> doorQuery, EntityQuery<DoorComponent> doorQuery,
EntityQuery<ClimbableComponent> climbableQuery, EntityQuery<ClimbableComponent> climbableQuery,
EntityQuery<FixturesComponent> fixturesQuery, EntityQuery<FixturesComponent> fixturesQuery,
EntityQuery<PhysicsComponent> physicsQuery,
EntityQuery<TransformComponent> xformQuery) EntityQuery<TransformComponent> xformQuery)
{ {
var sw = new Stopwatch(); var sw = new Stopwatch();

View File

@@ -85,12 +85,18 @@ namespace Content.Server.NPC.Pathfinding
public override void Update(float frameTime) public override void Update(float frameTime)
{ {
base.Update(frameTime); base.Update(frameTime);
UpdateGrid(); var options = new ParallelOptions()
{
MaxDegreeOfParallelism = _parallel.ParallelProcessCount,
};
UpdateGrid(options);
_stopwatch.Restart(); _stopwatch.Restart();
var amount = Math.Min(PathTickLimit, _pathRequests.Count); var amount = Math.Min(PathTickLimit, _pathRequests.Count);
var results = ArrayPool<PathResult>.Shared.Rent(amount); var results = ArrayPool<PathResult>.Shared.Rent(amount);
Parallel.For(0, amount, i =>
Parallel.For(0, amount, options, i =>
{ {
// If we're over the limit (either time-sliced or hard cap). // If we're over the limit (either time-sliced or hard cap).
if (_stopwatch.Elapsed >= PathTime) if (_stopwatch.Elapsed >= PathTime)

View File

@@ -254,7 +254,7 @@ public sealed partial class NPCSteeringSystem : SharedNPCSteeringSystem
// Dependency issues across threads. // Dependency issues across threads.
var options = new ParallelOptions var options = new ParallelOptions
{ {
MaxDegreeOfParallelism = _parallel.ParallelProcessCount, MaxDegreeOfParallelism = 1,
}; };
var curTime = _timing.CurTime; var curTime = _timing.CurTime;