mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 14:21:08 +00:00
optimize ElevationInterpolator
This commit is contained in:
+25
-4
@@ -8,8 +8,12 @@
|
|||||||
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.MathUtil;
|
||||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
public class ElevationInterpolator {
|
public class ElevationInterpolator {
|
||||||
private final double[][] values = new double[18][18];
|
private final double[][] values = new double[18][18];
|
||||||
@@ -32,14 +36,31 @@ public class ElevationInterpolator {
|
|||||||
for(int z = -1; z <= 16; z++) {
|
for(int z = -1; z <= 16; z++) {
|
||||||
double noise = 0;
|
double noise = 0;
|
||||||
double div = 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 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];
|
if(gens[x + 1 + smooth + xi][z + 1 + smooth + zi] != center) { // test referential equality because thats all we need to know
|
||||||
noise += gen.elevation().noise(seed, xOrigin + x, zOrigin + z) * gen.elevationWeight();
|
same = false;
|
||||||
div += gen.elevationWeight();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user