Add parallel NPC steering back in (#13159)

This commit is contained in:
metalgearsloth
2022-12-24 12:37:58 +11:00
committed by GitHub
parent e884be64fa
commit b78ca238c6
2 changed files with 24 additions and 3 deletions

View File

@@ -61,6 +61,20 @@ public sealed class HTNSystem : EntitySystem
private void OnLoad()
{
// Clear all NPCs in case they're hanging onto stale tasks
foreach (var comp in EntityQuery<HTNComponent>(true))
{
comp.PlanningToken?.Cancel();
comp.PlanningToken = null;
if (comp.Plan != null)
{
var currentOperator = comp.Plan.CurrentOperator;
currentOperator.Shutdown(comp.Blackboard, HTNOperatorStatus.Failed);
comp.Plan = null;
}
}
// Add dependencies for all operators.
// We put code on operators as I couldn't think of a clean way to put it on systems.
foreach (var compound in _prototypeManager.EnumeratePrototypes<HTNCompoundTask>())

View File

@@ -204,12 +204,19 @@ namespace Content.Server.NPC.Systems
var npcs = EntityQuery<NPCSteeringComponent, ActiveNPCComponent, InputMoverComponent, TransformComponent>()
.ToArray();
foreach (var (steering, _, mover, xform) in npcs)
var options = new ParallelOptions
{
MaxDegreeOfParallelism = _parallel.ParallelProcessCount,
};
Parallel.For(0, npcs.Length, options, i =>
{
var (steering, _, mover, xform) = npcs[i];
Steer(steering, mover, xform, modifierQuery, bodyQuery, xformQuery, frameTime);
steering.LastSteer = mover.CurTickSprintMovement;
}
});
if (_subscribedSessions.Count > 0)
{