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

This commit is contained in:
bob
2007-07-12 19:46:13 +00:00
parent 4139e4dac6
commit 9a6182bb17
9 changed files with 94 additions and 11 deletions

View File

@@ -104,8 +104,14 @@ namespace OpenRa.FileFormats
} }
for( int i = 0 ; i < 128 ; i++ ) for( int i = 0 ; i < 128 ; i++ )
{
for( int j = 0 ; j < 128 ; j++ ) for( int j = 0 ; j < 128 ; j++ )
{
MapTiles[ j, i ].image = ReadByte( ms ); 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 ) void ReadTrees( IniFile file )

View File

@@ -8,9 +8,9 @@ using System.Windows.Forms;
namespace OpenRa.Game namespace OpenRa.Game
{ {
class Actor abstract class Actor
{ {
public PointF location; public PointF location;
public SheetRectangle<Sheet>[] currentImages; public abstract SheetRectangle<Sheet>[] CurrentImages { get; }
} }
} }

View File

@@ -72,6 +72,9 @@ namespace OpenRa.Game
foreach (TreeReference treeReference in map.Trees) foreach (TreeReference treeReference in map.Trees)
world.Add(new Tree(treeReference, treeCache, map)); 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() void LoadVertexBuffer()

View File

@@ -2,18 +2,22 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using OpenRa.FileFormats; using OpenRa.FileFormats;
using System.Drawing;
namespace OpenRa.Game namespace OpenRa.Game
{ {
class Mcv : Actor class Mcv : Actor
{ {
int facing; //int facing; // not currently used
static Package unitsPackage = new Package("../../../conquer.mix"); public Mcv( PointF location )
public Mcv()
{ {
this.location = location;
}
public override SheetRectangle<Sheet>[] CurrentImages
{
get { return new SheetRectangle<Sheet>[] { UnitSheetBuilder.McvSheet[ 0 ] }; }
} }
} }
} }

View File

@@ -52,6 +52,7 @@
<Compile Include="Sheet.cs" /> <Compile Include="Sheet.cs" />
<Compile Include="Tree.cs" /> <Compile Include="Tree.cs" />
<Compile Include="TreeCache.cs" /> <Compile Include="TreeCache.cs" />
<Compile Include="UnitSheetBuilder.cs" />
<Compile Include="Util.cs" /> <Compile Include="Util.cs" />
<Compile Include="Vertex.cs" /> <Compile Include="Vertex.cs" />
<Compile Include="World.cs" /> <Compile Include="World.cs" />

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -9,10 +10,18 @@ namespace OpenRa.Game
[STAThread] [STAThread]
static void Main() static void Main()
{ {
Application.EnableVisualStyles(); try
Application.SetCompatibleTextRenderingDefault(false); {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
new MainWindow().Run(); new MainWindow().Run();
}
catch( Exception e )
{
File.WriteAllText( "error.log", e.ToString() );
throw;
}
} }
} }
} }

View File

@@ -13,5 +13,11 @@ namespace OpenRa.Game
location = new PointF(24 * (r.X - map.XOffset), 24 * (r.Y - map.YOffset)); location = new PointF(24 * (r.X - map.XOffset), 24 * (r.Y - map.YOffset));
currentImages = new SheetRectangle<Sheet>[] { renderer.GetImage(r.Image) }; currentImages = new SheetRectangle<Sheet>[] { renderer.GetImage(r.Image) };
} }
SheetRectangle<Sheet>[] currentImages;
public override SheetRectangle<Sheet>[] CurrentImages
{
get { return currentImages; }
}
} }
} }

View File

@@ -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<SheetRectangle<Sheet>> McvSheet = new List<SheetRectangle<Sheet>>();
public static void AddUnit( string name, GraphicsDevice device, Palette pal )
{
List<Sheet> sheets = new List<Sheet>();
Size pageSize = new Size( 1024, 512 );
Provider<Sheet> sheetProvider = delegate
{
Sheet sheet = new Sheet( new Bitmap( pageSize.Width, pageSize.Height ) );
sheets.Add( sheet );
return sheet;
};
TileSheetBuilder<Sheet> builder = new TileSheetBuilder<Sheet>( 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<Sheet> 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 );
}
}
}

View File

@@ -43,11 +43,20 @@ namespace OpenRa.Game
foreach (Actor a in actors) foreach (Actor a in actors)
{ {
if (a.currentImages == null) if (a.CurrentImages == null)
continue; continue;
foreach (SheetRectangle<Sheet> image in a.currentImages) foreach (SheetRectangle<Sheet> image in a.CurrentImages)
{ {
if( image.sheet != sheet && sprites > 0 && sheet != null )
{
DrawBatch( vertices, indices, renderer, sheet );
vertices = new List<Vertex>();
indices = new List<ushort>();
sprites = 0;
}
sheet = image.sheet; sheet = image.sheet;
Util.CreateQuad(vertices, indices, a.location, image); Util.CreateQuad(vertices, indices, a.location, image);