Files
2026-03-04 09:37:33 +08:00

81 lines
2.1 KiB
C#

namespace DebuggingEssentials
{
public class CullList
{
public SortedFastList<CullItem> cullItems;
public int startIndex;
public int endIndex;
public int currentCalcCullItem;
public GUIChangeBool show = new GUIChangeBool(value: true);
public float tStamp;
public DrawResult lastDrawResult;
public int lastAddedIndex;
public CullList(int capacity)
{
cullItems = new SortedFastList<CullItem>(capacity);
}
public bool Draw(CullList currentCullItems, ref double startHeight)
{
CullItem cullItem = cullItems.items[currentCalcCullItem++];
DrawResult drawResult = cullItem.DoDraw();
if (drawResult != DrawResult.DontDraw)
{
SortedFastList<CullItem> sortedFastList = currentCullItems.cullItems;
cullItem.Draw(ref startHeight);
sortedFastList.Add(cullItem);
if (drawResult == DrawResult.DrawHeaderAndRemoveLastHeader)
{
double num = sortedFastList.items[lastAddedIndex].endHeight - sortedFastList.items[lastAddedIndex].startHeight;
startHeight -= num;
sortedFastList.RemoveAt(lastAddedIndex);
for (int i = lastAddedIndex; i < sortedFastList.Count; i++)
{
sortedFastList.items[i].startHeight -= num;
sortedFastList.items[i].endHeight -= num;
}
}
if (drawResult == DrawResult.DrawHeader || drawResult == DrawResult.DrawHeaderAndRemoveLastHeader)
{
lastAddedIndex = sortedFastList.Count - 1;
}
currentCullItems.lastDrawResult = drawResult;
}
if (currentCalcCullItem >= cullItems.Count)
{
return false;
}
return true;
}
public void Cull(Double2 heights)
{
if (cullItems.Count != 0)
{
startIndex = Helper.BinarySearch(cullItems.items, cullItems.Count, heights.x);
if (cullItems.items[startIndex].endHeight <= heights.x)
{
startIndex++;
}
if (startIndex >= cullItems.Count)
{
startIndex = cullItems.Count - 1;
}
endIndex = Helper.BinarySearch(cullItems.items, cullItems.Count, heights.y);
if (endIndex + 1 < cullItems.Count && cullItems.items[endIndex + 1].startHeight < heights.y)
{
endIndex++;
}
}
}
}
}