mirror of
https://git.do.srb2.org/STJr/ZoneBuilder.git
synced 2025-04-22 17:44:06 +00:00
Only rebuild changed parts of the blockmap in visual mode
This commit is contained in:
parent
c2500cfd7d
commit
fce59907eb
4 changed files with 92 additions and 8 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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; } }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Linedef> 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
|
||||
|
|
Loading…
Reference in a new issue