mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 04:41:13 +00:00
improve elevation interp (TEMP DISABLE CARVING)
This commit is contained in:
@@ -1,25 +1,31 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.biome.pipeline.BiomeHolder;
|
||||
import com.dfsek.terra.biome.pipeline.BiomePipeline;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class StandardBiomeProvider implements BiomeProvider {
|
||||
private final LoadingCache<Vector2, BiomeHolder> holderCache;
|
||||
private final LoadingCache<Vector2, TerraBiome> biomeCache;
|
||||
private final BiomePipeline pipeline;
|
||||
private int resolution = 1;
|
||||
private final NoiseSampler xSampler;
|
||||
private final NoiseSampler zSampler;
|
||||
private final int noiseAmp;
|
||||
|
||||
protected StandardBiomeProvider(BiomePipeline pipeline, TerraPlugin main) {
|
||||
protected StandardBiomeProvider(BiomePipeline pipeline, TerraPlugin main, NoiseSampler xSampler, NoiseSampler zSampler, int noiseAmp) {
|
||||
this.xSampler = xSampler;
|
||||
this.zSampler = zSampler;
|
||||
this.noiseAmp = noiseAmp;
|
||||
holderCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(main == null ? 32 : main.getTerraConfig().getProviderCache())
|
||||
.build(
|
||||
@@ -30,27 +36,16 @@ public class StandardBiomeProvider implements BiomeProvider {
|
||||
}
|
||||
}
|
||||
);
|
||||
biomeCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(main == null ? 512 : main.getTerraConfig().getBiomeCache())
|
||||
.build(
|
||||
new CacheLoader<Vector2, TerraBiome>() {
|
||||
@Override
|
||||
public TerraBiome load(@NotNull Vector2 key) throws ExecutionException {
|
||||
int x = FastMath.floorToInt(key.getX());
|
||||
int z = FastMath.floorToInt(key.getZ());
|
||||
x /= resolution;
|
||||
z /= resolution;
|
||||
int fdX = FastMath.floorDiv(x, pipeline.getSize());
|
||||
int fdZ = FastMath.floorDiv(z, pipeline.getSize());
|
||||
return holderCache.get(new Vector2(fdX, fdZ)).getBiome(x - fdX * pipeline.getSize(), z - fdZ * pipeline.getSize());
|
||||
}
|
||||
}
|
||||
);
|
||||
this.pipeline = pipeline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraBiome getBiome(int x, int z) {
|
||||
return biomeCache.getUnchecked(new Vector2(x, z));
|
||||
x = FastMath.floorToInt(FastMath.floorDiv(x, resolution) + xSampler.getNoise(x, z) * noiseAmp);
|
||||
z = FastMath.floorToInt(FastMath.floorDiv(z, resolution) + zSampler.getNoise(x, z) * noiseAmp);
|
||||
int fdX = FastMath.floorDiv(x, pipeline.getSize());
|
||||
int fdZ = FastMath.floorDiv(z, pipeline.getSize());
|
||||
return holderCache.getUnchecked(new Vector2(fdX, fdZ)).getBiome(x - fdX * pipeline.getSize(), z - fdZ * pipeline.getSize());
|
||||
}
|
||||
|
||||
public int getResolution() {
|
||||
@@ -68,16 +63,33 @@ public class StandardBiomeProvider implements BiomeProvider {
|
||||
public static final class StandardBiomeProviderBuilder implements BiomeProviderBuilder {
|
||||
private final ExceptionalFunction<Long, BiomePipeline> pipelineBuilder;
|
||||
private final TerraPlugin main;
|
||||
private int resolution = 1;
|
||||
private int noiseAmp = 2;
|
||||
private NoiseBuilder builder = new NoiseBuilder();
|
||||
|
||||
public StandardBiomeProviderBuilder(ExceptionalFunction<Long, BiomePipeline> pipelineBuilder, TerraPlugin main) {
|
||||
this.pipelineBuilder = pipelineBuilder;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public void setResolution(int resolution) {
|
||||
this.resolution = resolution;
|
||||
}
|
||||
|
||||
public void setBuilder(NoiseBuilder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public void setNoiseAmp(int noiseAmp) {
|
||||
this.noiseAmp = noiseAmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardBiomeProvider build(long seed) {
|
||||
try {
|
||||
return new StandardBiomeProvider(pipelineBuilder.apply(seed), main);
|
||||
StandardBiomeProvider provider = new StandardBiomeProvider(pipelineBuilder.apply(seed), main, builder.build((int) seed), builder.build((int) (seed + 1)), noiseAmp);
|
||||
provider.setResolution(resolution);
|
||||
return provider;
|
||||
} catch(ConfigException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user