diff --git a/OpenRa.FileFormats/Map.cs b/OpenRa.FileFormats/Map.cs index 19e887ae61..b5704ac475 100644 --- a/OpenRa.FileFormats/Map.cs +++ b/OpenRa.FileFormats/Map.cs @@ -104,8 +104,14 @@ namespace OpenRa.FileFormats } for( int i = 0 ; i < 128 ; i++ ) + { for( int j = 0 ; j < 128 ; j++ ) + { MapTiles[ j, i ].image = ReadByte( ms ); + if( MapTiles[ j, i ].tile == 0xff || MapTiles[ j, i ].tile == 0xffff ) + MapTiles[ j, i ].image = (byte)( i % 4 + ( j % 4 ) * 4 ); + } + } } void ReadTrees( IniFile file ) diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 0b8ed203ef..397dc37553 100644 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -8,9 +8,9 @@ using System.Windows.Forms; namespace OpenRa.Game { - class Actor + abstract class Actor { public PointF location; - public SheetRectangle[] currentImages; + public abstract SheetRectangle[] CurrentImages { get; } } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index e2e991a18e..8820b6c46b 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -72,6 +72,9 @@ namespace OpenRa.Game foreach (TreeReference treeReference in map.Trees) world.Add(new Tree(treeReference, treeCache, map)); + + UnitSheetBuilder.AddUnit( "mcv", renderer.Device, pal ); + world.Add( new Mcv( new PointF( 24 * 5, 24 * 5 ) ) ); } void LoadVertexBuffer() diff --git a/OpenRa.Game/Mcv.cs b/OpenRa.Game/Mcv.cs index 65f914e75f..1d7d533a1b 100644 --- a/OpenRa.Game/Mcv.cs +++ b/OpenRa.Game/Mcv.cs @@ -2,18 +2,22 @@ using System; using System.Collections.Generic; using System.Text; using OpenRa.FileFormats; +using System.Drawing; namespace OpenRa.Game { class Mcv : Actor { - int facing; + //int facing; // not currently used - static Package unitsPackage = new Package("../../../conquer.mix"); - - public Mcv() + public Mcv( PointF location ) { + this.location = location; + } + public override SheetRectangle[] CurrentImages + { + get { return new SheetRectangle[] { UnitSheetBuilder.McvSheet[ 0 ] }; } } } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index cddbae16fe..e7f15c90ef 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -52,6 +52,7 @@ + diff --git a/OpenRa.Game/Program.cs b/OpenRa.Game/Program.cs index b09eca57aa..2a32eef6e5 100644 --- a/OpenRa.Game/Program.cs +++ b/OpenRa.Game/Program.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Windows.Forms; +using System.IO; namespace OpenRa.Game { @@ -9,10 +10,18 @@ namespace OpenRa.Game [STAThread] static void Main() { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); + try + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault( false ); - new MainWindow().Run(); + new MainWindow().Run(); + } + catch( Exception e ) + { + File.WriteAllText( "error.log", e.ToString() ); + throw; + } } } } \ No newline at end of file diff --git a/OpenRa.Game/Tree.cs b/OpenRa.Game/Tree.cs index 9228b424e5..d6e7213334 100644 --- a/OpenRa.Game/Tree.cs +++ b/OpenRa.Game/Tree.cs @@ -13,5 +13,11 @@ namespace OpenRa.Game location = new PointF(24 * (r.X - map.XOffset), 24 * (r.Y - map.YOffset)); currentImages = new SheetRectangle[] { renderer.GetImage(r.Image) }; } + + SheetRectangle[] currentImages; + public override SheetRectangle[] CurrentImages + { + get { return currentImages; } + } } } diff --git a/OpenRa.Game/UnitSheetBuilder.cs b/OpenRa.Game/UnitSheetBuilder.cs new file mode 100644 index 0000000000..4a5b7defa8 --- /dev/null +++ b/OpenRa.Game/UnitSheetBuilder.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenRa.FileFormats; +using System.Drawing; +using BluntDirectX.Direct3D; + +namespace OpenRa.Game +{ + static class UnitSheetBuilder + { + static readonly Package unitsPackage = new Package( "../../../conquer.mix" ); + public static readonly List> McvSheet = new List>(); + + public static void AddUnit( string name, GraphicsDevice device, Palette pal ) + { + List sheets = new List(); + Size pageSize = new Size( 1024, 512 ); + + Provider sheetProvider = delegate + { + Sheet sheet = new Sheet( new Bitmap( pageSize.Width, pageSize.Height ) ); + sheets.Add( sheet ); + return sheet; + }; + + TileSheetBuilder builder = new TileSheetBuilder( pageSize, sheetProvider ); + + ShpReader reader = new ShpReader( unitsPackage.GetContent( name + ".shp" ) ); + foreach( ImageHeader h in reader ) + { + Bitmap bitmap = BitmapBuilder.FromBytes( h.Image, reader.Width, reader.Height, pal ); + + SheetRectangle rect = builder.AddImage( bitmap.Size ); + using( Graphics g = Graphics.FromImage( rect.sheet.bitmap ) ) + g.DrawImage( bitmap, rect.origin ); + + McvSheet.Add( rect ); + } + + foreach( Sheet sheet in sheets ) + sheet.LoadTexture( device ); + } + } +} diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index 2551b0cd78..1c7ff658a1 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -43,11 +43,20 @@ namespace OpenRa.Game foreach (Actor a in actors) { - if (a.currentImages == null) + if (a.CurrentImages == null) continue; - foreach (SheetRectangle image in a.currentImages) + foreach (SheetRectangle image in a.CurrentImages) { + if( image.sheet != sheet && sprites > 0 && sheet != null ) + { + DrawBatch( vertices, indices, renderer, sheet ); + + vertices = new List(); + indices = new List(); + sprites = 0; + } + sheet = image.sheet; Util.CreateQuad(vertices, indices, a.location, image);