git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1329 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
(no author)
2007-07-23 12:15:42 +00:00
parent c8a81ffce4
commit d94b589650
8 changed files with 30 additions and 20 deletions

View File

@@ -13,6 +13,6 @@ namespace OpenRa.Game
public abstract float2 RenderLocation { get; } public abstract float2 RenderLocation { get; }
public int palette; public int palette;
public abstract Sprite[] CurrentImages { get; } public abstract Sprite[] CurrentImages { get; }
public virtual void Tick(Game game, double t) { } public virtual void Tick(Game game, int t) { }
} }
} }

View File

@@ -59,10 +59,10 @@ namespace OpenRa.Game
}; };
} }
double timeUntilNextFrame; int timeUntilNextFrame;
Action<double> tickFunc; Action<int> tickFunc;
public void Tick( double t ) public void Tick( int t )
{ {
if( tickAlways ) if( tickAlways )
tickFunc( t ); tickFunc( t );
@@ -71,8 +71,8 @@ namespace OpenRa.Game
timeUntilNextFrame -= t; timeUntilNextFrame -= t;
while( timeUntilNextFrame <= 0 ) while( timeUntilNextFrame <= 0 )
{ {
tickFunc( 40.0 / 1000.0 ); tickFunc( 40 );
timeUntilNextFrame += ( 40.0 / 1000.0 ); // 25 fps == 40 ms timeUntilNextFrame += 40; // 25 fps == 40 ms
} }
} }
} }

View File

@@ -18,7 +18,7 @@ namespace OpenRa.Game
animation.PlayThen( "make", delegate { animation.Play( "idle" ); } ); 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 ); animation.Tick( t );
} }

View File

@@ -9,7 +9,6 @@ namespace OpenRa.Game
{ {
public readonly World world; public readonly World world;
public readonly Map map; public readonly Map map;
public readonly SpriteRenderer SpriteRenderer;
public readonly TreeCache treeCache; public readonly TreeCache treeCache;
public readonly TerrainRenderer terrain; public readonly TerrainRenderer terrain;
public readonly Viewport viewport; public readonly Viewport viewport;
@@ -18,7 +17,6 @@ namespace OpenRa.Game
public Game( string mapName, Renderer renderer, int2 clientSize ) public Game( string mapName, Renderer renderer, int2 clientSize )
{ {
SheetBuilder.Initialize( renderer.Device );
map = new Map( new IniFile( FileSystem.Open( mapName ) ) ); map = new Map( new IniFile( FileSystem.Open( mapName ) ) );
FileSystem.Mount( new Package( "../../../" + map.Theater + ".mix" ) ); FileSystem.Mount( new Package( "../../../" + map.Theater + ".mix" ) );
@@ -35,5 +33,15 @@ namespace OpenRa.Game
network = new Network(); network = new Network();
} }
public void Tick()
{
viewport.DrawRegions( this );
}
public void Issue( IOrder order )
{
order.Apply();
}
} }
} }

View File

@@ -39,6 +39,7 @@ namespace OpenRa.Game
bool windowed = !settings.GetValue("fullscreeen", false); bool windowed = !settings.GetValue("fullscreeen", false);
renderer = new Renderer(this, GetResolution(settings), windowed); renderer = new Renderer(this, GetResolution(settings), windowed);
SheetBuilder.Initialize( renderer.Device );
game = new Game( settings.GetValue( "map", "scm12ea.ini" ), renderer, new int2( ClientSize ) ); game = new Game( settings.GetValue( "map", "scm12ea.ini" ), renderer, new int2( ClientSize ) );
@@ -60,7 +61,7 @@ namespace OpenRa.Game
{ {
while (Created && Visible) while (Created && Visible)
{ {
game.viewport.DrawRegions( game ); game.Tick();
Application.DoEvents(); Application.DoEvents();
} }
} }
@@ -75,7 +76,8 @@ namespace OpenRa.Game
if (e.Button == MouseButtons.Left) if (e.Button == MouseButtons.Left)
{ {
float2 xy = ( 1 / 24.0f ) * ( new float2( e.Location ) + game.viewport.Location ); 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 );
} }
} }

View File

@@ -16,7 +16,7 @@ namespace OpenRa.Game
public void AcceptDeployOrder() public void AcceptDeployOrder()
{ {
nextOrder = delegate( Game game, double t ) nextOrder = delegate( Game game, int t )
{ {
if( Turn( 12 ) ) if( Turn( 12 ) )
return; return;

View File

@@ -12,7 +12,7 @@ namespace OpenRa.Game
protected int2 fromCell, toCell; protected int2 fromCell, toCell;
protected int moveFraction, moveFractionTotal; 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 currentOrder = null;
protected TickFunc nextOrder = null; protected TickFunc nextOrder = null;
@@ -54,7 +54,7 @@ namespace OpenRa.Game
const int Speed = 6; const int Speed = 6;
public override void Tick( Game game, double t ) public override void Tick( Game game, int t )
{ {
animation.Tick( t ); animation.Tick( t );
if( currentOrder == null && nextOrder != null ) if( currentOrder == null && nextOrder != null )
@@ -69,7 +69,7 @@ namespace OpenRa.Game
public void AcceptMoveOrder( int2 destination ) public void AcceptMoveOrder( int2 destination )
{ {
nextOrder = delegate( Game game, double t ) nextOrder = delegate( Game game, int t )
{ {
if( nextOrder != null ) if( nextOrder != null )
destination = toCell; destination = toCell;
@@ -77,7 +77,7 @@ namespace OpenRa.Game
if( Turn( GetFacing( toCell - fromCell ) ) ) if( Turn( GetFacing( toCell - fromCell ) ) )
return; return;
moveFraction += (int)( t * ( Speed * 100 ) ); moveFraction += t * Speed;
if( moveFraction < moveFractionTotal ) if( moveFraction < moveFractionTotal )
return; return;
@@ -97,7 +97,7 @@ namespace OpenRa.Game
toCell = res[ res.Count - 1 ]; toCell = res[ res.Count - 1 ];
int2 dir = toCell - fromCell; int2 dir = toCell - fromCell;
moveFractionTotal = ( dir.X != 0 && dir.Y != 0 ) ? 250 : 200; moveFractionTotal = ( dir.X != 0 && dir.Y != 0 ) ? 2500 : 2000;
} }
else else
destination = toCell; destination = toCell;

View File

@@ -27,12 +27,12 @@ namespace OpenRa.Game
public void Remove( Actor a ) { actors.Remove( a ); } public void Remove( Actor a ) { actors.Remove( a ); }
public void AddFrameEndTask( Action<World> a ) { frameEndActions.Add( a ); } public void AddFrameEndTask( Action<World> a ) { frameEndActions.Add( a ); }
double lastTime = Environment.TickCount / 1000.0; int lastTime = Environment.TickCount;
void Draw( Game game ) void Draw( Game game )
{ {
double t = Environment.TickCount / 1000.0; int t = Environment.TickCount;
double dt = t - lastTime; int dt = t - lastTime;
lastTime = t; lastTime = t;
Range<float2> range = new Range<float2>(viewport.Location, viewport.Location + viewport.Size); Range<float2> range = new Range<float2>(viewport.Location, viewport.Location + viewport.Size);