Rename methods/activities with Visual in them
While they may be only 'visual' in terms of influence/cell grid, they all do update CenterPosition, which is essentially the actual world position of the actor. 'Visual' would imply that it only affects the position where the actor is drawn, which is inaccurate. Furthermore, using the term 'Visual' here would make naming future methods/properties related to visual interpolation unnecessarily complicated, because that's where we might need a real 'Visual(Only)Position'.
This commit is contained in:
committed by
Matthias Mailänder
parent
7073279ab8
commit
2473b8763b
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
public abstract class AffectsShroud : ConditionalTrait<AffectsShroudInfo>, ISync, INotifyAddedToWorld,
|
||||
INotifyRemovedFromWorld, INotifyMoving, INotifyVisualPositionChanged, ITick
|
||||
INotifyRemovedFromWorld, INotifyMoving, INotifyCenterPositionChanged, ITick
|
||||
{
|
||||
static readonly PPos[] NoCells = { };
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
void INotifyVisualPositionChanged.VisualPositionChanged(Actor self, byte oldLayer, byte newLayer)
|
||||
void INotifyCenterPositionChanged.CenterPositionChanged(Actor self, byte oldLayer, byte newLayer)
|
||||
{
|
||||
if (!self.IsInWorld)
|
||||
return;
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
IDisposable reservation;
|
||||
IEnumerable<int> speedModifiers;
|
||||
INotifyMoving[] notifyMoving;
|
||||
INotifyVisualPositionChanged[] notifyVisualPositionChanged;
|
||||
INotifyCenterPositionChanged[] notifyCenterPositionChanged;
|
||||
IOverrideAircraftLanding overrideAircraftLanding;
|
||||
|
||||
WRot orientation;
|
||||
@@ -344,7 +344,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
notifyMoving = self.TraitsImplementing<INotifyMoving>().ToArray();
|
||||
positionOffsets = self.TraitsImplementing<IAircraftCenterPositionOffset>().ToArray();
|
||||
overrideAircraftLanding = self.TraitOrDefault<IOverrideAircraftLanding>();
|
||||
notifyVisualPositionChanged = self.TraitsImplementing<INotifyVisualPositionChanged>().ToArray();
|
||||
notifyCenterPositionChanged = self.TraitsImplementing<INotifyCenterPositionChanged>().ToArray();
|
||||
base.Created(self);
|
||||
}
|
||||
|
||||
@@ -766,7 +766,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return SubCell.Invalid;
|
||||
}
|
||||
|
||||
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos); }
|
||||
public void SetCenterPosition(Actor self, WPos pos) { SetPosition(self, pos); }
|
||||
|
||||
// Changes position, but not altitude
|
||||
public void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.Any)
|
||||
@@ -797,10 +797,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
else if (!isCruising && cruising)
|
||||
OnCruisingAltitudeLeft();
|
||||
|
||||
// NB: This can be called from the constructor before notifyVisualPositionChanged is assigned.
|
||||
if (notify && notifyVisualPositionChanged != null)
|
||||
foreach (var n in notifyVisualPositionChanged)
|
||||
n.VisualPositionChanged(self, 0, 0);
|
||||
// NB: This can be called from the constructor before notifyCenterPositionChanged is assigned.
|
||||
if (notify && notifyCenterPositionChanged != null)
|
||||
foreach (var n in notifyCenterPositionChanged)
|
||||
n.CenterPositionChanged(self, 0, 0);
|
||||
|
||||
FinishedMoving(self);
|
||||
}
|
||||
@@ -946,10 +946,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return new Land(self, target);
|
||||
}
|
||||
|
||||
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
||||
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos)
|
||||
{
|
||||
// TODO: Ignore repulsion when moving
|
||||
var activities = new CallFunc(() => SetVisualPosition(self, fromPos));
|
||||
var activities = new CallFunc(() => SetCenterPosition(self, fromPos));
|
||||
activities.Queue(new Fly(self, Target.FromPos(toPos)));
|
||||
return activities;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
paxFacing[a.Actor].Facing = targetYaw;
|
||||
paxPos[a.Actor].SetVisualPosition(a.Actor, pos + PortOffset(self, port));
|
||||
paxPos[a.Actor].SetCenterPosition(a.Actor, pos + PortOffset(self, port));
|
||||
|
||||
var barrel = a.CheckFire(a.Actor, facing, target);
|
||||
if (barrel == null)
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class GrantConditionOnSubterraneanLayer : GrantConditionOnLayer<GrantConditionOnSubterraneanLayerInfo>, INotifyVisualPositionChanged
|
||||
public class GrantConditionOnSubterraneanLayer : GrantConditionOnLayer<GrantConditionOnSubterraneanLayerInfo>, INotifyCenterPositionChanged
|
||||
{
|
||||
WDist transitionDepth;
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Game.Sound.Play(SoundType.World, Info.SubterraneanTransitionSound);
|
||||
}
|
||||
|
||||
void INotifyVisualPositionChanged.VisualPositionChanged(Actor self, byte oldLayer, byte newLayer)
|
||||
void INotifyCenterPositionChanged.CenterPositionChanged(Actor self, byte oldLayer, byte newLayer)
|
||||
{
|
||||
var depth = self.World.Map.DistanceAboveTerrain(self.CenterPosition);
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly Actor self;
|
||||
readonly CrateInfo info;
|
||||
bool collected;
|
||||
INotifyVisualPositionChanged[] notifyVisualPositionChanged;
|
||||
INotifyCenterPositionChanged[] notifyCenterPositionChanged;
|
||||
|
||||
[Sync]
|
||||
int ticks;
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
notifyVisualPositionChanged = self.TraitsImplementing<INotifyVisualPositionChanged>().ToArray();
|
||||
notifyCenterPositionChanged = self.TraitsImplementing<INotifyCenterPositionChanged>().ToArray();
|
||||
}
|
||||
|
||||
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses) { }
|
||||
@@ -181,31 +181,31 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public WPos CenterPosition { get; private set; }
|
||||
|
||||
// Sets the location (Location) and visual position (CenterPosition)
|
||||
// Sets the location (Location) and position (CenterPosition)
|
||||
public void SetPosition(Actor self, WPos pos)
|
||||
{
|
||||
var cell = self.World.Map.CellContaining(pos);
|
||||
SetLocation(self, cell);
|
||||
SetVisualPosition(self, self.World.Map.CenterOfCell(cell) + new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(pos)));
|
||||
SetCenterPosition(self, self.World.Map.CenterOfCell(cell) + new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(pos)));
|
||||
}
|
||||
|
||||
// Sets the location (Location) and visual position (CenterPosition)
|
||||
// Sets the location (Location) and position (CenterPosition)
|
||||
public void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.Any)
|
||||
{
|
||||
SetLocation(self, cell, subCell);
|
||||
SetVisualPosition(self, self.World.Map.CenterOfCell(cell));
|
||||
SetCenterPosition(self, self.World.Map.CenterOfCell(cell));
|
||||
}
|
||||
|
||||
// Sets only the visual position (CenterPosition)
|
||||
public void SetVisualPosition(Actor self, WPos pos)
|
||||
// Sets only the CenterPosition
|
||||
public void SetCenterPosition(Actor self, WPos pos)
|
||||
{
|
||||
CenterPosition = pos;
|
||||
self.World.UpdateMaps(self, this);
|
||||
|
||||
// This can be called from the constructor before notifyVisualPositionChanged is assigned.
|
||||
if (notifyVisualPositionChanged != null)
|
||||
foreach (var n in notifyVisualPositionChanged)
|
||||
n.VisualPositionChanged(self, 0, 0);
|
||||
// This can be called from the constructor before notifyCenterPositionChanged is assigned.
|
||||
if (notifyCenterPositionChanged != null)
|
||||
foreach (var n in notifyCenterPositionChanged)
|
||||
n.CenterPositionChanged(self, 0, 0);
|
||||
}
|
||||
|
||||
// Sets only the location (Location)
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly int dragSpeed;
|
||||
readonly WPos finalPosition;
|
||||
|
||||
INotifyVisualPositionChanged[] notifyVisualPositionChanged;
|
||||
INotifyCenterPositionChanged[] notifyCenterPositionChanged;
|
||||
|
||||
[Sync]
|
||||
public CPos TopLeft { get; private set; }
|
||||
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (dragSpeed > 0 && distance > 0)
|
||||
self.QueueActivity(new Drag(self, CenterPosition, finalPosition, distance / dragSpeed));
|
||||
|
||||
notifyVisualPositionChanged = self.TraitsImplementing<INotifyVisualPositionChanged>().ToArray();
|
||||
notifyCenterPositionChanged = self.TraitsImplementing<INotifyCenterPositionChanged>().ToArray();
|
||||
}
|
||||
|
||||
public bool CanExistInCell(CPos cell)
|
||||
@@ -138,15 +138,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.Any) { SetPosition(self, self.World.Map.CenterOfCell(cell)); }
|
||||
|
||||
public void SetVisualPosition(Actor self, WPos pos)
|
||||
public void SetCenterPosition(Actor self, WPos pos)
|
||||
{
|
||||
CenterPosition = pos;
|
||||
self.World.ScreenMap.AddOrUpdate(self);
|
||||
|
||||
// This can be called from the constructor before notifyVisualPositionChanged is assigned.
|
||||
if (notifyVisualPositionChanged != null)
|
||||
foreach (var n in notifyVisualPositionChanged)
|
||||
n.VisualPositionChanged(self, 0, 0);
|
||||
// This can be called from the constructor before notifyCenterPositionChanged is assigned.
|
||||
if (notifyCenterPositionChanged != null)
|
||||
foreach (var n in notifyCenterPositionChanged)
|
||||
n.CenterPositionChanged(self, 0, 0);
|
||||
}
|
||||
|
||||
public void SetPosition(Actor self, WPos pos)
|
||||
|
||||
@@ -182,7 +182,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public SubCell FromSubCell, ToSubCell;
|
||||
|
||||
INotifyCustomLayerChanged[] notifyCustomLayerChanged;
|
||||
INotifyVisualPositionChanged[] notifyVisualPositionChanged;
|
||||
INotifyCenterPositionChanged[] notifyCenterPositionChanged;
|
||||
INotifyMoving[] notifyMoving;
|
||||
INotifyFinishedMoving[] notifyFinishedMoving;
|
||||
IWrapMove[] moveWrappers;
|
||||
@@ -262,18 +262,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (locationInit != null)
|
||||
{
|
||||
fromCell = toCell = locationInit.Value;
|
||||
SetVisualPosition(self, init.World.Map.CenterOfSubCell(FromCell, FromSubCell));
|
||||
SetCenterPosition(self, init.World.Map.CenterOfSubCell(FromCell, FromSubCell));
|
||||
}
|
||||
|
||||
Facing = oldFacing = init.GetValue<FacingInit, WAngle>(info.InitialFacing);
|
||||
|
||||
// Sets the initial visual position
|
||||
// Sets the initial center position
|
||||
// Unit will move into the cell grid (defined by LocationInit) as its initial activity
|
||||
var centerPositionInit = init.GetOrDefault<CenterPositionInit>();
|
||||
if (centerPositionInit != null)
|
||||
{
|
||||
oldPos = centerPositionInit.Value;
|
||||
SetVisualPosition(self, oldPos);
|
||||
SetCenterPosition(self, oldPos);
|
||||
returnToCellOnCreation = true;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
notifyCustomLayerChanged = self.TraitsImplementing<INotifyCustomLayerChanged>().ToArray();
|
||||
notifyVisualPositionChanged = self.TraitsImplementing<INotifyVisualPositionChanged>().ToArray();
|
||||
notifyCenterPositionChanged = self.TraitsImplementing<INotifyCenterPositionChanged>().ToArray();
|
||||
notifyMoving = self.TraitsImplementing<INotifyMoving>().ToArray();
|
||||
notifyFinishedMoving = self.TraitsImplementing<INotifyFinishedMoving>().ToArray();
|
||||
moveWrappers = self.TraitsImplementing<IWrapMove>().ToArray();
|
||||
@@ -451,7 +451,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return preferred;
|
||||
}
|
||||
|
||||
// Sets the location (fromCell, toCell, FromSubCell, ToSubCell) and visual position (CenterPosition)
|
||||
// Sets the location (fromCell, toCell, FromSubCell, ToSubCell) and CenterPosition
|
||||
public void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.Any)
|
||||
{
|
||||
subCell = GetValidSubCell(subCell);
|
||||
@@ -461,31 +461,31 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.World.GetCustomMovementLayers()[cell.Layer].CenterOfCell(cell);
|
||||
|
||||
var subcellOffset = self.World.Map.Grid.OffsetOfSubCell(subCell);
|
||||
SetVisualPosition(self, position + subcellOffset);
|
||||
SetCenterPosition(self, position + subcellOffset);
|
||||
FinishedMoving(self);
|
||||
}
|
||||
|
||||
// Sets the location (fromCell, toCell, FromSubCell, ToSubCell) and visual position (CenterPosition)
|
||||
// Sets the location (fromCell, toCell, FromSubCell, ToSubCell) and CenterPosition
|
||||
public void SetPosition(Actor self, WPos pos)
|
||||
{
|
||||
var cell = self.World.Map.CellContaining(pos);
|
||||
SetLocation(cell, FromSubCell, cell, FromSubCell);
|
||||
SetVisualPosition(self, self.World.Map.CenterOfSubCell(cell, FromSubCell) + new WVec(0, 0, self.World.Map.DistanceAboveTerrain(pos).Length));
|
||||
SetCenterPosition(self, self.World.Map.CenterOfSubCell(cell, FromSubCell) + new WVec(0, 0, self.World.Map.DistanceAboveTerrain(pos).Length));
|
||||
FinishedMoving(self);
|
||||
}
|
||||
|
||||
// Sets only the visual position (CenterPosition)
|
||||
public void SetVisualPosition(Actor self, WPos pos)
|
||||
// Sets only the CenterPosition
|
||||
public void SetCenterPosition(Actor self, WPos pos)
|
||||
{
|
||||
CenterPosition = pos;
|
||||
self.World.UpdateMaps(self, this);
|
||||
|
||||
// The first time SetVisualPosition is called is in the constructor before creation, so we need a null check here as well
|
||||
if (notifyVisualPositionChanged == null)
|
||||
// The first time SetCenterPosition is called is in the constructor before creation, so we need a null check here as well
|
||||
if (notifyCenterPositionChanged == null)
|
||||
return;
|
||||
|
||||
foreach (var n in notifyVisualPositionChanged)
|
||||
n.VisualPositionChanged(self, fromCell.Layer, toCell.Layer);
|
||||
foreach (var n in notifyCenterPositionChanged)
|
||||
n.CenterPositionChanged(self, fromCell.Layer, toCell.Layer);
|
||||
}
|
||||
|
||||
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any)
|
||||
@@ -665,12 +665,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Reserve the exit cell
|
||||
mobile.SetPosition(self, cell, subCell);
|
||||
mobile.SetVisualPosition(self, pos);
|
||||
mobile.SetCenterPosition(self, pos);
|
||||
|
||||
if (delay > 0)
|
||||
QueueChild(new Wait(delay));
|
||||
|
||||
QueueChild(mobile.VisualMove(self, pos, self.World.Map.CenterOfSubCell(cell, subCell)));
|
||||
QueueChild(mobile.LocalMove(self, pos, self.World.Map.CenterOfSubCell(cell, subCell)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -691,12 +691,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Activity cancels if the target moves by more than half a cell
|
||||
// to avoid problems with the cell grid
|
||||
return WrapMove(new VisualMoveIntoTarget(self, target, new WDist(512)));
|
||||
return WrapMove(new LocalMoveIntoTarget(self, target, new WDist(512)));
|
||||
}
|
||||
|
||||
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
||||
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos)
|
||||
{
|
||||
return WrapMove(VisualMove(self, fromPos, toPos, self.Location));
|
||||
return WrapMove(LocalMove(self, fromPos, toPos, self.Location));
|
||||
}
|
||||
|
||||
public int EstimatedMoveDuration(Actor self, WPos fromPos, WPos toPos)
|
||||
@@ -786,7 +786,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public Activity ScriptedMove(CPos cell) { return new Move(self, cell); }
|
||||
public Activity MoveTo(Func<BlockedByActor, List<CPos>> pathFunc) { return new Move(self, pathFunc); }
|
||||
|
||||
Activity VisualMove(Actor self, WPos fromPos, WPos toPos, CPos cell)
|
||||
Activity LocalMove(Actor self, WPos fromPos, WPos toPos, CPos cell)
|
||||
{
|
||||
var speed = MovementSpeedForCell(self, cell);
|
||||
var length = speed > 0 ? (toPos - fromPos).Length / speed : 0;
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
dropPositionable.SetPosition(dropActor, dropCell, dropSubCell);
|
||||
|
||||
var dropPosition = dropActor.CenterPosition + new WVec(0, 0, self.CenterPosition.Z - dropActor.CenterPosition.Z);
|
||||
dropPositionable.SetVisualPosition(dropActor, dropPosition);
|
||||
dropPositionable.SetCenterPosition(dropActor, dropPosition);
|
||||
w.Add(dropActor);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user