diff --git a/Build/Configurations/Includes/GZDoom_things.cfg b/Build/Configurations/Includes/GZDoom_things.cfg index d630fb98..382a921b 100755 --- a/Build/Configurations/Includes/GZDoom_things.cfg +++ b/Build/Configurations/Includes/GZDoom_things.cfg @@ -645,6 +645,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -671,6 +672,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -702,6 +704,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -732,6 +735,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -758,6 +762,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -788,6 +793,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -814,6 +820,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -845,6 +852,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -875,6 +883,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -901,6 +910,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -931,6 +941,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -957,6 +968,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -988,6 +1000,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -1018,6 +1031,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -1044,6 +1058,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -1074,6 +1089,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -1100,6 +1116,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -1131,6 +1148,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -1161,6 +1179,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { @@ -1187,6 +1206,7 @@ gzdoom_lights { title = "Color"; default = 16777215; + str = true; } arg1 { diff --git a/Source/Core/Config/ArgumentInfo.cs b/Source/Core/Config/ArgumentInfo.cs index f8c420a3..3fceecf8 100755 --- a/Source/Core/Config/ArgumentInfo.cs +++ b/Source/Core/Config/ArgumentInfo.cs @@ -129,7 +129,7 @@ namespace CodeImp.DoomBuilder.Config string rendercolor = cfg.ReadSetting(argspath + ".arg" + istr + ".rendercolor", string.Empty); this.rendercolor = General.Colors.InfoLine; - if(!string.IsNullOrEmpty(rendercolor) && !ZDTextParser.GetColorFromString(rendercolor, ref this.rendercolor)) + if(!string.IsNullOrEmpty(rendercolor) && !ZDTextParser.GetColorFromString(rendercolor, out this.rendercolor)) General.ErrorLogger.Add(ErrorType.Error, "\"" + argspath + ".arg" + istr + "\": action argument \"" + this.title + "\": unable to get rendercolor from value \"" + rendercolor + "\"!"); this.rendercolor.a = HELPER_SHAPE_ALPHA; @@ -142,7 +142,7 @@ namespace CodeImp.DoomBuilder.Config string minrangecolor = cfg.ReadSetting(argspath + ".arg" + istr + ".minrangecolor", string.Empty); this.minrangecolor = General.Colors.Indication; - if(!string.IsNullOrEmpty(minrangecolor) && !ZDTextParser.GetColorFromString(minrangecolor, ref this.minrangecolor)) + if(!string.IsNullOrEmpty(minrangecolor) && !ZDTextParser.GetColorFromString(minrangecolor, out this.minrangecolor)) General.ErrorLogger.Add(ErrorType.Error, "\"" + argspath + ".arg" + istr + "\": action argument \"" + this.title + "\": unable to get minrangecolor from value \"" + minrangecolor + "\"!"); this.minrangecolor.a = RANGE_SHAPE_ALPHA; @@ -156,7 +156,7 @@ namespace CodeImp.DoomBuilder.Config string maxrangecolor = cfg.ReadSetting(argspath + ".arg" + istr + ".maxrangecolor", string.Empty); this.maxrangecolor = General.Colors.Indication; - if(!string.IsNullOrEmpty(maxrangecolor) && !ZDTextParser.GetColorFromString(maxrangecolor, ref this.maxrangecolor)) + if(!string.IsNullOrEmpty(maxrangecolor) && !ZDTextParser.GetColorFromString(maxrangecolor, out this.maxrangecolor)) General.ErrorLogger.Add(ErrorType.Error, "\"" + argspath + ".arg" + istr + "\": action argument \"" + this.title + "\": unable to get maxrangecolor from value \"" + maxrangecolor + "\"!"); this.maxrangecolor.a = RANGE_SHAPE_ALPHA; @@ -303,7 +303,7 @@ namespace CodeImp.DoomBuilder.Config // Get rendercolor this.rendercolor = General.Colors.InfoLine; - if(!string.IsNullOrEmpty(rendercolor) && !ZDTextParser.GetColorFromString(rendercolor, ref this.rendercolor)) + if(!string.IsNullOrEmpty(rendercolor) && !ZDTextParser.GetColorFromString(rendercolor, out this.rendercolor)) General.ErrorLogger.Add(ErrorType.Error, actorname + ": action argument \"" + argtitle + "\": unable to get rendercolor from value \"" + rendercolor + "\"!"); this.rendercolor.a = HELPER_SHAPE_ALPHA; @@ -314,7 +314,7 @@ namespace CodeImp.DoomBuilder.Config // Get minrangecolor this.minrangecolor = General.Colors.Indication; - if(!string.IsNullOrEmpty(minrangecolor) && !ZDTextParser.GetColorFromString(minrangecolor, ref this.minrangecolor)) + if(!string.IsNullOrEmpty(minrangecolor) && !ZDTextParser.GetColorFromString(minrangecolor, out this.minrangecolor)) General.ErrorLogger.Add(ErrorType.Error, actorname + ": action argument \"" + this.title + "\": unable to get minrangecolor from value \"" + minrangecolor + "\"!"); this.minrangecolor.a = RANGE_SHAPE_ALPHA; @@ -326,7 +326,7 @@ namespace CodeImp.DoomBuilder.Config // Get minrangecolor this.maxrangecolor = General.Colors.Indication; - if(!string.IsNullOrEmpty(maxrangecolor) && !ZDTextParser.GetColorFromString(maxrangecolor, ref this.maxrangecolor)) + if(!string.IsNullOrEmpty(maxrangecolor) && !ZDTextParser.GetColorFromString(maxrangecolor, out this.maxrangecolor)) General.ErrorLogger.Add(ErrorType.Error, actorname + ": action argument \"" + this.title + "\": unable to get maxrangecolor from value \"" + maxrangecolor + "\"!"); this.maxrangecolor.a = RANGE_SHAPE_ALPHA; diff --git a/Source/Core/GZBuilder/Data/LinksCollector.cs b/Source/Core/GZBuilder/Data/LinksCollector.cs index aeb3db56..20dea32b 100755 --- a/Source/Core/GZBuilder/Data/LinksCollector.cs +++ b/Source/Core/GZBuilder/Data/LinksCollector.cs @@ -531,7 +531,81 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data #region ================== GetDynamicLightShapes - public static List GetDynamicLightShapes(IEnumerable things, bool highlight) + public static List GetPointLightShape(Thing t, bool highlight, GZGeneral.LightData ld, int linealpha) + { + // TODO: this basically duplicates VisualThing.UpdateLight()... + // Determine light radiii + int primaryradius; + int secondaryradius = 0; + + if (ld.LightDef != GZGeneral.LightDef.VAVOOM_GENERIC && + ld.LightDef != GZGeneral.LightDef.VAVOOM_COLORED) //if it's gzdoom light + { + if (ld.LightModifier == GZGeneral.LightModifier.SECTOR) + { + if (t.Sector == null) t.DetermineSector(); + int scaler = (t.Sector != null ? t.Sector.Brightness / 4 : 2); + primaryradius = t.Args[3] * scaler; + } + else + { + primaryradius = t.Args[3] * 2; //works... that.. way in GZDoom + if (ld.LightAnimated) secondaryradius = t.Args[4] * 2; + } + } + else //it's one of vavoom lights + { + primaryradius = t.Args[0] * 8; + } + + // Check radii... + if (primaryradius < 1 && secondaryradius < 1) return null; + + // Determine light color + PixelColor color; + if (highlight) + { + color = General.Colors.Highlight.WithAlpha((byte)linealpha); + } + else + { + switch (t.DynamicLightType.LightDef) + { + case GZGeneral.LightDef.VAVOOM_GENERIC: // Vavoom light + color = new PixelColor((byte)linealpha, 255, 255, 255); + break; + + case GZGeneral.LightDef.VAVOOM_COLORED: // Vavoom colored light + color = new PixelColor((byte)linealpha, (byte)t.Args[1], (byte)t.Args[2], (byte)t.Args[3]); + break; + + default: + color = new PixelColor((byte)linealpha, (byte)t.Args[0], (byte)t.Args[1], (byte)t.Args[2]); + break; + } + } + + // Add lines if visible + List circles = new List(); + if (primaryradius > 0) circles.AddRange(MakeCircleLines(t.Position, color, primaryradius, CIRCLE_SIDES)); + if (secondaryradius > 0) circles.AddRange(MakeCircleLines(t.Position, color, secondaryradius, CIRCLE_SIDES)); + return circles; + } + + public static List GetSpotLightShape(Thing t, bool highlight, GZGeneral.LightData ld, int linealpha) + { + List shapes = new List(); + float lAngle1 = Angle2D.DegToRad(t.Args[1] / 2); + float lAngle2 = Angle2D.DegToRad(t.Args[2] / 2); + float lRadius = t.Args[3]; + float lDirY = (float)Math.Sin(-lAngle1) * lRadius; + float lDirX = (float)Math.Cos(-lAngle1) * lRadius; + shapes.Add(new Line3D(new Vector3D(0, 0, 0), new Vector3D(lDirX, lDirY, 0))); + shapes.Add(new Line3D(new Vector3D(0, 0, 0), new Vector3D(lDirX, -lDirY, 0))); + return shapes; + } + + public static List GetDynamicLightShapes(IEnumerable things, bool highlight) { List circles = new List(); if(General.Map.DOOM) return circles; @@ -541,72 +615,17 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data { GZGeneral.LightData ld = t.DynamicLightType; if (ld == null) continue; - if (ld.LightType == GZGeneral.LightType.SPOT) - continue; // spotlights don't work well with the current representation. - // todo: have 2D ortho projection of actual light cone - // TODO: this basically duplicates VisualThing.UpdateLight()... - // Determine light radiii - int primaryradius; - int secondaryradius = 0; - - if (ld.LightDef != GZGeneral.LightDef.VAVOOM_GENERIC && - ld.LightDef != GZGeneral.LightDef.VAVOOM_COLORED) //if it's gzdoom light - { - if(ld.LightModifier == GZGeneral.LightModifier.SECTOR) - { - if(t.Sector == null) t.DetermineSector(); - int scaler = (t.Sector != null ? t.Sector.Brightness / 4 : 2); - primaryradius = t.Args[3] * scaler; - } - else - { - primaryradius = t.Args[3] * 2; //works... that.. way in GZDoom - if (ld.LightAnimated) secondaryradius = t.Args[4] * 2; - } - } - else //it's one of vavoom lights - { - primaryradius = t.Args[0] * 8; - } - - // Check radii... - if(primaryradius < 1 && secondaryradius < 1) continue; - - // Determine light color - PixelColor color; - if(highlight) - { - color = General.Colors.Highlight.WithAlpha(linealpha); - } - else - { - switch(t.DynamicLightType.LightDef) - { - case GZGeneral.LightDef.VAVOOM_GENERIC: // Vavoom light - color = new PixelColor(linealpha, 255, 255, 255); - break; - - case GZGeneral.LightDef.VAVOOM_COLORED: // Vavoom colored light - color = new PixelColor(linealpha, (byte)t.Args[1], (byte)t.Args[2], (byte)t.Args[3]); - break; - - case GZGeneral.LightDef.SPOT_NORMAL: - case GZGeneral.LightDef.SPOT_ADDITIVE: - case GZGeneral.LightDef.SPOT_SUBTRACTIVE: - case GZGeneral.LightDef.SPOT_ATTENUATED: - color = new PixelColor(linealpha, (byte)((t.Args[0] & 0xFF0000) >> 16), (byte)((t.Args[0] & 0x00FF00) >> 8), (byte)((t.Args[0] & 0x0000FF))); - break; - - default: - color = new PixelColor(linealpha, (byte)t.Args[0], (byte)t.Args[1], (byte)t.Args[2]); - break; - } - } - - // Add lines if visible - if(primaryradius > 0) circles.AddRange(MakeCircleLines(t.Position, color, primaryradius, CIRCLE_SIDES)); - if(secondaryradius > 0) circles.AddRange(MakeCircleLines(t.Position, color, secondaryradius, CIRCLE_SIDES)); + if (ld.LightType != GZGeneral.LightType.SPOT) + { + List lshape = GetPointLightShape(t, highlight, ld, linealpha); + circles.AddRange(lshape); + } + else + { + List lshape = GetSpotLightShape(t, highlight, ld, linealpha); + circles.AddRange(lshape); + } } // Done diff --git a/Source/Core/Rendering/Renderer2D.cs b/Source/Core/Rendering/Renderer2D.cs index af6b1ac8..fc4963b3 100755 --- a/Source/Core/Rendering/Renderer2D.cs +++ b/Source/Core/Rendering/Renderer2D.cs @@ -550,7 +550,16 @@ namespace CodeImp.DoomBuilder.Rendering if (t.DynamicLightType.LightDef == GZGeneral.LightDef.VAVOOM_COLORED) //vavoom colored light return new PixelColor(255, (byte)t.Args[1], (byte)t.Args[2], (byte)t.Args[3]); if (t.DynamicLightType.LightType == GZGeneral.LightType.SPOT) + { + if (t.Fields.ContainsKey("arg0str")) + { + PixelColor pc; + ZDoom.ZDTextParser.GetColorFromString(t.Fields["arg0str"].Value.ToString(), out pc); + pc.a = 255; + return pc; + } return new PixelColor(255, (byte)((t.Args[0] & 0xFF0000) >> 16), (byte)((t.Args[0] & 0x00FF00) >> 8), (byte)((t.Args[0] & 0x0000FF))); + } return new PixelColor(255, (byte)t.Args[0], (byte)t.Args[1], (byte)t.Args[2]); } diff --git a/Source/Core/VisualModes/VisualThing.cs b/Source/Core/VisualModes/VisualThing.cs index 6879b6a9..782cef55 100755 --- a/Source/Core/VisualModes/VisualThing.cs +++ b/Source/Core/VisualModes/VisualThing.cs @@ -688,9 +688,22 @@ namespace CodeImp.DoomBuilder.VisualModes } else { - int c1 = (thing.Args[0] & 0xFF0000) >> 16; - int c2 = (thing.Args[0] & 0x00FF00) >> 8; - int c3 = (thing.Args[0] & 0x0000FF); + int c1, c2, c3; + if (thing.Fields.ContainsKey("arg0str")) + { + PixelColor pc; + ZDoom.ZDTextParser.GetColorFromString(thing.Fields["arg0str"].Value.ToString(), out pc); + c1 = pc.r; + c2 = pc.g; + c3 = pc.b; + } + else + { + c1 = (thing.Args[0] & 0xFF0000) >> 16; + c2 = (thing.Args[0] & 0x00FF00) >> 8; + c3 = (thing.Args[0] & 0x0000FF); + } + if (ld.LightDef != GZGeneral.LightDef.SPOT_SUBTRACTIVE) { lightColor = new Color4((float)ld.LightRenderStyle / 100.0f, diff --git a/Source/Core/ZDoom/CvarInfoParser.cs b/Source/Core/ZDoom/CvarInfoParser.cs index 88f395b9..f709c839 100755 --- a/Source/Core/ZDoom/CvarInfoParser.cs +++ b/Source/Core/ZDoom/CvarInfoParser.cs @@ -160,7 +160,7 @@ namespace CodeImp.DoomBuilder.ZDoom case "color": PixelColor cv = new PixelColor(); - if(!string.IsNullOrEmpty(value) && !GetColorFromString(value, ref cv)) + if(!string.IsNullOrEmpty(value) && !GetColorFromString(value, out cv)) { ReportError("Cvar \"" + name + "\" has invalid color value: \"" + value + "\""); return false; diff --git a/Source/Core/ZDoom/GldefsParser.cs b/Source/Core/ZDoom/GldefsParser.cs index fc885403..adcbdcc0 100755 --- a/Source/Core/ZDoom/GldefsParser.cs +++ b/Source/Core/ZDoom/GldefsParser.cs @@ -637,7 +637,7 @@ namespace CodeImp.DoomBuilder.ZDoom SkipWhitespace(true); token = ReadToken(false); - if(!GetColorFromString(token, ref color)) + if(!GetColorFromString(token, out color)) { ReportError("Expected glow color value, but got \"" + token + "\""); return false; diff --git a/Source/Core/ZDoom/MapinfoParser.cs b/Source/Core/ZDoom/MapinfoParser.cs index 746537c7..c128003d 100755 --- a/Source/Core/ZDoom/MapinfoParser.cs +++ b/Source/Core/ZDoom/MapinfoParser.cs @@ -641,7 +641,7 @@ namespace CodeImp.DoomBuilder.ZDoom // Try to get the color... PixelColor color = new PixelColor(); - if(GetColorFromString(colorval, ref color)) + if(GetColorFromString(colorval, out color)) { if(fadetype == "fade") mapinfo.FadeColor = color.ToColorValue(); diff --git a/Source/Core/ZDoom/PatchStructure.cs b/Source/Core/ZDoom/PatchStructure.cs index 093b92a2..fbac843a 100755 --- a/Source/Core/ZDoom/PatchStructure.cs +++ b/Source/Core/ZDoom/PatchStructure.cs @@ -173,7 +173,7 @@ namespace CodeImp.DoomBuilder.ZDoom token = parser.ReadToken(false); if(!parser.ReadByte(token, ref color.r)) { - if(!ZDTextParser.GetColorFromString(token, ref color)) + if(!ZDTextParser.GetColorFromString(token, out color)) { parser.ReportError("Unsupported patch blend definition"); return; diff --git a/Source/Core/ZDoom/ZDTextParser.cs b/Source/Core/ZDoom/ZDTextParser.cs index 31089ed2..38366a55 100755 --- a/Source/Core/ZDoom/ZDTextParser.cs +++ b/Source/Core/ZDoom/ZDTextParser.cs @@ -605,7 +605,7 @@ namespace CodeImp.DoomBuilder.ZDoom } //mxd. This replicates ZDoom's V_GetColorFromString method - public static bool GetColorFromString(string name, ref PixelColor color) + public static bool GetColorFromString(string name, out PixelColor color) { name = StripQuotes(name.Replace(" ", "")); @@ -644,7 +644,8 @@ namespace CodeImp.DoomBuilder.ZDoom return true; } - return false; + color = new PixelColor(); + return false; } //mxd