New types for cell and pixel coordinate position/vectors.

This commit is contained in:
James Dunne
2012-06-20 23:22:27 -05:00
parent 0b98a8ce5e
commit 9c49143534
162 changed files with 1291 additions and 865 deletions

View File

@@ -57,8 +57,8 @@ namespace OpenRA.Mods.RA.Effects
if (info.Inaccuracy > 0)
{
var factor = ((Args.dest - Args.src).Length / Game.CellSize) / args.weapon.Range;
Args.dest += (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
var factor = ((Args.dest - Args.src).Length / (float)Game.CellSize) / args.weapon.Range;
Args.dest += (PVecInt) (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
}
if (Info.Image != null)
@@ -110,7 +110,7 @@ namespace OpenRA.Mods.RA.Effects
{
var at = (float)t / TotalTime();
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude);
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude);
var highPos = (Info.High || Info.Angle > 0)
? (pos - new float2(0, GetAltitude()))
@@ -119,24 +119,24 @@ namespace OpenRA.Mods.RA.Effects
if (Info.Trail != null && --ticksToNextSmoke < 0)
{
world.AddFrameEndTask(w => w.Add(
new Smoke(w, highPos.ToInt2(), Info.Trail)));
new Smoke(w, (PPos) highPos.ToInt2(), Info.Trail)));
ticksToNextSmoke = Info.TrailInterval;
}
if (Trail != null)
Trail.Tick(highPos);
Trail.Tick((PPos)highPos.ToInt2());
}
if (!Info.High) // check for hitting a wall
{
var at = (float)t / TotalTime();
var pos = float2.Lerp(Args.src, Args.dest, at);
var cell = Traits.Util.CellContaining(pos);
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at);
var cell = ((PPos) pos.ToInt2()).ToCPos();
if (world.ActorMap.GetUnitsAt(cell).Any(
a => a.HasTrait<IBlocksBullets>()))
{
Args.dest = pos.ToInt2();
Args.dest = (PPos) pos.ToInt2();
Explode(world);
}
}
@@ -151,9 +151,9 @@ namespace OpenRA.Mods.RA.Effects
var at = (float)t / TotalTime();
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude);
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude);
if (Args.firedBy.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(pos)))
if (Args.firedBy.World.LocalShroud.IsVisible(((PPos) pos.ToInt2()).ToCPos()))
{
if (Info.High || Info.Angle > 0)
{

View File

@@ -18,19 +18,20 @@ namespace OpenRA.Mods.RA.Effects
{
class CashTick : IEffect
{
string s;
readonly string s;
int remaining;
int velocity;
float2 pos, offset;
Color color;
SpriteFont font;
readonly int velocity;
PPos pos;
readonly float2 offset;
readonly Color color;
readonly SpriteFont font;
static string FormatCashAmount(int x) { return "{0}${1}".F(x < 0 ? "-" : "+", x); }
public CashTick(int value, int lifetime, int velocity, float2 pos, Color color)
public CashTick(int value, int lifetime, int velocity, PPos pos, Color color)
: this( FormatCashAmount(value), lifetime, velocity, pos, color ) { }
public CashTick(string value, int lifetime, int velocity, float2 pos, Color color)
public CashTick(string value, int lifetime, int velocity, PPos pos, Color color)
{
this.color = color;
this.velocity = velocity;
@@ -45,12 +46,12 @@ namespace OpenRA.Mods.RA.Effects
{
if (--remaining <= 0)
world.AddFrameEndTask(w => w.Remove(this));
pos.Y -= velocity;
pos -= new PVecInt(0, velocity);
}
public IEnumerable<Renderable> Render()
{
font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos - Game.viewport.Location) - offset, color, Color.Black,1);
font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos.ToFloat2() - Game.viewport.Location) - offset, color, Color.Black,1);
yield break;
}
}

View File

@@ -45,8 +45,7 @@ namespace OpenRA.Mods.RA
public void Tick(Actor self)
{
history.Tick(self.CenterLocation - new int2(0, move.Altitude)
- Combat.GetTurretPosition(self, facing, contrailTurret));
history.Tick(self.CenterLocation - new PVecInt(0, move.Altitude) - Combat.GetTurretPosition(self, facing, contrailTurret));
}
public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(self); }
@@ -54,7 +53,7 @@ namespace OpenRA.Mods.RA
class ContrailHistory
{
List<float2> positions = new List<float2>();
List<PPos> positions = new List<PPos>();
readonly int TrailLength;
readonly Color Color;
readonly int StartSkip;
@@ -75,7 +74,7 @@ namespace OpenRA.Mods.RA
this.StartSkip = startSkip;
}
public void Tick(float2 currentPos)
public void Tick(PPos currentPos)
{
positions.Add(currentPos);
if (positions.Count >= TrailLength)
@@ -85,22 +84,20 @@ namespace OpenRA.Mods.RA
public void Render(Actor self)
{
Color trailStart = Color;
Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R,
trailStart.G, trailStart.B);
Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R, trailStart.G, trailStart.B);
for (int i = positions.Count - 1 - StartSkip; i >= 1; --i)
{
var conPos = positions[i];
var nextPos = positions[i - 1];
if (self.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(conPos)) ||
self.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(nextPos)))
if (self.World.LocalShroud.IsVisible(conPos.ToCPos()) ||
self.World.LocalShroud.IsVisible(nextPos.ToCPos()))
{
Game.Renderer.WorldLineRenderer.DrawLine(conPos, nextPos, trailStart, trailEnd);
Game.Renderer.WorldLineRenderer.DrawLine(conPos.ToFloat2(), nextPos.ToFloat2(), trailStart, trailEnd);
trailStart = trailEnd;
trailEnd = Color.FromArgb(trailStart.A - 255 / positions.Count, trailStart.R,
trailStart.G, trailStart.B);
trailEnd = Color.FromArgb(trailStart.A - 255 / positions.Count, trailStart.R, trailStart.G, trailStart.B);
}
}
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Effects
anim.PlayThen(sequence,
() => fromActor.World.AddFrameEndTask(w => w.Remove(this)));
pos = fromActor.CenterLocation;
pos = fromActor.CenterLocation.ToFloat2();
}
public void Tick( World world ) { anim.Tick(); }

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Effects
{
if (a.IsInWorld)
yield return new Renderable(anim.Image,
a.CenterLocation - .5f * anim.Image.size + offset, "effect", (int)a.CenterLocation.Y);
a.CenterLocation.ToFloat2() - .5f * anim.Image.size + offset, "effect", (int)a.CenterLocation.Y);
}
}
}

View File

@@ -18,10 +18,10 @@ namespace OpenRA.Mods.RA.Effects
public class Explosion : IEffect
{
Animation anim;
int2 pos;
PPos pos;
int altitude;
public Explosion(World world, int2 pixelPos, string style, bool isWater, int altitude)
public Explosion(World world, PPos pixelPos, string style, bool isWater, int altitude)
{
this.pos = pixelPos;
this.altitude = altitude;
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image,
pos - .5f * anim.Image.size - new int2(0,altitude),
pos.ToFloat2() - .5f * anim.Image.size - new int2(0,altitude),
"effect", (int)pos.Y - altitude);
}

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Effects
if (show && !self.Destroyed)
{
var p = self.CenterLocation;
yield return new Renderable(anim.Image, p - 0.5f * anim.Image.size, rs.Palette(self.Owner), p.Y)
yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, rs.Palette(self.Owner), p.Y)
.WithScale(1.5f);
}
}

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image,
Args.dest - new int2(0, altitude) - .5f * anim.Image.size, "effect", Args.dest.Y);
Args.dest.ToInt2() - new int2(0, altitude) - .5f * anim.Image.size, "effect", Args.dest.Y);
}
}
}

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA.Effects
{
if (explosion != null)
yield return new Renderable(explosion.Image,
args.dest - .5f * explosion.Image.size, "effect", (int)args.dest.Y);
args.dest.ToFloat2() - .5f * explosion.Image.size, "effect", (int)args.dest.Y);
if (ticks >= info.BeamDuration)
yield break;
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA.Effects
var wlr = Game.Renderer.WorldLineRenderer;
wlr.LineWidth = info.BeamRadius * 2;
wlr.DrawLine(args.src, args.dest, rc, rc);
wlr.DrawLine(args.src.ToFloat2(), args.dest.ToFloat2(), rc, rc);
wlr.Flush();
wlr.LineWidth = 1f;
}

View File

@@ -46,9 +46,9 @@ namespace OpenRA.Mods.RA.Effects
readonly MissileInfo Info;
readonly ProjectileArgs Args;
int2 offset;
PVecInt offset;
public int2 SubPxPosition;
public int2 PxPosition { get { return new int2( SubPxPosition.X / 1024, SubPxPosition.Y / 1024 ); } }
public PPos PxPosition { get { return new PPos(SubPxPosition.X / 1024, SubPxPosition.Y / 1024); } }
readonly Animation anim;
int Facing;
@@ -61,12 +61,12 @@ namespace OpenRA.Mods.RA.Effects
Info = info;
Args = args;
SubPxPosition = 1024 * Args.src;
SubPxPosition = 1024 * Args.src.ToInt2();
Altitude = Args.srcAltitude;
Facing = Args.facing;
if (info.Inaccuracy > 0)
offset = (info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
offset = (PVecInt)(info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
if (Info.Image != null)
{
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA.Effects
if (Info.Trail != null)
{
var sp = (SubPxPosition - (move * 3) / 2) / 1024 - new int2(0, Altitude);
var sp = (PPos)((SubPxPosition - (move * 3) / 2) / 1024) - new PVecInt(0, Altitude);
if (--ticksToNextSmoke < 0)
{
@@ -135,14 +135,13 @@ namespace OpenRA.Mods.RA.Effects
if (!Info.High) // check for hitting a wall
{
var cell = Traits.Util.CellContaining(PxPosition);
if (world.ActorMap.GetUnitsAt(cell).Any(
a => a.HasTrait<IBlocksBullets>()))
var cell = PxPosition.ToCPos();
if (world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait<IBlocksBullets>()))
Explode(world);
}
if (Trail != null)
Trail.Tick(PxPosition - new float2(0,Altitude));
Trail.Tick(PxPosition - new PVecInt(0, Altitude));
}
void Explode(World world)
@@ -155,8 +154,8 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
if (Args.firedBy.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(PxPosition.ToFloat2())))
yield return new Renderable(anim.Image,PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude),
if (Args.firedBy.World.LocalShroud.IsVisible(PxPosition.ToCPos()))
yield return new Renderable(anim.Image, PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude),
Args.weapon.Underwater ? "shadow" : "effect", PxPosition.Y);
if (Trail != null)

View File

@@ -19,13 +19,13 @@ namespace OpenRA.Mods.RA.Effects
{
readonly Player firedBy;
Animation anim;
int2 pos;
int2 targetLocation;
PPos pos;
CPos targetLocation;
int altitude;
bool goingUp = true;
string weapon;
public NukeLaunch(Player firedBy, Actor silo, string weapon, int2 spawnOffset, int2 targetLocation)
public NukeLaunch(Player firedBy, Actor silo, string weapon, PVecInt spawnOffset, CPos targetLocation)
{
this.firedBy = firedBy;
this.targetLocation = targetLocation;
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA.Effects
{
world.AddFrameEndTask(w => w.Remove(this));
Combat.DoExplosion(firedBy.PlayerActor, weapon, pos, 0);
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos, 5);
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos.ToFloat2(), 5);
foreach (var a in world.ActorsWithTrait<NukePaletteEffect>())
a.Trait.Enable();
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image, pos - 0.5f * anim.Image.size - new float2(0, altitude),
yield return new Renderable(anim.Image, pos.ToFloat2() - 0.5f * anim.Image.size - new float2(0, altitude),
"effect", (int)pos.Y);
}
}

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Effects
readonly Animation anim;
readonly string palette;
readonly Animation paraAnim;
readonly float2 location;
readonly PPos location;
readonly Actor cargo;
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Effects
float altitude;
const float fallRate = .3f;
public Parachute(Player owner, float2 location, int altitude, Actor cargo)
public Parachute(Player owner, PPos location, int altitude, Actor cargo)
{
this.location = location;
this.altitude = altitude;
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Effects
world.AddFrameEndTask(w =>
{
w.Remove(this);
var loc = Traits.Util.CellContaining(location);
var loc = location.ToCPos();
cargo.CancelActivity();
cargo.Trait<ITeleportable>().SetPosition(cargo, loc);
w.Add(cargo);
@@ -72,8 +72,8 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
var pos = location - new float2(0, altitude);
yield return new Renderable(anim.Image, location - .5f * anim.Image.size, "shadow", 0);
var pos = location.ToFloat2() - new float2(0, altitude);
yield return new Renderable(anim.Image, location.ToFloat2() - .5f * anim.Image.size, "shadow", 0);
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, palette, 2);
yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, palette, 3);
}

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Effects
{
if (!a.Destroyed && (a.World.LocalPlayer == null || a.Owner.Stances[a.Owner.World.LocalPlayer] == Stance.Ally))
yield return new Renderable(anim.Image,
a.CenterLocation - .5f * anim.Image.size, "chrome", (int)a.CenterLocation.Y);
a.CenterLocation.ToFloat2() - .5f * anim.Image.size, "chrome", (int)a.CenterLocation.Y);
}
}
}

View File

@@ -18,8 +18,8 @@ namespace OpenRA.Mods.RA.Effects
{
class RallyPoint : IEffect
{
Actor building;
RA.RallyPoint rp;
readonly Actor building;
readonly RA.RallyPoint rp;
public Animation flag = new Animation("rallypoint");
public Animation circles = new Animation("rallypoint");
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Effects
circles.Play("circles");
}
int2 cachedLocation;
CPos cachedLocation;
public void Tick( World world )
{
flag.Tick();
@@ -55,11 +55,11 @@ namespace OpenRA.Mods.RA.Effects
var palette = building.Trait<RenderSimple>().Palette(building.Owner);
yield return new Renderable(circles.Image,
pos - .5f * circles.Image.size,
pos.ToFloat2() - .5f * circles.Image.size,
palette, (int)pos.Y);
yield return new Renderable(flag.Image,
pos + new float2(-1,-17),
pos.ToFloat2() + new float2(-1,-17),
palette, (int)pos.Y);
}
}

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Effects
var palette = building.Trait<RenderSimple>().Palette(player);
yield return new Renderable(anim.Image,
building.CenterLocation - .5f * anim.Image.size, palette, (int)building.CenterLocation.Y);
building.CenterLocation.ToFloat2() - .5f * anim.Image.size, palette, (int)building.CenterLocation.Y);
}
}
}

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Effects
doors.PlayThen("active",
() => a.World.AddFrameEndTask(w => w.Remove(this)));
pos = a.CenterLocation - .5f * doors.Image.size + doorOffset;
pos = a.CenterLocation.ToFloat2() - .5f * doors.Image.size + doorOffset;
}
public void Tick( World world )

View File

@@ -17,10 +17,10 @@ namespace OpenRA.Mods.RA.Effects
{
public class Smoke : IEffect
{
readonly int2 pos;
readonly PPos pos;
readonly Animation anim;
public Smoke(World world, int2 pos, string trail)
public Smoke(World world, PPos pos, string trail)
{
this.pos = pos;
anim = new Animation(trail);
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, "effect", (int)pos.Y);
yield return new Renderable(anim.Image, pos.ToFloat2() - .5f * anim.Image.size, "effect", (int)pos.Y);
}
}
}

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render() { return renderables; }
static IEnumerable<Renderable> DrawZapWandering(int2 from, int2 to, Sequence s)
static IEnumerable<Renderable> DrawZapWandering(PPos from, PPos to, Sequence s)
{
var z = float2.Zero; /* hack */
var dist = to - from;
@@ -73,19 +73,19 @@ namespace OpenRA.Mods.RA.Effects
var renderables = new List<Renderable>();
if (Game.CosmeticRandom.Next(2) != 0)
{
var p1 = from + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
var p2 = from + (2 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
var p1 = from.ToFloat2() + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
var p2 = from.ToFloat2() + (2 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
renderables.AddRange(DrawZap(from, p1, s, out p1));
renderables.AddRange(DrawZap(from.ToFloat2(), p1, s, out p1));
renderables.AddRange(DrawZap(p1, p2, s, out p2));
renderables.AddRange(DrawZap(p2, to, s, out z));
renderables.AddRange(DrawZap(p2, to.ToFloat2(), s, out z));
}
else
{
var p1 = from + (1 / 2f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
var p1 = from.ToFloat2() + (1 / 2f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
renderables.AddRange(DrawZap(from, p1, s, out p1));
renderables.AddRange(DrawZap(p1, to, s, out z));
renderables.AddRange(DrawZap(from.ToFloat2(), p1, s, out p1));
renderables.AddRange(DrawZap(p1, to.ToFloat2(), s, out z));
}
return renderables;