git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1195 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -24,28 +24,26 @@ namespace OpenRa.FileFormats
|
||||
if( countStr == null || startStr == null || pattern == null )
|
||||
break;
|
||||
|
||||
//try
|
||||
int count = int.Parse( countStr );
|
||||
int start = int.Parse( startStr, NumberStyles.HexNumber );
|
||||
for( int i = 0 ; i < count ; i++ )
|
||||
{
|
||||
int count = int.Parse( countStr );
|
||||
int start = int.Parse( startStr, NumberStyles.HexNumber );
|
||||
for( int i = 0 ; i < count ; i++ )
|
||||
Stream s;
|
||||
try
|
||||
{
|
||||
Stream s;
|
||||
try
|
||||
{
|
||||
s = mixFile.GetContent( string.Format( pattern, i + 1 ) );
|
||||
}
|
||||
catch { continue; }
|
||||
Terrain t = new Terrain( s, pal );
|
||||
if( tiles.ContainsKey( (ushort)( start + i ) ) )
|
||||
continue;
|
||||
tiles.Add( (ushort)( start + i ), t );
|
||||
s = mixFile.GetContent( string.Format( pattern, i + 1 ) );
|
||||
}
|
||||
catch { continue; }
|
||||
Terrain t = new Terrain( s, pal );
|
||||
if( tiles.ContainsKey( (ushort)( start + i ) ) )
|
||||
continue;
|
||||
tiles.Add( (ushort)( start + i ), t );
|
||||
}
|
||||
//catch { }
|
||||
}
|
||||
|
||||
tileIdFile.Close();
|
||||
}
|
||||
|
||||
public byte[] GetBytes(TileReference r) { return tiles[r.tile].TileBitmapBytes[r.image]; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,24 @@ namespace OpenRa.FileFormats
|
||||
|
||||
T current = null;
|
||||
int x = 0, y = 0, rowHeight = 0;
|
||||
TextureChannel? channel;
|
||||
|
||||
TextureChannel? NextChannel(TextureChannel? t)
|
||||
{
|
||||
if (t == null)
|
||||
return TextureChannel.Red;
|
||||
|
||||
if (t == TextureChannel.Red)
|
||||
return TextureChannel.Green;
|
||||
|
||||
if (t == TextureChannel.Green)
|
||||
return TextureChannel.Blue;
|
||||
|
||||
if (t == TextureChannel.Blue)
|
||||
return TextureChannel.Alpha;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public SheetRectangle<T> AddImage(Size imageSize)
|
||||
{
|
||||
@@ -28,7 +46,10 @@ namespace OpenRa.FileFormats
|
||||
return null;
|
||||
|
||||
if (current == null)
|
||||
{
|
||||
current = pageProvider();
|
||||
channel = NextChannel(null);
|
||||
}
|
||||
|
||||
if (rowHeight == 0 || imageSize.Width + x > pageSize.Width)
|
||||
{
|
||||
@@ -42,11 +63,17 @@ namespace OpenRa.FileFormats
|
||||
|
||||
if (y + imageSize.Height > pageSize.Height)
|
||||
{
|
||||
current = pageProvider();
|
||||
|
||||
if (null == (channel = NextChannel(channel)))
|
||||
{
|
||||
current = pageProvider();
|
||||
channel = NextChannel(channel);
|
||||
}
|
||||
|
||||
x = y = rowHeight = 0;
|
||||
}
|
||||
|
||||
SheetRectangle<T> rect = new SheetRectangle<T>(current, new Point(x, y), imageSize);
|
||||
SheetRectangle<T> rect = new SheetRectangle<T>(current, new Point(x, y), imageSize, channel.Value);
|
||||
x += imageSize.Width;
|
||||
|
||||
return rect;
|
||||
@@ -68,11 +95,6 @@ namespace OpenRa.FileFormats
|
||||
this.sheet = sheet;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
internal SheetRectangle(T sheet, Point origin, Size size)
|
||||
: this(sheet, origin, size, TextureChannel.Red)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public enum TextureChannel
|
||||
|
||||
28
OpenRa.Game/CoreSheetBuilder.cs
Normal file
28
OpenRa.Game/CoreSheetBuilder.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using BluntDirectX.Direct3D;
|
||||
using OpenRa.FileFormats;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
static class CoreSheetBuilder
|
||||
{
|
||||
static TileSheetBuilder<Sheet> builder;
|
||||
static Size pageSize = new Size(512,512);
|
||||
|
||||
public static void Initialize(GraphicsDevice device)
|
||||
{
|
||||
Provider<Sheet> sheetProvider = delegate { return new Sheet(pageSize, device); };
|
||||
builder = new TileSheetBuilder<Sheet>(pageSize, sheetProvider);
|
||||
}
|
||||
|
||||
public static SheetRectangle<Sheet> Add(byte[] src, Size size)
|
||||
{
|
||||
SheetRectangle<Sheet> rect = builder.AddImage(size);
|
||||
Util.CopyIntoChannel(rect, src);
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,18 +33,7 @@ namespace OpenRa.Game
|
||||
|
||||
void LoadTextures()
|
||||
{
|
||||
List<Sheet> sheets = new List<Sheet>();
|
||||
|
||||
Size pageSize = new Size(1024, 512);
|
||||
|
||||
Provider<Sheet> sheetProvider = delegate
|
||||
{
|
||||
Sheet t = new Sheet(pageSize, renderer.Device);
|
||||
sheets.Add(t);
|
||||
return t;
|
||||
};
|
||||
|
||||
TileSheetBuilder<Sheet> builder = new TileSheetBuilder<Sheet>(pageSize, sheetProvider);
|
||||
Size tileSize = new Size(24, 24);
|
||||
|
||||
for (int i = 0; i < map.Width; i++)
|
||||
for (int j = 0; j < map.Height; j++)
|
||||
@@ -52,13 +41,7 @@ namespace OpenRa.Game
|
||||
TileReference tileRef = map.MapTiles[i + map.XOffset, j + map.YOffset];
|
||||
|
||||
if (!tileMapping.ContainsKey(tileRef))
|
||||
{
|
||||
SheetRectangle<Sheet> rect = builder.AddImage(new Size(24, 24));
|
||||
Util.CopyIntoChannel(rect.sheet.bitmap, TextureChannel.Red,
|
||||
tileSet.tiles[tileRef.tile].TileBitmapBytes[tileRef.image], rect);
|
||||
|
||||
tileMapping.Add(tileRef, rect);
|
||||
}
|
||||
tileMapping.Add(tileRef, CoreSheetBuilder.Add(tileSet.GetBytes(tileRef), tileSize));
|
||||
}
|
||||
|
||||
world = new World(renderer.Device);
|
||||
@@ -67,7 +50,6 @@ namespace OpenRa.Game
|
||||
foreach (TreeReference treeReference in map.Trees)
|
||||
world.Add(new Tree(treeReference, treeCache, map));
|
||||
|
||||
UnitSheetBuilder.Initialize(renderer.Device);
|
||||
UnitSheetBuilder.AddUnit("mcv");
|
||||
UnitSheetBuilder.AddUnit("1tnk");
|
||||
UnitSheetBuilder.AddUnit("2tnk");
|
||||
@@ -120,6 +102,8 @@ namespace OpenRa.Game
|
||||
renderer = new Renderer(this, GetResolution(settings), false);
|
||||
Visible = true;
|
||||
|
||||
CoreSheetBuilder.Initialize(renderer.Device);
|
||||
|
||||
string mapName = settings.GetValue("map", "scm12ea.ini");
|
||||
|
||||
IniFile mapFile = new IniFile(File.OpenRead("../../../" + mapName));
|
||||
@@ -177,7 +161,9 @@ namespace OpenRa.Game
|
||||
foreach (KeyValuePair<Sheet, IndexBuffer> batch in drawBatches)
|
||||
DrawTerrainBatch(batch);
|
||||
|
||||
world.Draw(renderer);
|
||||
world.Draw(renderer,
|
||||
new Range<float>(scrollPos.X, scrollPos.X + ClientSize.Width),
|
||||
new Range<float>(scrollPos.Y, scrollPos.Y + ClientSize.Height));
|
||||
|
||||
renderer.EndFrame();
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Actor.cs" />
|
||||
<Compile Include="Clock.cs" />
|
||||
<Compile Include="CoreSheetBuilder.cs" />
|
||||
<Compile Include="HardwarePalette.cs" />
|
||||
<Compile Include="MainWindow.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace OpenRa.Game
|
||||
bitmap = new Bitmap(size.Width, size.Height);
|
||||
device = d;
|
||||
|
||||
using (Graphics g = Graphics.FromImage(bitmap))
|
||||
g.FillRectangle(Brushes.Fuchsia, 0, 0, size.Width, size.Height);
|
||||
//using (Graphics g = Graphics.FromImage(bitmap))
|
||||
// g.FillRectangle(Brushes.Fuchsia, 0, 0, size.Width, size.Height);
|
||||
}
|
||||
|
||||
public Texture Texture
|
||||
|
||||
@@ -11,22 +11,8 @@ namespace OpenRa.Game
|
||||
{
|
||||
Dictionary<string, SheetRectangle<Sheet>> trees = new Dictionary<string, SheetRectangle<Sheet>>();
|
||||
|
||||
public readonly Sheet sh;
|
||||
|
||||
public TreeCache(GraphicsDevice device, Map map, Package package)
|
||||
{
|
||||
Size pageSize = new Size(1024, 512);
|
||||
List<Sheet> sheets = new List<Sheet>();
|
||||
|
||||
Provider<Sheet> sheetProvider = delegate
|
||||
{
|
||||
Sheet sheet = new Sheet(pageSize, device);
|
||||
sheets.Add(sheet);
|
||||
return sheet;
|
||||
};
|
||||
|
||||
TileSheetBuilder<Sheet> builder = new TileSheetBuilder<Sheet>(pageSize, sheetProvider);
|
||||
|
||||
foreach (TreeReference r in map.Trees)
|
||||
{
|
||||
if (trees.ContainsKey(r.Image))
|
||||
@@ -35,17 +21,10 @@ namespace OpenRa.Game
|
||||
string filename = r.Image + "." + map.Theater.Substring(0, 3);
|
||||
|
||||
ShpReader reader = new ShpReader(package.GetContent(filename));
|
||||
SheetRectangle<Sheet> rect = builder.AddImage(reader.Size);
|
||||
Util.CopyIntoChannel(rect.sheet.bitmap, TextureChannel.Red, reader[0].Image, rect);
|
||||
trees.Add(r.Image, rect);
|
||||
trees.Add(r.Image, CoreSheetBuilder.Add(reader[0].Image, reader.Size));
|
||||
}
|
||||
|
||||
sh = sheets[0];
|
||||
}
|
||||
|
||||
public SheetRectangle<Sheet> GetImage(string tree)
|
||||
{
|
||||
return trees[tree];
|
||||
}
|
||||
public SheetRectangle<Sheet> GetImage(string tree) { return trees[tree]; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,31 +12,11 @@ namespace OpenRa.Game
|
||||
static readonly Package unitsPackage = new Package( "../../../conquer.mix" );
|
||||
public static readonly List<SheetRectangle<Sheet>> McvSheet = new List<SheetRectangle<Sheet>>();
|
||||
|
||||
static TileSheetBuilder<Sheet> builder;
|
||||
static List<Sheet> sheets = new List<Sheet>();
|
||||
static Size pageSize = new Size(1024, 512);
|
||||
|
||||
public static void Initialize( GraphicsDevice device )
|
||||
{
|
||||
Provider<Sheet> sheetProvider = delegate
|
||||
{
|
||||
Sheet sheet = new Sheet(pageSize, device);
|
||||
sheets.Add(sheet);
|
||||
return sheet;
|
||||
};
|
||||
|
||||
builder = new TileSheetBuilder<Sheet>(pageSize, sheetProvider);
|
||||
}
|
||||
|
||||
public static void AddUnit( string name )
|
||||
{
|
||||
ShpReader reader = new ShpReader( unitsPackage.GetContent( name + ".shp" ) );
|
||||
foreach( ImageHeader h in reader )
|
||||
{
|
||||
SheetRectangle<Sheet> rect = builder.AddImage(reader.Size);
|
||||
Util.CopyIntoChannel(rect.sheet.bitmap, TextureChannel.Red, h.Image, rect);
|
||||
McvSheet.Add( rect );
|
||||
}
|
||||
foreach (ImageHeader h in reader)
|
||||
McvSheet.Add(CoreSheetBuilder.Add(h.Image, reader.Size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,15 +76,15 @@ namespace OpenRa.Game
|
||||
indices.Add((ushort)(offset + 2));
|
||||
}
|
||||
|
||||
public static void CopyIntoChannel(Bitmap bitmap, TextureChannel channel, byte[] src, SheetRectangle<Sheet> s)
|
||||
public static void CopyIntoChannel(SheetRectangle<Sheet> dest, byte[] src)
|
||||
{
|
||||
for( int i = 0; i < s.size.Width; i++ )
|
||||
for (int j = 0; j < s.size.Height; j++)
|
||||
for (int i = 0; i < dest.size.Width; i++)
|
||||
for (int j = 0; j < dest.size.Height; j++)
|
||||
{
|
||||
Point p = new Point(s.origin.X + i, s.origin.Y + j);
|
||||
byte b = src[i + s.size.Width * j];
|
||||
Color original = bitmap.GetPixel(p.X, p.Y);
|
||||
bitmap.SetPixel(p.X, p.Y, ReplaceChannel(original, channel, b));
|
||||
Point p = new Point(dest.origin.X + i, dest.origin.Y + j);
|
||||
byte b = src[i + dest.size.Width * j];
|
||||
Color original = dest.sheet.bitmap.GetPixel(p.X, p.Y);
|
||||
dest.sheet.bitmap.SetPixel(p.X, p.Y, ReplaceChannel(original, dest.channel, b));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace OpenRa.Game
|
||||
|
||||
// assumption: when people fix these items, they might update the warning comment?
|
||||
|
||||
public void Draw(Renderer renderer)
|
||||
public void Draw(Renderer renderer, Range<float> xr, Range<float> yr)
|
||||
{
|
||||
int sprites = 0;
|
||||
List<Vertex> vertices = new List<Vertex>();
|
||||
@@ -46,10 +46,18 @@ namespace OpenRa.Game
|
||||
|
||||
foreach (Actor a in actors)
|
||||
{
|
||||
if (a.CurrentImages == null)
|
||||
SheetRectangle<Sheet>[] images = a.CurrentImages;
|
||||
|
||||
if (images == null)
|
||||
continue;
|
||||
|
||||
foreach (SheetRectangle<Sheet> image in a.CurrentImages)
|
||||
if (a.location.X > xr.End || a.location.X < xr.Start - images[0].size.Width)
|
||||
continue;
|
||||
|
||||
if (a.location.Y > yr.End || a.location.Y < yr.Start - images[0].size.Height)
|
||||
continue;
|
||||
|
||||
foreach (SheetRectangle<Sheet> image in images)
|
||||
{
|
||||
if( image.sheet != sheet && sprites > 0 && sheet != null )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user