From 2cbe6640a6da4731f7c0ea575571e154a1962744 Mon Sep 17 00:00:00 2001 From: MaxED Date: Mon, 25 Jan 2016 13:42:53 +0000 Subject: [PATCH] Fixed, Visual mode: in some cases ceiling glow effect was interfering with Transfer Brightness effect resulting in incorrectly lit sidedef geometry. Fixed, Visual mode: UDMF sidedef brightness should be ignored when a wall section is affected by Transfer Brightness effect. Fixed, Visual mode: any custom fog should be rendered regardless of sector brightness. Fixed, Visual mode: "fogdensity" and "outsidefogdensity" MAPINFO values were processed incorrectly. Fixed, Visual mode: in some cases Things were rendered twice during a render pass. Fixed, Visual mode: floor glow effect should affect thing brightness only when applied to floor of the sector thing is in. Fixed, TEXTURES parser: TEXTURES group was named incorrectly in the Textures Browser window when parsed from a WAD file. Fixed, MAPINFO, GLDEFS, DECORATE parsers: "//$GZDB_SKIP" special comment was processed incorrectly. Fixed, MAPINFO parser: "fogdensity" and "outsidefogdensity" properties are now initialized using GZDoom default value (255) instead of 0. --- Build/Scripting/ZDoom_DECORATE.cfg | 1 + Source/Core/GZBuilder/Data/MapInfo.cs | 2 + Source/Core/GZBuilder/GZDoom/GldefsParser.cs | 6 +- Source/Core/GZBuilder/GZDoom/MapinfoParser.cs | 20 ++--- Source/Core/Map/Sector.cs | 51 ++++++++----- Source/Core/Rendering/Renderer3D.cs | 12 +-- Source/Core/VisualModes/VisualGeometry.cs | 42 ++++++----- Source/Core/VisualModes/VisualMode.cs | 14 ++-- Source/Core/ZDoom/ActorStructure.cs | 3 + Source/Core/ZDoom/DecorateParser.cs | 7 +- Source/Core/ZDoom/TexturesParser.cs | 17 ++++- .../VisualModes/BaseVisualGeometrySidedef.cs | 28 ++++--- .../VisualModes/BaseVisualMode.cs | 2 +- .../VisualModes/BaseVisualThing.cs | 74 +++++-------------- .../BuilderModes/VisualModes/VisualCeiling.cs | 2 +- .../BuilderModes/VisualModes/VisualFloor.cs | 2 +- .../VisualModes/VisualFogBoundary.cs | 6 +- .../BuilderModes/VisualModes/VisualLower.cs | 2 +- .../VisualModes/VisualMiddle3D.cs | 2 +- .../VisualModes/VisualMiddleBack.cs | 2 +- .../VisualModes/VisualMiddleDouble.cs | 2 +- .../VisualModes/VisualMiddleSingle.cs | 2 +- .../BuilderModes/VisualModes/VisualUpper.cs | 2 +- 23 files changed, 148 insertions(+), 153 deletions(-) diff --git a/Build/Scripting/ZDoom_DECORATE.cfg b/Build/Scripting/ZDoom_DECORATE.cfg index 712c31a8..5d20d2c2 100644 --- a/Build/Scripting/ZDoom_DECORATE.cfg +++ b/Build/Scripting/ZDoom_DECORATE.cfg @@ -1146,6 +1146,7 @@ constants TF_USEACTORFOG; TF_NOJUMP; TF_OVERRIDE; + TF_SENSITIVEZ; TIF_NOTAKEINFINITE; VAF_DMGTYPEAPPLYTODIRECT; WARPF_ABSOLUTEOFFSET; diff --git a/Source/Core/GZBuilder/Data/MapInfo.cs b/Source/Core/GZBuilder/Data/MapInfo.cs index d7aef9a6..be500bcc 100644 --- a/Source/Core/GZBuilder/Data/MapInfo.cs +++ b/Source/Core/GZBuilder/Data/MapInfo.cs @@ -62,6 +62,8 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data { vertwallshade = 16; horizwallshade = -16; + fogdensity = 255; + outsidefogdensity = 255; } #endregion diff --git a/Source/Core/GZBuilder/GZDoom/GldefsParser.cs b/Source/Core/GZBuilder/GZDoom/GldefsParser.cs index 9b8c297d..80051d84 100644 --- a/Source/Core/GZBuilder/GZDoom/GldefsParser.cs +++ b/Source/Core/GZBuilder/GZDoom/GldefsParser.cs @@ -144,7 +144,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom // Find classname SkipWhitespace(true); - string lightname = StripTokenQuotes(ReadToken()).ToLowerInvariant(); + string lightname = StripTokenQuotes(ReadToken()); if(string.IsNullOrEmpty(lightname)) { @@ -439,7 +439,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom SkipWhitespace(true); // Read object class - string objectclass = StripTokenQuotes(ReadToken()).ToLowerInvariant(); + string objectclass = StripTokenQuotes(ReadToken()); if(string.IsNullOrEmpty(objectclass)) { @@ -476,7 +476,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom else if(!foundlight && foundframe && token == "light") // Just use first light and be done with it { SkipWhitespace(true); - token = ReadToken().ToLowerInvariant(); // Should be light name + token = ReadToken(); // Should be light name if(!string.IsNullOrEmpty(token)) { diff --git a/Source/Core/GZBuilder/GZDoom/MapinfoParser.cs b/Source/Core/GZBuilder/GZDoom/MapinfoParser.cs index 6bb8ce3f..028ddf9a 100644 --- a/Source/Core/GZBuilder/GZDoom/MapinfoParser.cs +++ b/Source/Core/GZBuilder/GZDoom/MapinfoParser.cs @@ -81,8 +81,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom while(SkipWhitespace(true)) { string token = ReadToken().ToLowerInvariant(); - if(string.IsNullOrEmpty(token)) break; - bool stopparsing = false; + if(string.IsNullOrEmpty(token) || token == "$gzdb_skip") break; switch(token) { @@ -158,20 +157,14 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom case "spawnnums": if(!ParseSpawnNums()) return false; break; - - case "$gzdb_skip": - stopparsing = true; // Finished with this file - break; } - - if(stopparsing) break; } // Check values - if(mapinfo.FadeColor.Red > 0 || mapinfo.FadeColor.Green > 0 || mapinfo.FadeColor.Blue > 0) + if(mapinfo.FogDensity > 0 && (mapinfo.FadeColor.Red > 0 || mapinfo.FadeColor.Green > 0 || mapinfo.FadeColor.Blue > 0)) mapinfo.HasFadeColor = true; - if(mapinfo.OutsideFogColor.Red > 0 || mapinfo.OutsideFogColor.Green > 0 || mapinfo.OutsideFogColor.Blue > 0) + if(mapinfo.OutsideFogDensity > 0 && (mapinfo.OutsideFogColor.Red > 0 || mapinfo.OutsideFogColor.Green > 0 || mapinfo.OutsideFogColor.Blue > 0)) mapinfo.HasOutsideFogColor = true; // All done @@ -643,10 +636,9 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom return false; } - if(densitytype == "fogdensity") - mapinfo.FogDensity = (int)(1024 * (256.0f / val)); - else - mapinfo.OutsideFogDensity = (int)(1024 * (256.0f / val)); + val = Math.Max(0, val); + if(densitytype == "fogdensity") mapinfo.FogDensity = val; + else mapinfo.OutsideFogDensity = val; // All done here return true; diff --git a/Source/Core/Map/Sector.cs b/Source/Core/Map/Sector.cs index 2efed678..512b6e11 100644 --- a/Source/Core/Map/Sector.cs +++ b/Source/Core/Map/Sector.cs @@ -29,6 +29,15 @@ using SlimDX; namespace CodeImp.DoomBuilder.Map { + public enum SectorFogMode //mxd + { + NONE, // no fog + CLASSIC, // black fog when sector brightness < 243 + FOGDENSITY, // sector uses "fogdensity" MAPINFO property + OUTSIDEFOGDENSITY, // sector uses "outsidefogdensity" MAPINFO property + FADE // sector uses UDMF "fade" sector property + } + public sealed class Sector : SelectableElement { #region ================== Constants @@ -77,9 +86,8 @@ namespace CodeImp.DoomBuilder.Map private readonly SurfaceEntryCollection surfaceentries; //mxd. Rendering - private Color4 fogColor; - private bool hasFogColor; - private bool useOutsideFog; + private Color4 fogcolor; + private SectorFogMode fogmode; //mxd. Slopes private Vector3D floorslope; @@ -118,9 +126,8 @@ namespace CodeImp.DoomBuilder.Map public ReadOnlyCollection Labels { get { return labels; } } //mxd. Rednering - public Color4 FogColor { get { return fogColor; } } - public bool HasFogColor { get { return hasFogColor; } } - public bool UsesOutsideFog { get { return useOutsideFog; } } + public Color4 FogColor { get { return fogcolor; } } + public SectorFogMode FogMode { get { return fogmode; } } //mxd. Slopes public Vector3D FloorSlope { get { return floorslope; } set { BeforePropsChange(); floorslope = value; updateneeded = true; } } @@ -473,8 +480,7 @@ namespace CodeImp.DoomBuilder.Map this.Fields.Clear(); if(isvirtual) this.Fields.Add(MapSet.VirtualSectorField, MapSet.VirtualSectorValue); this.Flags.Clear(); - hasFogColor = false; - useOutsideFog = false; + this.fogmode = SectorFogMode.NONE; // Reset Slopes floorslope = new Vector3D(); @@ -879,19 +885,28 @@ namespace CodeImp.DoomBuilder.Map //mxd public void UpdateFogColor() { - // Sector uses outisde fog when it's ceiling is sky or Sector_Outside effect (87) is set - useOutsideFog = (General.Map.Data.MapInfo.HasOutsideFogColor && (ceiltexname == General.Map.Config.SkyFlatName || (effect == 87 && General.Map.Config.SectorEffects.ContainsKey(effect)))); - if(General.Map.UDMF && Fields.ContainsKey("fadecolor")) - fogColor = new Color4((int)Fields["fadecolor"].Value); - else if(useOutsideFog) - fogColor = General.Map.Data.MapInfo.OutsideFogColor; + { + fogcolor = new Color4((int)Fields["fadecolor"].Value); + fogmode = SectorFogMode.FADE; + } + // Sector uses outisde fog when it's ceiling is sky or Sector_Outside effect (87) is set + else if(General.Map.Data.MapInfo.HasOutsideFogColor && + (ceiltexname == General.Map.Config.SkyFlatName || (effect == 87 && General.Map.Config.SectorEffects.ContainsKey(effect)))) + { + fogcolor = General.Map.Data.MapInfo.OutsideFogColor; + fogmode = SectorFogMode.OUTSIDEFOGDENSITY; + } else if(General.Map.Data.MapInfo.HasFadeColor) - fogColor = General.Map.Data.MapInfo.FadeColor; + { + fogcolor = General.Map.Data.MapInfo.FadeColor; + fogmode = SectorFogMode.FOGDENSITY; + } else - fogColor = new Color4(); - - hasFogColor = fogColor.Red > 0 || fogColor.Green > 0 || fogColor.Blue > 0; + { + fogcolor = new Color4(); + fogmode = (brightness < 248 ? SectorFogMode.CLASSIC : SectorFogMode.NONE); + } } #endregion diff --git a/Source/Core/Rendering/Renderer3D.cs b/Source/Core/Rendering/Renderer3D.cs index 257e8d4b..9e416be4 100644 --- a/Source/Core/Rendering/Renderer3D.cs +++ b/Source/Core/Rendering/Renderer3D.cs @@ -771,7 +771,7 @@ namespace CodeImp.DoomBuilder.Rendering int wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass; //mxd. Render fog? - if(General.Settings.GZDrawFog && !fullbrightness && sector.Sector.Brightness < 248) + if(General.Settings.GZDrawFog && !fullbrightness && sector.Sector.FogMode != SectorFogMode.NONE) wantedshaderpass += 8; // Switch shader pass? @@ -849,7 +849,7 @@ namespace CodeImp.DoomBuilder.Rendering int wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass; //mxd. If fog is enagled, switch to shader, which calculates it - if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && (t.Thing.Sector.HasFogColor || t.Thing.Sector.Brightness < 248)) + if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE) wantedshaderpass += 8; //mxd. Create the matrix for positioning @@ -1049,7 +1049,7 @@ namespace CodeImp.DoomBuilder.Rendering int wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass; //mxd. Render fog? - if(General.Settings.GZDrawFog && !fullbrightness && sector.Sector.Brightness < 248) + if(General.Settings.GZDrawFog && !fullbrightness && sector.Sector.FogMode != SectorFogMode.NONE) wantedshaderpass += 8; // Switch shader pass? @@ -1158,7 +1158,7 @@ namespace CodeImp.DoomBuilder.Rendering int wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass; //mxd. if fog is enagled, switch to shader, which calculates it - if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && (t.Thing.Sector.HasFogColor || t.Thing.Sector.Brightness < 248)) + if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE) wantedshaderpass += 8; //mxd. Create the matrix for positioning @@ -1411,7 +1411,7 @@ namespace CodeImp.DoomBuilder.Rendering int wantedshaderpass = ((((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass); //mxd. if fog is enagled, switch to shader, which calculates it - if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && (t.Thing.Sector.HasFogColor || t.Thing.Sector.Brightness < 248)) + if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE) wantedshaderpass += 8; // Switch shader pass? @@ -1512,7 +1512,7 @@ namespace CodeImp.DoomBuilder.Rendering int wantedshaderpass = ((((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass); //mxd. if fog is enagled, switch to shader, which calculates it - if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && (t.Thing.Sector.HasFogColor || t.Thing.Sector.Brightness < 248)) + if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE) wantedshaderpass += 8; // Switch shader pass? diff --git a/Source/Core/VisualModes/VisualGeometry.cs b/Source/Core/VisualModes/VisualGeometry.cs index 1a45d4ed..f68a6cee 100644 --- a/Source/Core/VisualModes/VisualGeometry.cs +++ b/Source/Core/VisualModes/VisualGeometry.cs @@ -202,29 +202,33 @@ namespace CodeImp.DoomBuilder.VisualModes //TODO: this doesn't match any GZDoom light mode... //GZDoom: gl_renderstate.h, SetFog(); //GZDoom: gl_lightlevel.cpp gl_SetFog(); - protected float CalculateFogDensity(int brightness) + protected float CalculateFogFactor(int brightness) { return CalculateFogFactor(Sector.Sector.FogMode, brightness); } + public static float CalculateFogFactor(SectorFogMode mode, int brightness) { float density; - if(Sector.Sector.UsesOutsideFog && General.Map.Data.MapInfo.OutsideFogDensity > 0) + switch(mode) { - density = General.Map.Data.MapInfo.OutsideFogDensity; - } - else if(!Sector.Sector.UsesOutsideFog && General.Map.Data.MapInfo.FogDensity > 0) - { - density = General.Map.Data.MapInfo.FogDensity; - } - else if(brightness < 248) - { - density = General.Clamp(255 - brightness, 30, 255); - } - else - { - density = 0f; - } + case SectorFogMode.OUTSIDEFOGDENSITY: + density = General.Map.Data.MapInfo.OutsideFogDensity; + break; - if(Sector.Sector.HasFogColor) - { - density *= 4; + case SectorFogMode.FOGDENSITY: + density = General.Map.Data.MapInfo.FogDensity; + break; + + case SectorFogMode.FADE: + density = General.Clamp(255 - brightness, 30, 255) * 4; + break; + + case SectorFogMode.CLASSIC: + density = General.Clamp(255 - brightness, 30, 255); + break; + + case SectorFogMode.NONE: + density = 0f; + break; + + default: throw new NotImplementedException("Unknown SectorFogMode!"); } return density * FOG_DENSITY_SCALER; diff --git a/Source/Core/VisualModes/VisualMode.cs b/Source/Core/VisualModes/VisualMode.cs index 731aa1a2..6dc0ae27 100644 --- a/Source/Core/VisualModes/VisualMode.cs +++ b/Source/Core/VisualModes/VisualMode.cs @@ -73,7 +73,7 @@ namespace CodeImp.DoomBuilder.VisualModes protected Dictionary allthings; protected Dictionary allsectors; protected List visibleblocks; - protected List visiblethings; + protected Dictionary visiblethings; protected Dictionary visiblesectors; protected List visiblegeometry; @@ -102,11 +102,11 @@ namespace CodeImp.DoomBuilder.VisualModes this.renderer = General.Map.Renderer3D; this.blockmap = new VisualBlockMap(); this.allsectors = new Dictionary(General.Map.Map.Sectors.Count); - this.allthings = new Dictionary(General.Map.Map.Things.Count); + this.allthings = new Dictionary(General.Map.Map.Things.Count); this.visibleblocks = new List(); this.visiblesectors = new Dictionary(50); this.visiblegeometry = new List(200); - this.visiblethings = new List(100); + this.visiblethings = new Dictionary(100); this.processgeometry = true; this.processthings = true; this.vertices = new Dictionary(); //mxd @@ -515,7 +515,7 @@ namespace CodeImp.DoomBuilder.VisualModes // Make collections visiblesectors = new Dictionary(visiblesectors.Count); visiblegeometry = new List(visiblegeometry.Capacity); - visiblethings = new List(visiblethings.Capacity); + visiblethings = new Dictionary(visiblethings.Count); // Get the blocks within view range visibleblocks = blockmap.GetFrustumRange(renderer.Frustum2D); @@ -569,9 +569,9 @@ namespace CodeImp.DoomBuilder.VisualModes allthings.Add(t, vt); } - if(vt != null) + if(vt != null && !visiblethings.ContainsKey(vt.Thing)) { - visiblethings.Add(vt); + visiblethings.Add(vt.Thing, vt); } } } @@ -799,7 +799,7 @@ namespace CodeImp.DoomBuilder.VisualModes } // Add all the visible things - foreach(VisualThing vt in visiblethings) pickables.Add(vt); + foreach(VisualThing vt in visiblethings.Values) pickables.Add(vt); //mxd. And all visual vertices if(General.Map.UDMF && General.Settings.GZShowVisualVertices) diff --git a/Source/Core/ZDoom/ActorStructure.cs b/Source/Core/ZDoom/ActorStructure.cs index c6331729..1a1a8dcc 100644 --- a/Source/Core/ZDoom/ActorStructure.cs +++ b/Source/Core/ZDoom/ActorStructure.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Globalization; using CodeImp.DoomBuilder.Config; +using CodeImp.DoomBuilder.Data; #endregion @@ -590,6 +591,8 @@ namespace CodeImp.DoomBuilder.ZDoom if(HasPropertyWithValue("$sprite")) { string sprite = GetPropertyValueString("$sprite", 0); //mxd + if((sprite.Length > DataManager.INTERNAL_PREFIX.Length) && + sprite.ToLowerInvariant().StartsWith(DataManager.INTERNAL_PREFIX)) return sprite; //mxd if(General.Map.Data.GetSpriteExists(sprite)) return sprite; //mxd. Added availability check //mxd. Bitch and moan diff --git a/Source/Core/ZDoom/DecorateParser.cs b/Source/Core/ZDoom/DecorateParser.cs index 96d03cc4..997c96a8 100644 --- a/Source/Core/ZDoom/DecorateParser.cs +++ b/Source/Core/ZDoom/DecorateParser.cs @@ -86,8 +86,8 @@ namespace CodeImp.DoomBuilder.ZDoom specialtokens = ":{}+-\n;,"; // Initialize - actors = new Dictionary(StringComparer.Ordinal); - archivedactors = new Dictionary(StringComparer.Ordinal); + actors = new Dictionary(StringComparer.OrdinalIgnoreCase); + archivedactors = new Dictionary(StringComparer.OrdinalIgnoreCase); parsedlumps = new HashSet(StringComparer.OrdinalIgnoreCase); //mxd } @@ -124,6 +124,7 @@ namespace CodeImp.DoomBuilder.ZDoom if(!string.IsNullOrEmpty(objdeclaration)) { objdeclaration = objdeclaration.ToLowerInvariant(); + if(objdeclaration == "$gzdb_skip") break; switch(objdeclaration) { case "actor": @@ -226,8 +227,6 @@ namespace CodeImp.DoomBuilder.ZDoom } break; - case "$gzdb_skip": break; - default: { // Unknown structure! diff --git a/Source/Core/ZDoom/TexturesParser.cs b/Source/Core/ZDoom/TexturesParser.cs index 95cf4ff0..06607345 100644 --- a/Source/Core/ZDoom/TexturesParser.cs +++ b/Source/Core/ZDoom/TexturesParser.cs @@ -78,8 +78,19 @@ namespace CodeImp.DoomBuilder.ZDoom if(!base.Parse(stream, sourcefilename, clearerrors)) return false; //mxd. Make vitrual path from filename - string virtualpath = sourcefilename.Substring(8).TrimStart(pathtrimchars); - if(virtualpath.ToLowerInvariant() == "txt") virtualpath = string.Empty; + string virtualpath; + if(sourcefilename.Contains("#")) // It's TEXTURES lump + { + virtualpath = Path.GetFileName(sourcefilename); + if(!string.IsNullOrEmpty(virtualpath)) virtualpath = virtualpath.Substring(0, virtualpath.LastIndexOf("#", StringComparison.Ordinal)); + } + else // If it's actual filename, try to use extension(s) as virtualpath + { + virtualpath = Path.GetFileName(sourcefilename); + if(!string.IsNullOrEmpty(virtualpath)) virtualpath = virtualpath.Substring(8).TrimStart(pathtrimchars); + if(!string.IsNullOrEmpty(virtualpath) && virtualpath.ToLowerInvariant() == "txt") virtualpath = string.Empty; + if(string.IsNullOrEmpty(virtualpath)) virtualpath = "[TEXTURES]"; + } // Continue until at the end of the stream while(SkipWhitespace(true)) @@ -194,7 +205,7 @@ namespace CodeImp.DoomBuilder.ZDoom } break; - case "$gzdb_skip": break; + case "$gzdb_skip": return !this.HasError; default: { diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs index c0450c52..3d8abc52 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs @@ -214,18 +214,26 @@ namespace CodeImp.DoomBuilder.BuilderModes WallPolygon np = SplitPoly(ref p, plane, false); if(np.Count > 0) { - //mxd. Determine color - int lightlevel; - - // Sidedef part is not affected by 3d floor brightness - if(l.disablelighting || !l.extrafloor) - lightlevel = (lightabsolute ? lightvalue : l.brightnessbelow + lightvalue); - // 3d floor transfers brightness below it ignoring sidedef's brightness + if(l.type == SectorLevelType.Glow) + { + //mxd. Glow levels should not affect light level + np.color = p.color; + } else - lightlevel = l.brightnessbelow; + { + //mxd. Determine color + int lightlevel; - PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lightlevel, Sidedef)); //mxd - np.color = PixelColor.Modulate(l.colorbelow, wallbrightness).WithAlpha(255).ToInt(); + // Sidedef part is not affected by 3d floor brightness + if(l.type != SectorLevelType.Light && (l.disablelighting || !l.extrafloor)) + lightlevel = (lightabsolute ? lightvalue : l.brightnessbelow + lightvalue); + // 3d floors and light transfer effects transfers brightness below them ignoring sidedef's brightness + else + lightlevel = l.brightnessbelow; + + PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lightlevel, Sidedef)); //mxd + np.color = PixelColor.Modulate(l.colorbelow, wallbrightness).WithAlpha(255).ToInt(); + } if(p.Count == 0) { diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index 1a2720c1..efb97a1c 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -1216,7 +1216,7 @@ namespace CodeImp.DoomBuilder.BuilderModes renderer.DrawThingCages = ((BuilderPlug.Me.ShowVisualThings & 2) != 0); // Render all visible things - foreach(VisualThing t in visiblethings) + foreach(VisualThing t in visiblethings.Values) renderer.AddThingGeometry(t); } diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs index 893fd929..f8db38f3 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs @@ -219,19 +219,22 @@ namespace CodeImp.DoomBuilder.BuilderModes // Level is glowing if(level.affectedbyglow && level.type == SectorLevelType.Floor) { - // Get glow brightness - SectorData glowdata = (level.sector != Thing.Sector ? mode.GetSectorData(level.sector) : sd); - float planez = level.plane.GetZ(thingpos); - - int glowbrightness = glowdata.FloorGlow.Brightness / 2; - SectorLevel nexthigher = sd.GetLevelAbove(new Vector3D(thingpos, planez)); - - // Interpolate thing brightness between glow and regular ones - if(nexthigher != null) + // Extrafloor glow doesn't affect thing brightness + if(level.sector == Thing.Sector) { - float higherz = nexthigher.plane.GetZ(thingpos); - float delta = General.Clamp(1.0f - (thingpos.z - planez) / (higherz - planez), 0f, 1f); - brightness = (int)((glowbrightness + level.sector.Brightness / 2) * delta + nexthigher.sector.Brightness * (1.0f - delta)); + float planez = level.plane.GetZ(thingpos); + + // Get glow brightness + int glowbrightness = sd.FloorGlow.Brightness / 2; + SectorLevel nexthigher = sd.GetLevelAbove(new Vector3D(thingpos, planez)); + + // Interpolate thing brightness between glow and regular ones + if(nexthigher != null) + { + float higherz = nexthigher.plane.GetZ(thingpos); + float delta = General.Clamp(1.0f - (thingpos.z - planez) / (higherz - planez), 0f, 1f); + brightness = (int)((glowbrightness + level.sector.Brightness / 2) * delta + nexthigher.sector.Brightness * (1.0f - delta)); + } } } // Level below this one is glowing. Only possible for floor glow(?) @@ -254,30 +257,7 @@ namespace CodeImp.DoomBuilder.BuilderModes sectorcolor = areacolor.WithAlpha(alpha).ToInt(); //mxd. Calculate fogfactor - float density; - if(Thing.Sector.UsesOutsideFog && General.Map.Data.MapInfo.OutsideFogDensity > 0) - { - density = General.Map.Data.MapInfo.OutsideFogDensity; - } - else if(!Thing.Sector.UsesOutsideFog && General.Map.Data.MapInfo.FogDensity > 0) - { - density = General.Map.Data.MapInfo.FogDensity; - } - else if(brightness < 248) - { - density = General.Clamp(255 - brightness, 30, 255); - } - else - { - density = 0f; - } - - if(level.sector.HasFogColor) - { - density *= 4; - } - - fogfactor = density * VisualGeometry.FOG_DENSITY_SCALER; + fogfactor = VisualGeometry.CalculateFogFactor(level.sector.FogMode, brightness); } } //TECH: even Bright Thing frames are affected by custom fade... @@ -286,28 +266,10 @@ namespace CodeImp.DoomBuilder.BuilderModes Vector3D thingpos = new Vector3D(Thing.Position.x, Thing.Position.y, Thing.Position.z + sd.Floor.plane.GetZ(Thing.Position)); SectorLevel level = sd.GetLevelAboveOrAt(thingpos); - if(level != null && level.sector.HasFogColor) + if(level != null && level.sector.FogMode > SectorFogMode.CLASSIC) { //mxd. Calculate fogfactor - float density; - if(Thing.Sector.UsesOutsideFog && General.Map.Data.MapInfo.OutsideFogDensity > 0) - { - density = General.Map.Data.MapInfo.OutsideFogDensity; - } - else if(!Thing.Sector.UsesOutsideFog && General.Map.Data.MapInfo.FogDensity > 0) - { - density = General.Map.Data.MapInfo.FogDensity; - } - else if(level.brightnessbelow < 248) - { - density = General.Clamp(255 - level.brightnessbelow, 30, 255); - } - else - { - density = 0f; - } - - fogfactor = density * VisualGeometry.FOG_DENSITY_SCALER * 4; + fogfactor = VisualGeometry.CalculateFogFactor(level.sector.FogMode, level.brightnessbelow); } } } diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualCeiling.cs b/Source/Plugins/BuilderModes/VisualModes/VisualCeiling.cs index 718d53e3..9881b21d 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualCeiling.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualCeiling.cs @@ -136,7 +136,7 @@ namespace CodeImp.DoomBuilder.BuilderModes } //mxd. Determine fog density - fogfactor = CalculateFogDensity(targetbrightness); + fogfactor = CalculateFogFactor(targetbrightness); // Make vertices ReadOnlyCollection triverts = Sector.Sector.Triangles.Vertices; diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualFloor.cs b/Source/Plugins/BuilderModes/VisualModes/VisualFloor.cs index f87149ee..b6747cce 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualFloor.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualFloor.cs @@ -137,7 +137,7 @@ namespace CodeImp.DoomBuilder.BuilderModes } //mxd. Determine fog density - fogfactor = CalculateFogDensity(targetbrightness); + fogfactor = CalculateFogFactor(targetbrightness); // Make vertices ReadOnlyCollection triverts = Sector.Sector.Triangles.Vertices; diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualFogBoundary.cs b/Source/Plugins/BuilderModes/VisualModes/VisualFogBoundary.cs index fc98d5ac..d23ed86d 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualFogBoundary.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualFogBoundary.cs @@ -96,7 +96,7 @@ namespace CodeImp.DoomBuilder.BuilderModes int lightlevel = sd.Ceiling.brightnessbelow + lightvalue; // Calculate fog density - fogfactor = CalculateFogDensity(lightlevel); + fogfactor = CalculateFogFactor(lightlevel); poly.color = PixelColor.INT_WHITE; // Cut off the part below the other floor and above the other ceiling @@ -138,10 +138,8 @@ namespace CodeImp.DoomBuilder.BuilderModes private bool IsFogBoundary() { if(Sidedef.Sector.Index == Sidedef.Other.Sector.Index) return false; // There can't be a boundary if both sides are in the same sector. - if(Sidedef.Sector.HasFogColor == Sidedef.Other.Sector.HasFogColor) return false; - if(!Sidedef.Sector.HasFogColor && !Sidedef.Other.Sector.HasFogColor) return false; if(Sidedef.Sector.CeilTexture == General.Map.Config.SkyFlatName && Sidedef.Other.Sector.CeilTexture == General.Map.Config.SkyFlatName) return false; - return true; + return (Sidedef.Sector.FogMode > SectorFogMode.CLASSIC && Sidedef.Other.Sector.FogMode <= SectorFogMode.CLASSIC); } // This performs a fast test in object picking diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs b/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs index 36fb079c..ee7410b0 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs @@ -176,7 +176,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. This calculates light with doom-style wall shading PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lightlevel, Sidedef)); PixelColor wallcolor = PixelColor.Modulate(sd.Ceiling.colorbelow, wallbrightness); - fogfactor = CalculateFogDensity(lightlevel); + fogfactor = CalculateFogFactor(lightlevel); poly.color = wallcolor.WithAlpha(255).ToInt(); // Cut off the part above the other floor diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualMiddle3D.cs b/Source/Plugins/BuilderModes/VisualModes/VisualMiddle3D.cs index 46644ec1..2ff6ebc2 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualMiddle3D.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualMiddle3D.cs @@ -220,7 +220,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. This calculates light with doom-style wall shading PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lightlevel, Sidedef)); PixelColor wallcolor = PixelColor.Modulate(sd.Ceiling.colorbelow, wallbrightness); - fogfactor = CalculateFogDensity(lightlevel); + fogfactor = CalculateFogFactor(lightlevel); poly.color = wallcolor.WithAlpha(255).ToInt(); // Cut off the part above the 3D floor and below the 3D ceiling diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleBack.cs b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleBack.cs index c13af195..bebb7cf1 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleBack.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleBack.cs @@ -206,7 +206,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. This calculates light with doom-style wall shading PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lightlevel, Sidedef)); int wallcolor = PixelColor.Modulate(levelcolor, wallbrightness).WithAlpha((byte)extrafloor.Alpha).ToInt(); - fogfactor = CalculateFogDensity(lightlevel); + fogfactor = CalculateFogFactor(lightlevel); // Cut off the part above the 3D floor and below the 3D ceiling CropPoly(ref poly, bottom, false); diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleDouble.cs b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleDouble.cs index 02ff611f..e6052403 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleDouble.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleDouble.cs @@ -184,7 +184,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. This calculates light with doom-style wall shading PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lightlevel, Sidedef)); PixelColor wallcolor = PixelColor.Modulate(sd.Ceiling.colorbelow, wallbrightness); - fogfactor = CalculateFogDensity(lightlevel); + fogfactor = CalculateFogFactor(lightlevel); poly.color = wallcolor.WithAlpha(255).ToInt(); // Cut off the part below the other floor and above the other ceiling diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleSingle.cs b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleSingle.cs index e0d8c9b2..f0f93c86 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleSingle.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleSingle.cs @@ -182,7 +182,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. This calculates light with doom-style wall shading PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lightlevel, Sidedef)); PixelColor wallcolor = PixelColor.Modulate(sd.Ceiling.colorbelow, wallbrightness); - fogfactor = CalculateFogDensity(lightlevel); + fogfactor = CalculateFogFactor(lightlevel); poly.color = wallcolor.WithAlpha(255).ToInt(); // Cut out pieces that overlap 3D floors in this sector diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs b/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs index cf665df4..f9f23061 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs @@ -171,7 +171,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. This calculates light with doom-style wall shading PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lightlevel, Sidedef)); PixelColor wallcolor = PixelColor.Modulate(sd.Ceiling.colorbelow, wallbrightness); - fogfactor = CalculateFogDensity(lightlevel); + fogfactor = CalculateFogFactor(lightlevel); poly.color = wallcolor.WithAlpha(255).ToInt(); // Cut off the part below the other ceiling