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

This commit is contained in:
chrisf
2007-07-07 03:29:45 +00:00
parent ac94527e91
commit 34fc937db2
5 changed files with 117 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ using System.Drawing;
using BluntDirectX.Direct3D;
using OpenRa.FileFormats;
using System.IO;
using System.Runtime.InteropServices;
namespace OpenRa.Game
{
@@ -21,6 +22,58 @@ namespace OpenRa.Game
const string mapName = "scm12ea.ini";
Dictionary<TileReference, SheetRectangle<Sheet>> tileMapping =
new Dictionary<TileReference, SheetRectangle<Sheet>>();
FvfVertexBuffer<Vertex> vertexBuffer;
IndexBuffer indexBuffer;
void LoadTextures()
{
List<Sheet> tempSheets = new List<Sheet>();
Provider<Sheet> sheetProvider = delegate
{
Sheet t = new Sheet( new Bitmap(256, 256));
tempSheets.Add(t);
return t;
};
TileSheetBuilder<Sheet> builder = new TileSheetBuilder<Sheet>( new Size(256,256), sheetProvider );
for( int i = 0; i < 128; i++ )
for (int j = 0; j < 128; j++)
{
TileReference tileRef = map.MapTiles[i, j];
if (!tileMapping.ContainsKey(tileRef))
{
SheetRectangle<Sheet> rect = builder.AddImage(new Size(24, 24));
Bitmap srcImage = tileSet.tiles[ tileRef.tile ].GetTile( tileRef.image );
using (Graphics g = Graphics.FromImage(rect.sheet.bitmap))
g.DrawImage(srcImage, rect.origin);
tileMapping.Add(tileRef, rect);
}
}
foreach (Sheet s in tempSheets)
s.LoadTexture(device);
}
void LoadVertexBuffer()
{
Vertex[] vertices = new Vertex[4 * map.Width * map.Height];
vertexBuffer = new FvfVertexBuffer<Vertex>(device, vertices.Length, Vertex.Format);
vertexBuffer.SetData(vertices);
ushort[] indices = new ushort[6 * map.Width * map.Height];
indexBuffer = new IndexBuffer(device, indices.Length);
indexBuffer.SetData(indices);
}
public MainWindow()
{
ClientSize = new Size(640, 480);
@@ -35,6 +88,9 @@ namespace OpenRa.Game
Text = string.Format("OpenRA - {0} - {1}", map.Title, mapName);
tileSet = LoadTileSet(map);
LoadTextures();
LoadVertexBuffer();
}
internal void Run()
@@ -53,6 +109,11 @@ namespace OpenRa.Game
// render something :)
//vertexBuffer.Bind(0);
//indexBuffer.Bind();
//device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 2 * map.Width * map.Height);
device.End();
device.Present();
}
@@ -81,5 +142,7 @@ namespace OpenRa.Game
}
return new TileSet(TileMix, TileSuffix, pal);
}
}
}