Remove the 2D cache bypass

Hydrology sampling now goes through the engine 2D caches; the thread-local bypass and its test are gone.
This commit is contained in:
Brian Neumann-Fopiano committed 2026-09-01 19:22:42 -04:00
1 parent 5b1b636539
commit b57a2e2fc8
6 files changed
+3 -226

No files matched your search

@@ -95,13 +95,9 @@ public final class IrisHydrologyRuntime implements AutoCloseable {
this.settings = createSettings(context.dimension(), hydrology);
HydrologyGeometrySampler geometrySampler = geometrySampler(context, hydrology);
IrisHydrologyRoutingTerrainSampler.Sources terrainSources = new IrisHydrologyRoutingTerrainSampler.Sources(
(int x, int z, double rawNaturalHeight) -> ProceduralStream.bypass2DCaches(
() -> createTerrainBasis(x, z, rawNaturalHeight)
),
this::createTerrainBasis,
(int x, int z) -> context.naturalHeightProvider().sample(x, z),
(int x, int z) -> ProceduralStream.bypass2DCaches(
() -> context.naturalOceanClassifier().isOcean(x, z)
)
(int x, int z) -> context.naturalOceanClassifier().isOcean(x, z)
);
this.routingTerrainSampler = new IrisHydrologyRoutingTerrainSampler(
terrainSources,
@@ -370,7 +366,7 @@ public final class IrisHydrologyRuntime implements AutoCloseable {
return cached;
}
}
HydrologyTerrainSample sampled = ProceduralStream.bypass2DCaches(() -> createDetailedTerrainSample(x, z));
HydrologyTerrainSample sampled = createDetailedTerrainSample(x, z);
synchronized (terrainSampleLock) {
HydrologyTerrainSample existing = terrainSamples.get(packed);
if (existing != null) {
@@ -72,18 +72,9 @@ import art.arcane.iris.util.project.stream.utility.SynchronizedStream;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
@SuppressWarnings("ALL")
public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
static <V> V bypass2DCaches(Supplier<V> operation) {
return ProceduralStreamCacheBypass.supply(operation);
}
static boolean is2DCacheBypassActive() {
return ProceduralStreamCacheBypass.isActive();
}
static ProceduralStream<Double> ofDouble(Function2<Double, Double, Double> f) {
try {
return of(f, Interpolated.DOUBLE);
@@ -1,28 +0,0 @@
package art.arcane.iris.util.project.stream;
import java.util.function.Supplier;
final class ProceduralStreamCacheBypass {
private static final ThreadLocal<Integer> DEPTH = new ThreadLocal<>();
private ProceduralStreamCacheBypass() {
}
static boolean isActive() {
return DEPTH.get() != null;
}
static <T> T supply(Supplier<T> operation) {
Integer previousDepth = DEPTH.get();
DEPTH.set(previousDepth == null ? 1 : previousDepth + 1);
try {
return operation.get();
} finally {
if (previousDepth == null) {
DEPTH.remove();
} else {
DEPTH.set(previousDepth);
}
}
}
}
@@ -34,9 +34,6 @@ public class CachedDoubleStream2D extends BasicStream<Double> implements Procedu
@Override
public Double get(double x, double z) {
if (ProceduralStream.is2DCacheBypassActive()) {
return stream.getDouble((int) x, (int) z);
}
return cache.get((int) x, (int) z);
}
@@ -47,9 +44,6 @@ public class CachedDoubleStream2D extends BasicStream<Double> implements Procedu
@Override
public double getDouble(double x, double z) {
if (ProceduralStream.is2DCacheBypassActive()) {
return stream.getDouble((int) x, (int) z);
}
return cache.get((int) x, (int) z);
}
@@ -55,9 +55,6 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
@Override
public T get(double x, double z) {
if (ProceduralStream.is2DCacheBypassActive()) {
return stream.get((int) x, (int) z);
}
return cache.get((int) x, (int) z);
}