git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1213 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -48,7 +48,6 @@
|
|||||||
<Compile Include="ShpReader.cs" />
|
<Compile Include="ShpReader.cs" />
|
||||||
<Compile Include="Terrain.cs" />
|
<Compile Include="Terrain.cs" />
|
||||||
<Compile Include="TileSet.cs" />
|
<Compile Include="TileSet.cs" />
|
||||||
<Compile Include="TileSheetBuilder.cs" />
|
|
||||||
<Compile Include="Tuple.cs" />
|
<Compile Include="Tuple.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace OpenRa.FileFormats
|
|
||||||
{
|
|
||||||
public delegate T Provider<T>();
|
|
||||||
|
|
||||||
public class TileSheetBuilder<T>
|
|
||||||
where T : class
|
|
||||||
{
|
|
||||||
readonly Size pageSize;
|
|
||||||
readonly Provider<T> pageProvider;
|
|
||||||
|
|
||||||
public TileSheetBuilder(Size pageSize, Provider<T> pageProvider)
|
|
||||||
{
|
|
||||||
this.pageSize = pageSize;
|
|
||||||
this.pageProvider = pageProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
T current = null;
|
|
||||||
int x = 0, y = 0, rowHeight = 0;
|
|
||||||
TextureChannel? channel;
|
|
||||||
|
|
||||||
TextureChannel? NextChannel(TextureChannel? t)
|
|
||||||
{
|
|
||||||
if (t == null)
|
|
||||||
return TextureChannel.Red;
|
|
||||||
|
|
||||||
switch (t.Value)
|
|
||||||
{
|
|
||||||
case TextureChannel.Red: return TextureChannel.Green;
|
|
||||||
case TextureChannel.Green: return TextureChannel.Blue;
|
|
||||||
case TextureChannel.Blue: return TextureChannel.Alpha;
|
|
||||||
case TextureChannel.Alpha: return null;
|
|
||||||
|
|
||||||
default: return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public SheetRectangle<T> AddImage(Size imageSize)
|
|
||||||
{
|
|
||||||
if (imageSize.Width > pageSize.Width || imageSize.Height > pageSize.Height)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (current == null)
|
|
||||||
{
|
|
||||||
current = pageProvider();
|
|
||||||
channel = NextChannel(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rowHeight == 0 || imageSize.Width + x > pageSize.Width)
|
|
||||||
{
|
|
||||||
y += rowHeight;
|
|
||||||
rowHeight = imageSize.Height;
|
|
||||||
x = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (imageSize.Height > rowHeight)
|
|
||||||
rowHeight = imageSize.Height;
|
|
||||||
|
|
||||||
if (y + imageSize.Height > pageSize.Height)
|
|
||||||
{
|
|
||||||
|
|
||||||
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, channel.Value);
|
|
||||||
x += imageSize.Width;
|
|
||||||
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SheetRectangle<T>
|
|
||||||
where T : class
|
|
||||||
{
|
|
||||||
public readonly Point origin;
|
|
||||||
public readonly Size size;
|
|
||||||
public readonly T sheet;
|
|
||||||
public readonly TextureChannel channel;
|
|
||||||
|
|
||||||
internal SheetRectangle(T sheet, Point origin, Size size, TextureChannel channel)
|
|
||||||
{
|
|
||||||
this.origin = origin;
|
|
||||||
this.size = size;
|
|
||||||
this.sheet = sheet;
|
|
||||||
this.channel = channel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum TextureChannel
|
|
||||||
{
|
|
||||||
Red,
|
|
||||||
Green,
|
|
||||||
Blue,
|
|
||||||
Alpha,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,6 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
public PointF location;
|
public PointF location;
|
||||||
public int palette;
|
public int palette;
|
||||||
public abstract SheetRectangle<Sheet>[] CurrentImages { get; }
|
public abstract Sprite[] CurrentImages { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SheetRectangle<Sheet> Add(Size size, byte paletteIndex)
|
|
||||||
{
|
|
||||||
byte[] data = new byte[size.Width * size.Height];
|
|
||||||
for (int i = 0; i < data.Length; i++)
|
|
||||||
data[i] = paletteIndex;
|
|
||||||
|
|
||||||
return Add(data, size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class SpriteSheetBuilder
|
|
||||||
{
|
|
||||||
static Dictionary<string, SheetRectangle<Sheet>> sprites =
|
|
||||||
new Dictionary<string, SheetRectangle<Sheet>>();
|
|
||||||
|
|
||||||
public static SheetRectangle<Sheet> LoadSprite(Package package, string filename)
|
|
||||||
{
|
|
||||||
SheetRectangle<Sheet> value;
|
|
||||||
if (!sprites.TryGetValue(filename, out value))
|
|
||||||
{
|
|
||||||
ShpReader shp = new ShpReader(package.GetContent(filename));
|
|
||||||
sprites.Add(filename, value = CoreSheetBuilder.Add(shp[0].Image, shp.Size));
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,7 +38,7 @@ namespace OpenRa.Game
|
|||||||
renderer = new Renderer(this, GetResolution(settings), false);
|
renderer = new Renderer(this, GetResolution(settings), false);
|
||||||
Visible = true;
|
Visible = true;
|
||||||
|
|
||||||
CoreSheetBuilder.Initialize(renderer.Device);
|
SheetBuilder.Initialize(renderer.Device);
|
||||||
|
|
||||||
map = new Map(new IniFile(File.OpenRead("../../../" + settings.GetValue("map", "scm12ea.ini"))));
|
map = new Map(new IniFile(File.OpenRead("../../../" + settings.GetValue("map", "scm12ea.ini"))));
|
||||||
|
|
||||||
|
|||||||
@@ -20,18 +20,13 @@ namespace OpenRa.Game
|
|||||||
mcvRange = UnitSheetBuilder.AddUnit("mcv");
|
mcvRange = UnitSheetBuilder.AddUnit("mcv");
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetFacing()
|
int GetFacing() { return (Environment.TickCount >> 6) % 32; }
|
||||||
{
|
|
||||||
int x = (Environment.TickCount >> 6) % 32;
|
|
||||||
return x;
|
|
||||||
//return x < 32 ? x : 63 - x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override SheetRectangle<Sheet>[] CurrentImages
|
public override Sprite[] CurrentImages
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new SheetRectangle<Sheet>[]
|
return new Sprite[]
|
||||||
{
|
{
|
||||||
UnitSheetBuilder.sprites[GetFacing() + mcvRange.Value.Start]
|
UnitSheetBuilder.sprites[GetFacing() + mcvRange.Value.Start]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Actor.cs" />
|
<Compile Include="Actor.cs" />
|
||||||
<Compile Include="Clock.cs" />
|
<Compile Include="Clock.cs" />
|
||||||
<Compile Include="CoreSheetBuilder.cs" />
|
<Compile Include="SheetBuilder.cs" />
|
||||||
<Compile Include="HardwarePalette.cs" />
|
<Compile Include="HardwarePalette.cs" />
|
||||||
<Compile Include="MainWindow.cs">
|
<Compile Include="MainWindow.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
@@ -55,7 +55,9 @@
|
|||||||
<Compile Include="Settings.cs" />
|
<Compile Include="Settings.cs" />
|
||||||
<Compile Include="Sheet.cs" />
|
<Compile Include="Sheet.cs" />
|
||||||
<Compile Include="Sidebar.cs" />
|
<Compile Include="Sidebar.cs" />
|
||||||
|
<Compile Include="Sprite.cs" />
|
||||||
<Compile Include="SpriteRenderer.cs" />
|
<Compile Include="SpriteRenderer.cs" />
|
||||||
|
<Compile Include="SpriteSheetBuilder.cs" />
|
||||||
<Compile Include="TerrainRenderer.cs" />
|
<Compile Include="TerrainRenderer.cs" />
|
||||||
<Compile Include="Tree.cs" />
|
<Compile Include="Tree.cs" />
|
||||||
<Compile Include="TreeCache.cs" />
|
<Compile Include="TreeCache.cs" />
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
File.WriteAllText( "error.log", e.ToString() );
|
File.WriteAllText( "error.log", e.ToString() );
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,16 +20,13 @@ namespace OpenRa.Game
|
|||||||
this.palette = palette;
|
this.palette = palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetFrame()
|
int GetFrame() { return 1; }
|
||||||
{
|
|
||||||
return 1;//
|
|
||||||
}
|
|
||||||
|
|
||||||
public override SheetRectangle<Sheet>[] CurrentImages
|
public override Sprite[] CurrentImages
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new SheetRectangle<Sheet>[] { UnitSheetBuilder.sprites[refineryRange.Value.Start + GetFrame()] };
|
return new Sprite[] { UnitSheetBuilder.sprites[refineryRange.Value.Start + GetFrame()] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,12 @@ namespace OpenRa.Game
|
|||||||
readonly GraphicsDevice device;
|
readonly GraphicsDevice device;
|
||||||
Texture texture;
|
Texture texture;
|
||||||
|
|
||||||
|
public Size Size { get { return bitmap.Size; } }
|
||||||
|
|
||||||
public Sheet(Size size, GraphicsDevice d)
|
public Sheet(Size size, GraphicsDevice d)
|
||||||
{
|
{
|
||||||
bitmap = new Bitmap(size.Width, size.Height);
|
bitmap = new Bitmap(size.Width, size.Height);
|
||||||
device = d;
|
device = d;
|
||||||
|
|
||||||
//using (Graphics g = Graphics.FromImage(bitmap))
|
|
||||||
// g.FillRectangle(Brushes.Fuchsia, 0, 0, size.Width, size.Height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture Texture
|
public Texture Texture
|
||||||
|
|||||||
92
OpenRa.Game/SheetBuilder.cs
Normal file
92
OpenRa.Game/SheetBuilder.cs
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Drawing;
|
||||||
|
using BluntDirectX.Direct3D;
|
||||||
|
using OpenRa.FileFormats;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
delegate T Provider<T>();
|
||||||
|
|
||||||
|
static class SheetBuilder
|
||||||
|
{
|
||||||
|
public static void Initialize(GraphicsDevice device)
|
||||||
|
{
|
||||||
|
pageProvider = delegate { return new Sheet(new Size(512,512), device); };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sprite Add(byte[] src, Size size)
|
||||||
|
{
|
||||||
|
Sprite rect = AddImage(size);
|
||||||
|
Util.CopyIntoChannel(rect, src);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sprite Add(Size size, byte paletteIndex)
|
||||||
|
{
|
||||||
|
byte[] data = new byte[size.Width * size.Height];
|
||||||
|
for (int i = 0; i < data.Length; i++)
|
||||||
|
data[i] = paletteIndex;
|
||||||
|
|
||||||
|
return Add(data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Provider<Sheet> pageProvider;
|
||||||
|
static Sheet current = null;
|
||||||
|
static int x = 0, y = 0, rowHeight = 0;
|
||||||
|
static TextureChannel? channel = null;
|
||||||
|
|
||||||
|
static TextureChannel? NextChannel(TextureChannel? t)
|
||||||
|
{
|
||||||
|
if (t == null)
|
||||||
|
return TextureChannel.Red;
|
||||||
|
|
||||||
|
switch (t.Value)
|
||||||
|
{
|
||||||
|
case TextureChannel.Red: return TextureChannel.Green;
|
||||||
|
case TextureChannel.Green: return TextureChannel.Blue;
|
||||||
|
case TextureChannel.Blue: return TextureChannel.Alpha;
|
||||||
|
case TextureChannel.Alpha: return null;
|
||||||
|
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Sprite AddImage(Size imageSize)
|
||||||
|
{
|
||||||
|
if (current == null)
|
||||||
|
{
|
||||||
|
current = pageProvider();
|
||||||
|
channel = NextChannel(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rowHeight == 0 || imageSize.Width + x > current.Size.Width)
|
||||||
|
{
|
||||||
|
y += rowHeight;
|
||||||
|
rowHeight = imageSize.Height;
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageSize.Height > rowHeight)
|
||||||
|
rowHeight = imageSize.Height;
|
||||||
|
|
||||||
|
if (y + imageSize.Height > current.Size.Height)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (null == (channel = NextChannel(channel)))
|
||||||
|
{
|
||||||
|
current = pageProvider();
|
||||||
|
channel = NextChannel(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
x = y = rowHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sprite rect = new Sprite(current, new Point(x, y), imageSize, channel.Value);
|
||||||
|
x += imageSize.Width;
|
||||||
|
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,6 @@ using System.IO;
|
|||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
using Sprite = SheetRectangle<Sheet>;
|
|
||||||
class Sidebar
|
class Sidebar
|
||||||
{
|
{
|
||||||
TechTree.TechTree techTree = new TechTree.TechTree();
|
TechTree.TechTree techTree = new TechTree.TechTree();
|
||||||
@@ -37,7 +36,7 @@ namespace OpenRa.Game
|
|||||||
LoadSprites("../../../buildings.txt");
|
LoadSprites("../../../buildings.txt");
|
||||||
LoadSprites("../../../units.txt");
|
LoadSprites("../../../units.txt");
|
||||||
|
|
||||||
sprites.Add("BLANK", CoreSheetBuilder.Add(new Size(64, 48), 16));
|
sprites.Add("BLANK", SheetBuilder.Add(new Size(64, 48), 16));
|
||||||
techTree.CurrentRace = race;
|
techTree.CurrentRace = race;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
OpenRa.Game/Sprite.cs
Normal file
31
OpenRa.Game/Sprite.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
class Sprite
|
||||||
|
{
|
||||||
|
public readonly Point origin;
|
||||||
|
public readonly Size size;
|
||||||
|
public readonly Sheet sheet;
|
||||||
|
public readonly TextureChannel channel;
|
||||||
|
|
||||||
|
internal Sprite(Sheet sheet, Point origin, Size size, TextureChannel channel)
|
||||||
|
{
|
||||||
|
this.origin = origin;
|
||||||
|
this.size = size;
|
||||||
|
this.sheet = sheet;
|
||||||
|
this.channel = channel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TextureChannel
|
||||||
|
{
|
||||||
|
Red,
|
||||||
|
Green,
|
||||||
|
Blue,
|
||||||
|
Alpha,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,7 +49,7 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawSprite(SheetRectangle<Sheet> s, PointF location)
|
public void DrawSprite(Sprite s, PointF location)
|
||||||
{
|
{
|
||||||
if (s.sheet != currentSheet)
|
if (s.sheet != currentSheet)
|
||||||
Flush();
|
Flush();
|
||||||
|
|||||||
25
OpenRa.Game/SpriteSheetBuilder.cs
Normal file
25
OpenRa.Game/SpriteSheetBuilder.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRa.FileFormats;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
static class SpriteSheetBuilder
|
||||||
|
{
|
||||||
|
static Dictionary<string, Sprite> sprites =
|
||||||
|
new Dictionary<string, Sprite>();
|
||||||
|
|
||||||
|
public static Sprite LoadSprite(Package package, string filename)
|
||||||
|
{
|
||||||
|
Sprite value;
|
||||||
|
if (!sprites.TryGetValue(filename, out value))
|
||||||
|
{
|
||||||
|
ShpReader shp = new ShpReader(package.GetContent(filename));
|
||||||
|
sprites.Add(filename, value = SheetBuilder.Add(shp[0].Image, shp.Size));
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,8 +25,8 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
tileSet = new TileSet(tilePackage, map.TileSuffix);
|
tileSet = new TileSet(tilePackage, map.TileSuffix);
|
||||||
|
|
||||||
Dictionary<TileReference, SheetRectangle<Sheet>> tileMapping =
|
Dictionary<TileReference, Sprite> tileMapping =
|
||||||
new Dictionary<TileReference, SheetRectangle<Sheet>>();
|
new Dictionary<TileReference, Sprite>();
|
||||||
|
|
||||||
Size tileSize = new Size(24, 24);
|
Size tileSize = new Size(24, 24);
|
||||||
|
|
||||||
@@ -37,10 +37,10 @@ namespace OpenRa.Game
|
|||||||
for (int i = 0; i < map.Width; i++)
|
for (int i = 0; i < map.Width; i++)
|
||||||
{
|
{
|
||||||
TileReference tileRef = map.MapTiles[i + map.XOffset, j + map.YOffset];
|
TileReference tileRef = map.MapTiles[i + map.XOffset, j + map.YOffset];
|
||||||
SheetRectangle<Sheet> tile;
|
Sprite tile;
|
||||||
|
|
||||||
if (!tileMapping.TryGetValue(tileRef, out tile))
|
if (!tileMapping.TryGetValue(tileRef, out tile))
|
||||||
tileMapping.Add(tileRef, tile = CoreSheetBuilder.Add(tileSet.GetBytes(tileRef), tileSize));
|
tileMapping.Add(tileRef, tile = SheetBuilder.Add(tileSet.GetBytes(tileRef), tileSize));
|
||||||
|
|
||||||
terrainSheet = tile.sheet;
|
terrainSheet = tile.sheet;
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ namespace OpenRa.Game
|
|||||||
public Tree(TreeReference r, TreeCache renderer, Map map)
|
public Tree(TreeReference r, TreeCache renderer, Map map)
|
||||||
{
|
{
|
||||||
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 Sprite[] { renderer.GetImage(r.Image) };
|
||||||
}
|
}
|
||||||
|
|
||||||
SheetRectangle<Sheet>[] currentImages;
|
Sprite[] currentImages;
|
||||||
public override SheetRectangle<Sheet>[] CurrentImages
|
public override Sprite[] CurrentImages
|
||||||
{
|
{
|
||||||
get { return currentImages; }
|
get { return currentImages; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
class TreeCache
|
class TreeCache
|
||||||
{
|
{
|
||||||
Dictionary<string, SheetRectangle<Sheet>> trees = new Dictionary<string, SheetRectangle<Sheet>>();
|
Dictionary<string, Sprite> trees = new Dictionary<string, Sprite>();
|
||||||
|
|
||||||
public TreeCache(GraphicsDevice device, Map map, Package package)
|
public TreeCache(GraphicsDevice device, Map map, Package package)
|
||||||
{
|
{
|
||||||
@@ -21,10 +21,10 @@ namespace OpenRa.Game
|
|||||||
string filename = r.Image + "." + map.Theater.Substring(0, 3);
|
string filename = r.Image + "." + map.Theater.Substring(0, 3);
|
||||||
|
|
||||||
ShpReader reader = new ShpReader(package.GetContent(filename));
|
ShpReader reader = new ShpReader(package.GetContent(filename));
|
||||||
trees.Add(r.Image, CoreSheetBuilder.Add(reader[0].Image, reader.Size));
|
trees.Add(r.Image, SheetBuilder.Add(reader[0].Image, reader.Size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SheetRectangle<Sheet> GetImage(string tree) { return trees[tree]; }
|
public Sprite GetImage(string tree) { return trees[tree]; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace OpenRa.Game
|
|||||||
static readonly Package unitsPackage = new Package( "../../../conquer.mix" );
|
static readonly Package unitsPackage = new Package( "../../../conquer.mix" );
|
||||||
static readonly Package otherUnitsPackage = new Package("../../../hires.mix");
|
static readonly Package otherUnitsPackage = new Package("../../../hires.mix");
|
||||||
|
|
||||||
public static readonly List<SheetRectangle<Sheet>> sprites = new List<SheetRectangle<Sheet>>();
|
public static readonly List<Sprite> sprites = new List<Sprite>();
|
||||||
|
|
||||||
static ShpReader Load(string filename)
|
static ShpReader Load(string filename)
|
||||||
{
|
{
|
||||||
@@ -28,7 +28,7 @@ namespace OpenRa.Game
|
|||||||
int low = sprites.Count;
|
int low = sprites.Count;
|
||||||
ShpReader reader = Load(name + ".shp");
|
ShpReader reader = Load(name + ".shp");
|
||||||
foreach (ImageHeader h in reader)
|
foreach (ImageHeader h in reader)
|
||||||
sprites.Add(CoreSheetBuilder.Add(h.Image, reader.Size));
|
sprites.Add(SheetBuilder.Add(h.Image, reader.Size));
|
||||||
|
|
||||||
return new Range<int>(low, sprites.Count - 1);
|
return new Range<int>(low, sprites.Count - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
static class Util
|
static class Util
|
||||||
{
|
{
|
||||||
public static float U(SheetRectangle<Sheet> s, float u)
|
public static float U(Sprite s, float u)
|
||||||
{
|
{
|
||||||
float u0 = (float)(s.origin.X + 0.5f) / (float)s.sheet.bitmap.Width;
|
float u0 = (float)(s.origin.X + 0.5f) / (float)s.sheet.bitmap.Width;
|
||||||
float u1 = (float)(s.origin.X + s.size.Width) / (float)s.sheet.bitmap.Width;
|
float u1 = (float)(s.origin.X + s.size.Width) / (float)s.sheet.bitmap.Width;
|
||||||
@@ -17,7 +17,7 @@ namespace OpenRa.Game
|
|||||||
return (u > 0) ? u1 : u0;
|
return (u > 0) ? u1 : u0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float V(SheetRectangle<Sheet> s, float v)
|
public static float V(Sprite s, float v)
|
||||||
{
|
{
|
||||||
float v0 = (float)(s.origin.Y + 0.5f) / (float)s.sheet.bitmap.Height;
|
float v0 = (float)(s.origin.Y + 0.5f) / (float)s.sheet.bitmap.Height;
|
||||||
float v1 = (float)(s.origin.Y + s.size.Height) / (float)s.sheet.bitmap.Height;
|
float v1 = (float)(s.origin.Y + s.size.Height) / (float)s.sheet.bitmap.Height;
|
||||||
@@ -48,7 +48,7 @@ namespace OpenRa.Game
|
|||||||
return new PointF(paletteLine / 16.0f, channelEncoder(channel));
|
return new PointF(paletteLine / 16.0f, channelEncoder(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vertex MakeVertex(PointF o, float u, float v, SheetRectangle<Sheet> r, int palette)
|
public static Vertex MakeVertex(PointF o, float u, float v, Sprite r, int palette)
|
||||||
{
|
{
|
||||||
float x2 = o.X + r.size.Width;
|
float x2 = o.X + r.size.Width;
|
||||||
float y2 = o.Y + r.size.Height;
|
float y2 = o.Y + r.size.Height;
|
||||||
@@ -64,7 +64,7 @@ namespace OpenRa.Game
|
|||||||
return (1 - t) * a + t * b;
|
return (1 - t) * a + t * b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateQuad(List<Vertex> vertices, List<ushort> indices, PointF o, SheetRectangle<Sheet> r, int palette)
|
public static void CreateQuad(List<Vertex> vertices, List<ushort> indices, PointF o, Sprite r, int palette)
|
||||||
{
|
{
|
||||||
ushort offset = (ushort)vertices.Count;
|
ushort offset = (ushort)vertices.Count;
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ namespace OpenRa.Game
|
|||||||
indices.Add((ushort)(offset + 2));
|
indices.Add((ushort)(offset + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CopyIntoChannel(SheetRectangle<Sheet> dest, byte[] src)
|
public static void CopyIntoChannel(Sprite dest, byte[] src)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < dest.size.Width; i++)
|
for (int i = 0; i < dest.size.Width; i++)
|
||||||
for (int j = 0; j < dest.size.Height; j++)
|
for (int j = 0; j < dest.size.Height; j++)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
foreach (Actor a in actors)
|
foreach (Actor a in actors)
|
||||||
{
|
{
|
||||||
SheetRectangle<Sheet>[] images = a.CurrentImages;
|
Sprite[] images = a.CurrentImages;
|
||||||
|
|
||||||
if (images == null)
|
if (images == null)
|
||||||
continue;
|
continue;
|
||||||
@@ -57,7 +57,7 @@ namespace OpenRa.Game
|
|||||||
if (a.location.Y > yr.End || a.location.Y < yr.Start - images[0].size.Height)
|
if (a.location.Y > yr.End || a.location.Y < yr.Start - images[0].size.Height)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (SheetRectangle<Sheet> image in images)
|
foreach (Sprite image in images)
|
||||||
{
|
{
|
||||||
if( image.sheet != sheet && sprites > 0 && sheet != null )
|
if( image.sheet != sheet && sprites > 0 && sheet != null )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user