optimize ElevationInterpolator

This commit is contained in:
dfsek 2022-01-01 22:14:48 -07:00
parent 29580e125d
commit 999e09a653

View File

@ -8,8 +8,12 @@
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
import com.dfsek.terra.api.util.MathUtil;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import java.util.HashSet;
import java.util.Set;
public class ElevationInterpolator {
private final double[][] values = new double[18][18];
@ -32,14 +36,31 @@ public class ElevationInterpolator {
for(int z = -1; z <= 16; z++) {
double noise = 0;
double div = 0;
BiomeNoiseProperties center = gens[x + 1 + smooth][z + 1 + smooth];
boolean same = true;
for(int xi = -smooth; xi <= smooth; xi++) {
for(int zi = -smooth; zi <= smooth; zi++) {
BiomeNoiseProperties gen = gens[x + 1 + smooth + xi][z + 1 + smooth + zi];
noise += gen.elevation().noise(seed, xOrigin + x, zOrigin + z) * gen.elevationWeight();
div += gen.elevationWeight();
if(gens[x + 1 + smooth + xi][z + 1 + smooth + zi] != center) { // test referential equality because thats all we need to know
same = false;
break;
}
}
}
values[x + 1][z + 1] = noise / div;
if(same) {
values[x + 1][z + 1] = center.elevation().noise(seed, xOrigin + x, zOrigin + z); // no weighting needed!
} else {
for(int xi = -smooth; xi <= smooth; xi++) {
for(int zi = -smooth; zi <= smooth; zi++) {
BiomeNoiseProperties gen = gens[x + 1 + smooth + xi][z + 1 + smooth + zi];
noise += gen.elevation().noise(seed, xOrigin + x, zOrigin + z) * gen.elevationWeight();
div += gen.elevationWeight();
}
}
values[x + 1][z + 1] = noise / div;
}
}
}
}