reduces duplication; textures get put in hardware on demand now.
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1187 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -39,7 +39,7 @@ namespace OpenRa.Game
|
||||
|
||||
Provider<Sheet> sheetProvider = delegate
|
||||
{
|
||||
Sheet t = new Sheet( new Bitmap(pageSize.Width, pageSize.Height));
|
||||
Sheet t = new Sheet( new Bitmap(pageSize.Width, pageSize.Height),renderer.Device);
|
||||
sheets.Add(t);
|
||||
return t;
|
||||
};
|
||||
@@ -63,22 +63,18 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Sheet s in sheets)
|
||||
s.LoadTexture(renderer.Device);
|
||||
|
||||
world = new World(renderer.Device);
|
||||
treeCache = new TreeCache(renderer.Device, map, TileMix, pal);
|
||||
|
||||
foreach (TreeReference treeReference in map.Trees)
|
||||
world.Add(new Tree(treeReference, treeCache, map));
|
||||
|
||||
UnitSheetBuilder.Initialize(renderer.Device);
|
||||
UnitSheetBuilder.AddUnit( "mcv", playerPal );
|
||||
UnitSheetBuilder.AddUnit("1tnk", playerPal);
|
||||
UnitSheetBuilder.AddUnit("2tnk", playerPal);
|
||||
UnitSheetBuilder.AddUnit("3tnk", playerPal);
|
||||
|
||||
UnitSheetBuilder.Resolve(renderer.Device);
|
||||
|
||||
world.Add( new Mcv( new PointF( 24 * 5, 24 * 5 ) ) );
|
||||
}
|
||||
|
||||
@@ -207,7 +203,7 @@ namespace OpenRa.Game
|
||||
renderer.DrawBatch(vertexBuffer, batch.Value,
|
||||
new Range<int>(verticesPerRow * firstRow, verticesPerRow * lastRow),
|
||||
new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow),
|
||||
batch.Key.texture);
|
||||
batch.Key.Texture);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,24 @@ namespace OpenRa.Game
|
||||
class Sheet
|
||||
{
|
||||
public readonly Bitmap bitmap;
|
||||
public Texture texture;
|
||||
|
||||
public Sheet(Bitmap b) { bitmap = b; }
|
||||
readonly GraphicsDevice device;
|
||||
Texture texture;
|
||||
|
||||
public void LoadTexture(GraphicsDevice device)
|
||||
public Sheet(Bitmap b, GraphicsDevice d) { bitmap = b; device = d; }
|
||||
|
||||
public Texture Texture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (texture == null)
|
||||
LoadTexture();
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadTexture()
|
||||
{
|
||||
string tempFile = string.Format("../../../block-cache-{0}.png", suffix++);
|
||||
bitmap.Save(tempFile);
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace OpenRa.Game
|
||||
|
||||
Provider<Sheet> sheetProvider = delegate
|
||||
{
|
||||
Sheet sheet = new Sheet(new Bitmap(pageSize.Width, pageSize.Height));
|
||||
Sheet sheet = new Sheet(new Bitmap(pageSize.Width, pageSize.Height), device);
|
||||
sheets.Add(sheet);
|
||||
return sheet;
|
||||
};
|
||||
@@ -42,9 +42,6 @@ namespace OpenRa.Game
|
||||
trees.Add(r.Image, rect);
|
||||
}
|
||||
|
||||
foreach (Sheet sheet in sheets)
|
||||
sheet.LoadTexture(device);
|
||||
|
||||
sh = sheets[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace OpenRa.Game
|
||||
static List<Sheet> sheets = new List<Sheet>();
|
||||
static Size pageSize = new Size(1024, 512);
|
||||
|
||||
static UnitSheetBuilder()
|
||||
public static void Initialize( GraphicsDevice device )
|
||||
{
|
||||
Provider<Sheet> sheetProvider = delegate
|
||||
{
|
||||
Sheet sheet = new Sheet(new Bitmap(pageSize.Width, pageSize.Height));
|
||||
Sheet sheet = new Sheet(new Bitmap(pageSize.Width, pageSize.Height), device);
|
||||
sheets.Add(sheet);
|
||||
return sheet;
|
||||
};
|
||||
@@ -28,12 +28,6 @@ namespace OpenRa.Game
|
||||
builder = new TileSheetBuilder<Sheet>(pageSize, sheetProvider);
|
||||
}
|
||||
|
||||
public static void Resolve( GraphicsDevice device )
|
||||
{
|
||||
foreach (Sheet sheet in sheets)
|
||||
sheet.LoadTexture(device);
|
||||
}
|
||||
|
||||
public static void AddUnit( string name, Palette pal )
|
||||
{
|
||||
ShpReader reader = new ShpReader( unitsPackage.GetContent( name + ".shp" ) );
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace OpenRa.Game
|
||||
renderer.DrawBatch(vb, ib,
|
||||
new Range<int>(0, vertices.Count),
|
||||
new Range<int>(0, indices.Count),
|
||||
sheet.texture);
|
||||
sheet.Texture);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user