Cut more per-frame allocations in terrain and rendering (#2193)

This commit is contained in:
Jason Mitchell authored and GitHub committed 2026-10-02 22:06:57 -07:00
1 parent 85892c0f7f
commit d876a203da
46 files changed
+833 -150

No files matched your search

@@ -8,21 +8,24 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.Locale;
import java.util.Objects;
public record PassOverride(SpecialCondition special, Boolean translucent, WorldRenderingPhase phase) {
public final class PassOverride {
public static final PassOverride NONE = new PassOverride(null, null, null);
private static final ObjectArrayList<PassOverride> INTERNED = new ObjectArrayList<>();
private static final ObjectArrayList<Boolean> translucencyStack = new ObjectArrayList<>();
public PassOverride(SpecialCondition special, Boolean translucent) {
this(special, translucent, null);
private final SpecialCondition special;
private final Boolean translucent;
private final WorldRenderingPhase phase;
private PassOverride(SpecialCondition special, Boolean translucent, WorldRenderingPhase phase) {
this.special = special;
this.translucent = translucent;
this.phase = phase;
}
public static PassOverride capture() {
final SpecialCondition special = GbufferPrograms.getSpecialCondition();
final Boolean translucent = GbufferPrograms.getDeclaredTranslucency();
final WorldRenderingPhase phase = GbufferPrograms.getOverridePhase();
public static PassOverride of(SpecialCondition special, Boolean translucent, WorldRenderingPhase phase) {
if (special == null && translucent == null && phase == null) {
return NONE;
}
@@ -37,6 +40,10 @@ public record PassOverride(SpecialCondition special, Boolean translucent, WorldR
return created;
}
public static PassOverride capture() {
return of(GbufferPrograms.getSpecialCondition(), GbufferPrograms.getDeclaredTranslucency(), GbufferPrograms.getOverridePhase());
}
public void apply() {
GbufferPrograms.setupSpecialRenderCondition(special);
translucencyStack.add(GbufferPrograms.beginTranslucencyDeclaration(translucent));
@@ -5,6 +5,7 @@ import java.util.Objects;
public class NamespacedId {
private final String namespace;
private final String name;
private final int hash;
public NamespacedId(String combined) {
int colonIdx = combined.indexOf(':');
@@ -16,11 +17,17 @@ public class NamespacedId {
namespace = combined.substring(0, colonIdx);
name = combined.substring(colonIdx + 1);
}
hash = hash(namespace, name);
}
public NamespacedId(String namespace, String name) {
this.namespace = Objects.requireNonNull(namespace);
this.name = Objects.requireNonNull(name);
this.hash = hash(namespace, name);
}
private static int hash(String namespace, String name) {
return 31 * (31 + namespace.hashCode()) + name.hashCode();
}
public String getNamespace() {
@@ -43,12 +50,12 @@ public class NamespacedId {
NamespacedId that = (NamespacedId) o;
return namespace.equals(that.namespace) && name.equals(that.name);
return hash == that.hash && namespace.equals(that.namespace) && name.equals(that.name);
}
@Override
public int hashCode() {
return Objects.hash(namespace, name);
return hash;
}
@Override