mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
use Caffeine cache in SamplerProvider
This commit is contained in:
parent
3000547ee9
commit
901b58f56a
@ -17,16 +17,13 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
|
package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
|
||||||
|
|
||||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
import com.dfsek.terra.api.properties.PropertyKey;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import net.jafama.FastMath;
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
|
import com.dfsek.terra.api.properties.PropertyKey;
|
||||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||||
|
|
||||||
@ -38,8 +35,11 @@ public class SamplerProvider {
|
|||||||
private final int maxBlend;
|
private final int maxBlend;
|
||||||
|
|
||||||
public SamplerProvider(Platform platform, int elevationSmooth, PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int maxBlend) {
|
public SamplerProvider(Platform platform, int elevationSmooth, PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int maxBlend) {
|
||||||
|
cache = Caffeine
|
||||||
|
.newBuilder()
|
||||||
|
.maximumSize(platform.getTerraConfig().getSamplerCache())
|
||||||
|
.build();
|
||||||
this.elevationSmooth = elevationSmooth;
|
this.elevationSmooth = elevationSmooth;
|
||||||
cache = CacheBuilder.newBuilder().maximumSize(platform.getTerraConfig().getSamplerCache()).build();
|
|
||||||
this.noisePropertiesKey = noisePropertiesKey;
|
this.noisePropertiesKey = noisePropertiesKey;
|
||||||
this.maxBlend = maxBlend;
|
this.maxBlend = maxBlend;
|
||||||
}
|
}
|
||||||
@ -52,13 +52,8 @@ public class SamplerProvider {
|
|||||||
|
|
||||||
public Sampler3D getChunk(int cx, int cz, WorldProperties world, BiomeProvider provider) {
|
public Sampler3D getChunk(int cx, int cz, WorldProperties world, BiomeProvider provider) {
|
||||||
WorldContext context = new WorldContext(cx, cz, world.getSeed(), world.getMinHeight(), world.getMaxHeight());
|
WorldContext context = new WorldContext(cx, cz, world.getSeed(), world.getMinHeight(), world.getMaxHeight());
|
||||||
try {
|
return cache.get(context, c -> new Sampler3D(c.cx, c.cz, c.seed, c.minHeight, c.maxHeight, provider,
|
||||||
return cache.get(context,
|
elevationSmooth, noisePropertiesKey, maxBlend));
|
||||||
() -> new Sampler3D(context.cx, context.cz, context.seed, context.minHeight, context.maxHeight, provider,
|
|
||||||
elevationSmooth, noisePropertiesKey, maxBlend));
|
|
||||||
} catch(ExecutionException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private record WorldContext(int cx, int cz, long seed, int minHeight, int maxHeight) {
|
private record WorldContext(int cx, int cz, long seed, int minHeight, int maxHeight) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user