Only rebuild changed parts of the blockmap in visual mode

This commit is contained in:
Louis-Antoine 2019-06-18 18:19:24 +02:00 committed by sphere
parent c2500cfd7d
commit fce59907eb
4 changed files with 92 additions and 8 deletions

View File

@ -113,6 +113,8 @@ namespace CodeImp.DoomBuilder.Map
internal bool ImpassableFlag { get { return impassableflag; } } internal bool ImpassableFlag { get { return impassableflag; } }
internal int ColorPresetIndex { get { return colorPresetIndex; } } //mxd internal int ColorPresetIndex { get { return colorPresetIndex; } } //mxd
internal bool ExtraFloorFlag; //mxd internal bool ExtraFloorFlag; //mxd
public Vector2D BlockMapStart { get; set; }
public Vector2D BlockMapEnd { get; set; }
#endregion #endregion

View File

@ -119,6 +119,7 @@ namespace CodeImp.DoomBuilder.Map
public int Brightness { get { return brightness; } set { BeforePropsChange(); brightness = value; updateneeded = true; } } public int Brightness { get { return brightness; } set { BeforePropsChange(); brightness = value; updateneeded = true; } }
public bool UpdateNeeded { get { return updateneeded; } set { updateneeded |= value; triangulationneeded |= value; } } public bool UpdateNeeded { get { return updateneeded; } set { updateneeded |= value; triangulationneeded |= value; } }
public RectangleF BBox { get { return bbox; } } public RectangleF BBox { get { return bbox; } }
public Rectangle BlockMapRect { get; set; }
internal Sector Clone { get { return clone; } set { clone = value; } } internal Sector Clone { get { return clone; } set { clone = value; } }
internal int SerializedIndex { get { return serializedindex; } set { serializedindex = value; } } internal int SerializedIndex { get { return serializedindex; } set { serializedindex = value; } }
public Triangulation Triangles { get { return triangles; } } public Triangulation Triangles { get { return triangles; } }

View File

@ -132,6 +132,7 @@ namespace CodeImp.DoomBuilder.Map
} }
public bool IsReverse { get { return General.Map.SRB2 && !Unflippable && IsFlagSet("2"); } } public bool IsReverse { get { return General.Map.SRB2 && !Unflippable && IsFlagSet("2"); } }
public bool Unflippable { get { return General.Map.Data.GetThingInfo(SRB2Type).IsUnflippable; } } public bool Unflippable { get { return General.Map.Data.GetThingInfo(SRB2Type).IsUnflippable; } }
public Rectangle BlockMapRect { get; set; }
#endregion #endregion
#region ================== Constructor / Disposer #region ================== Constructor / Disposer

View File

@ -276,6 +276,23 @@ namespace CodeImp.DoomBuilder.VisualModes
block.Things.Add(t); 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 // This puts a secotr in the blockmap
@ -297,8 +314,25 @@ namespace CodeImp.DoomBuilder.VisualModes
block.Sectors.Add(s); 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 // This puts a whole set of linedefs in the blocks they cross
public void AddLinedefsSet(ICollection<Linedef> lines) public void AddLinedefsSet(ICollection<Linedef> lines)
{ {
@ -307,10 +341,32 @@ namespace CodeImp.DoomBuilder.VisualModes
// This puts a single linedef in all blocks it crosses // This puts a single linedef in all blocks it crosses
public void AddLinedef(Linedef line) 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 // Get coordinates
Vector2D v1 = line.Start.Position; Vector2D v1;
Vector2D v2 = line.End.Position; Vector2D v2;
if (adding)
{
v1 = line.Start.Position;
v2 = line.End.Position;
}
else
{
v1 = line.BlockMapStart;
v2 = line.BlockMapEnd;
}
// Find start and end block // Find start and end block
Point pos = GetBlockCoordinates(v1); Point pos = GetBlockCoordinates(v1);
@ -323,9 +379,15 @@ namespace CodeImp.DoomBuilder.VisualModes
int dirx = Math.Sign(v2.x - v1.x); int dirx = Math.Sign(v2.x - v1.x);
for(int x = pos.X; x != end.X; x += dirx) 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? // Vertical straight line?
else if(pos.X == end.X) else if(pos.X == end.X)
@ -334,14 +396,23 @@ namespace CodeImp.DoomBuilder.VisualModes
int diry = Math.Sign(v2.y - v1.y); int diry = Math.Sign(v2.y - v1.y);
for(int y = pos.Y; y != end.Y; y += diry) 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 else
{ {
// Add lines to this block // 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? // Moving outside the block?
if(pos != end) if(pos != end)
@ -411,10 +482,19 @@ namespace CodeImp.DoomBuilder.VisualModes
} }
// Add lines to this block // 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 #endregion