Simplify edge definition

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

View File

@ -7,8 +7,7 @@ public class PotentiallyVisibleSet
{ {
private class Edge private class Edge
{ {
public int Left; public int Destination;
public int Right;
public Poly Poly; public Poly Poly;
} }
@ -49,7 +48,6 @@ public class PotentiallyVisibleSet
_edges = []; _edges = [];
_visibilitySet = new Dictionary<int, HashSet<int>>(); _visibilitySet = new Dictionary<int, HashSet<int>>();
// TODO: Ignore blocksvision portals
_portalGraph = new List<int>[cells.Length]; _portalGraph = new List<int>[cells.Length];
for (var i = 0; i < cells.Length; i++) for (var i = 0; i < cells.Length; i++)
{ {
@ -87,8 +85,7 @@ public class PotentiallyVisibleSet
var edge = new Edge var edge = new Edge
{ {
Left = i, Destination = other,
Right = other,
Poly = new Poly(vs, cell.Planes[poly.PlaneId]), Poly = new Poly(vs, cell.Planes[poly.PlaneId]),
}; };
_edges.Add(edge); _edges.Add(edge);
@ -125,22 +122,20 @@ public class PotentiallyVisibleSet
foreach (var edgeIndex in _portalGraph[cellIdx]) foreach (var edgeIndex in _portalGraph[cellIdx])
{ {
var edge = _edges[edgeIndex]; var edge = _edges[edgeIndex];
var neighbourIdx = edge.Left == cellIdx ? edge.Right : edge.Left; var neighbourIdx = edge.Destination;
visible.Add(neighbourIdx); visible.Add(neighbourIdx);
// Neighbours of our direct neighbour are always visible, unless they're coplanar // Neighbours of our direct neighbour are always visible, unless they're coplanar
foreach (var innerEdgeIndex in _portalGraph[neighbourIdx]) foreach (var innerEdgeIndex in _portalGraph[neighbourIdx])
{ {
var innerEdge = _edges[innerEdgeIndex]; var innerEdge = _edges[innerEdgeIndex];
var leadsBack = innerEdge.Left == cellIdx || innerEdge.Right == cellIdx; if (innerEdge.Destination == cellIdx || edge.Poly.IsCoplanar(innerEdge.Poly))
if (leadsBack || edge.Poly.IsCoplanar(innerEdge.Poly))
{ {
continue; continue;
} }
// Now we get to the recursive section // Now we get to the recursive section
var destination = innerEdge.Left == neighbourIdx ? innerEdge.Right : innerEdge.Left; ComputeClippedVisibility(visible, edge.Poly, innerEdge.Poly, neighbourIdx, innerEdge.Destination, 0);
ComputeClippedVisibility(visible, edge.Poly, innerEdge.Poly, neighbourIdx, destination, 0);
} }
} }
@ -173,8 +168,7 @@ public class PotentiallyVisibleSet
foreach (var edgeIndex in _portalGraph[currentCellIdx]) foreach (var edgeIndex in _portalGraph[currentCellIdx])
{ {
var edge = _edges[edgeIndex]; var edge = _edges[edgeIndex];
var loopsBack = edge.Left == previousCellIdx || edge.Right == previousCellIdx; if (edge.Destination == previousCellIdx || previousPoly.IsCoplanar(edge.Poly))
if (loopsBack || previousPoly.IsCoplanar(edge.Poly))
{ {
continue; continue;
} }
@ -185,8 +179,7 @@ public class PotentiallyVisibleSet
continue; continue;
} }
var destination = edge.Left == currentCellIdx ? edge.Right : edge.Left; ComputeClippedVisibility(visible, sourcePoly, poly, currentCellIdx, edge.Destination, depth + 1);
ComputeClippedVisibility(visible, sourcePoly, poly, currentCellIdx, destination, depth + 1);
} }
} }