diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 176876f6f8..5321298f5b 100644 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -13,6 +13,6 @@ namespace OpenRa.Game public abstract float2 RenderLocation { get; } public int palette; public abstract Sprite[] CurrentImages { get; } - public virtual void Tick(Game game, double t) { } + public virtual void Tick(Game game, int t) { } } } diff --git a/OpenRa.Game/Animation.cs b/OpenRa.Game/Animation.cs index 715fc40853..a2620644c1 100644 --- a/OpenRa.Game/Animation.cs +++ b/OpenRa.Game/Animation.cs @@ -59,10 +59,10 @@ namespace OpenRa.Game }; } - double timeUntilNextFrame; + int timeUntilNextFrame; - Action tickFunc; - public void Tick( double t ) + Action tickFunc; + public void Tick( int t ) { if( tickAlways ) tickFunc( t ); @@ -71,8 +71,8 @@ namespace OpenRa.Game timeUntilNextFrame -= t; while( timeUntilNextFrame <= 0 ) { - tickFunc( 40.0 / 1000.0 ); - timeUntilNextFrame += ( 40.0 / 1000.0 ); // 25 fps == 40 ms + tickFunc( 40 ); + timeUntilNextFrame += 40; // 25 fps == 40 ms } } } diff --git a/OpenRa.Game/Building.cs b/OpenRa.Game/Building.cs index 890afd2499..1ab5fbf1b4 100644 --- a/OpenRa.Game/Building.cs +++ b/OpenRa.Game/Building.cs @@ -18,7 +18,7 @@ namespace OpenRa.Game animation.PlayThen( "make", delegate { animation.Play( "idle" ); } ); } - public override void Tick( Game game, double t ) + public override void Tick( Game game, int t ) { animation.Tick( t ); } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index fe54b56969..cdd5477194 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -9,7 +9,6 @@ namespace OpenRa.Game { public readonly World world; public readonly Map map; - public readonly SpriteRenderer SpriteRenderer; public readonly TreeCache treeCache; public readonly TerrainRenderer terrain; public readonly Viewport viewport; @@ -18,7 +17,6 @@ namespace OpenRa.Game public Game( string mapName, Renderer renderer, int2 clientSize ) { - SheetBuilder.Initialize( renderer.Device ); map = new Map( new IniFile( FileSystem.Open( mapName ) ) ); FileSystem.Mount( new Package( "../../../" + map.Theater + ".mix" ) ); @@ -35,5 +33,15 @@ namespace OpenRa.Game network = new Network(); } + + public void Tick() + { + viewport.DrawRegions( this ); + } + + public void Issue( IOrder order ) + { + order.Apply(); + } } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index dac26706e1..1859bc80aa 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -39,6 +39,7 @@ namespace OpenRa.Game bool windowed = !settings.GetValue("fullscreeen", false); renderer = new Renderer(this, GetResolution(settings), windowed); + SheetBuilder.Initialize( renderer.Device ); game = new Game( settings.GetValue( "map", "scm12ea.ini" ), renderer, new int2( ClientSize ) ); @@ -60,7 +61,7 @@ namespace OpenRa.Game { while (Created && Visible) { - game.viewport.DrawRegions( game ); + game.Tick(); Application.DoEvents(); } } @@ -75,7 +76,8 @@ namespace OpenRa.Game if (e.Button == MouseButtons.Left) { float2 xy = ( 1 / 24.0f ) * ( new float2( e.Location ) + game.viewport.Location ); - game.world.myUnit.Order( new int2( (int)xy.X, (int)xy.Y ) ).Apply(); + IOrder order = game.world.myUnit.Order( new int2( (int)xy.X, (int)xy.Y ) ); + game.Issue( order ); } } diff --git a/OpenRa.Game/Mcv.cs b/OpenRa.Game/Mcv.cs index 88d22d8081..02c995b37f 100644 --- a/OpenRa.Game/Mcv.cs +++ b/OpenRa.Game/Mcv.cs @@ -16,7 +16,7 @@ namespace OpenRa.Game public void AcceptDeployOrder() { - nextOrder = delegate( Game game, double t ) + nextOrder = delegate( Game game, int t ) { if( Turn( 12 ) ) return; diff --git a/OpenRa.Game/Unit.cs b/OpenRa.Game/Unit.cs index 9a000a7314..5789f11435 100644 --- a/OpenRa.Game/Unit.cs +++ b/OpenRa.Game/Unit.cs @@ -12,7 +12,7 @@ namespace OpenRa.Game protected int2 fromCell, toCell; protected int moveFraction, moveFractionTotal; - protected delegate void TickFunc( Game game, double t ); + protected delegate void TickFunc( Game game, int t ); protected TickFunc currentOrder = null; protected TickFunc nextOrder = null; @@ -54,7 +54,7 @@ namespace OpenRa.Game const int Speed = 6; - public override void Tick( Game game, double t ) + public override void Tick( Game game, int t ) { animation.Tick( t ); if( currentOrder == null && nextOrder != null ) @@ -69,7 +69,7 @@ namespace OpenRa.Game public void AcceptMoveOrder( int2 destination ) { - nextOrder = delegate( Game game, double t ) + nextOrder = delegate( Game game, int t ) { if( nextOrder != null ) destination = toCell; @@ -77,7 +77,7 @@ namespace OpenRa.Game if( Turn( GetFacing( toCell - fromCell ) ) ) return; - moveFraction += (int)( t * ( Speed * 100 ) ); + moveFraction += t * Speed; if( moveFraction < moveFractionTotal ) return; @@ -97,7 +97,7 @@ namespace OpenRa.Game toCell = res[ res.Count - 1 ]; int2 dir = toCell - fromCell; - moveFractionTotal = ( dir.X != 0 && dir.Y != 0 ) ? 250 : 200; + moveFractionTotal = ( dir.X != 0 && dir.Y != 0 ) ? 2500 : 2000; } else destination = toCell; diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index f71bcfd220..35127926d1 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -27,12 +27,12 @@ namespace OpenRa.Game public void Remove( Actor a ) { actors.Remove( a ); } public void AddFrameEndTask( Action a ) { frameEndActions.Add( a ); } - double lastTime = Environment.TickCount / 1000.0; + int lastTime = Environment.TickCount; void Draw( Game game ) { - double t = Environment.TickCount / 1000.0; - double dt = t - lastTime; + int t = Environment.TickCount; + int dt = t - lastTime; lastTime = t; Range range = new Range(viewport.Location, viewport.Location + viewport.Size);