Remove CVec -> WVec conversion.

This commit is contained in:
Paul Chote
2014-04-26 00:10:40 +12:00
parent a256e722d5
commit d7f1b1c9e2
15 changed files with 23 additions and 27 deletions

View File

@@ -44,8 +44,6 @@ namespace OpenRA
public int LengthSquared { get { return X * X + Y * Y; } }
public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
public WVec ToWVec() { return new WVec(X*1024, Y*1024, 0); }
public CVec Clamp(Rectangle r)
{
return new CVec(
@@ -115,7 +113,6 @@ namespace OpenRA
{
case "X": return X;
case "Y": return Y;
case "Facing": return Traits.Util.GetFacing(this, 0);
default: throw new LuaException("CVec does not define a member '{0}'".F(key));
}
}

View File

@@ -476,6 +476,11 @@ namespace OpenRA
return new CPos(pos.X / 1024, pos.Y / 1024);
}
public int FacingBetween(CPos cell, CPos towards, int fallbackfacing)
{
return Traits.Util.GetFacing(CenterOfCell(towards) - CenterOfCell(cell), fallbackfacing);
}
public void Resize(int width, int height) // editor magic.
{
var oldMapTiles = MapTiles.Value;

View File

@@ -42,11 +42,6 @@ namespace OpenRA.Traits
return (angle / 4 - 0x40) & 0xFF;
}
public static int GetFacing(CVec d, int currentFacing)
{
return GetFacing(d.ToWVec(), currentFacing);
}
public static int GetNearestFacing(int facing, int desiredFacing)
{
var turn = desiredFacing - facing;

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
{
// Offset effective position to the top of the northernmost occupied cell
var bi = self.Info.Traits.GetOrDefault<BuildingInfo>();
offset = ((bi != null) ? -FootprintUtils.CenterOffset(bi).Y : 0) - 512;
offset = ((bi != null) ? -FootprintUtils.CenterOffset(self.World, bi).Y : 0) - 512;
}
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Buildings
{
var width = bi.Dimensions.X;
var bibOffset = bi.Dimensions.Y - 1;
var centerOffset = FootprintUtils.CenterOffset(bi);
var centerOffset = FootprintUtils.CenterOffset(self.World, bi);
var location = self.Location;
var rows = info.HasMinibib ? 1 : 2;
var map = self.World.Map;
@@ -49,16 +49,17 @@ namespace OpenRA.Mods.RA.Buildings
var index = i;
var anim = new Animation(self.World, rs.GetImage(self));
var cellOffset = new CVec(i % width, i / width + bibOffset);
var cell = location + cellOffset;
// Some mods may define terrain-specific bibs
var terrain = map.GetTerrainInfo(location + cellOffset).Type;
var terrain = map.GetTerrainInfo(cell).Type;
var testSequence = info.Sequence + "-" + terrain;
var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence;
anim.PlayFetchIndex(sequence, () => index);
anim.IsDecoration = true;
// Z-order is one set to the top of the footprint
var offset = cellOffset.ToWVec() - centerOffset;
var offset = self.World.Map.CenterOfCell(cell) - self.World.Map.CenterOfCell(location) - centerOffset;
var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512));
rs.Add("bib_{0}".F(i), awo, info.Palette);
}

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Buildings
public Actor FindBaseProvider(World world, Player p, CPos topLeft)
{
var center = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(this);
var center = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, this);
foreach (var bp in world.ActorsWithTrait<BaseProvider>())
{
var validOwner = bp.Actor.Owner == p || (world.LobbyInfo.GlobalSettings.AllyBuildRadius && bp.Actor.Owner.Stances[p] == Stance.Ally);
@@ -137,7 +137,7 @@ namespace OpenRA.Mods.RA.Buildings
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(Info);
CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info);
BuildComplete = init.Contains<SkipMakeAnimsInit>();
}

View File

@@ -62,11 +62,10 @@ namespace OpenRA.Mods.RA.Buildings
return new CVec(dim.X / 2, dim.Y > 1 ? (dim.Y + 1) / 2 : 0);
}
public static WVec CenterOffset(BuildingInfo buildingInfo)
public static WVec CenterOffset(World w, BuildingInfo buildingInfo)
{
var dim = buildingInfo.Dimensions;
// Offset is measured relative to the center of the cell, so need to subtract an additional half cell.
return new CVec(dim.X, dim.Y).ToWVec() / 2 - new WVec(512, 512, 0);
return (w.Map.CenterOfCell(CPos.Zero + new CVec(dim.X, dim.Y)) - w.Map.CenterOfCell(new CPos(1, 1))) / 2;
}
}
}

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA
{
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(w.WorldActor.Owner),
new FacingInit(Util.GetFacing(p - startPos, 0))
new FacingInit(w.Map.FacingBetween(startPos, p, 0))
});
plane.CancelActivity();

View File

@@ -139,8 +139,7 @@ namespace OpenRA.Mods.RA.Move
if (nextCell == null)
return this;
var dir = nextCell.Value.First - mobile.fromCell;
var firstFacing = Util.GetFacing(dir, mobile.Facing);
var firstFacing = self.World.Map.FacingBetween(mobile.fromCell, nextCell.Value.First, mobile.Facing);
if (firstFacing != mobile.Facing)
{
path.Add(nextCell.Value.First);
@@ -362,7 +361,7 @@ namespace OpenRA.Mods.RA.Move
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
Util.BetweenCells(self.World, mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
mobile.Facing,
Util.GetNearestFacing(mobile.Facing, Util.GetFacing(nextCell.Value.First - mobile.toCell, mobile.Facing)),
Util.GetNearestFacing(mobile.Facing, self.World.Map.FacingBetween(mobile.toCell, nextCell.Value.First, mobile.Facing)),
moveFraction - moveFractionTotal);
mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second);

View File

@@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA.Orders
initialized = true;
}
var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(BuildingInfo) - WPos.Zero;
var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, BuildingInfo) - WPos.Zero;
foreach (var r in preview)
r.OffsetBy(offset).Render(wr);

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Render
var bi = init.self.Info.Traits.Get<BuildingInfo>();
// Additional 512 units move from center -> top of cell
var offset = FootprintUtils.CenterOffset(bi).Y + 512;
var offset = FootprintUtils.CenterOffset(init.world, bi).Y + 512;
Add("roof", new AnimationWithOffset(roof, null,
() => !buildComplete, offset));
}

View File

@@ -229,7 +229,7 @@ namespace OpenRA.Mods.RA.Scripting
public int GetFacing(object vec, double currentFacing)
{
if (vec is CVec)
return Util.GetFacing((CVec)vec, (int)currentFacing);
return world.Map.FacingBetween(CPos.Zero, CPos.Zero + (CVec)vec, (int)currentFacing);
if (vec is WVec)
return Util.GetFacing((WVec)vec, (int)currentFacing);
throw new ArgumentException("Unsupported vector type: {0}".F(vec.GetType()));

View File

@@ -226,7 +226,7 @@ namespace OpenRA.Mods.RA
// Unit previews
foreach (var unit in power.UnitsInRange(sourceLocation))
{
var offset = (xy - sourceLocation).ToWVec();
var offset = world.Map.CenterOfCell(xy) - world.Map.CenterOfCell(sourceLocation);
if (manager.self.Owner.Shroud.IsTargetable(unit))
foreach (var r in unit.Render(wr))
yield return r.OffsetBy(offset);

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA
{
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(self.Owner),
new FacingInit(Util.GetFacing(order.TargetLocation - startPos, 0))
new FacingInit(w.Map.FacingBetween(startPos, order.TargetLocation, 0))
});
a.CancelActivity();

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA
{
new CenterPositionInit(self.World.Map.CenterOfCell(enterCell) + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(self.Owner),
new FacingInit(Util.GetFacing(order.TargetLocation - enterCell, 0))
new FacingInit(self.World.Map.FacingBetween(enterCell, order.TargetLocation, 0))
});
plane.CancelActivity();