Merge branch 'ver/6.6.0' into dev/biomes3

This commit is contained in:
Zoe Gidiere 2024-10-12 15:39:03 -06:00
commit da16f65ea2
2 changed files with 40 additions and 32 deletions

View File

@ -24,6 +24,7 @@ public class CacheSampler implements NoiseSampler {
public CacheSampler(NoiseSampler sampler, int dimensions) { public CacheSampler(NoiseSampler sampler, int dimensions) {
this.sampler = sampler; this.sampler = sampler;
if (dimensions == 2) { if (dimensions == 2) {
this.cache2D = ThreadLocal.withInitial(() -> {
LoadingCache<DoubleSeededVector2Key, Double> cache = Caffeine LoadingCache<DoubleSeededVector2Key, Double> cache = Caffeine
.newBuilder() .newBuilder()
.executor(CACHE_EXECUTOR) .executor(CACHE_EXECUTOR)
@ -31,9 +32,11 @@ public class CacheSampler implements NoiseSampler {
.initialCapacity(256) .initialCapacity(256)
.maximumSize(256) .maximumSize(256)
.build(this::sampleNoise); .build(this::sampleNoise);
this.cache2D = ThreadLocal.withInitial(() -> Pair.of(new DoubleSeededVector2Key(0, 0, 0), cache).mutable()); return Pair.of(new DoubleSeededVector2Key(0, 0, 0), cache).mutable();
});
this.cache3D = null; this.cache3D = null;
} else { } else {
this.cache3D = ThreadLocal.withInitial(() -> {
LoadingCache<DoubleSeededVector3Key, Double> cache = Caffeine LoadingCache<DoubleSeededVector3Key, Double> cache = Caffeine
.newBuilder() .newBuilder()
.executor(CACHE_EXECUTOR) .executor(CACHE_EXECUTOR)
@ -41,7 +44,8 @@ public class CacheSampler implements NoiseSampler {
.initialCapacity(981504) .initialCapacity(981504)
.maximumSize(981504) .maximumSize(981504)
.build(this::sampleNoise); .build(this::sampleNoise);
this.cache3D = ThreadLocal.withInitial(() -> Pair.of(new DoubleSeededVector3Key(0, 0, 0, 0), cache).mutable()); return Pair.of(new DoubleSeededVector3Key(0, 0, 0, 0), cache).mutable();
});
this.cache2D = null; this.cache2D = null;
} }
} }

View File

@ -33,6 +33,7 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
this.delegate = delegate; this.delegate = delegate;
this.res = delegate.resolution(); this.res = delegate.resolution();
this.baseCache = ThreadLocal.withInitial(() -> {
LoadingCache<SeededVector2Key, Optional<Biome>> cache = Caffeine LoadingCache<SeededVector2Key, Optional<Biome>> cache = Caffeine
.newBuilder() .newBuilder()
.executor(CACHE_EXECUTOR) .executor(CACHE_EXECUTOR)
@ -40,8 +41,10 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
.initialCapacity(256) .initialCapacity(256)
.maximumSize(256) .maximumSize(256)
.build(this::sampleBiome); .build(this::sampleBiome);
this.baseCache = ThreadLocal.withInitial(() -> Pair.of(new SeededVector2Key(0, 0, 0), cache).mutable()); return Pair.of(new SeededVector2Key(0, 0, 0), cache).mutable();
});
this.cache = ThreadLocal.withInitial(() -> {
LoadingCache<SeededVector3Key, Biome> cache3D = Caffeine LoadingCache<SeededVector3Key, Biome> cache3D = Caffeine
.newBuilder() .newBuilder()
.executor(CACHE_EXECUTOR) .executor(CACHE_EXECUTOR)
@ -49,7 +52,8 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
.initialCapacity(981504) .initialCapacity(981504)
.maximumSize(981504) .maximumSize(981504)
.build(this::sampleBiome); .build(this::sampleBiome);
this.cache = ThreadLocal.withInitial(() -> Pair.of(new SeededVector3Key(0, 0, 0, 0), cache3D).mutable()); return Pair.of(new SeededVector3Key(0, 0, 0, 0), cache3D).mutable();
});