From cb54dbf81be6012d9028959863de471b501afb50 Mon Sep 17 00:00:00 2001 From: chrisf Date: Fri, 13 Jul 2007 09:36:58 +0000 Subject: [PATCH] hax! git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1191 993157c7-ee19-0410-b2c4-bb4e9862e678 --- OpenRa.FileFormats/TileSheetBuilder.cs | 17 +++++++++- OpenRa.Game/Actor.cs | 1 + OpenRa.Game/MainWindow.cs | 4 +-- OpenRa.Game/Mcv.cs | 1 + OpenRa.Game/Sheet.cs | 2 -- OpenRa.Game/Util.cs | 44 ++++++++++++++++---------- OpenRa.Game/World.cs | 2 +- 7 files changed, 49 insertions(+), 22 deletions(-) diff --git a/OpenRa.FileFormats/TileSheetBuilder.cs b/OpenRa.FileFormats/TileSheetBuilder.cs index 31b81c6954..450c49f259 100644 --- a/OpenRa.FileFormats/TileSheetBuilder.cs +++ b/OpenRa.FileFormats/TileSheetBuilder.cs @@ -59,12 +59,27 @@ namespace OpenRa.FileFormats public readonly Point origin; public readonly Size size; 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.size = size; 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, + } } diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 397dc37553..d6eff22170 100644 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -11,6 +11,7 @@ namespace OpenRa.Game abstract class Actor { public PointF location; + public int palette; public abstract SheetRectangle[] CurrentImages { get; } } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index dd8412e927..831c29654c 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -39,7 +39,7 @@ namespace OpenRa.Game Provider sheetProvider = delegate { - Sheet t = new Sheet(new Bitmap(pageSize.Width, pageSize.Height), renderer.Device); + Sheet t = new Sheet(pageSize, renderer.Device); sheets.Add(t); return t; }; @@ -90,7 +90,7 @@ namespace OpenRa.Game if (!indexMap.TryGetValue(tile.sheet, out indexList)) indexMap.Add(tile.sheet, indexList = new List()); - 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(renderer.Device, vertices.Count, Vertex.Format); diff --git a/OpenRa.Game/Mcv.cs b/OpenRa.Game/Mcv.cs index b492f742bc..a20298e1c1 100644 --- a/OpenRa.Game/Mcv.cs +++ b/OpenRa.Game/Mcv.cs @@ -11,6 +11,7 @@ namespace OpenRa.Game public Mcv( PointF location ) { this.location = location; + this.palette = 3; } int GetFacing() diff --git a/OpenRa.Game/Sheet.cs b/OpenRa.Game/Sheet.cs index 7b34245a1c..b45e743419 100644 --- a/OpenRa.Game/Sheet.cs +++ b/OpenRa.Game/Sheet.cs @@ -15,8 +15,6 @@ namespace OpenRa.Game readonly GraphicsDevice device; Texture texture; - public Sheet(Bitmap b, GraphicsDevice d) { bitmap = b; device = d; } - public Sheet(Size size, GraphicsDevice d) { bitmap = new Bitmap(size.Width, size.Height); diff --git a/OpenRa.Game/Util.cs b/OpenRa.Game/Util.cs index bae229797b..7136e908d7 100644 --- a/OpenRa.Game/Util.cs +++ b/OpenRa.Game/Util.cs @@ -24,13 +24,33 @@ namespace OpenRa.Game return (v > 0) ? v1 : v0; } - public static Vertex MakeVertex(PointF o, float u, float v, SheetRectangle r) + static PointF EncodeVertexAttributes(TextureChannel channel, int paletteLine) + { + Converter 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 r, int palette) { float x2 = o.X + r.size.Width; 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), - 0, 1); + PointF p = EncodeVertexAttributes(r.channel, palette); + + 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) @@ -38,14 +58,14 @@ namespace OpenRa.Game return (1 - t) * a + t * b; } - public static void CreateQuad(List vertices, List indices, PointF o, SheetRectangle r) + public static void CreateQuad(List vertices, List indices, PointF o, SheetRectangle r, int palette) { ushort offset = (ushort)vertices.Count; - vertices.Add(Util.MakeVertex(o, 0, 0, r)); - vertices.Add(Util.MakeVertex(o, 1, 0, r)); - vertices.Add(Util.MakeVertex(o, 0, 1, r)); - vertices.Add(Util.MakeVertex(o, 1, 1, r)); + vertices.Add(Util.MakeVertex(o, 0, 0, r, palette)); + vertices.Add(Util.MakeVertex(o, 1, 0, r, palette)); + vertices.Add(Util.MakeVertex(o, 0, 1, r, palette)); + vertices.Add(Util.MakeVertex(o, 1, 1, r, palette)); indices.Add(offset); indices.Add((ushort)(offset + 1)); @@ -82,12 +102,4 @@ namespace OpenRa.Game } } } - - enum TextureChannel - { - Red, - Green, - Blue, - Alpha, - } } diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index 514cfa97fa..8806d98a0b 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -61,7 +61,7 @@ namespace OpenRa.Game } sheet = image.sheet; - Util.CreateQuad(vertices, indices, a.location, image); + Util.CreateQuad(vertices, indices, a.location, image, a.palette); if (++sprites >= spritesPerBatch) {