Compare commits
No commits in common. "fafae43c5664a24ab56fd740143bc11ef7829160" and "ec9c20423d3e59d32b9987ef93cc771abfa1a0db" have entirely different histories.
fafae43c56
...
ec9c20423d
|
@ -482,13 +482,8 @@ public class LightMapper
|
|||
}
|
||||
});
|
||||
|
||||
var pvs = new PotentiallyVisibleSet(worldRep.Cells);
|
||||
Parallel.ForEach(lightCellMap, i =>
|
||||
{
|
||||
if (i != -1) pvs.ComputeVisibility(i);
|
||||
});
|
||||
|
||||
var visibleCellMap = new List<int[]>(_lights.Count);
|
||||
var pvs = new PotentiallyVisibleSet(worldRep.Cells);
|
||||
for (var i = 0; i < _lights.Count; i++)
|
||||
{
|
||||
var cellIdx = lightCellMap[i];
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
using System.Collections;
|
||||
using System.Numerics;
|
||||
using KeepersCompound.LGS.Database.Chunks;
|
||||
using Serilog;
|
||||
|
||||
namespace KeepersCompound.Lightmapper;
|
||||
|
||||
public class PotentiallyVisibleSet
|
||||
{
|
||||
private readonly struct Node(List<int> edgeIndices)
|
||||
private struct Node(List<int> edgeIndices)
|
||||
{
|
||||
public readonly HashSet<int> VisibleNodes = [];
|
||||
public bool VisibilityComputed = false;
|
||||
public HashSet<int> VisibleNodes = [];
|
||||
public readonly List<int> EdgeIndices = edgeIndices;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,6 @@ public class PotentiallyVisibleSet
|
|||
}
|
||||
|
||||
private readonly Node[] _graph;
|
||||
private readonly bool[] _computedMap;
|
||||
private readonly List<Edge> _edges;
|
||||
|
||||
private const float Epsilon = 0.1f;
|
||||
|
@ -99,18 +98,14 @@ public class PotentiallyVisibleSet
|
|||
public PotentiallyVisibleSet(WorldRep.Cell[] cells)
|
||||
{
|
||||
_graph = new Node[cells.Length];
|
||||
_computedMap = new bool[cells.Length];
|
||||
_edges = [];
|
||||
|
||||
var portalCount = 0;
|
||||
for (var i = 0; i < cells.Length; i++)
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
_computedMap[i] = false;
|
||||
portalCount += cells[i].PortalPolyCount;
|
||||
portalCount += cell.PortalPolyCount;
|
||||
}
|
||||
|
||||
_edges = new List<Edge>(portalCount);
|
||||
Log.Information("Mission contains {PortalCount} portals.", portalCount);
|
||||
|
||||
for (var i = 0; i < cells.Length; i++)
|
||||
{
|
||||
var cell = cells[i];
|
||||
|
@ -144,7 +139,7 @@ public class PotentiallyVisibleSet
|
|||
vs.Add(cell.Vertices[cell.Indices[indicesOffset + vIdx]]);
|
||||
}
|
||||
|
||||
var edge = new Edge(cells.Length, poly.Destination, new Poly(vs, cell.Planes[poly.PlaneId]));
|
||||
var edge = new Edge(portalCount, poly.Destination, new Poly(vs, cell.Planes[poly.PlaneId]));
|
||||
edgeIndices.Add(_edges.Count);
|
||||
_edges.Add(edge);
|
||||
indicesOffset += poly.VertexCount;
|
||||
|
@ -153,21 +148,23 @@ public class PotentiallyVisibleSet
|
|||
_graph[i] = new Node(edgeIndices);
|
||||
}
|
||||
|
||||
// Parallel.ForEach(_edges, ComputeEdgeMightSee);
|
||||
Parallel.ForEach(_edges, ComputeEdgeMightSee);
|
||||
}
|
||||
|
||||
public int[] GetVisible(int cellIdx)
|
||||
{
|
||||
// TODO: Handle out of range indices
|
||||
var node = _graph[cellIdx];
|
||||
if (_computedMap[cellIdx])
|
||||
if (node.VisibilityComputed)
|
||||
{
|
||||
return [..node.VisibleNodes];
|
||||
}
|
||||
|
||||
ComputeVisibility(cellIdx);
|
||||
var visibleCells = ComputeVisibility(cellIdx);
|
||||
node.VisibilityComputed = true;
|
||||
node.VisibleNodes = visibleCells;
|
||||
_graph[cellIdx] = node;
|
||||
return [.._graph[cellIdx].VisibleNodes];
|
||||
return [..visibleCells];
|
||||
}
|
||||
|
||||
private void ComputeEdgeMightSee(Edge source)
|
||||
|
@ -239,29 +236,30 @@ public class PotentiallyVisibleSet
|
|||
}
|
||||
}
|
||||
|
||||
public void ComputeVisibility(int cellIdx)
|
||||
private HashSet<int> ComputeVisibility(int cellIdx)
|
||||
{
|
||||
if (cellIdx >= _graph.Length)
|
||||
{
|
||||
return;
|
||||
return [];
|
||||
}
|
||||
|
||||
// A cell can always see itself, so we'll add that now
|
||||
_graph[cellIdx].VisibleNodes.Add(cellIdx);
|
||||
var visible = new HashSet<int>();
|
||||
visible.Add(cellIdx);
|
||||
|
||||
foreach (var edgeIdx in _graph[cellIdx].EdgeIndices)
|
||||
{
|
||||
var edge = _edges[edgeIdx];
|
||||
ComputeEdgeMightSee(edge);
|
||||
for (var i = 0; i < edge.MightSee.Length; i++)
|
||||
{
|
||||
if (edge.MightSee[i])
|
||||
{
|
||||
_graph[cellIdx].VisibleNodes.Add(i);
|
||||
visible.Add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_computedMap[cellIdx] = true;
|
||||
return visible;
|
||||
|
||||
// if (cellIdx >= _portalGraph.Length)
|
||||
// {
|
||||
|
|
Loading…
Reference in New Issue