hax!
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1191 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -59,12 +59,27 @@ namespace OpenRa.FileFormats
|
|||||||
public readonly Point origin;
|
public readonly Point origin;
|
||||||
public readonly Size size;
|
public readonly Size size;
|
||||||
public readonly T sheet;
|
public readonly T sheet;
|
||||||
|
public readonly TextureChannel channel;
|
||||||
|
|
||||||
internal SheetRectangle(T sheet, Point origin, Size size)
|
internal SheetRectangle(T sheet, Point origin, Size size, TextureChannel channel)
|
||||||
{
|
{
|
||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
this.sheet = sheet;
|
this.sheet = sheet;
|
||||||
|
this.channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal SheetRectangle(T sheet, Point origin, Size size)
|
||||||
|
: this(sheet, origin, size, TextureChannel.Red)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum TextureChannel
|
||||||
|
{
|
||||||
|
Red,
|
||||||
|
Green,
|
||||||
|
Blue,
|
||||||
|
Alpha,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace OpenRa.Game
|
|||||||
abstract class Actor
|
abstract class Actor
|
||||||
{
|
{
|
||||||
public PointF location;
|
public PointF location;
|
||||||
|
public int palette;
|
||||||
public abstract SheetRectangle<Sheet>[] CurrentImages { get; }
|
public abstract SheetRectangle<Sheet>[] CurrentImages { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
Provider<Sheet> sheetProvider = delegate
|
Provider<Sheet> sheetProvider = delegate
|
||||||
{
|
{
|
||||||
Sheet t = new Sheet(new Bitmap(pageSize.Width, pageSize.Height), renderer.Device);
|
Sheet t = new Sheet(pageSize, renderer.Device);
|
||||||
sheets.Add(t);
|
sheets.Add(t);
|
||||||
return t;
|
return t;
|
||||||
};
|
};
|
||||||
@@ -90,7 +90,7 @@ namespace OpenRa.Game
|
|||||||
if (!indexMap.TryGetValue(tile.sheet, out indexList))
|
if (!indexMap.TryGetValue(tile.sheet, out indexList))
|
||||||
indexMap.Add(tile.sheet, indexList = new List<ushort>());
|
indexMap.Add(tile.sheet, indexList = new List<ushort>());
|
||||||
|
|
||||||
Util.CreateQuad(vertices, indexList, new PointF(24 * i, 24 * j), tile);
|
Util.CreateQuad(vertices, indexList, new PointF(24 * i, 24 * j), tile, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexBuffer = new FvfVertexBuffer<Vertex>(renderer.Device, vertices.Count, Vertex.Format);
|
vertexBuffer = new FvfVertexBuffer<Vertex>(renderer.Device, vertices.Count, Vertex.Format);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace OpenRa.Game
|
|||||||
public Mcv( PointF location )
|
public Mcv( PointF location )
|
||||||
{
|
{
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
this.palette = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetFacing()
|
int GetFacing()
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ namespace OpenRa.Game
|
|||||||
readonly GraphicsDevice device;
|
readonly GraphicsDevice device;
|
||||||
Texture texture;
|
Texture texture;
|
||||||
|
|
||||||
public Sheet(Bitmap b, GraphicsDevice d) { bitmap = b; device = d; }
|
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -24,13 +24,33 @@ namespace OpenRa.Game
|
|||||||
return (v > 0) ? v1 : v0;
|
return (v > 0) ? v1 : v0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vertex MakeVertex(PointF o, float u, float v, SheetRectangle<Sheet> r)
|
static PointF EncodeVertexAttributes(TextureChannel channel, int paletteLine)
|
||||||
|
{
|
||||||
|
Converter<TextureChannel, float> channelEncoder = delegate(TextureChannel c)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case TextureChannel.Red: return 0.75f;
|
||||||
|
case TextureChannel.Green: return 0.25f;
|
||||||
|
case TextureChannel.Blue: return -0.25f;
|
||||||
|
case TextureChannel.Alpha: return -0.75f;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new PointF(paletteLine / 16.0f, channelEncoder(channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vertex MakeVertex(PointF o, float u, float v, SheetRectangle<Sheet> 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;
|
||||||
|
|
||||||
return new Vertex(Lerp(o.X, x2, u), Lerp(o.Y, y2, v), 0, U(r, u), V(r, v),
|
PointF p = EncodeVertexAttributes(r.channel, palette);
|
||||||
0, 1);
|
|
||||||
|
return new Vertex(Lerp(o.X, x2, u), Lerp(o.Y, y2, v), 0, U(r, u), V(r, v),
|
||||||
|
p.X, p.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float Lerp(float a, float b, float t)
|
static float Lerp(float a, float b, float t)
|
||||||
@@ -38,14 +58,14 @@ 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)
|
public static void CreateQuad(List<Vertex> vertices, List<ushort> indices, PointF o, SheetRectangle<Sheet> r, int palette)
|
||||||
{
|
{
|
||||||
ushort offset = (ushort)vertices.Count;
|
ushort offset = (ushort)vertices.Count;
|
||||||
|
|
||||||
vertices.Add(Util.MakeVertex(o, 0, 0, r));
|
vertices.Add(Util.MakeVertex(o, 0, 0, r, palette));
|
||||||
vertices.Add(Util.MakeVertex(o, 1, 0, r));
|
vertices.Add(Util.MakeVertex(o, 1, 0, r, palette));
|
||||||
vertices.Add(Util.MakeVertex(o, 0, 1, r));
|
vertices.Add(Util.MakeVertex(o, 0, 1, r, palette));
|
||||||
vertices.Add(Util.MakeVertex(o, 1, 1, r));
|
vertices.Add(Util.MakeVertex(o, 1, 1, r, palette));
|
||||||
|
|
||||||
indices.Add(offset);
|
indices.Add(offset);
|
||||||
indices.Add((ushort)(offset + 1));
|
indices.Add((ushort)(offset + 1));
|
||||||
@@ -82,12 +102,4 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TextureChannel
|
|
||||||
{
|
|
||||||
Red,
|
|
||||||
Green,
|
|
||||||
Blue,
|
|
||||||
Alpha,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
sheet = image.sheet;
|
sheet = image.sheet;
|
||||||
Util.CreateQuad(vertices, indices, a.location, image);
|
Util.CreateQuad(vertices, indices, a.location, image, a.palette);
|
||||||
|
|
||||||
if (++sprites >= spritesPerBatch)
|
if (++sprites >= spritesPerBatch)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user