From fce59907eb537e622c3a5e27cabb170a5dfecad6 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Tue, 18 Jun 2019 18:19:24 +0200 Subject: [PATCH] Only rebuild changed parts of the blockmap in visual mode --- Source/Core/Map/Linedef.cs | 2 + Source/Core/Map/Sector.cs | 1 + Source/Core/Map/Thing.cs | 1 + Source/Core/VisualModes/VisualBlockMap.cs | 96 +++++++++++++++++++++-- 4 files changed, 92 insertions(+), 8 deletions(-) diff --git a/Source/Core/Map/Linedef.cs b/Source/Core/Map/Linedef.cs index 6c676c3..668b7f8 100644 --- a/Source/Core/Map/Linedef.cs +++ b/Source/Core/Map/Linedef.cs @@ -113,6 +113,8 @@ namespace CodeImp.DoomBuilder.Map internal bool ImpassableFlag { get { return impassableflag; } } internal int ColorPresetIndex { get { return colorPresetIndex; } } //mxd internal bool ExtraFloorFlag; //mxd + public Vector2D BlockMapStart { get; set; } + public Vector2D BlockMapEnd { get; set; } #endregion diff --git a/Source/Core/Map/Sector.cs b/Source/Core/Map/Sector.cs index 538716e..a3916d8 100644 --- a/Source/Core/Map/Sector.cs +++ b/Source/Core/Map/Sector.cs @@ -119,6 +119,7 @@ namespace CodeImp.DoomBuilder.Map public int Brightness { get { return brightness; } set { BeforePropsChange(); brightness = value; updateneeded = true; } } public bool UpdateNeeded { get { return updateneeded; } set { updateneeded |= value; triangulationneeded |= value; } } public RectangleF BBox { get { return bbox; } } + public Rectangle BlockMapRect { get; set; } internal Sector Clone { get { return clone; } set { clone = value; } } internal int SerializedIndex { get { return serializedindex; } set { serializedindex = value; } } public Triangulation Triangles { get { return triangles; } } diff --git a/Source/Core/Map/Thing.cs b/Source/Core/Map/Thing.cs index 475130d..f844aaf 100644 --- a/Source/Core/Map/Thing.cs +++ b/Source/Core/Map/Thing.cs @@ -132,6 +132,7 @@ namespace CodeImp.DoomBuilder.Map } public bool IsReverse { get { return General.Map.SRB2 && !Unflippable && IsFlagSet("2"); } } public bool Unflippable { get { return General.Map.Data.GetThingInfo(SRB2Type).IsUnflippable; } } + public Rectangle BlockMapRect { get; set; } #endregion #region ================== Constructor / Disposer diff --git a/Source/Core/VisualModes/VisualBlockMap.cs b/Source/Core/VisualModes/VisualBlockMap.cs index 02ef0ae..6412dd9 100644 --- a/Source/Core/VisualModes/VisualBlockMap.cs +++ b/Source/Core/VisualModes/VisualBlockMap.cs @@ -276,6 +276,23 @@ namespace CodeImp.DoomBuilder.VisualModes block.Things.Add(t); } } + + t.BlockMapRect = new Rectangle(p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y); + } + + // This removes a thing from the blockmap + public void RemoveThing(Thing t) + { + Point p1 = t.BlockMapRect.Location; + Point p2 = t.BlockMapRect.Location + t.BlockMapRect.Size; + for(int x = p1.X; x <= p2.X; x++) + { + for(int y = p1.Y; y <= p2.Y; y++) + { + VisualBlockEntry block = GetBlock(new Point(x, y)); + block.Things.Remove(t); + } + } } // This puts a secotr in the blockmap @@ -297,8 +314,25 @@ namespace CodeImp.DoomBuilder.VisualModes block.Sectors.Add(s); } } + + s.BlockMapRect = new Rectangle(p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y); } + // This removes a sector from the blockmap + public void RemoveSector(Sector s) + { + Point p1 = s.BlockMapRect.Location; + Point p2 = s.BlockMapRect.Location + s.BlockMapRect.Size; + for(int x = p1.X; x <= p2.X; x++) + { + for(int y = p1.Y; y <= p2.Y; y++) + { + VisualBlockEntry block = GetBlock(new Point(x, y)); + block.Sectors.Remove(s); + } + } + } + // This puts a whole set of linedefs in the blocks they cross public void AddLinedefsSet(ICollection lines) { @@ -307,10 +341,32 @@ namespace CodeImp.DoomBuilder.VisualModes // This puts a single linedef in all blocks it crosses public void AddLinedef(Linedef line) + { + AddOrRemoveLinedef(line, true); + } + + // This puts a single linedef in all blocks it crosses + public void RemoveLinedef(Linedef line) + { + AddOrRemoveLinedef(line, false); + } + + // This puts a single linedef in all blocks it crosses + public void AddOrRemoveLinedef(Linedef line, bool adding) { // Get coordinates - Vector2D v1 = line.Start.Position; - Vector2D v2 = line.End.Position; + Vector2D v1; + Vector2D v2; + if (adding) + { + v1 = line.Start.Position; + v2 = line.End.Position; + } + else + { + v1 = line.BlockMapStart; + v2 = line.BlockMapEnd; + } // Find start and end block Point pos = GetBlockCoordinates(v1); @@ -323,9 +379,15 @@ namespace CodeImp.DoomBuilder.VisualModes int dirx = Math.Sign(v2.x - v1.x); for(int x = pos.X; x != end.X; x += dirx) { - GetBlock(new Point(x, pos.Y)).Lines.Add(line); + if (adding) + GetBlock(new Point(x, pos.Y)).Lines.Add(line); + else + GetBlock(new Point(x, pos.Y)).Lines.Remove(line); } - GetBlock(end).Lines.Add(line); + if (adding) + GetBlock(end).Lines.Add(line); + else + GetBlock(end).Lines.Remove(line); } // Vertical straight line? else if(pos.X == end.X) @@ -334,14 +396,23 @@ namespace CodeImp.DoomBuilder.VisualModes int diry = Math.Sign(v2.y - v1.y); for(int y = pos.Y; y != end.Y; y += diry) { - GetBlock(new Point(pos.X, y)).Lines.Add(line); + if (adding) + GetBlock(new Point(pos.X, y)).Lines.Add(line); + else + GetBlock(new Point(pos.X, y)).Lines.Remove(line); } - GetBlock(end).Lines.Add(line); + if (adding) + GetBlock(end).Lines.Add(line); + else + GetBlock(end).Lines.Remove(line); } else { // Add lines to this block - GetBlock(pos).Lines.Add(line); + if (adding) + GetBlock(pos).Lines.Add(line); + else + GetBlock(pos).Lines.Remove(line); // Moving outside the block? if(pos != end) @@ -411,10 +482,19 @@ namespace CodeImp.DoomBuilder.VisualModes } // Add lines to this block - GetBlock(pos).Lines.Add(line); + if (adding) + GetBlock(pos).Lines.Add(line); + else + GetBlock(pos).Lines.Remove(line); } } } + + if (adding) + { + line.BlockMapStart = v1; + line.BlockMapEnd = v2; + } } #endregion