Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity, fixes. #18792

Merged
merged 1 commit into from Dec 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 21 additions & 14 deletions OpenRA.Game/Activities/Activity.cs
Expand Up @@ -74,7 +74,7 @@ internal static Activity SkipDoneActivities(Activity first)
// drop valid activities queued after it. Walk the queue until we find a valid activity or
// (more likely) run out of activities.
while (first != null && first.State == ActivityState.Done)
first = first.NextActivity;
first = first.nextActivity;

return first;
}
Expand Down Expand Up @@ -120,7 +120,8 @@ public Activity TickOuter(Actor self)
lastRun = Tick(self);

// Avoid a single tick delay if the childactivity was just queued.
if (ChildActivity != null && ChildActivity.State == ActivityState.Queued)
var ca = ChildActivity;
if (ca != null && ca.State == ActivityState.Queued)
Comment on lines -123 to +124
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that this is note done in the optimization? Ie have you checked the IL?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm far from an expert at understanding IL, but this does appear to be evaluating ChildActivity twice on bleed:

// if ChildActivity != null
	IL_00c2:  ldarg.0 
	IL_00c3:  call instance class OpenRA.Activities.Activity class OpenRA.Activities.Activity::get_ChildActivity()
	IL_00c8:  brfalse.s IL_0101

// if ChildActivity.State == ActivityState.Queued
	IL_00ca:  ldarg.0 
	IL_00cb:  call instance class OpenRA.Activities.Activity class OpenRA.Activities.Activity::get_ChildActivity()
	IL_00d0:  callvirt instance valuetype OpenRA.Activities.ActivityState class OpenRA.Activities.Activity::get_State()
	IL_00d5:  brtrue.s IL_0101

// if ChildHasPriority
	IL_00d7:  ldarg.0 
	IL_00d8:  call instance bool class OpenRA.Activities.Activity::get_ChildHasPriority()
	IL_00dd:  brfalse.s IL_00f9

{
if (ChildHasPriority)
lastRun = TickChild(self) && finishing;
Expand Down Expand Up @@ -206,18 +207,18 @@ public virtual void Cancel(Actor self, bool keepQueue = false)

public void Queue(Activity activity)
{
if (NextActivity != null)
NextActivity.Queue(activity);
else
NextActivity = activity;
var it = this;
while (it.nextActivity != null)
it = it.nextActivity;
it.nextActivity = activity;
}

public void QueueChild(Activity activity)
{
if (ChildActivity != null)
ChildActivity.Queue(activity);
if (childActivity != null)
childActivity.Queue(activity);
else
ChildActivity = activity;
childActivity = activity;
}

/// <summary>
Expand Down Expand Up @@ -269,15 +270,21 @@ public IEnumerable<string> DebugLabelComponents()

public IEnumerable<T> ActivitiesImplementing<T>(bool includeChildren = true) where T : IActivityInterface
{
if (includeChildren && ChildActivity != null)
foreach (var a in ChildActivity.ActivitiesImplementing<T>())
yield return a;
// Skips Done child and next activities
if (includeChildren)
{
var ca = ChildActivity;
if (ca != null)
foreach (var a in ca.ActivitiesImplementing<T>())
yield return a;
}

if (this is T)
yield return (T)(object)this;

if (NextActivity != null)
foreach (var a in NextActivity.ActivitiesImplementing<T>())
var na = NextActivity;
if (na != null)
foreach (var a in na.ActivitiesImplementing<T>())
yield return a;
}
}
Expand Down