mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 06:11:24 +00:00
optimize ElevationInterpolator
This commit is contained in:
+8
-5
@@ -18,13 +18,17 @@ public class ElevationInterpolator {
|
|||||||
int xOrigin = chunkX << 4;
|
int xOrigin = chunkX << 4;
|
||||||
int zOrigin = chunkZ << 4;
|
int zOrigin = chunkZ << 4;
|
||||||
|
|
||||||
BiomeNoiseProperties[][] gens = new BiomeNoiseProperties[18 + 2 * smooth][18 + 2 * smooth];
|
double[][] noiseStorage = new double[18 + 2 * smooth][18 + 2 * smooth];
|
||||||
|
double[][] weightStorage = new double[18 + 2 * smooth][18 + 2 * smooth];
|
||||||
|
|
||||||
// Precompute generators.
|
// Precompute generators.
|
||||||
for(int x = -1 - smooth; x <= 16 + smooth; x++) {
|
for(int x = -1 - smooth; x <= 16 + smooth; x++) {
|
||||||
for(int z = -1 - smooth; z <= 16 + smooth; z++) {
|
for(int z = -1 - smooth; z <= 16 + smooth; z++) {
|
||||||
gens[x + 1 + smooth][z + 1 + smooth] = provider.getBiome(xOrigin + x, zOrigin + z, seed).getContext().get(
|
BiomeNoiseProperties noiseProperties = provider.getBiome(xOrigin + x, zOrigin + z, seed).getContext().get(
|
||||||
BiomeNoiseProperties.class);
|
BiomeNoiseProperties.class);
|
||||||
|
noiseStorage[x + 1 + smooth][z + 1 + smooth] = noiseProperties.elevation().noise(seed, xOrigin + x, zOrigin + z)
|
||||||
|
* noiseProperties.elevationWeight();
|
||||||
|
weightStorage[x + 1 + smooth][z + 1 + smooth] = noiseProperties.elevationWeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,9 +38,8 @@ public class ElevationInterpolator {
|
|||||||
double div = 0;
|
double div = 0;
|
||||||
for(int xi = -smooth; xi <= smooth; xi++) {
|
for(int xi = -smooth; xi <= smooth; xi++) {
|
||||||
for(int zi = -smooth; zi <= smooth; zi++) {
|
for(int zi = -smooth; zi <= smooth; zi++) {
|
||||||
BiomeNoiseProperties gen = gens[x + 1 + smooth + xi][z + 1 + smooth + zi];
|
noise += noiseStorage[x + 1 + smooth + xi][z + 1 + smooth + zi];
|
||||||
noise += gen.elevation().noise(seed, xOrigin + x, zOrigin + z) * gen.elevationWeight();
|
div += weightStorage[x + 1 + smooth + xi][z + 1 + smooth + zi];
|
||||||
div += gen.elevationWeight();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
values[x + 1][z + 1] = noise / div;
|
values[x + 1][z + 1] = noise / div;
|
||||||
|
|||||||
Reference in New Issue
Block a user