mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-02-18 10:01:48 +00:00
Fixed a problem where linedefs were not split correctly under certain conditions when drawing or moving lines
This commit is contained in:
parent
926fcd486d
commit
0d78a48bd5
1 changed files with 47 additions and 39 deletions
|
@ -2988,52 +2988,60 @@ namespace CodeImp.DoomBuilder.Map
|
||||||
lineverts.Add(l.End);
|
lineverts.Add(l.End);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int w = 0; w < bmWidth; w++)
|
foreach (Vertex v in verts)
|
||||||
{
|
{
|
||||||
for(int h = 0; h < bmHeight; h++)
|
HashSet<BlockEntry> blocks;
|
||||||
|
|
||||||
|
// If a vertex is in the very bottom left of it's block, and a linedef passes through the vertex it can
|
||||||
|
// happen (depending on the linedef's direction) that the vertex and the linedef are not in the same
|
||||||
|
// block. This will cause the linedef to not be split correctly. The prevent this we'll get all blocks
|
||||||
|
// surrounding the vertex, since the linedef will definitely be in at least one of them. Otherwise
|
||||||
|
// just take the block the vertex is in.
|
||||||
|
if ((blockmap.Range.Left - (int)v.Position.x) % blockmap.BlockSize == 0 && (blockmap.Range.Bottom - (int)v.Position.y) % blockmap.BlockSize == 0)
|
||||||
{
|
{
|
||||||
BlockEntry block = bmap[w, h];
|
blocks = blockmap.GetSquareRange(v.Position.x - 1, v.Position.y - 1, 2, 2);
|
||||||
if(block.Vertices.Count == 0 || block.Lines.Count == 0) continue;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
blocks = new HashSet<BlockEntry>() { blockmap.GetBlockAt(v.Position) };
|
||||||
|
}
|
||||||
|
|
||||||
// Go for all the lines
|
foreach (BlockEntry be in blocks)
|
||||||
for(int i = 0; i < block.Lines.Count; i++)
|
{
|
||||||
|
if (be == null) continue;
|
||||||
|
|
||||||
|
for (int i = 0; i < be.Lines.Count; i++)
|
||||||
{
|
{
|
||||||
Linedef l = block.Lines[i];
|
Linedef l = be.Lines[i];
|
||||||
|
|
||||||
// Go for all the vertices
|
// Check if v is close enough to l for splitting
|
||||||
for(int c = 0; c < block.Vertices.Count; c++)
|
if (l.DistanceToSq(v.Position, true) <= splitdist2)
|
||||||
{
|
{
|
||||||
Vertex v = block.Vertices[c];
|
// Line is not already referencing v?
|
||||||
|
Vector2D deltastart = l.Start.Position - v.Position;
|
||||||
// Check if v is close enough to l for splitting
|
Vector2D deltaend = l.End.Position - v.Position;
|
||||||
if(l.DistanceToSq(v.Position, true) <= splitdist2)
|
if (((Math.Abs(deltastart.x) > 0.001) || (Math.Abs(deltastart.y) > 0.001)) &&
|
||||||
|
((Math.Abs(deltaend.x) > 0.001) || (Math.Abs(deltaend.y) > 0.001)))
|
||||||
{
|
{
|
||||||
// Line is not already referencing v?
|
// Split line l with vertex v
|
||||||
Vector2D deltastart = l.Start.Position - v.Position;
|
Linedef nl = l.Split(v);
|
||||||
Vector2D deltaend = l.End.Position - v.Position;
|
if (nl == null) return false;
|
||||||
if(((Math.Abs(deltastart.x) > 0.001f) || (Math.Abs(deltastart.y) > 0.001f)) &&
|
v.Marked = true; //mxd
|
||||||
((Math.Abs(deltaend.x) > 0.001f) || (Math.Abs(deltaend.y) > 0.001f)))
|
splitverts.Add(v); //mxd
|
||||||
|
|
||||||
|
// Add the new line to the list
|
||||||
|
lines.Add(nl);
|
||||||
|
blockmap.AddLinedef(nl);
|
||||||
|
|
||||||
|
// Both lines must be updated because their new length is relevant for next iterations!
|
||||||
|
l.UpdateCache();
|
||||||
|
nl.UpdateCache();
|
||||||
|
|
||||||
|
// Add both lines to changedlines
|
||||||
|
if (changedlines != null)
|
||||||
{
|
{
|
||||||
// Split line l with vertex v
|
changedlines.Add(l);
|
||||||
Linedef nl = l.Split(v);
|
changedlines.Add(nl);
|
||||||
if(nl == null) return false;
|
|
||||||
v.Marked = true; //mxd
|
|
||||||
splitverts.Add(v); //mxd
|
|
||||||
|
|
||||||
// Add the new line to the list
|
|
||||||
lines.Add(nl);
|
|
||||||
blockmap.AddLinedef(nl);
|
|
||||||
|
|
||||||
// Both lines must be updated because their new length is relevant for next iterations!
|
|
||||||
l.UpdateCache();
|
|
||||||
nl.UpdateCache();
|
|
||||||
|
|
||||||
// Add both lines to changedlines
|
|
||||||
if(changedlines != null)
|
|
||||||
{
|
|
||||||
changedlines.Add(l);
|
|
||||||
changedlines.Add(nl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue