Skip to content

Commit

Permalink
Let movement trigger visibility recalculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tovl committed Nov 28, 2019
1 parent c9a859e commit 653bff0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions OpenRA.Mods.Common/Traits/AffectsShroud.cs
Expand Up @@ -30,7 +30,8 @@ public abstract class AffectsShroudInfo : ConditionalTraitInfo
public readonly VisibilityType Type = VisibilityType.Footprint;
}

public abstract class AffectsShroud : ConditionalTrait<AffectsShroudInfo>, ITick, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyMoving
public abstract class AffectsShroud : ConditionalTrait<AffectsShroudInfo>, ISync, INotifyAddedToWorld,
INotifyRemovedFromWorld, INotifyMoving, INotifyVisualPositionChanged
{
static readonly PPos[] NoCells = { };

Expand Down Expand Up @@ -83,7 +84,7 @@ PPos[] ProjectedCells(Actor self)
.ToArray();
}

void ITick.Tick(Actor self)
void INotifyVisualPositionChanged.VisualPositionChanged(Actor self, byte oldLayer, byte newLayer)
{
if (!self.IsInWorld)
return;
Expand Down
13 changes: 13 additions & 0 deletions OpenRA.Mods.Common/Traits/Air/Aircraft.cs
Expand Up @@ -205,6 +205,7 @@ public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder
IDisposable reservation;
IEnumerable<int> speedModifiers;
INotifyMoving[] notifyMoving;
INotifyVisualPositionChanged[] notifyVisualPositionChanged;
IOverrideAircraftLanding overrideAircraftLanding;

[Sync]
Expand All @@ -223,6 +224,8 @@ public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder
bool requireForceMove;
int creationActivityDelay;

bool notify = true;

public static WPos GroundPosition(Actor self)
{
return self.CenterPosition - new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(self.CenterPosition));
Expand Down Expand Up @@ -312,6 +315,7 @@ protected virtual void Created(Actor self)
notifyMoving = self.TraitsImplementing<INotifyMoving>().ToArray();
positionOffsets = self.TraitsImplementing<IAircraftCenterPositionOffset>().ToArray();
overrideAircraftLanding = self.TraitOrDefault<IOverrideAircraftLanding>();
notifyVisualPositionChanged = self.TraitsImplementing<INotifyVisualPositionChanged>().ToArray();
}

void INotifyAddedToWorld.AddedToWorld(Actor self)
Expand Down Expand Up @@ -396,7 +400,12 @@ public void Repulse()
return;

var speed = Info.RepulsionSpeed != -1 ? Info.RepulsionSpeed : MovementSpeed;

// HACK: Prevent updating visibility twice per tick. We really shouldn't be
// moving twice in a tick in the first place.
notify = false;
SetPosition(self, CenterPosition + FlyStep(speed, repulsionForce.Yaw.Facing));
notify = true;
}

public virtual WVec GetRepulsionForce()
Expand Down Expand Up @@ -746,6 +755,10 @@ public void SetPosition(Actor self, WPos pos)
else if (!isCruising && cruising)
OnCruisingAltitudeLeft();

if (notify && notifyVisualPositionChanged != null)
foreach (var n in notifyVisualPositionChanged)
n.VisualPositionChanged(self, 0, 0);

FinishedMoving(self);
}

Expand Down

0 comments on commit 653bff0

Please sign in to comment.