Reviewed terrain cache coordination

- Concurrent terrain requests share completion and coordinate claims per batch
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-13 14:58:00 -04:00
commit 5b5f3dae89
2 files changed
+129 -40

No files matched your search

@@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
@@ -39,6 +40,34 @@ public class HydrologyBasisCacheTest {
assertEquals(3, sampler.slopeFreeCalls.get());
}
@Test
public void batchOwnershipKeepsProviderOrderAcrossStripes() {
HydrologyBasisCache cache = new HydrologyBasisCache();
CountingSampler sampler = new CountingSampler() {
@Override
public HydrologyTerrainSample[] sampleBasisWithoutSlopeBatch(long[] coordinates, int count) {
assertArrayEquals(new long[]{RiverFootprint.pack(7, 0), RiverFootprint.pack(-9, 0),
RiverFootprint.pack(-17, 0)}, Arrays.copyOf(coordinates, count));
return super.sampleBasisWithoutSlopeBatch(coordinates, count);
}
@Override
public HydrologyTerrainSample sampleBasisWithoutSlope(int x, int z) {
return HydrologyTerrainSample.openLand(63 + x, 0D, "land");
}
};
HydrologyTerrainSample seeded = cache.sampleWithoutSlope(4, 0, sampler);
HydrologyTerrainSample[] samples = cache.sampleWithoutSlopeBatch(new long[]{
RiverFootprint.pack(7, 0), RiverFootprint.pack(-9, 0), RiverFootprint.pack(7, 0),
RiverFootprint.pack(4, 0), RiverFootprint.pack(-17, 0), RiverFootprint.pack(4, 0)}, 6, sampler);
assertEquals(70, samples[0].naturalHeight());
assertEquals(54, samples[1].naturalHeight());
assertSame(samples[0], samples[2]);
assertSame(seeded, samples[3]);
assertEquals(46, samples[4].naturalHeight());
assertSame(seeded, samples[5]);
}
@Test(timeout = 10_000)
public void overlappingBatchesDispatchOnlyTheirOwnedCoordinates() throws Exception {
HydrologyBasisCache cache = new HydrologyBasisCache();