From dbe0a7b41425dd86ad7b9587b90439e9ab9636e9 Mon Sep 17 00:00:00 2001 From: biwa <6475593+biwa@users.noreply.github.com> Date: Sat, 20 Jun 2020 14:39:23 +0200 Subject: [PATCH] 3D Floor Mode: increased performance when creating new 3D floors --- Source/Plugins/3DFloorMode/BuilderPlug.cs | 34 ++++++++++++--- .../Plugins/3DFloorMode/ControlSectorArea.cs | 12 +++++- Source/Plugins/3DFloorMode/ThreeDFloor.cs | 43 +++++++------------ Source/Plugins/3DFloorMode/ThreeDFloorMode.cs | 4 +- 4 files changed, 56 insertions(+), 37 deletions(-) diff --git a/Source/Plugins/3DFloorMode/BuilderPlug.cs b/Source/Plugins/3DFloorMode/BuilderPlug.cs index 68288e8f..44998236 100644 --- a/Source/Plugins/3DFloorMode/BuilderPlug.cs +++ b/Source/Plugins/3DFloorMode/BuilderPlug.cs @@ -789,6 +789,7 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode var sectorsToThreeDFloors = new Dictionary>(); var sectorGroups = new List>(); List tagblacklist = new List(); + int numnewcontrolsectors = 0; if(selectedSectors == null) selectedSectors = new List(General.Map.Map.GetSelectedSectors(true)); @@ -818,22 +819,30 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode General.Map.UndoRedo.CreateUndo("Modify 3D floors"); - // Create a list of all tags used by the control sectors. This is necessary so that - // tags that will be assigned to not yet existing geometry will not be used foreach (ThreeDFloor tdf in threedfloors) + { + // Create a list of all tags used by the control sectors. This is necessary so that + // tags that will be assigned to not yet existing geometry will not be used foreach (int tag in tdf.Tags) if (!tagblacklist.Contains(tag)) tagblacklist.Add(tag); + // Collect the number of control sectors that have to be created + if (tdf.IsNew) + numnewcontrolsectors++; + } + try { + List drawnvertices = new List(); + + if (numnewcontrolsectors > 0) + drawnvertices = Me.ControlSectorArea.GetNewControlSectorVertices(numnewcontrolsectors); + foreach (ThreeDFloor tdf in threedfloors) { - if (tdf.Rebuild) - tdf.DeleteControlSector(); - - if (tdf.IsNew || tdf.Rebuild) - tdf.CreateGeometry(tagblacklist); + if (tdf.IsNew) + tdf.CreateGeometry(tagblacklist, drawnvertices); tdf.UpdateGeometry(); } @@ -959,6 +968,17 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode // Remove unused tags from the 3D floors foreach (ThreeDFloor tdf in threedfloors) tdf.Cleanup(); + + // Snap to map format accuracy + General.Map.Map.SnapAllToAccuracy(); + + // Update textures + General.Map.Data.UpdateUsedTextures(); + + // Update caches + General.Map.Map.Update(); + General.Interface.RedrawDisplay(); + General.Map.IsChanged = true; } public SlopeVertexGroup AddSlopeVertexGroup(List vertices, out int id) diff --git a/Source/Plugins/3DFloorMode/ControlSectorArea.cs b/Source/Plugins/3DFloorMode/ControlSectorArea.cs index 1987e1cf..7f4cef65 100644 --- a/Source/Plugins/3DFloorMode/ControlSectorArea.cs +++ b/Source/Plugins/3DFloorMode/ControlSectorArea.cs @@ -336,6 +336,12 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode public List GetNewControlSectorVertices() { + return GetNewControlSectorVertices(1); + } + + public List GetNewControlSectorVertices(int numsectors) + { + List dv = new List(); BlockMap blockmap = CreateBlockmap(); int margin = (int)((gridsize - sectorsize) / 2); @@ -353,7 +359,6 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode // The way our blockmap is built and queried we will always get exactly one block if (blocks[0].Sectors.Count == 0) { - List dv = new List(); Point p = new Point(x + margin, y - margin); dv.Add(SectorVertex(p.X, p.Y)); @@ -362,7 +367,10 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode dv.Add(SectorVertex(p.X, p.Y - BuilderPlug.Me.ControlSectorArea.SectorSize)); dv.Add(SectorVertex(p.X, p.Y)); - return dv; + numsectors--; + + if (numsectors == 0) + return dv; } } } diff --git a/Source/Plugins/3DFloorMode/ThreeDFloor.cs b/Source/Plugins/3DFloorMode/ThreeDFloor.cs index 9e622f7e..a03bbd0d 100644 --- a/Source/Plugins/3DFloorMode/ThreeDFloor.cs +++ b/Source/Plugins/3DFloorMode/ThreeDFloor.cs @@ -53,7 +53,6 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode private int topheight; private int bottomheight; private bool isnew; - private bool rebuild; private int udmftag; private List tags; @@ -73,7 +72,6 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode public int TopHeight { get { return topheight; } set { topheight = value; } } public int BottomHeight { get { return bottomheight; } set { bottomheight = value; } } public bool IsNew { get { return isnew; } set { isnew = value; } } - public bool Rebuild { get { return rebuild; } set { rebuild = value; } } public int UDMFTag { get { return udmftag; } set { udmftag = value; } } public List Tags { get { return tags; } set { tags = value; } } public Vector3D FloorSlope { get { return floorslope; } set { floorslope = value; } } @@ -217,16 +215,15 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode } } - public bool CreateGeometry(List tagblacklist) + public bool CreateGeometry(List tagblacklist, List alldrawnvertices) { int newtag; - return CreateGeometry(tagblacklist, false, out newtag); + return CreateGeometry(tagblacklist, alldrawnvertices, false, out newtag); } - public bool CreateGeometry(List tagblacklist, bool forcenewtag, out int newtag) + public bool CreateGeometry(List tagblacklist, List alldrawnvertices, bool forcenewtag, out int newtag) { - List drawnvertices = new List(); List vertices = new List(); Vector3D slopetopthingpos = new Vector3D(0, 0, 0); Vector3D slopebottomthingpos = new Vector3D(0, 0, 0); @@ -234,7 +231,19 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode newtag = -1; - drawnvertices = BuilderPlug.Me.ControlSectorArea.GetNewControlSectorVertices(); + // We need 5 vertices to draw the control sector + if(alldrawnvertices.Count < 5) + { + General.Interface.DisplayStatus(StatusType.Warning, "Could not draw new sector: not enough vertices"); + return false; + } + + // Get the first 5 vertices in the list and also remove them from the list, so that creating further + // control sectors won't use them + List drawnvertices = alldrawnvertices.GetRange(0, 5); + alldrawnvertices.RemoveRange(0, 5); + + // drawnvertices = BuilderPlug.Me.ControlSectorArea.GetNewControlSectorVertices(); if (Tools.DrawLines(drawnvertices) == false) { @@ -275,21 +284,6 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode BindTag(udmftag); } - // Snap to map format accuracy - General.Map.Map.SnapAllToAccuracy(); - - General.Map.Map.BeginAddRemove(); - //MapSet.JoinVertices(vertices, vertices, false, MapSet.STITCH_DISTANCE); - General.Map.Map.EndAddRemove(); - - // Update textures - General.Map.Data.UpdateUsedTextures(); - - // Update caches - General.Map.Map.Update(); - General.Interface.RedrawDisplay(); - General.Map.IsChanged = true; - return true; } @@ -372,11 +366,6 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode } General.Map.Map.EndAddRemove(); - - // Update cache values - General.Map.IsChanged = true; - General.Map.Map.Update(); - } public void DeleteControlSector() diff --git a/Source/Plugins/3DFloorMode/ThreeDFloorMode.cs b/Source/Plugins/3DFloorMode/ThreeDFloorMode.cs index ceae21f8..435caeb3 100644 --- a/Source/Plugins/3DFloorMode/ThreeDFloorMode.cs +++ b/Source/Plugins/3DFloorMode/ThreeDFloorMode.cs @@ -1539,6 +1539,8 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode General.Map.UndoRedo.CreateUndo(duplicateundodescription); + List drawnvertices = BuilderPlug.Me.ControlSectorArea.GetNewControlSectorVertices(duplicatethreedfloors.Count); + // Create a new control sector for each 3D floor that needs to be duplicated. Force it to generate // a new tag, and store the old (current) and new tag foreach (ThreeDFloor tdf in duplicatethreedfloors) @@ -1548,7 +1550,7 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode try { - tdf.CreateGeometry(new List(), true, out newtag); + tdf.CreateGeometry(new List(), drawnvertices, true, out newtag); tagreplacements[oldtag] = newtag; } catch(NoSpaceInCSAException e)