diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index e31ca2ef3d..64a43ce5f0 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -74,22 +74,11 @@ namespace OpenRa.Game PathFinder.Instance = new PathFinder( map, terrain.tileSet ); } - void PrecacheStructure(string name) - { - UnitSheetBuilder.GetUnit(name); - UnitSheetBuilder.GetUnit(name + "make"); - } - - void PrecacheUnit(string name) - { - UnitSheetBuilder.GetUnit(name); - } - internal void Run() { while (Created && Visible) { - Frame(); + viewport.DrawRegions(); Application.DoEvents(); } } @@ -120,10 +109,5 @@ namespace OpenRa.Game lastPos = p; } } - - void Frame() - { - viewport.DrawRegions(); - } } } diff --git a/OpenRa.Game/Mcv.cs b/OpenRa.Game/Mcv.cs index 59a1756d5a..1628c0ccbd 100644 --- a/OpenRa.Game/Mcv.cs +++ b/OpenRa.Game/Mcv.cs @@ -7,6 +7,8 @@ using BluntDirectX.Direct3D; namespace OpenRa.Game { + delegate void TickFunc(World world, double t); + class Mcv : Actor, ISelectable { static Range mcvRange = UnitSheetBuilder.GetUnit("mcv"); @@ -15,14 +17,11 @@ namespace OpenRa.Game int2 fromCell, toCell; int moveFraction, moveFractionTotal; - delegate void TickFunc( World world, double t ); - TickFunc currentOrder = null; - TickFunc nextOrder = null; + TickFunc currentOrder, nextOrder; public Mcv(int2 cell, int palette) { fromCell = toCell = cell; - // HACK: display the mcv centered in it's cell; renderLocation = (cell * 24).ToFloat2() - new float2(12, 12); this.palette = palette; } @@ -116,9 +115,7 @@ namespace OpenRa.Game else location = 24 * fromCell.ToFloat2(); - renderLocation = location - new float2( 12, 12 ); // HACK: center mcv in it's cell - - renderLocation = renderLocation.Round(); + renderLocation = (location - new float2( 12, 12 )).Round(); }; } diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index 1c566445c1..c64c764049 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -34,8 +34,6 @@ namespace OpenRa.Game } } - static bool first = true; - public List FindUnitPath( World world, Mcv unit, int2 destination ) { int2 offset = new int2( map.XOffset, map.YOffset ); @@ -61,24 +59,18 @@ namespace OpenRa.Game queue.Add( new PathDistance( Estimate( startLocation, destination ), startLocation ) ); minCost[ startLocation.X, startLocation.Y ] = Estimate( startLocation, destination ); - int hax = 0; int seenCount = 0; int impassableCount = 0; while( !queue.Empty ) { - ++hax; PathDistance p = queue.Pop(); int2 here = p.Location; seen[ here.X, here.Y ] = true; - if( hax < 128 ) - world.AddFrameEndTask( delegate { world.Add( new Mcv( here - offset, 2 ) ); } ); - if( p.Location == destination ) { - Log.Write( "{0}, {1}, {2}", hax, seenCount, impassableCount ); - first = false; + Log.Write( "{0}, {1}", seenCount, impassableCount ); return MakePath( path, destination, offset ); } @@ -147,22 +139,22 @@ namespace OpenRa.Game int straight = Math.Abs( d.X - d.Y ); return 1.5 * diag + straight; } + } - struct PathDistance : IComparable + struct PathDistance : IComparable + { + public double EstTotal; + public int2 Location; + + public PathDistance(double estTotal, int2 location) { - public double EstTotal; - public int2 Location; + EstTotal = estTotal; + Location = location; + } - public PathDistance( double estTotal, int2 location ) - { - EstTotal = estTotal; - Location = location; - } - - public int CompareTo( PathDistance other ) - { - return Math.Sign( EstTotal - other.EstTotal ); - } + public int CompareTo(PathDistance other) + { + return Math.Sign(EstTotal - other.EstTotal); } } } diff --git a/OpenRa.Game/Sheet.cs b/OpenRa.Game/Sheet.cs index 1200b6312e..22fd1c1449 100644 --- a/OpenRa.Game/Sheet.cs +++ b/OpenRa.Game/Sheet.cs @@ -15,6 +15,8 @@ namespace OpenRa.Game readonly GraphicsDevice device; Texture texture; + string filename = string.Format("../../../block-cache-{0}.png", suffix++); + public Size Size { get { return bitmap.Size; } } public Sheet(Size size, GraphicsDevice d) @@ -36,10 +38,9 @@ namespace OpenRa.Game void LoadTexture() { - string tempFile = string.Format("../../../block-cache-{0}.png", suffix++); - bitmap.Save(tempFile); + bitmap.Save(filename); - using( Stream s = File.OpenRead(tempFile) ) + using( Stream s = File.OpenRead(filename) ) texture = Texture.Create(s, device); } diff --git a/OpenRa.Game/SpriteRenderer.cs b/OpenRa.Game/SpriteRenderer.cs index 6ca78320bc..916da648ab 100644 --- a/OpenRa.Game/SpriteRenderer.cs +++ b/OpenRa.Game/SpriteRenderer.cs @@ -16,7 +16,7 @@ namespace OpenRa.Game const int spritesPerBatch = 1024; List vertices = new List(); - List indicies = new List(); + List indices = new List(); Sheet currentSheet = null; int sprites = 0; ShaderQuality quality; @@ -38,15 +38,15 @@ namespace OpenRa.Game renderer.DrawWithShader(quality, delegate { vertexBuffer.SetData(vertices.ToArray()); - indexBuffer.SetData(indicies.ToArray()); + indexBuffer.SetData(indices.ToArray()); renderer.DrawBatch(vertexBuffer, indexBuffer, new Range(0, vertices.Count), - new Range(0, indicies.Count), + new Range(0, indices.Count), currentSheet.Texture); }); vertices = new List(); - indicies = new List(); + indices = new List(); currentSheet = null; sprites = 0; } @@ -58,7 +58,7 @@ namespace OpenRa.Game Flush(); currentSheet = s.sheet; - Util.CreateQuad(vertices, indicies, location, s, palette); + Util.CreateQuad(vertices, indices, location, s, palette); if (++sprites >= spritesPerBatch) Flush();