diff --git a/OpenRA.FileFormats/FieldLoader.cs b/OpenRA.FileFormats/FieldLoader.cs index fc64c526f3..0dc062df43 100755 --- a/OpenRA.FileFormats/FieldLoader.cs +++ b/OpenRA.FileFormats/FieldLoader.cs @@ -127,6 +127,14 @@ namespace OpenRA.FileFormats return InvalidValueAction(value, fieldType, fieldName); } + if (fieldType == typeof(long)) + { + long res; + if (long.TryParse(value, out res)) + return res; + return InvalidValueAction(value, fieldType, fieldName); + } + else if (fieldType == typeof(float)) { float res; diff --git a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs index 9be4681fc8..efd2bb6cfb 100755 --- a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs +++ b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs @@ -32,7 +32,7 @@ namespace OpenRA.FileFormats.Graphics IGraphicsDevice Create( Size size, WindowMode windowMode ); } - public enum BlendMode { None, Alpha, Additive } + public enum BlendMode { None, Alpha, Additive, Subtractive } public interface IGraphicsDevice { diff --git a/OpenRA.FileFormats/Graphics/R8Reader.cs b/OpenRA.FileFormats/Graphics/R8Reader.cs index 0ecd31c802..d737af6cee 100644 --- a/OpenRA.FileFormats/Graphics/R8Reader.cs +++ b/OpenRA.FileFormats/Graphics/R8Reader.cs @@ -53,15 +53,11 @@ namespace OpenRA.FileFormats // Skip alignment byte s.ReadUInt8(); - // Ignore palette header - if (type == 1 && paletteOffset != 0) - s.Seek(8, SeekOrigin.Current); - Image = s.ReadBytes(width*height); - // Ignore palette data + // Ignore palette if (type == 1 && paletteOffset != 0) - s.Seek(512, SeekOrigin.Current); + s.Seek(520, SeekOrigin.Current); } } diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj index 01d307f517..f0c67781f0 100644 --- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj +++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj @@ -79,6 +79,7 @@ + diff --git a/OpenRA.Mods.D2k/PaletteFromR8.cs b/OpenRA.Mods.D2k/PaletteFromR8.cs new file mode 100644 index 0000000000..901fef682c --- /dev/null +++ b/OpenRA.Mods.D2k/PaletteFromR8.cs @@ -0,0 +1,55 @@ +#region Copyright & License Information +/* + * Copyright 2007-2012 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System.IO; +using OpenRA.FileFormats; +using OpenRA.Traits; +using OpenRA.Graphics; + +namespace OpenRA.Mods.RA +{ + class PaletteFromR8Info : ITraitInfo + { + [Desc("Internal palette name")] + public readonly string Name = null; + [Desc("Filename to load")] + public readonly string Filename = null; + [Desc("Palette byte offset")] + public readonly long Offset = 0; + public readonly bool AllowModifiers = true; + + public object Create(ActorInitializer init) { return new PaletteFromR8(this); } + } + + class PaletteFromR8 : IPalette + { + readonly PaletteFromR8Info info; + public PaletteFromR8(PaletteFromR8Info info) { this.info = info; } + + public void InitPalette(WorldRenderer wr) + { + var colors = new uint[256]; + using (var s = FileSystem.Open(info.Filename)) + { + s.Seek(info.Offset, SeekOrigin.Begin); + + for (var i = 0; i < 256; i++) + { + // The custom palette is scaled into the range 0-128. + // This makes the move-flash match the original game, but may not be correct in other cases. + var packed = s.ReadUInt16(); + colors[i] = (uint)((255 << 24) | ((packed & 0xF800) << 7) | ((packed & 0x7E0) << 4) | ((packed & 0x1f) << 2)); + } + } + + wr.AddPalette(info.Name, new Palette(colors), info.AllowModifiers); + } + } +} diff --git a/OpenRA.Renderer.SdlCommon/SdlGraphics.cs b/OpenRA.Renderer.SdlCommon/SdlGraphics.cs index f8ab2ecde7..8c8de209e3 100644 --- a/OpenRA.Renderer.SdlCommon/SdlGraphics.cs +++ b/OpenRA.Renderer.SdlCommon/SdlGraphics.cs @@ -154,6 +154,9 @@ namespace OpenRA.Renderer.SdlCommon public void SetBlendMode(BlendMode mode) { + Gl.glBlendEquation(Gl.GL_FUNC_ADD); + ErrorHandler.CheckGlError(); + switch (mode) { case BlendMode.None: @@ -169,6 +172,13 @@ namespace OpenRA.Renderer.SdlCommon ErrorHandler.CheckGlError(); Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE); break; + case BlendMode.Subtractive: + Gl.glEnable(Gl.GL_BLEND); + ErrorHandler.CheckGlError(); + Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE); + ErrorHandler.CheckGlError(); + Gl.glBlendEquation(Gl.GL_FUNC_REVERSE_SUBTRACT); + break; } ErrorHandler.CheckGlError(); }