mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
add biome cache to ChunkInterpolator
This commit is contained in:
parent
849b3116c9
commit
13c696b392
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.util.vector.Vector2Int;
|
||||||
|
import com.dfsek.terra.api.world.biome.Biome;
|
||||||
|
|
||||||
import net.jafama.FastMath;
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -53,11 +56,14 @@ public class ChunkInterpolator {
|
|||||||
|
|
||||||
double[][][] noiseStorage = new double[5][5][size + 1];
|
double[][][] noiseStorage = new double[5][5][size + 1];
|
||||||
|
|
||||||
|
BiomeCache cache = new BiomeCache(provider);
|
||||||
|
|
||||||
|
|
||||||
for(int x = 0; x < 5; x++) {
|
for(int x = 0; x < 5; x++) {
|
||||||
for(int z = 0; z < 5; z++) {
|
for(int z = 0; z < 5; z++) {
|
||||||
BiomeNoiseProperties generationSettings = provider.getBiome(xOrigin + (x << 2), zOrigin + (z << 2), seed).getContext().get(
|
BiomeNoiseProperties generationSettings = cache.get(xOrigin + (x << 2), zOrigin + (z << 2), seed)
|
||||||
BiomeNoiseProperties.class);
|
.getContext()
|
||||||
|
.get(BiomeNoiseProperties.class);
|
||||||
Map<BiomeNoiseProperties, MutableInteger> genMap = new HashMap<>();
|
Map<BiomeNoiseProperties, MutableInteger> genMap = new HashMap<>();
|
||||||
|
|
||||||
int step = generationSettings.blendStep();
|
int step = generationSettings.blendStep();
|
||||||
@ -66,7 +72,7 @@ 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 + (x << 2) + (xi * step), zOrigin + (z << 2) + (zi * step), seed)
|
cache.get(xOrigin + (x << 2) + (xi * step), zOrigin + (z << 2) + (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
|
||||||
@ -96,6 +102,20 @@ public class ChunkInterpolator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class BiomeCache {
|
||||||
|
|
||||||
|
private final BiomeProvider provider;
|
||||||
|
private final Map<Vector2Int, Biome> cache = new HashMap<>();
|
||||||
|
|
||||||
|
private BiomeCache(BiomeProvider provider) {
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Biome get(int x, int z, long seed) {
|
||||||
|
return cache.computeIfAbsent(Vector2Int.of(x, z), vec -> provider.getBiome(x, z, seed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static int reRange(int value, int high) {
|
private static int reRange(int value, int high) {
|
||||||
return FastMath.max(FastMath.min(value, high), 0);
|
return FastMath.max(FastMath.min(value, high), 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user