Always create a new edge to the portal graph

This commit is contained in:
Jarrod Doyle 2025-01-04 21:12:54 +00:00
parent c5cbeddcd5
commit 74283f976d
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 14 additions and 20 deletions

View File

@ -77,28 +77,22 @@ public class PotentiallyVisibleSet
var other = poly.Destination; var other = poly.Destination;
// If there's already an existing edge between the two cells then we just need to add a reference to it // Checking if there's already an edge is super slow. It's much faster to just add a new edge, even with
// otherwise we need to actually build the edge // the duplicated poly
var edgeIndex = _edges.FindIndex(e => (e.Left == i && e.Right == other) || (e.Left == other && e.Right == i)); var vs = new Vector3[poly.VertexCount];
if (edgeIndex == -1) for (var vIdx = 0; vIdx < poly.VertexCount; vIdx++)
{ {
var vs = new Vector3[poly.VertexCount]; vs[vIdx] = cell.Vertices[cell.Indices[indicesOffset + vIdx]];
for (var vIdx = 0; vIdx < poly.VertexCount; vIdx++)
{
vs[vIdx] = cell.Vertices[cell.Indices[indicesOffset + vIdx]];
}
var edge = new Edge
{
Left = i,
Right = other,
Poly = new Poly(vs, cell.Planes[poly.PlaneId]),
};
_edges.Add(edge);
edgeIndex = _edges.Count - 1;
} }
_portalGraph[i].Add(edgeIndex); var edge = new Edge
{
Left = i,
Right = other,
Poly = new Poly(vs, cell.Planes[poly.PlaneId]),
};
_edges.Add(edge);
_portalGraph[i].Add(_edges.Count - 1);
indicesOffset += poly.VertexCount; indicesOffset += poly.VertexCount;
} }
} }