Introduce MoveCooldownHelper to prevent lag spikes from failed pathfinding

Several activities that queue child Move activities can get into a bad scenario where the actor is pathfinding and then gets stuck because the destination is unreachable. When the Move activity then completes, then parent activity sees it has yet to reach the destination and tries to move again. However, the actor is still blocked in the same spot as before and thus the movment finishes immediately. This causes a performance death spiral where the actor attempts to pathfind every tick. The pathfinding attempt can also be very expensive if it must exhaustively check the whole map to determine no route is possible.

In order to prevent blocked actors from running into this scenario, we introduce MoveCooldownHelper. In its default setup it allows the parent activity to bail out if the actor was blocked during a pathfinding attempt. This means the activity will be dropped rather than trying to move endlessly. It also has an option to allow retrying if pathfinding was blocked, but applies a cooldown to avoid the performance penalty. For activities such as Enter, this means the actors will still try and enter their target if it is unreachable, but will only attempt once a second now rather than every tick.

MoveAdjacentTo will now cancel if it fails to reach the destination. This fixes MoveOntoAndTurn to skip the Turn if the move didn't reach the intended destination. Any other derived classes will similarly benefit from skipping follow-up actions.
This commit is contained in:
RoosterDragon
2024-04-07 15:02:53 +01:00
committed by Gustas
parent fe35c42ead
commit 2ed0656d1b
16 changed files with 239 additions and 47 deletions

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Terrain;
using OpenRA.Mods.Common.Widgets;
@@ -262,7 +263,7 @@ namespace OpenRA.Mods.Common.Traits
void OnDockCompleted(Actor self, Actor clientActor, DockClientManager client);
/// <summary>If <paramref name="client"/> is not in range of <see cref="IDockHost"/> queues a child move activity and returns true. If in range returns false.</summary>
bool QueueMoveActivity(Activity moveToDockActivity, Actor self, Actor clientActor, DockClientManager client);
bool QueueMoveActivity(Activity moveToDockActivity, Actor self, Actor clientActor, DockClientManager client, MoveCooldownHelper moveCooldownHelper);
/// <summary>Should be called when in range of <see cref="IDockHost"/>.</summary>
void QueueDockActivity(Activity moveToDockActivity, Actor self, Actor clientActor, DockClientManager client);
@@ -728,6 +729,14 @@ namespace OpenRA.Mods.Common.Traits
Turn = 4
}
public enum MoveResult
{
InProgress,
CompleteCanceled,
CompleteDestinationReached,
CompleteDestinationBlocked,
}
[RequireExplicitImplementation]
public interface INotifyMoving
{