mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
cache column in ChunkInterpolator
This commit is contained in:
@@ -48,9 +48,10 @@ public class NoiseChunkGenerator3DAddon implements AddonInitializer {
|
||||
event.getPack()
|
||||
.getOrCreateRegistry(ChunkGeneratorProvider.class)
|
||||
.register(addon.key("NOISE_3D"),
|
||||
pack -> new NoiseChunkGenerator3D(platform, config.getElevationBlend(), config.getHorizontalRes(),
|
||||
config.getVerticalRes(),
|
||||
noisePropertiesPropertyKey, paletteInfoPropertyKey));
|
||||
pack -> new NoiseChunkGenerator3D(pack, platform, config.getElevationBlend(),
|
||||
config.getHorizontalRes(),
|
||||
config.getVerticalRes(), noisePropertiesPropertyKey,
|
||||
paletteInfoPropertyKey));
|
||||
event.getPack()
|
||||
.applyLoader(SlantLayer.class, SlantLayer::new);
|
||||
})
|
||||
|
||||
@@ -16,10 +16,9 @@ import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler3D;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.SamplerProvider;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.properties.PropertyKey;
|
||||
import com.dfsek.terra.api.util.Column;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
@@ -44,7 +43,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
private final PropertyKey<PaletteInfo> paletteInfoPropertyKey;
|
||||
private final PropertyKey<BiomeNoiseProperties> noisePropertiesKey;
|
||||
|
||||
public NoiseChunkGenerator3D(Platform platform, int elevationBlend, int carverHorizontalResolution,
|
||||
public NoiseChunkGenerator3D(ConfigPack pack, Platform platform, int elevationBlend, int carverHorizontalResolution,
|
||||
int carverVerticalResolution,
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey,
|
||||
PropertyKey<PaletteInfo> paletteInfoPropertyKey) {
|
||||
@@ -54,7 +53,15 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
this.carverVerticalResolution = carverVerticalResolution;
|
||||
this.paletteInfoPropertyKey = paletteInfoPropertyKey;
|
||||
this.noisePropertiesKey = noisePropertiesKey;
|
||||
this.samplerCache = new SamplerProvider(platform, elevationBlend, noisePropertiesKey);
|
||||
int maxBlend = pack
|
||||
.getBiomeProvider()
|
||||
.stream()
|
||||
.map(biome -> biome.getContext().get(noisePropertiesKey))
|
||||
.mapToInt(properties -> properties.blendDistance() * properties.blendStep())
|
||||
.max()
|
||||
.orElse(0);
|
||||
|
||||
this.samplerCache = new SamplerProvider(platform, elevationBlend, noisePropertiesKey, maxBlend);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,7 +35,8 @@ public class ChunkInterpolator {
|
||||
* @param min
|
||||
* @param max
|
||||
*/
|
||||
public ChunkInterpolator(long seed, int chunkX, int chunkZ, BiomeProvider provider, int min, int max, PropertyKey<BiomeNoiseProperties> noisePropertiesKey) {
|
||||
public ChunkInterpolator(long seed, int chunkX, int chunkZ, BiomeProvider provider, int min, int max,
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int maxBlend) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
|
||||
@@ -50,19 +51,31 @@ public class ChunkInterpolator {
|
||||
|
||||
double[][][] noiseStorage = new double[5][5][size + 1];
|
||||
|
||||
int maxBlendAndChunk = 17 + 2 * maxBlend;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Column<Biome>[] columns = new Column[maxBlendAndChunk * maxBlendAndChunk];
|
||||
|
||||
for(int x = 0; x < 5; x++) {
|
||||
int scaledX = x << 2;
|
||||
int absoluteX = xOrigin + scaledX;
|
||||
for(int z = 0; z < 5; z++) {
|
||||
int scaledZ = z << 2;
|
||||
int absoluteZ = zOrigin + scaledZ;
|
||||
|
||||
Column<Biome> biomeColumn = provider.getColumn(absoluteX, absoluteZ, seed, min, max);
|
||||
|
||||
int index = (scaledX + maxBlend) + maxBlendAndChunk * (scaledZ + maxBlend);
|
||||
Column<Biome> biomeColumn = columns[index];
|
||||
|
||||
if(biomeColumn == null) {
|
||||
biomeColumn = provider.getColumn(absoluteX, absoluteZ, seed, min, max);
|
||||
columns[index] = biomeColumn;
|
||||
}
|
||||
|
||||
for(int y = 0; y < size; y++) {
|
||||
int scaledY = (y << 2) + min;
|
||||
BiomeNoiseProperties generationSettings = biomeColumn.get(scaledY)
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
|
||||
int step = generationSettings.blendStep();
|
||||
int blend = generationSettings.blendDistance();
|
||||
@@ -72,8 +85,19 @@ public class ChunkInterpolator {
|
||||
|
||||
for(int xi = -blend; xi <= blend; xi++) {
|
||||
for(int zi = -blend; zi <= blend; zi++) {
|
||||
BiomeNoiseProperties properties = provider
|
||||
.getBiome(absoluteX + (xi * step), scaledY, absoluteZ + (zi * step), seed)
|
||||
int blendX = (xi * step);
|
||||
int blendZ = (zi * step);
|
||||
|
||||
int localIndex = (scaledX + maxBlend + blendX) + maxBlendAndChunk * (scaledZ + maxBlend + blendZ);
|
||||
Column<Biome> column = columns[localIndex];
|
||||
|
||||
if(column == null) {
|
||||
column = provider.getColumn(absoluteX + blendX, absoluteZ + blendZ, seed, min, max);
|
||||
columns[localIndex] = column;
|
||||
}
|
||||
|
||||
BiomeNoiseProperties properties = column
|
||||
.get(scaledY)
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
double sample = properties.noiseHolder().getNoise(properties.base(), absoluteX, scaledY, absoluteZ, seed);
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.api.properties.PropertyKey;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.ChunkInterpolator;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.ElevationInterpolator;
|
||||
import com.dfsek.terra.api.properties.PropertyKey;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
@@ -21,9 +20,10 @@ public class Sampler3D {
|
||||
private final ChunkInterpolator interpolator;
|
||||
private final ElevationInterpolator elevationInterpolator;
|
||||
|
||||
public Sampler3D(int x, int z, long seed, int minHeight, int maxHeight, BiomeProvider provider, int elevationSmooth, PropertyKey<BiomeNoiseProperties> noisePropertiesKey) {
|
||||
public Sampler3D(int x, int z, long seed, int minHeight, int maxHeight, BiomeProvider provider, int elevationSmooth,
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int maxBlend) {
|
||||
this.interpolator = new ChunkInterpolator(seed, x, z, provider,
|
||||
minHeight, maxHeight, noisePropertiesKey);
|
||||
minHeight, maxHeight, noisePropertiesKey, maxBlend);
|
||||
this.elevationInterpolator = new ElevationInterpolator(seed, x, z, provider, elevationSmooth, noisePropertiesKey);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,13 @@ public class SamplerProvider {
|
||||
private final Cache<WorldContext, Sampler3D> cache;
|
||||
private final int elevationSmooth;
|
||||
private final PropertyKey<BiomeNoiseProperties> noisePropertiesKey;
|
||||
private final int maxBlend;
|
||||
|
||||
public SamplerProvider(Platform platform, int elevationSmooth, PropertyKey<BiomeNoiseProperties> noisePropertiesKey) {
|
||||
public SamplerProvider(Platform platform, int elevationSmooth, PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int maxBlend) {
|
||||
this.elevationSmooth = elevationSmooth;
|
||||
cache = CacheBuilder.newBuilder().maximumSize(platform.getTerraConfig().getSamplerCache()).build();
|
||||
this.noisePropertiesKey = noisePropertiesKey;
|
||||
this.maxBlend = maxBlend;
|
||||
}
|
||||
|
||||
public Sampler3D get(int x, int z, WorldProperties world, BiomeProvider provider) {
|
||||
@@ -53,7 +55,7 @@ public class SamplerProvider {
|
||||
try {
|
||||
return cache.get(context,
|
||||
() -> new Sampler3D(context.cx, context.cz, context.seed, context.minHeight, context.maxHeight, provider,
|
||||
elevationSmooth, noisePropertiesKey));
|
||||
elevationSmooth, noisePropertiesKey, maxBlend));
|
||||
} catch(ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user