From a4abafc6fc01dc158cd3a5878f8a6b602c05b352 Mon Sep 17 00:00:00 2001
From: MaxED <j.maxed@gmail.com>
Date: Sat, 2 Jun 2012 20:25:46 +0000
Subject: [PATCH] Doom-style walls shading is now disabled for light levels 253
 and above (as in GZDoom r1400) Doom-style walls shading is now applied in
 Visual Mode

---
 Source/Core/General/General.cs                       |  2 +-
 Source/Core/Properties/AssemblyInfo.cs               |  6 +++---
 Source/Core/Rendering/Renderer.cs                    |  2 +-
 Source/Core/Rendering/Renderer3D.cs                  | 12 ++++++++----
 .../BuilderModes/VisualModes/BaseVisualMode.cs       |  5 +++++
 .../BuilderModes/VisualModes/BaseVisualThing.cs      |  3 ---
 .../Plugins/BuilderModes/VisualModes/VisualLower.cs  |  4 +++-
 .../BuilderModes/VisualModes/VisualMiddleDouble.cs   |  4 +++-
 .../BuilderModes/VisualModes/VisualMiddleSingle.cs   |  4 +++-
 .../Plugins/BuilderModes/VisualModes/VisualUpper.cs  |  4 +++-
 .../GZDoomEditing/VisualModes/BaseVisualThing.cs     |  3 ---
 11 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/Source/Core/General/General.cs b/Source/Core/General/General.cs
index 8d5ae3447..49e29fcca 100644
--- a/Source/Core/General/General.cs
+++ b/Source/Core/General/General.cs
@@ -575,7 +575,7 @@ namespace CodeImp.DoomBuilder
 			// Remove the previous log file and start logging
 			if(File.Exists(logfile)) File.Delete(logfile);
             //mxd
-            General.WriteLogLine("GZDoomBuilder " + CodeImp.DoomBuilder.GZBuilder.GZGeneral.Version + " startup");
+            General.WriteLogLine("GZDoom Builder " + CodeImp.DoomBuilder.GZBuilder.GZGeneral.Version + " startup");
 			//General.WriteLogLine("Doom Builder " + thisversion.Major + "." + thisversion.Minor + " startup");
 			General.WriteLogLine("Application path:        " + apppath);
 			General.WriteLogLine("Temporary path:          " + temppath);
diff --git a/Source/Core/Properties/AssemblyInfo.cs b/Source/Core/Properties/AssemblyInfo.cs
index c5b7f5500..a4baed7b7 100644
--- a/Source/Core/Properties/AssemblyInfo.cs
+++ b/Source/Core/Properties/AssemblyInfo.cs
@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
 // General Information about an assembly is controlled through the following 
 // set of attributes. Change these attribute values to modify the information
 // associated with an assembly.
-[assembly: AssemblyTitle("GZDoomBuilder")]
+[assembly: AssemblyTitle("GZDoom Builder")]
 [assembly: AssemblyDescription("Doom, Heretic and Hexen map editor")]
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("CodeImp, MaxED")]
-[assembly: AssemblyProduct("GZDoomBuilder")]
+[assembly: AssemblyProduct("GZDoom Builder")]
 [assembly: AssemblyCopyright("Copyright © 2007, 2012")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
@@ -29,4 +29,4 @@ using System.Runtime.InteropServices;
 //      Build Number
 //      Revision
 //
-[assembly: AssemblyVersion("2.1.2.0")]
+[assembly: AssemblyVersion("2.1.2.1551")]
diff --git a/Source/Core/Rendering/Renderer.cs b/Source/Core/Rendering/Renderer.cs
index f5ef3394a..85c104231 100644
--- a/Source/Core/Rendering/Renderer.cs
+++ b/Source/Core/Rendering/Renderer.cs
@@ -103,7 +103,7 @@ namespace CodeImp.DoomBuilder.Rendering
 
         //mxd. This calculates wall brightness level with doom-style shading
         public int CalculateBrightness(int level, Sidedef sd) {
-            if (!General.Map.Data.MapInfo.EvenLighting && sd != null) {
+            if (level < 253 && !General.Map.Data.MapInfo.EvenLighting && sd != null) {
                 //all walls are shaded by their angle
                 if (General.Map.Data.MapInfo.SmoothLighting) {
                     float ammount = Math.Abs((float)Math.Sin(sd.Angle));
diff --git a/Source/Core/Rendering/Renderer3D.cs b/Source/Core/Rendering/Renderer3D.cs
index f34f5eb58..9bf23a3c9 100644
--- a/Source/Core/Rendering/Renderer3D.cs
+++ b/Source/Core/Rendering/Renderer3D.cs
@@ -996,6 +996,8 @@ namespace CodeImp.DoomBuilder.Rendering
 
             foreach (KeyValuePair<ModeldefEntry, List<VisualThing>> group in thingsWithModel) {
                 foreach (VisualThing t in group.Value) {
+                    t.Update();
+                    
                     Color4 vertexColor = new Color4(t.VertexColor);
                     vertexColor.Alpha = 1.0f;
                     //check if model is affected by dynamic lights and set color accordingly
@@ -1173,18 +1175,20 @@ namespace CodeImp.DoomBuilder.Rendering
                 }
             }
 
+            if (!isThingOnScreen(t.BoundingBox)) {
+                return;
+            }
+
             //mxd. gather models
             if (General.Settings.GZDrawModels && (!General.Settings.GZDrawSelectedModelsOnly || t.Selected) && t.Thing.IsModel) {
                 ModeldefEntry mde = General.Map.Data.ModeldefEntries[t.Thing.Type];
 
-                if (!isThingOnScreen(t.BoundingBox))
-                    return;
+                //if (!isThingOnScreen(t.BoundingBox))
+                    //return;
 
                 if (!thingsWithModel.ContainsKey(mde)) 
                     thingsWithModel.Add(mde, new List<VisualThing>());
                 thingsWithModel[mde].Add(t);
-            }else if (!isThingOnScreen(t.BoundingBox)) {
-                return;
             }
             
             // Make sure the distance to camera is calculated
diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs
index 02b9491f3..cc3bf2b64 100644
--- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs
@@ -160,6 +160,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
 		{
 			return renderer.CalculateBrightness(level);
 		}
+
+        //mxd. This calculates brightness level with doom-style shading
+        internal int CalculateBrightness(int level, Sidedef sd) {
+            return renderer.CalculateBrightness(level, sd);
+        }
 		
 		// This adds a selected object
 		internal void AddSelectedObject(IVisualEventReceiver obj)
diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
index d7ac49754..ddbb61abd 100644
--- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
@@ -202,9 +202,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
 					pos.z = Thing.Sector.CeilHeight - info.Height;
 				}
 			}
-
-            checkModelState(); //mxd. check model state
-            checkLightState(); //mxd. check gldefs light state
 			
 			// Apply settings
 			SetPosition(pos);
diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs b/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs
index ae45660bb..16ad6e045 100644
--- a/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs
@@ -65,7 +65,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
 		// This builds the geometry. Returns false when no geometry created.
 		public override bool Setup()
 		{
-			int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness);
+			//mxd
+            //int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness);
+            int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness, Sidedef);
 
 			// Calculate size of this wall part
 			float geotop = (float)Sidedef.Other.Sector.FloorHeight;
diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleDouble.cs b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleDouble.cs
index f715b1bea..222841d63 100644
--- a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleDouble.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleDouble.cs
@@ -70,7 +70,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
 		{
 			WorldVertex[] verts;
 
-			int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness);
+            //mxd
+			//int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness);
+            int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness, Sidedef);
 			
 			// Calculate size of this wall part
 			float geotop = (float)Math.Min(Sidedef.Sector.CeilHeight, Sidedef.Other.Sector.CeilHeight);
diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleSingle.cs b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleSingle.cs
index e5a0a625b..ca66d7c61 100644
--- a/Source/Plugins/BuilderModes/VisualModes/VisualMiddleSingle.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/VisualMiddleSingle.cs
@@ -65,7 +65,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
 		// This builds the geometry. Returns false when no geometry created.
 		public override bool Setup()
 		{
-			int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness);
+			//mxd
+            //int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness);
+            int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness, Sidedef);
 
 			// Calculate size of this wall part
 			float geotop = (float)Sidedef.Sector.CeilHeight;
diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs b/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs
index efcf70e5a..8e01847de 100644
--- a/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs
@@ -65,7 +65,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
 		// This builds the geometry. Returns false when no geometry created.
 		public override bool Setup()
 		{
-			int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness);
+			//mxd
+            //int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness);
+            int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness, Sidedef);
 
 			// Calculate size of this wall part
 			float geotop = (float)Sidedef.Sector.CeilHeight;
diff --git a/Source/Plugins/GZDoomEditing/VisualModes/BaseVisualThing.cs b/Source/Plugins/GZDoomEditing/VisualModes/BaseVisualThing.cs
index 8e4d02d75..51c53f481 100644
--- a/Source/Plugins/GZDoomEditing/VisualModes/BaseVisualThing.cs
+++ b/Source/Plugins/GZDoomEditing/VisualModes/BaseVisualThing.cs
@@ -238,9 +238,6 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
 					pos.z = sd.Ceiling.plane.GetZ(Thing.Position) - info.Height;
 				}
 			}
-
-            checkModelState(); //mxd. check model state
-            checkLightState(); //mxd. check gldefs light state
 			
 			// Apply settings
 			SetPosition(pos);
-- 
GitLab