Add parallel NPC steering back in (#13159)
This commit is contained in:
@@ -61,6 +61,20 @@ public sealed class HTNSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnLoad()
|
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.
|
// Add dependencies for all operators.
|
||||||
// We put code on operators as I couldn't think of a clean way to put it on systems.
|
// 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>())
|
foreach (var compound in _prototypeManager.EnumeratePrototypes<HTNCompoundTask>())
|
||||||
|
|||||||
@@ -204,12 +204,19 @@ 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
|
||||||
foreach (var (steering, _, mover, xform) in npcs)
|
|
||||||
{
|
{
|
||||||
|
MaxDegreeOfParallelism = _parallel.ParallelProcessCount,
|
||||||
|
};
|
||||||
|
|
||||||
|
Parallel.For(0, npcs.Length, options, i =>
|
||||||
|
{
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user