Remove fp from CenterLocation and aircraft.

This commit is contained in:
Paul Chote
2011-01-01 13:21:22 +13:00
parent d395c5e05d
commit 60e3f7621f
13 changed files with 26 additions and 25 deletions

View File

@@ -27,7 +27,7 @@ namespace OpenRA
public readonly uint ActorID; public readonly uint ActorID;
public int2 Location { get { return Trait<IOccupySpace>().TopLeft; } } public int2 Location { get { return Trait<IOccupySpace>().TopLeft; } }
public float2 CenterLocation { get { return Trait<IHasLocation>().PxPosition; } } public int2 CenterLocation { get { return Trait<IHasLocation>().PxPosition; } }
[Sync] [Sync]
public Player Owner; public Player Owner;

View File

@@ -116,11 +116,10 @@ namespace OpenRA.Graphics
{ {
if (!actors.Any()) return; if (!actors.Any()) return;
var avgPos = (1f / actors.Count()) * actors var avgPos = actors
.Select(a => a.CenterLocation) .Select(a => a.CenterLocation)
.Aggregate((a, b) => a + b); .Aggregate((a, b) => a + b) / actors.Count();
scrollPosition = this.NormalizeScrollPosition((avgPos - screenSize / 2));
scrollPosition = this.NormalizeScrollPosition((avgPos.ToInt2() - screenSize / 2));
} }
public Rectangle ViewBounds(World world) public Rectangle ViewBounds(World world)

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Traits
var p = target.CenterLocation; var p = target.CenterLocation;
var move = self.TraitOrDefault<IMove>(); var move = self.TraitOrDefault<IMove>();
var origin = move != null ? self.CenterLocation - new float2(0, move.Altitude) : self.CenterLocation; var origin = move != null ? self.CenterLocation - new int2(0, move.Altitude) : self.CenterLocation;
Game.Renderer.LineRenderer.DrawLine(origin, p, c, c); Game.Renderer.LineRenderer.DrawLine(origin, p, c, c);
for (bool b = false; !b; p = origin, b = true) for (bool b = false; !b; p = origin, b = true)

View File

@@ -231,7 +231,7 @@ namespace OpenRA.Traits
public bool IsValid { get { return valid && (actor == null || actor.IsInWorld); } } public bool IsValid { get { return valid && (actor == null || actor.IsInWorld); } }
public int2 PxPosition { get { return IsActor ? actor.Trait<IHasLocation>().PxPosition : pos.ToInt2(); } } public int2 PxPosition { get { return IsActor ? actor.Trait<IHasLocation>().PxPosition : pos.ToInt2(); } }
public float2 CenterLocation { get { return PxPosition; } } public int2 CenterLocation { get { return PxPosition; } }
public Actor Actor { get { return IsActor ? actor : null; } } public Actor Actor { get { return IsActor ? actor : null; } }
public bool IsActor { get { return actor != null && !actor.Destroyed; } } public bool IsActor { get { return actor != null && !actor.Destroyed; } }

View File

@@ -34,8 +34,9 @@ namespace OpenRA.Traits
static float2[] fvecs = Graphics.Util.MakeArray<float2>( 32, static float2[] fvecs = Graphics.Util.MakeArray<float2>( 32,
i => -float2.FromAngle( i / 16.0f * (float)Math.PI ) * new float2( 1f, 1.3f ) ); i => -float2.FromAngle( i / 16.0f * (float)Math.PI ) * new float2( 1f, 1.3f ) );
public static int GetFacing( float2 d, int currentFacing ) public static int GetFacing( int2 dd, int currentFacing )
{ {
var d = dd.ToFloat2();
if (float2.WithinEpsilon(d, float2.Zero, 0.001f)) if (float2.WithinEpsilon(d, float2.Zero, 0.001f))
return currentFacing; return currentFacing;

View File

@@ -139,7 +139,7 @@ namespace OpenRA.Traits
if (cells.Any()) return cells; if (cells.Any()) return cells;
} }
return new[] { (1f / Game.CellSize * a.CenterLocation).ToInt2() }; return new[] { a.CenterLocation / Game.CellSize };
} }
void RemoveActor(Actor a) void RemoveActor(Actor a)

View File

@@ -17,11 +17,11 @@ namespace OpenRA.Mods.RA.Air
{ {
public class Fly : CancelableActivity public class Fly : CancelableActivity
{ {
public readonly float2 Pos; public readonly int2 Pos;
private Fly( float2 px ) { Pos = px; } private Fly( int2 px ) { Pos = px; }
public static Fly ToPx( float2 px ) { return new Fly( px ); } public static Fly ToPx( int2 px ) { return new Fly( px ); }
public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); } public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); }
public override IActivity Tick(Actor self) public override IActivity Tick(Actor self)

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Air
bool isCalculated; bool isCalculated;
Actor dest; Actor dest;
float2 w1, w2, w3; /* tangent points to turn circles */ int2 w1, w2, w3; /* tangent points to turn circles */
public static Actor ChooseAirfield(Actor self) public static Actor ChooseAirfield(Actor self)
{ {
@@ -74,9 +74,9 @@ namespace OpenRA.Mods.RA.Air
if (f.X > 0) f = -f; if (f.X > 0) f = -f;
w1 = c1 + f; w1 = (c1 + f).ToInt2();
w2 = c2 + f; w2 = (c2 + f).ToInt2();
w3 = approachStart; w3 = (approachStart).ToInt2();
isCalculated = true; isCalculated = true;
} }

View File

@@ -47,8 +47,8 @@ namespace OpenRA.Mods.RA
{ {
srcAltitude = self.Trait<IMove>().Altitude, srcAltitude = self.Trait<IMove>().Altitude,
destAltitude = 0, destAltitude = 0,
src = self.CenterLocation.ToInt2(), src = self.CenterLocation,
dest = self.CenterLocation.ToInt2(), dest = self.CenterLocation,
facing = self.Trait<IFacing>().Facing, facing = self.Trait<IFacing>().Facing,
firedBy = self, firedBy = self,
weapon = weapon weapon = weapon

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Effects
if (!doneDamage) if (!doneDamage)
{ {
if (args.target.IsValid) if (args.target.IsValid)
args.dest = args.target.CenterLocation.ToInt2(); args.dest = args.target.CenterLocation;
Combat.DoImpacts(args); Combat.DoImpacts(args);
doneDamage = true; doneDamage = true;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Effects
readonly ProjectileArgs Args; readonly ProjectileArgs Args;
int2 offset; int2 offset;
float2 Pos; int2 Pos;
readonly Animation anim; readonly Animation anim;
int Facing; int Facing;
int t; int t;
@@ -93,12 +93,13 @@ namespace OpenRA.Mods.RA.Effects
var speed = Scale * Info.Speed * ((targetAltitude > 0 && Info.TurboBoost) ? 1.5f : 1f); var speed = Scale * Info.Speed * ((targetAltitude > 0 && Info.TurboBoost) ? 1.5f : 1f);
var angle = Facing / 128f * Math.PI; var angle = Facing / 128f * Math.PI;
var move = speed * -float2.FromAngle((float)angle); // TODO: Replace float2.FromAngle with int2.FromFacing
var move = (speed * -float2.FromAngle((float)angle)).ToInt2();
Pos += move; Pos += move;
if (Info.Trail != null) if (Info.Trail != null)
world.AddFrameEndTask(w => w.Add( world.AddFrameEndTask(w => w.Add(
new Smoke(w, (Pos - 1.5f * move - new int2(0, Altitude)).ToInt2(), Info.Trail))); new Smoke(w, (Pos - 1.5f * move.ToFloat2() - new int2(0, Altitude)).ToInt2(), Info.Trail)));
if (Info.RangeLimit != 0 && t > Info.RangeLimit * 40) if (Info.RangeLimit != 0 && t > Info.RangeLimit * 40)
Explode(world); Explode(world);
@@ -116,7 +117,7 @@ namespace OpenRA.Mods.RA.Effects
void Explode(World world) void Explode(World world)
{ {
world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
Args.dest = Pos.ToInt2(); Args.dest = Pos;
if (t > Info.Arm * 40) /* don't blow up in our launcher's face! */ if (t > Info.Arm * 40) /* don't blow up in our launcher's face! */
Combat.DoImpacts(Args); Combat.DoImpacts(Args);
} }

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Effects
if (!doneDamage) if (!doneDamage)
{ {
if (Args.target.IsValid) if (Args.target.IsValid)
Args.dest = Args.target.CenterLocation.ToInt2(); Args.dest = Args.target.CenterLocation;
Combat.DoImpacts(Args); Combat.DoImpacts(Args);
doneDamage = true; doneDamage = true;

View File

@@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA
+ Combat.GetTurretPosition(self, facing, Turret) + Combat.GetTurretPosition(self, facing, Turret)
+ Combat.GetBarrelPosition(self, facing, Turret, barrel)).ToInt2(), + Combat.GetBarrelPosition(self, facing, Turret, barrel)).ToInt2(),
srcAltitude = move != null ? move.Altitude : 0, srcAltitude = move != null ? move.Altitude : 0,
dest = target.CenterLocation.ToInt2(), dest = target.CenterLocation,
destAltitude = destMove != null ? destMove.Altitude : 0, destAltitude = destMove != null ? destMove.Altitude : 0,
facing = barrel.Facing + facing = barrel.Facing +