Files
Angelica/src/main/java/com/gtnewhorizons/angelica/profiling/BailClassCounts.java
T
Jason Mitchell 3876f7e693 Instance more things (#2104)
* Flyby: pin the start origin and fly just above the route's terrain

* Instancing: particles, dropped items, entity cubes + shadow batching and some SDL-GPU fixes
2026-09-16 14:56:24 -07:00

88 lines
3.1 KiB
Java

package com.gtnewhorizons.angelica.profiling;
import com.gtnewhorizons.angelica.glsm.profiling.Tracy;
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2IntMaps;
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import net.minecraft.client.Minecraft;
public final class BailClassCounts {
public static final BailClassCounts MATERIAL = new BailClassCounts("tesr.bailCls.mat.", "BailMat");
public static final BailClassCounts TEMPLATE = new BailClassCounts("tesr.bailCls.tmpl.", "BailTmpl");
public static final BailClassCounts PARTICLE_SPILL = new BailClassCounts("particles.spillCls.", "PartSpill");
private final String plotPrefix;
private final String label;
private final Reference2IntOpenHashMap<Class<?>> counts = new Reference2IntOpenHashMap<>();
private final Reference2ObjectOpenHashMap<Class<?>, String> plotNames = new Reference2ObjectOpenHashMap<>();
private String debugLine = "";
private BailClassCounts(String plotPrefix, String label) {
this.plotPrefix = plotPrefix;
this.label = label;
}
public void add(Class<?> cls) {
counts.addTo(cls == null ? Object.class : cls, 1);
}
public void flushFrame(boolean plot) {
if (counts.isEmpty()) {
debugLine = "";
return;
}
final boolean debugScreen = Minecraft.getMinecraft().gameSettings.showDebugInfo;
if (!plot && !debugScreen) {
debugLine = "";
counts.clear();
return;
}
Class<?> a = null, b = null, c = null;
int an = 0, bn = 0, cn = 0;
final var it = Reference2IntMaps.fastIterator(counts);
while (it.hasNext()) {
final Reference2IntMap.Entry<Class<?>> entry = it.next();
final int v = entry.getIntValue();
if (plot) Tracy.plotInt(plotName(entry.getKey()), v);
if (v > an) {
c = b; cn = bn;
b = a; bn = an;
a = entry.getKey(); an = v;
} else if (v > bn) {
c = b; cn = bn;
b = entry.getKey(); bn = v;
} else if (v > cn) {
c = entry.getKey(); cn = v;
}
}
if (!debugScreen) {
debugLine = "";
} else {
final StringBuilder sb = new StringBuilder(label).append(": ");
appendEntry(sb, a, an);
if (b != null) appendEntry(sb.append(", "), b, bn);
if (c != null) appendEntry(sb.append(", "), c, cn);
debugLine = sb.toString();
}
counts.clear();
}
private String plotName(Class<?> cls) {
String name = plotNames.get(cls);
if (name == null) {
name = plotPrefix + cls.getSimpleName();
plotNames.put(cls, name);
}
return name;
}
private void appendEntry(StringBuilder sb, Class<?> cls, int count) {
sb.append(cls.getSimpleName()).append(" x").append(count);
}
public String debugLine() {
return debugLine;
}
}