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