Add OnActorDispose plumbing to Activity
This allows activities to perform necessary cleanups on actor death/disposal, for example by running OnLastRun directly, which would otherwise be skipped when the actor dies or is disposed through other means.
This commit is contained in:
@@ -200,6 +200,24 @@ namespace OpenRA.Activities
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnLastRun(Actor self) { }
|
protected virtual void OnLastRun(Actor self) { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs once on Actor.Dispose() (through OnActorDisposeOuter) and can be used to perform activity clean-up on actor death/disposal,
|
||||||
|
/// for example by force-triggering OnLastRun (which would otherwise be skipped).
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnActorDispose(Actor self) { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs once on Actor.Dispose().
|
||||||
|
/// Main purpose is to ensure ChildActivity.OnActorDispose runs as well (which isn't otherwise accessible due to protection level).
|
||||||
|
/// </summary>
|
||||||
|
internal void OnActorDisposeOuter(Actor self)
|
||||||
|
{
|
||||||
|
if (ChildActivity != null)
|
||||||
|
ChildActivity.OnActorDisposeOuter(self);
|
||||||
|
|
||||||
|
OnActorDispose(self);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool Cancel(Actor self, bool keepQueue = false)
|
public virtual bool Cancel(Actor self, bool keepQueue = false)
|
||||||
{
|
{
|
||||||
if (!IsInterruptible)
|
if (!IsInterruptible)
|
||||||
|
|||||||
@@ -265,6 +265,11 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
// If CurrentActivity isn't null, run OnActorDisposeOuter in case some cleanups are needed.
|
||||||
|
// This should be done before the FrameEndTask to avoid dependency issues.
|
||||||
|
if (CurrentActivity != null)
|
||||||
|
CurrentActivity.RootActivity.OnActorDisposeOuter(this);
|
||||||
|
|
||||||
World.AddFrameEndTask(w =>
|
World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (Disposed)
|
if (Disposed)
|
||||||
|
|||||||
Reference in New Issue
Block a user