From 437fe9ce864eccdc2fbd8227ef5471b4608090cb Mon Sep 17 00:00:00 2001 From: MaxED Date: Wed, 9 Nov 2016 10:07:21 +0000 Subject: [PATCH] Updated, GLDEFS parser: updated glowing texture parsing logic to better match GZDoom logic. Removed, GLDEFS parser: removed GLOOME glow definitions support code. --- Source/Core/GZBuilder/Data/GlowingFlatData.cs | 2 - Source/Core/ZDoom/GldefsParser.cs | 88 +++++-------------- Source/Core/ZDoom/PatchStructure.cs | 2 +- .../ZDoom/Scripting/ScriptTypeParserSE.cs | 2 +- Source/Core/ZDoom/TextureStructure.cs | 4 +- Source/Core/ZDoom/ZDTextParser.cs | 18 ++++ .../BuilderModes/General/BuilderPlug.cs | 8 +- .../VisualModes/BaseVisualGeometrySidedef.cs | 17 ++-- .../BuilderModes/VisualModes/SectorData.cs | 8 +- 9 files changed, 58 insertions(+), 91 deletions(-) diff --git a/Source/Core/GZBuilder/Data/GlowingFlatData.cs b/Source/Core/GZBuilder/Data/GlowingFlatData.cs index de25eb81..4ad2538b 100644 --- a/Source/Core/GZBuilder/Data/GlowingFlatData.cs +++ b/Source/Core/GZBuilder/Data/GlowingFlatData.cs @@ -8,8 +8,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data public int Height; public int Brightness = 255; public bool Fullbright; - public bool Fullblack; // GLOOME only - public bool Subtractive; // GLOOME only public bool CalculateTextureColor; } } diff --git a/Source/Core/ZDoom/GldefsParser.cs b/Source/Core/ZDoom/GldefsParser.cs index fca09275..895a899d 100644 --- a/Source/Core/ZDoom/GldefsParser.cs +++ b/Source/Core/ZDoom/GldefsParser.cs @@ -579,11 +579,12 @@ namespace CodeImp.DoomBuilder.ZDoom while(SkipWhitespace(true)) { - token = ReadToken(); + token = StripQuotes(ReadToken(false)); + if(string.IsNullOrEmpty(token)) continue; if(token == "}") break; - // Add glow data - long flatnamehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(token, General.Map.Options.UseLongTextureNames)); + // Add glow data. Hash the name exactly as given. + long flatnamehash = Lump.MakeLongName(token, true); glowingflats[flatnamehash] = new GlowingFlatData { Height = DEFAULT_GLOW_HEIGHT * 2, @@ -594,43 +595,16 @@ namespace CodeImp.DoomBuilder.ZDoom } break; - case "subwalls": - case "subflats": - if(!NextTokenIs("{", false)) - { - ReportError("Expected opening brace"); - return false; - } - - while(SkipWhitespace(true)) - { - token = ReadToken(); - if(token == "}") break; - - // Add glow data - long flatnamehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(token, General.Map.Options.UseLongTextureNames)); - glowingflats[flatnamehash] = new GlowingFlatData - { - Height = DEFAULT_GLOW_HEIGHT * 2, - Fullblack = true, - Subtractive = true, - Color = new PixelColor(255, 0, 0, 0), - CalculateTextureColor = false - }; - } - break; - - case "subtexture": case "texture": { - int color; + PixelColor color = new PixelColor(); int glowheight = DEFAULT_GLOW_HEIGHT; - bool subtractivetexture = (token == "subtexture"); - string texturename = StripQuotes(ReadToken(false)); + string texturename; + if(!ReadTextureName(out texturename)) return false; if(string.IsNullOrEmpty(texturename)) { - ReportError("expected " + token + " name"); + ReportError("Expected " + token + " name"); return false; } @@ -643,25 +617,16 @@ namespace CodeImp.DoomBuilder.ZDoom // Next is color SkipWhitespace(true); - token = ReadToken(); + token = ReadToken(false); - if(!int.TryParse(token, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out color)) + if(!GetColorFromString(token, ref color)) { - //probably it's a color name? - Color c = Color.FromName(token); //should be similar to C++ color name detection, I suppose - if(c.IsKnownColor) - { - color = PixelColor.FromColor(c).ToInt(); - } - else - { - ReportError("expected glow color value, but got \"" + token + "\""); - return false; - } + ReportError("Expected glow color value, but got \"" + token + "\""); + return false; } - // The glow data is valid at thispoint. Let's get texture hash - long texturehash = General.Map.Data.GetFullLongFlatName(Lump.MakeLongName(texturename, General.Map.Options.UseLongTextureNames)); + // The glow data is valid at thispoint. Hash the name exactly as given. + long texturehash = Lump.MakeLongName(texturename, true); // Now we can find a comma if(!NextTokenIs(",", false)) @@ -670,8 +635,7 @@ namespace CodeImp.DoomBuilder.ZDoom glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, - Subtractive = subtractivetexture, - Color = PixelColor.FromInt(color).WithAlpha(255), + Color = color.WithAlpha(255), CalculateTextureColor = false }; continue; @@ -694,8 +658,7 @@ namespace CodeImp.DoomBuilder.ZDoom glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, - Subtractive = subtractivetexture, - Color = PixelColor.FromInt(color).WithAlpha(255), + Color = color.WithAlpha(255), CalculateTextureColor = false }; continue; @@ -706,14 +669,10 @@ namespace CodeImp.DoomBuilder.ZDoom token = ReadToken().ToLowerInvariant(); } - // Next is "fullbright" or "fullblack" flag - bool fullbright = (token == "fullbright"); - bool fullblack = (!subtractivetexture && token == "fullblack"); - - if(!fullblack && !fullbright) + // Next must be "fullbright" flag + if(token != "fullbright") { - string expectedflags = (subtractivetexture ? "\"fullbright\"" : "\"fullbright\" or \"fullblack\""); - ReportError("expected " + expectedflags + " flag, but got \"" + token + "\""); + ReportError("Expected \"fullbright\" flag, but got \"" + token + "\""); return false; } @@ -721,10 +680,8 @@ namespace CodeImp.DoomBuilder.ZDoom glowingflats[texturehash] = new GlowingFlatData { Height = glowheight * 2, - Fullbright = fullbright, - Fullblack = fullblack, - Subtractive = subtractivetexture, - Color = PixelColor.FromInt(color).WithAlpha(255), + Fullbright = true, + Color = color.WithAlpha(255), CalculateTextureColor = false }; } @@ -739,8 +696,9 @@ namespace CodeImp.DoomBuilder.ZDoom private bool ParseSkybox() { SkipWhitespace(true); - string name = StripQuotes(ReadToken()); + string name; + if(!ReadTextureName(out name)) return false; if(string.IsNullOrEmpty(name)) { ReportError("Expected skybox name"); diff --git a/Source/Core/ZDoom/PatchStructure.cs b/Source/Core/ZDoom/PatchStructure.cs index fb997a18..093b92a2 100644 --- a/Source/Core/ZDoom/PatchStructure.cs +++ b/Source/Core/ZDoom/PatchStructure.cs @@ -84,7 +84,7 @@ namespace CodeImp.DoomBuilder.ZDoom // First token is the class name parser.SkipWhitespace(true); - name = parser.StripTokenQuotes(parser.ReadToken(false)); //mxd. Don't skip newline + if(!parser.ReadTextureName(out name, "patch")) return; //mxd if(string.IsNullOrEmpty(name)) { parser.ReportError("Expected patch name"); diff --git a/Source/Core/ZDoom/Scripting/ScriptTypeParserSE.cs b/Source/Core/ZDoom/Scripting/ScriptTypeParserSE.cs index e1e1bde8..48d7299b 100644 --- a/Source/Core/ZDoom/Scripting/ScriptTypeParserSE.cs +++ b/Source/Core/ZDoom/Scripting/ScriptTypeParserSE.cs @@ -9,7 +9,7 @@ using CodeImp.DoomBuilder.Data; //mxd. Parser used to determine which script type given text is. namespace CodeImp.DoomBuilder.ZDoom.Scripting { - internal sealed class ScriptTypeParserSE :ZDTextParser + internal sealed class ScriptTypeParserSE : ZDTextParser { internal override ScriptType ScriptType { get { return scripttype; } } private ScriptType scripttype; diff --git a/Source/Core/ZDoom/TextureStructure.cs b/Source/Core/ZDoom/TextureStructure.cs index 8cefea50..41addc65 100644 --- a/Source/Core/ZDoom/TextureStructure.cs +++ b/Source/Core/ZDoom/TextureStructure.cs @@ -86,14 +86,14 @@ namespace CodeImp.DoomBuilder.ZDoom // First token is the texture name parser.SkipWhitespace(true); - name = parser.StripTokenQuotes(parser.ReadToken(false)); //mxd. Don't skip newline + if(!parser.ReadTextureName(out name, typename)) return; //mxd //mxd. It can also be "optional" keyword. if(name.ToLowerInvariant() == "optional") { optional = true; parser.SkipWhitespace(true); - name = parser.StripTokenQuotes(parser.ReadToken(false)); //mxd. Don't skip newline + if(!parser.ReadTextureName(out name, typename)) return; //mxd } if(string.IsNullOrEmpty(name)) diff --git a/Source/Core/ZDoom/ZDTextParser.cs b/Source/Core/ZDoom/ZDTextParser.cs index a0e0b25f..4224074d 100644 --- a/Source/Core/ZDoom/ZDTextParser.cs +++ b/Source/Core/ZDoom/ZDTextParser.cs @@ -214,6 +214,24 @@ namespace CodeImp.DoomBuilder.ZDoom return token; } + + //mxd + internal bool ReadTextureName(out string name) { return ReadTextureName(out name, "texture"); } + internal bool ReadTextureName(out string name, string elementname) + { + string token = ReadToken(false); + name = StripQuotes(token); + + if(!string.IsNullOrEmpty(name) + && name.Length > DataManager.CLASIC_IMAGE_NAME_LENGTH + && name.Length == token.Length) + { + ReportError("Long " + elementname + " names must be quoted. See \"" + token + "\""); + return false; + } + + return true; + } // This skips whitespace on the stream, placing the read // position right before the first non-whitespace character diff --git a/Source/Plugins/BuilderModes/General/BuilderPlug.cs b/Source/Plugins/BuilderModes/General/BuilderPlug.cs index 45743e29..a92540e0 100644 --- a/Source/Plugins/BuilderModes/General/BuilderPlug.cs +++ b/Source/Plugins/BuilderModes/General/BuilderPlug.cs @@ -340,10 +340,10 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. Apply GLDEFS override? if(General.Map.Data.GlowingFlats.ContainsKey(s.LongFloorTexture) - && (General.Map.Data.GlowingFlats[s.LongFloorTexture].Fullbright || General.Map.Data.GlowingFlats[s.LongFloorTexture].Fullblack)) + && General.Map.Data.GlowingFlats[s.LongFloorTexture].Fullbright) { color = -1; - light = (General.Map.Data.GlowingFlats[s.LongFloorTexture].Fullbright ? 255 : 0); + light = 255; absolute = true; } else @@ -392,10 +392,10 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. Apply GLDEFS override? if(General.Map.Data.GlowingFlats.ContainsKey(s.LongCeilTexture) - && (General.Map.Data.GlowingFlats[s.LongCeilTexture].Fullbright || General.Map.Data.GlowingFlats[s.LongCeilTexture].Fullblack)) + && General.Map.Data.GlowingFlats[s.LongCeilTexture].Fullbright) { color = -1; - light = (General.Map.Data.GlowingFlats[s.LongCeilTexture].Fullbright ? 255 : 0); + light = 255; absolute = true; } else diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs index 1cfc43ed..d6037d18 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs @@ -303,8 +303,9 @@ namespace CodeImp.DoomBuilder.BuilderModes { float cz = data.Ceiling.plane.GetZ(v.x, v.y); float delta = 1.0f - (((v.z - cgz) / (cz - cgz)) * 0.9f); - PixelColor vc = PixelColor.FromInt(v.c); - v.c = InterpolationTools.InterpolateColor(GetGlowColor(data.CeilingGlow, vc), vc, delta).WithAlpha(255).ToInt(); + PixelColor vertexcolor = PixelColor.FromInt(v.c); + PixelColor glowcolor = PixelColor.Add(vertexcolor, data.CeilingGlow.Color); + v.c = InterpolationTools.InterpolateColor(glowcolor, vertexcolor, delta).WithAlpha(255).ToInt(); } } @@ -318,20 +319,14 @@ namespace CodeImp.DoomBuilder.BuilderModes { float fz = data.Floor.plane.GetZ(v.x, v.y); float delta = 1.0f - (((v.z - fz) / (fgz - fz)) * 0.9f); - PixelColor vc = PixelColor.FromInt(v.c); - v.c = InterpolationTools.InterpolateColor(vc, GetGlowColor(data.FloorGlow, vc), delta).WithAlpha(255).ToInt(); + PixelColor vertexcolor = PixelColor.FromInt(v.c); + PixelColor glowcolor = PixelColor.Add(vertexcolor, data.FloorGlow.Color); + v.c = InterpolationTools.InterpolateColor(vertexcolor, glowcolor, delta).WithAlpha(255).ToInt(); } } return v; } - - //mxd - private static PixelColor GetGlowColor(GlowingFlatData data, PixelColor vertexcolor) - { - if(data.Subtractive) return PixelColor.Subtract(vertexcolor, data.Color); - return PixelColor.Add(vertexcolor, data.Color); - } // This splits a polygon with a plane and returns the other part as a new polygon // The polygon is expected to be convex and clockwise diff --git a/Source/Plugins/BuilderModes/VisualModes/SectorData.cs b/Source/Plugins/BuilderModes/VisualModes/SectorData.cs index 50926a0a..9c381f45 100644 --- a/Source/Plugins/BuilderModes/VisualModes/SectorData.cs +++ b/Source/Plugins/BuilderModes/VisualModes/SectorData.cs @@ -465,18 +465,16 @@ namespace CodeImp.DoomBuilder.BuilderModes } //mxd. Apply ceiling glow effect? - if(CeilingGlow != null) + if(CeilingGlow != null && CeilingGlow.Fullbright) { - if(CeilingGlow.Fullbright) ceiling.color = PixelColor.INT_WHITE; - else if(CeilingGlow.Fullblack) ceiling.color = PixelColor.INT_BLACK; + ceiling.color = PixelColor.INT_WHITE; } //mxd. Apply floor glow effect? if(FloorGlow != null) { // Update floor color - if(FloorGlow.Fullbright) floor.color = PixelColor.INT_WHITE; - else if(FloorGlow.Fullblack) floor.color = PixelColor.INT_BLACK; + if(FloorGlow.Fullbright) floor.color = PixelColor.INT_WHITE; // Update brightness floor.brightnessbelow = (FloorGlow.Fullbright ? 255 : Math.Max(128, floor.brightnessbelow));