mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 09:46:24 +00:00
use column in ChunkInterpolator
This commit is contained in:
@@ -42,6 +42,13 @@ public class BiomeExtrusionProvider implements BiomeProvider {
|
||||
return delegate.getBaseBiome(x, z, seed);
|
||||
}
|
||||
|
||||
public Biome getBiome(int x, int y, int z, long seed, Biome biome) {
|
||||
for(Extrusion extrusion : extrusions) {
|
||||
biome = extrusion.extrude(biome, x, y, z, seed);
|
||||
}
|
||||
return biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Biome> getBiomes() {
|
||||
return biomes;
|
||||
@@ -51,8 +58,12 @@ public class BiomeExtrusionProvider implements BiomeProvider {
|
||||
return resolution;
|
||||
}
|
||||
|
||||
public BiomeProvider getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Column<Biome> getColumn(int x, int z, WorldProperties properties) {
|
||||
return new ExtrusionColumn(properties, this, x, z);
|
||||
return new ExtrusionColumn(properties, this, x, z, properties.getSeed());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,16 @@ public class ExtrusionColumn implements Column<Biome> {
|
||||
private final BiomeExtrusionProvider provider;
|
||||
private final int x, z;
|
||||
private final long seed;
|
||||
private final Column<Biome> delegate;
|
||||
|
||||
public ExtrusionColumn(WorldProperties worldProperties, BiomeExtrusionProvider provider, int x, int z) {
|
||||
public ExtrusionColumn(WorldProperties worldProperties, BiomeExtrusionProvider provider, int x, int z, long seed) {
|
||||
this.min = worldProperties.getMinHeight();
|
||||
this.max = worldProperties.getMaxHeight();
|
||||
this.provider = provider;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.seed = worldProperties.getSeed();
|
||||
this.delegate = provider.getDelegate().getColumn(x, z, seed, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,7 +46,7 @@ public class ExtrusionColumn implements Column<Biome> {
|
||||
|
||||
@Override
|
||||
public Biome get(int y) {
|
||||
return provider.getBiome(x, y, z, seed);
|
||||
return provider.getBiome(x, y, z, seed, delegate.get(y));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.api.util.Column;
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
@@ -54,12 +56,15 @@ public class ChunkInterpolator {
|
||||
double[][][] noiseStorage = new double[5][5][size + 1];
|
||||
|
||||
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> column = provider.getColumn(absoluteX, absoluteZ, seed, min, max);
|
||||
for(int y = 0; y < size; y++) {
|
||||
int scaledX = x << 2;
|
||||
int scaledY = (y << 2) + min;
|
||||
int scaledZ = z << 2;
|
||||
BiomeNoiseProperties generationSettings = provider.getBiome(xOrigin + scaledX, scaledY, zOrigin + scaledZ, seed)
|
||||
BiomeNoiseProperties generationSettings = column.get(scaledY)
|
||||
.getContext()
|
||||
.get(BiomeNoiseProperties.class);
|
||||
Map<BiomeNoiseProperties, MutableInteger> genMap = new HashMap<>();
|
||||
@@ -70,13 +75,13 @@ public class ChunkInterpolator {
|
||||
for(int xi = -blend; xi <= blend; xi++) {
|
||||
for(int zi = -blend; zi <= blend; zi++) {
|
||||
genMap.computeIfAbsent(
|
||||
provider.getBiome(xOrigin + scaledX + (xi * step), scaledY, zOrigin + scaledZ + (zi * step), seed)
|
||||
provider.getBiome(absoluteX + (xi * step), scaledY, absoluteZ + (zi * step), seed)
|
||||
.getContext()
|
||||
.get(BiomeNoiseProperties.class),
|
||||
g -> new MutableInteger(0)).increment(); // Increment by 1
|
||||
}
|
||||
}
|
||||
double noise = computeNoise(genMap, scaledX + xOrigin, scaledY, scaledZ + zOrigin);
|
||||
double noise = computeNoise(genMap, absoluteX, scaledY, absoluteZ);
|
||||
noiseStorage[x][z][y] = noise;
|
||||
if(y == size - 1) {
|
||||
noiseStorage[x][z][size] = noise;
|
||||
|
||||
@@ -70,7 +70,11 @@ public interface BiomeProvider {
|
||||
|
||||
|
||||
default Column<Biome> getColumn(int x, int z, WorldProperties properties) {
|
||||
return new BiomeColumn(this, properties.getMinHeight(), properties.getMaxHeight(), x, z, properties.getSeed());
|
||||
return getColumn(x, z, properties.getSeed(), properties.getMinHeight(), properties.getMaxHeight());
|
||||
}
|
||||
|
||||
default Column<Biome> getColumn(int x, int z, long seed, int min, int max) {
|
||||
return new BiomeColumn(this, min, max, x, z, seed);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
|
||||
private final int minY;
|
||||
private final int maxY;
|
||||
private final Map<Long, Biome[]> cache = new HashMap<>();
|
||||
private final Map<Long, Column<Biome>> columnCache = new HashMap<>();
|
||||
|
||||
protected CachingBiomeProvider(BiomeProvider delegate, int minY, int maxY) {
|
||||
this.delegate = delegate;
|
||||
@@ -51,8 +52,8 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Column<Biome> getColumn(int x, int z, WorldProperties properties) {
|
||||
return delegate.getColumn(x, z, properties);
|
||||
public Column<Biome> getColumn(int x, int z, long seed, int min, int max) {
|
||||
return columnCache.computeIfAbsent(MathUtil.squash(x, z), k -> delegate.getColumn(x, z, seed, min, max));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user