mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 14:21:08 +00:00
dont use world as cache parameter
This commit is contained in:
+7
-9
@@ -31,19 +31,15 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
|||||||
|
|
||||||
|
|
||||||
public class SamplerProvider {
|
public class SamplerProvider {
|
||||||
private final LoadingCache<Pair<Long, World>, Sampler3D> cache;
|
private final LoadingCache<WorldContext, Sampler3D> cache;
|
||||||
|
|
||||||
|
|
||||||
public SamplerProvider(Platform platform, BiomeProvider provider, int elevationSmooth) {
|
public SamplerProvider(Platform platform, BiomeProvider provider, int elevationSmooth) {
|
||||||
cache = CacheBuilder.newBuilder().maximumSize(platform.getTerraConfig().getSamplerCache())
|
cache = CacheBuilder.newBuilder().maximumSize(platform.getTerraConfig().getSamplerCache())
|
||||||
.build(new CacheLoader<>() {
|
.build(new CacheLoader<>() {
|
||||||
@Override
|
@Override
|
||||||
public Sampler3D load(@NotNull Pair<Long, World> pair) {
|
public Sampler3D load(@NotNull WorldContext context) {
|
||||||
long key = pair.getLeft();
|
return new Sampler3D(context.cx, context.cz, context.seed, context.minHeight, context.maxHeight, provider,
|
||||||
int cx = (int) (key >> 32);
|
|
||||||
int cz = (int) key;
|
|
||||||
World world = pair.getRight();
|
|
||||||
return new Sampler3D(cx, cz, world.getSeed(), world.getMinHeight(), world.getMaxHeight(), provider,
|
|
||||||
elevationSmooth);
|
elevationSmooth);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -56,7 +52,9 @@ public class SamplerProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Sampler3D getChunk(int cx, int cz, World world) {
|
public Sampler3D getChunk(int cx, int cz, World world) {
|
||||||
long key = MathUtil.squash(cx, cz);
|
return cache.getUnchecked(new WorldContext(cx, cz, world.getSeed(), world.getMinHeight(), world.getMaxHeight()));
|
||||||
return cache.getUnchecked(Pair.of(key, world));
|
}
|
||||||
|
|
||||||
|
private record WorldContext(int cx, int cz, long seed, int minHeight, int maxHeight) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user