Simplify MovePart code

InnerActivity and UpdateCenterLocation made this
overly complex and hard to read & debug.

This also fixes a bug that would make an outdated
facing being passed during OnComplete (because
InnerActivity was cached before UpdateCenterLocation
could set the correct final facing).
This commit is contained in:
reaperrr
2021-03-06 14:55:32 +01:00
committed by teinarss
parent a9661a233a
commit 646495fc5f

View File

@@ -435,34 +435,19 @@ namespace OpenRA.Mods.Common.Activities
public override bool Tick(Actor self) public override bool Tick(Actor self)
{ {
var ret = InnerTick(self, Move.mobile); var mobile = Move.mobile;
moveFraction += mobile.MovementSpeedForCell(self, mobile.ToCell);
if (moveFraction > MoveFractionTotal) if (moveFraction >= MoveFractionTotal)
{
moveFraction = MoveFractionTotal; moveFraction = MoveFractionTotal;
mobile.SetCenterPosition(self, To);
mobile.Facing = ToFacing;
UpdateCenterLocation(self, Move.mobile); Queue(OnComplete(self, mobile, Move));
if (ret == this)
return false;
Queue(ret);
return true; return true;
} }
Activity InnerTick(Actor self, Mobile mobile)
{
moveFraction += mobile.MovementSpeedForCell(self, mobile.ToCell);
if (moveFraction <= MoveFractionTotal)
return this;
return OnComplete(self, mobile, Move);
}
void UpdateCenterLocation(Actor self, Mobile mobile)
{
// Avoid division through zero
if (MoveFractionTotal != 0)
{
WPos pos; WPos pos;
if (EnableArc) if (EnableArc)
{ {
@@ -478,14 +463,8 @@ namespace OpenRA.Mods.Common.Activities
pos -= new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(pos)); pos -= new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(pos));
mobile.SetCenterPosition(self, pos); mobile.SetCenterPosition(self, pos);
}
else
mobile.SetCenterPosition(self, To);
if (moveFraction >= MoveFractionTotal)
mobile.Facing = ToFacing;
else
mobile.Facing = WAngle.Lerp(FromFacing, ToFacing, moveFraction, MoveFractionTotal); mobile.Facing = WAngle.Lerp(FromFacing, ToFacing, moveFraction, MoveFractionTotal);
return false;
} }
protected abstract MovePart OnComplete(Actor self, Mobile mobile, Move parent); protected abstract MovePart OnComplete(Actor self, Mobile mobile, Move parent);