Skip to content

Commit

Permalink
Set Mobile.IsMoving to "true" if queueing a turn that takes only a si…
Browse files Browse the repository at this point in the history
…ngle tick

At the end of L-turns, actors often end up with an internal facing not 100% matching the direction of the next cell on their path.
As a result, if they haven't reached their destination yet, Move queues a quick Turn as ChildActivity, which previously was not considered as IsMoving.
However, we don't want those mini-turns to interrupt move animations, so we now consider them a move as well. Additionally, to avoid any issues, we make these mini-turns non-interruptible, just like the MovePart activities already are.
  • Loading branch information
reaperrr committed Jun 9, 2018
1 parent 4338fc7 commit 4524229
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 15 additions & 1 deletion OpenRA.Mods.Common/Activities/Move/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,21 @@ public override Activity Tick(Actor self)
if (firstFacing != mobile.Facing)
{
path.Add(nextCell.Value.First);
QueueChild(new Turn(self, firstFacing));

// HACK: To fix visual hiccups on actors with move animations during "L-turn to next part of movement" transitions
// or invisible mini-turns (due to less sprite facings than internal facings), we set IsMoving to 'true' during Turn activity
// when the facing delta is low enough to be covered with a single Turn tick.
// To avoid issues, we make these mini-turns uninterruptible (like MovePart activities) to ensure the actor
// finishes that mini-turn before starting something else.
var facingWithinTolerance = Util.FacingWithinTolerance(mobile.Facing, firstFacing, mobile.TurnSpeed);
if (facingWithinTolerance)
{
mobile.IsMoving = true;
QueueChild(new Turn(self, firstFacing, false));
}
else
QueueChild(new Turn(self, firstFacing));

ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
return this;
}
Expand Down
10 changes: 10 additions & 0 deletions OpenRA.Mods.Common/Activities/Turn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,15 @@ public override Activity Tick(Actor self)

return this;
}

protected override void OnLastRun(Actor self)
{
// If Mobile.IsMoving was set to 'true' from the parent Move activity, we want to reset it to 'false' before the next tick,
// but as late as possible on this tick, to make sure any places looking up IsMoving will still see it as 'true'
// on the last tick this activity runs.
var mobile = self.TraitOrDefault<Mobile>();
if (mobile != null && mobile.IsMoving)
self.World.AddFrameEndTask(w => mobile.IsMoving = false);
}
}
}

0 comments on commit 4524229

Please sign in to comment.