Locked frame times; SAM, GUN, AGUN work again.

- all frames are 40ms long. (except something in the sidebar, which should really be PlayFetchIndex anyway)
    - SAM, GUN, and AGUN no longer crash the game when built. (Turreted used Mobile, which those buildings don't have)
This commit is contained in:
Bob
2009-10-20 00:57:50 +13:00
parent a7ce0f97d1
commit 707ba7d957
14 changed files with 32 additions and 31 deletions

View File

@@ -128,10 +128,10 @@ namespace OpenRa.Game
traits.Add( new Traits.Tree( treeRenderer.GetImage( tree.Image ) ) );
}
public void Tick( Game game, int dt )
public void Tick( Game game )
{
foreach( var tick in traits.WithInterface<Traits.ITick>() )
tick.Tick( this, game, dt );
tick.Tick( this, game );
}
public float2 CenterLocation;

View File

@@ -41,12 +41,12 @@ namespace OpenRa.Game
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
public void Tick(Game game, int dt)
public void Tick(Game game)
{
if (t == 0)
game.PlaySound(Weapon.Report + ".aud", false);
t += dt;
t += 40;
if (t > TotalTime()) /* remove finished bullets */
game.world.AddFrameEndTask(w => w.Remove(this));

View File

@@ -56,6 +56,11 @@ namespace OpenRa.Game.Graphics
int timeUntilNextFrame;
Action tickFunc;
public void Tick()
{
Tick( 40 ); // tick one frame
}
public void Tick( int t )
{
if( tickAlways )

View File

@@ -18,7 +18,7 @@ namespace OpenRa.Game.Traits
self.traits.Get<Turreted>();
}
public void Tick( Actor self, Game game, int dt )
public void Tick( Actor self, Game game )
{
if( primaryFireDelay > 0 )
--primaryFireDelay;
@@ -28,7 +28,6 @@ namespace OpenRa.Game.Traits
if( target == null )
return;
var mobile = self.traits.Get<Mobile>();
var turreted = self.traits.Get<Turreted>();
turreted.desiredFacing = Util.GetFacing( target.CenterLocation - self.CenterLocation, turreted.turretFacing );
if( turreted.desiredFacing != turreted.turretFacing )

View File

@@ -12,7 +12,7 @@ namespace OpenRa.Game.Traits
}
bool first = true;
public void Tick(Actor self, Game game, int dt)
public void Tick(Actor self, Game game)
{
if (first && self.Owner == game.LocalPlayer)
{

View File

@@ -23,7 +23,7 @@ namespace OpenRa.Game.Traits
return null;
}
public void Tick(Actor self, Game game, int dt)
public void Tick(Actor self, Game game)
{
if( self.Location != DeployLocation )
return;

View File

@@ -29,13 +29,13 @@ namespace OpenRa.Game.Traits
self.CenterLocation = new float2(12, 12) + Game.CellSize * float2.Lerp(fromCell, toCell, fraction);
}
public void Tick(Actor self, Game game, int dt)
public void Tick(Actor self, Game game)
{
Move(self, game, dt);
Move(self, game);
UpdateCenterLocation();
}
void Move(Actor self, Game game, int dt)
void Move(Actor self, Game game)
{
if( fromCell != toCell )
desiredFacing = Util.GetFacing( toCell - fromCell, facing );
@@ -48,7 +48,7 @@ namespace OpenRa.Game.Traits
desiredFacing = null;
if( fromCell != toCell )
moveFraction += dt * ((UnitInfo.MobileInfo)self.unitInfo).Speed;
moveFraction += ((UnitInfo.MobileInfo)self.unitInfo).Speed;
if (moveFraction < moveFractionTotal)
return;
@@ -66,7 +66,7 @@ namespace OpenRa.Game.Traits
self.Location = res[res.Count - 1];
int2 dir = toCell - fromCell;
moveFractionTotal = (dir.X != 0 && dir.Y != 0) ? 2500 : 2000;
moveFractionTotal = (dir.X != 0 && dir.Y != 0) ? 70 : 50;
}
else
destination = toCell;

View File

@@ -33,10 +33,10 @@ namespace OpenRa.Game.Traits
return base.Render(self);
}
public override void Tick(Actor self, Game game, int dt)
public override void Tick(Actor self, Game game)
{
base.Tick(self, game, dt);
roof.Tick(dt);
base.Tick(self, game);
roof.Tick();
}
}
}

View File

@@ -18,9 +18,9 @@ namespace OpenRa.Game.Traits
public abstract IEnumerable<Pair<Sprite, float2>> Render(Actor self);
public virtual void Tick(Actor self, Game game, int dt)
public virtual void Tick(Actor self, Game game)
{
anim.Tick(dt);
anim.Tick();
}
}
}

View File

@@ -25,10 +25,10 @@ namespace OpenRa.Game.Traits
yield return Centered(turretAnim.Image, self.CenterLocation);
}
public override void Tick(Actor self, Game game, int dt)
public override void Tick(Actor self, Game game)
{
base.Tick(self, game, dt);
turretAnim.Tick(dt);
base.Tick(self, game);
turretAnim.Tick();
}
}
}

View File

@@ -7,7 +7,7 @@ using IjwFramework.Types;
namespace OpenRa.Game.Traits
{
interface ITick { void Tick(Actor self, Game game, int dt); }
interface ITick { void Tick(Actor self, Game game); }
interface IRender { IEnumerable<Pair<Sprite, float2>> Render(Actor self); }
interface IOrder { Order Order(Actor self, Game game, int2 xy); }
}

View File

@@ -14,12 +14,9 @@ namespace OpenRa.Game.Traits
{
}
public void Tick( Actor self, Game game, int dt )
public void Tick( Actor self, Game game )
{
// TODO: desiredFacing should follow the base unit's facing only when not in combat.
// also, we want to be able to use this for GUN; avoid referencing Mobile.
var df = desiredFacing ?? self.traits.Get<Mobile>().facing;
var df = desiredFacing ?? ( self.traits.Contains<Mobile>() ? self.traits.Get<Mobile>().facing : turretFacing );
Util.TickFacing( ref turretFacing, df, self.unitInfo.ROT );
}
}

View File

@@ -41,9 +41,9 @@ namespace OpenRa.Game
lastTime += timestep;
foreach( var a in actors )
a.Tick(game, timestep);
a.Tick(game);
foreach (var b in bullets)
b.Tick(game, timestep);
b.Tick(game);
Renderer.waterFrame += 0.00125f * timestep;
}