32 lines
979 B
C#
32 lines
979 B
C#
namespace Sand.ChunkPrototype;
|
|
|
|
internal sealed class ChunkActivityTracker
|
|
{
|
|
private readonly List<ChunkCoord> _activeChunks = new();
|
|
private readonly List<ChunkCoord> _sleepingChunks = new();
|
|
|
|
public (IReadOnlyList<ChunkCoord> ActiveChunks, int SleepingChunks) Build(IReadOnlyDictionary<ChunkCoord, ChunkCellPage> pages)
|
|
{
|
|
_activeChunks.Clear();
|
|
_sleepingChunks.Clear();
|
|
foreach (var (coord, page) in pages)
|
|
{
|
|
if (page.IsActive || page.HasFieldActivity || page.PendingActiveSteps > 0)
|
|
{
|
|
_activeChunks.Add(coord);
|
|
}
|
|
else
|
|
{
|
|
_sleepingChunks.Add(coord);
|
|
}
|
|
}
|
|
|
|
_activeChunks.Sort(static (left, right) =>
|
|
{
|
|
var yCompare = right.Y.CompareTo(left.Y);
|
|
return yCompare != 0 ? yCompare : left.X.CompareTo(right.X);
|
|
});
|
|
return (_activeChunks, _sleepingChunks.Count);
|
|
}
|
|
}
|