From 5ed77c5d05f1dda8fc421d18a97117a0676ffe5b Mon Sep 17 00:00:00 2001 From: biwa <6475593+biwa@users.noreply.github.com> Date: Sat, 6 Feb 2021 14:51:00 +0100 Subject: [PATCH] Improved performance in visual mode related to visual slopes --- Source/Core/Rendering/IRenderer3D.cs | 2 +- Source/Core/Rendering/Renderer3D.cs | 4 +- Source/Core/VisualModes/VisualMode.cs | 3 + .../VisualModes/BaseVisualMode.cs | 80 +++++++++++++------ .../VisualModes/BaseVisualSlope.cs | 20 ++++- 5 files changed, 79 insertions(+), 30 deletions(-) diff --git a/Source/Core/Rendering/IRenderer3D.cs b/Source/Core/Rendering/IRenderer3D.cs index 17a7579e..9beb3c60 100755 --- a/Source/Core/Rendering/IRenderer3D.cs +++ b/Source/Core/Rendering/IRenderer3D.cs @@ -50,7 +50,7 @@ namespace CodeImp.DoomBuilder.Rendering void AddSectorGeometry(VisualGeometry g); void AddThingGeometry(VisualThing t); void SetVisualVertices(List verts); - void SetVisualSlopeHandles(List handles); + void SetVisualSlopeHandles(ICollection handles); void SetEventLines(List lines); void RenderCrosshair(); void SetFogMode(bool usefog); diff --git a/Source/Core/Rendering/Renderer3D.cs b/Source/Core/Rendering/Renderer3D.cs index 90d2f284..4a710bdc 100755 --- a/Source/Core/Rendering/Renderer3D.cs +++ b/Source/Core/Rendering/Renderer3D.cs @@ -116,7 +116,7 @@ namespace CodeImp.DoomBuilder.Rendering private List visualvertices; // Visual slope handles - private List visualslopehandles; + private ICollection visualslopehandles; //mxd. Event lines private List eventlines; @@ -1842,7 +1842,7 @@ namespace CodeImp.DoomBuilder.Rendering //mxd public void SetVisualVertices(List verts) { visualvertices = verts; } - public void SetVisualSlopeHandles(List handles) { visualslopehandles = handles; } + public void SetVisualSlopeHandles(ICollection handles) { visualslopehandles = handles; } //mxd public void SetEventLines(List lines) { eventlines = lines; } diff --git a/Source/Core/VisualModes/VisualMode.cs b/Source/Core/VisualModes/VisualMode.cs index a02d63cf..26c94ef0 100755 --- a/Source/Core/VisualModes/VisualMode.cs +++ b/Source/Core/VisualModes/VisualMode.cs @@ -89,6 +89,7 @@ namespace CodeImp.DoomBuilder.VisualModes protected List visiblethings; protected List visiblesectors; protected List visiblegeometry; + protected HashSet renderslopehandles; #endregion @@ -101,6 +102,7 @@ namespace CodeImp.DoomBuilder.VisualModes public Dictionary> AllSlopeHandles { get { return allslopehandles; } } public Dictionary> SidedefSlopeHandles { get { return sidedefslopehandles; } } public Dictionary> VertexSlopeHandles { get { return vertexslopehandles; } } + public HashSet RenderSlopeHandles { get { return renderslopehandles; } } // Rendering public IRenderer3D Renderer { get { return renderer; } } @@ -126,6 +128,7 @@ namespace CodeImp.DoomBuilder.VisualModes this.visiblesectors = new List(50); this.visiblegeometry = new List(200); this.visiblethings = new List(100); + this.renderslopehandles = new HashSet(); this.processgeometry = true; this.processthings = true; this.vertices = new Dictionary(); //mxd diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index a0f52ceb..ac69a306 100755 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -524,26 +524,49 @@ namespace CodeImp.DoomBuilder.BuilderModes if (updateinfo) { - if (newtarget.picked is VisualSidedefSlope) - { - // Get the smart pivot handle for the targeted slope handle, so that it can be drawn - VisualSlope handle = VisualSidedefSlope.GetSmartPivotHandle((VisualSidedefSlope)newtarget.picked, this); - if (handle != null) - handle.SmartPivot = true; - } - else if(newtarget.picked is VisualVertexSlope) - { - // Get the smart pivot handle for the targeted slope handle, so that it can be drawn - VisualSlope handle = VisualVertexSlope.GetSmartPivotHandle((VisualVertexSlope)newtarget.picked, this); - if (handle != null) - handle.SmartPivot = true; - } - else if(target.picked is VisualSlope) + if (target.picked is VisualSlope) // Old target { + // Don't render old slope handle anymore + if (!((VisualSlope)target.picked).Selected && !((VisualSlope)target.picked).Pivot) + renderslopehandles.Remove((VisualSlope)target.picked); + // Clear smart pivot handles, otherwise it will keep being displayed foreach (KeyValuePair> kvp in allslopehandles) foreach (VisualSlope checkhandle in kvp.Value) - checkhandle.SmartPivot = false; + { + if (checkhandle.SmartPivot) + { + checkhandle.SmartPivot = false; + + if (!checkhandle.Selected && !checkhandle.Pivot) + renderslopehandles.Remove(checkhandle); + } + } + } + + if (newtarget.picked is VisualSidedefSlope) + { + renderslopehandles.Add((VisualSidedefSlope)newtarget.picked); + + // Get the smart pivot handle for the targeted slope handle, so that it can be drawn + VisualSlope handle = VisualSidedefSlope.GetSmartPivotHandle((VisualSidedefSlope)newtarget.picked, this); + if (handle != null) + { + handle.SmartPivot = true; + renderslopehandles.Add(handle); + } + } + else if(newtarget.picked is VisualVertexSlope) + { + renderslopehandles.Add((VisualVertexSlope)newtarget.picked); + + // Get the smart pivot handle for the targeted slope handle, so that it can be drawn + VisualSlope handle = VisualVertexSlope.GetSmartPivotHandle((VisualVertexSlope)newtarget.picked, this); + if (handle != null) + { + handle.SmartPivot = true; + renderslopehandles.Add(handle); + } } } @@ -1633,14 +1656,7 @@ namespace CodeImp.DoomBuilder.BuilderModes renderer.SetVisualVertices(verts); } - // Visual slope handles - List handles = new List(); - foreach (KeyValuePair> kvp in allslopehandles) - foreach (VisualSlope handle in kvp.Value) - if (handle.Selected || handle.Pivot || handle.SmartPivot || target.picked == handle) - handles.Add(handle); - - renderer.SetVisualSlopeHandles(handles); + renderer.SetVisualSlopeHandles(renderslopehandles); // Done rendering geometry renderer.FinishGeometry(); @@ -2482,6 +2498,8 @@ namespace CodeImp.DoomBuilder.BuilderModes handle.Pivot = false; } } + + renderslopehandles.Clear(); } } @@ -4329,7 +4347,11 @@ namespace CodeImp.DoomBuilder.BuilderModes // Clear smart pivot handles, otherwise it will keep being displayed foreach (KeyValuePair> kvp in allslopehandles) foreach (VisualSlope checkhandle in kvp.Value) - checkhandle.SmartPivot = false; + if (checkhandle.SmartPivot && !(checkhandle.Selected || checkhandle.Pivot)) + { + checkhandle.SmartPivot = false; + renderslopehandles.Remove(checkhandle); + } } } @@ -4345,7 +4367,13 @@ namespace CodeImp.DoomBuilder.BuilderModes // Clear smart pivot handles, otherwise it will keep being displayed foreach (KeyValuePair> kvp in allslopehandles) foreach (VisualSlope checkhandle in kvp.Value) - checkhandle.SmartPivot = false; + { + if (checkhandle.SmartPivot && !(checkhandle.Selected || checkhandle.Pivot)) + { + checkhandle.SmartPivot = false; + renderslopehandles.Remove(checkhandle); + } + } } } diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualSlope.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualSlope.cs index 7a28bf11..9e9f1bc2 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualSlope.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualSlope.cs @@ -50,6 +50,7 @@ namespace CodeImp.DoomBuilder.VisualModes { this.selected = false; mode.RemoveSelectedObject(this); + mode.RenderSlopeHandles.Remove(this); } else { @@ -61,6 +62,7 @@ namespace CodeImp.DoomBuilder.VisualModes this.selected = true; mode.AddSelectedObject(this); + mode.RenderSlopeHandles.Add(this); } } @@ -76,10 +78,26 @@ namespace CodeImp.DoomBuilder.VisualModes if (handle.Selected) General.Interface.DisplayStatus(Windows.StatusType.Warning, "It is not allowed to mark selected slope handles as pivot slope handles."); else - handle.Pivot = !handle.Pivot; + { + if (handle.Pivot) + { + mode.RenderSlopeHandles.Remove(handle); + handle.Pivot = false; + } + else + { + mode.RenderSlopeHandles.Add(handle); + handle.Pivot = true; + } + } } else + { + if(!handle.Selected && !handle.SmartPivot) + mode.RenderSlopeHandles.Remove(handle); + handle.Pivot = false; + } } } }