mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Cache 2D noise results to increase performance, update to latest Gaea
This commit is contained in:
@@ -42,7 +42,7 @@ version = versionObj
|
||||
dependencies {
|
||||
implementation("org.jetbrains:annotations:20.1.0") // more recent.
|
||||
implementation("commons-io:commons-io:2.4")
|
||||
implementation(name = "Gaea-1.12.2", group = "")
|
||||
implementation(name = "Gaea-1.13.0", group = "")
|
||||
implementation("org.apache.commons:commons-imaging:1.0-alpha2")
|
||||
implementation("com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT")
|
||||
implementation("org.bstats:bstats-bukkit:1.7")
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -18,7 +18,7 @@ public class CoordinatePerturb {
|
||||
* @param amplitude Offset amplitude
|
||||
* @param seed Noise seed
|
||||
*/
|
||||
public CoordinatePerturb(float frequency, int amplitude, long seed) {
|
||||
public CoordinatePerturb(double frequency, int amplitude, long seed) {
|
||||
perturbX = new FastNoiseLite((int) seed);
|
||||
perturbX.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
perturbX.setFrequency(frequency);
|
||||
|
||||
@@ -9,7 +9,7 @@ public class ErosionNoise {
|
||||
private final double thresh;
|
||||
private final FastNoiseLite noise;
|
||||
|
||||
public ErosionNoise(float freq1, double thresh, int octaves, long seed) {
|
||||
public ErosionNoise(double freq1, double thresh, int octaves, long seed) {
|
||||
FastNoiseLite main = new FastNoiseLite((int) (seed + 1));
|
||||
main.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
main.setFractalType(FastNoiseLite.FractalType.FBm);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class TerraBiomeGrid extends BiomeGrid {
|
||||
|
||||
private final BiomeZone zone;
|
||||
|
||||
public TerraBiomeGrid(World w, float freq1, float freq2, BiomeZone zone, ConfigPack c, UserDefinedGrid erosion) {
|
||||
public TerraBiomeGrid(World w, double freq1, double freq2, BiomeZone zone, ConfigPack c, UserDefinedGrid erosion) {
|
||||
super(w, freq1, freq2, 0, 0);
|
||||
if(c.biomeBlend) {
|
||||
perturb = new CoordinatePerturb(c.blendFreq, c.blendAmp, w.getSeed());
|
||||
|
||||
@@ -15,7 +15,7 @@ public class UserDefinedGrid extends BiomeGrid {
|
||||
private final ImageLoader.Channel channelX;
|
||||
private final ImageLoader.Channel channelZ;
|
||||
|
||||
public UserDefinedGrid(World w, float freq1, float freq2, UserDefinedBiome[][] b, WorldConfig c) {
|
||||
public UserDefinedGrid(World w, double freq1, double freq2, UserDefinedBiome[][] b, WorldConfig c) {
|
||||
super(w, freq1, freq2, b.length, b[0].length);
|
||||
super.setGrid(b);
|
||||
imageLoader = c.imageLoader;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class DeformedSphereCommand extends PlayerCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
float freq;
|
||||
double freq;
|
||||
try {
|
||||
freq = Float.parseFloat(args[2]);
|
||||
} catch(NumberFormatException e) {
|
||||
|
||||
@@ -60,11 +60,11 @@ public class ConfigPack extends YamlConfiguration {
|
||||
|
||||
public final List<String> biomeList;
|
||||
|
||||
public final float zoneFreq;
|
||||
public final float freq1;
|
||||
public final float freq2;
|
||||
public final double zoneFreq;
|
||||
public final double freq1;
|
||||
public final double freq2;
|
||||
|
||||
public final float erosionFreq;
|
||||
public final double erosionFreq;
|
||||
public final double erosionThresh;
|
||||
public final boolean erosionEnable;
|
||||
public final int erosionOctaves;
|
||||
@@ -72,10 +72,10 @@ public class ConfigPack extends YamlConfiguration {
|
||||
|
||||
public final int blendAmp;
|
||||
public final boolean biomeBlend;
|
||||
public final float blendFreq;
|
||||
public final double blendFreq;
|
||||
|
||||
public final int octaves;
|
||||
public final float frequency;
|
||||
public final double frequency;
|
||||
|
||||
public final Map<StructureTypeEnum, StructureConfig> locatable = new HashMap<>();
|
||||
|
||||
@@ -111,15 +111,15 @@ public class ConfigPack extends YamlConfiguration {
|
||||
|
||||
biomeBlend = getBoolean("blend.enable", false);
|
||||
blendAmp = getInt("blend.amplitude", 8);
|
||||
blendFreq = (float) getDouble("blend.frequency", 0.01);
|
||||
blendFreq = getDouble("blend.frequency", 0.01);
|
||||
|
||||
erosionEnable = getBoolean("erode.enable", false);
|
||||
erosionFreq = (float) getDouble("erode.frequency", 0.01);
|
||||
erosionFreq = getDouble("erode.frequency", 0.01);
|
||||
erosionThresh = getDouble("erode.threshold", 0.04);
|
||||
erosionOctaves = getInt("erode.octaves", 3);
|
||||
|
||||
octaves = getInt("noise.octaves", 4);
|
||||
frequency = (float) getDouble("noise.frequency", 1f / 96);
|
||||
frequency = getDouble("noise.frequency", 1f / 96);
|
||||
|
||||
erosionName = getString("erode.grid");
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ public final class ConfigUtil {
|
||||
public static boolean debug;
|
||||
public static long dataSave; // Period of population data saving, in ticks.
|
||||
public static boolean masterDisableCaves;
|
||||
public static int cacheSize;
|
||||
public static FailType failType;
|
||||
|
||||
public static void loadConfig(JavaPlugin main) {
|
||||
@@ -39,6 +40,7 @@ public final class ConfigUtil {
|
||||
LangUtil.load(config.getString("language", "en_us"), main);
|
||||
|
||||
debug = config.getBoolean("debug", false);
|
||||
cacheSize = config.getInt("cache-size", 3);
|
||||
dataSave = Duration.parse(Objects.requireNonNull(config.getString("data-save", "PT6M"))).toMillis() / 20L;
|
||||
masterDisableCaves = config.getBoolean("master-disable.caves", false);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class OreConfig extends TerraConfig {
|
||||
public void doVein(Vector l, Chunk chunk, Random r) {
|
||||
FastNoiseLite ore = new FastNoiseLite(r.nextInt());
|
||||
ore.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
ore.setFrequency((float) deformFrequency);
|
||||
ore.setFrequency(deformFrequency);
|
||||
int rad = randomInRange(r);
|
||||
Map<ChunkCoordinate, Chunk> chunks = new HashMap<>(); // Cache chunks to prevent re-loading chunks every time one is needed.
|
||||
chunks.put(new ChunkCoordinate(chunk), chunk);
|
||||
@@ -94,7 +94,7 @@ public class OreConfig extends TerraConfig {
|
||||
public void doVeinSingle(Vector l, Chunk chunk, Random r) {
|
||||
FastNoiseLite ore = new FastNoiseLite(r.nextInt());
|
||||
ore.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
ore.setFrequency((float) deformFrequency);
|
||||
ore.setFrequency(deformFrequency);
|
||||
int rad = randomInRange(r);
|
||||
for(int x = - rad; x <= rad; x++) {
|
||||
for(int y = - rad; y <= rad; y++) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class PaletteConfig extends TerraConfig {
|
||||
FastNoiseLite pNoise = new FastNoiseLite(getInt("seed", 2403));
|
||||
pNoise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
pNoise.setFractalOctaves(4);
|
||||
pNoise.setFrequency((float) getDouble("frequency", 0.02));
|
||||
pNoise.setFrequency(getDouble("frequency", 0.02));
|
||||
pal = new SimplexPalette<>(pNoise);
|
||||
} else pal = new RandomPalette<>(new Random(getInt("seed", 2403)));
|
||||
palette = getPalette(getMapList("layers"), pal);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class BiomeFloraConfig extends TerraConfigSection {
|
||||
floraSimplex = parent.getBoolean("flora.simplex.enable", false);
|
||||
floraAttempts = parent.getInt("flora.attempts", 1);
|
||||
floraChance = parent.getInt("flora.chance", 0);
|
||||
float floraFreq = (float) parent.getDouble("flora.simplex.frequency", 0.1);
|
||||
double floraFreq = parent.getDouble("flora.simplex.frequency", 0.1);
|
||||
int floraSeed = parent.getInt("flora.simplex.seed", 2403);
|
||||
if(floraSimplex) {
|
||||
floraNoise = new FastNoiseLite(floraSeed);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
private final PopulationManager popMan = new PopulationManager(Terra.getInstance());
|
||||
private boolean needsLoad = true;
|
||||
private final int octaves;
|
||||
private final float frequency;
|
||||
private final double frequency;
|
||||
|
||||
|
||||
private static final Map<World, PopulationManager> popMap = new HashMap<>();
|
||||
@@ -167,7 +167,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getNoiseFrequency(World world) {
|
||||
public double getNoiseFrequency(World world) {
|
||||
return frequency;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ImageLoader {
|
||||
BiomeZone z = TerraWorld.getWorld(w).getZone();
|
||||
for(int x = 0; x < newImg.getWidth(); x++) {
|
||||
for(int y = 0; y < newImg.getHeight(); y++) {
|
||||
float[] noise;
|
||||
double[] noise;
|
||||
if(align.equals(Align.CENTER))
|
||||
noise = tb.getGrid(x - original.getWidth() / 2, y - original.getHeight() / 2).getRawNoise(x - original.getWidth() / 2, y - original.getHeight() / 2);
|
||||
else noise = tb.getGrid(x, y).getRawNoise(x, y);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class WorldImageGenerator {
|
||||
int imX = 0;
|
||||
for(int x = centerX - (draw.getWidth() / 2); x < centerX + (draw.getWidth() / 2); x++) {
|
||||
int zone = NormalizationUtil.normalize(tw.getZone().getRawNoise(x, y), 256, 4);
|
||||
float[] noise = tb.getGrid(x, y).getRawNoise(x, y);
|
||||
double[] noise = tb.getGrid(x, y).getRawNoise(x, y);
|
||||
Color c = new Color(NormalizationUtil.normalize(noise[0], 256, 4), NormalizationUtil.normalize(noise[1], 256, 4), zone);
|
||||
draw.setRGB(imX, imY, c.getRGB());
|
||||
imX++;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.math;
|
||||
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
import parsii.eval.Expression;
|
||||
import parsii.eval.Function;
|
||||
@@ -8,6 +9,7 @@ import java.util.List;
|
||||
|
||||
public class NoiseFunction2 implements Function {
|
||||
private FastNoiseLite gen;
|
||||
private final Cache cache = new Cache();
|
||||
|
||||
@Override
|
||||
public int getNumberOfArguments() {
|
||||
@@ -16,7 +18,7 @@ public class NoiseFunction2 implements Function {
|
||||
|
||||
@Override
|
||||
public double eval(List<Expression> list) {
|
||||
return gen.getNoise((float) list.get(0).evaluate(), (float) list.get(1).evaluate());
|
||||
return cache.get(list.get(0).evaluate(), list.get(1).evaluate());
|
||||
}
|
||||
|
||||
public void setNoise(FastNoiseLite gen) {
|
||||
@@ -27,4 +29,24 @@ public class NoiseFunction2 implements Function {
|
||||
public boolean isNaturalFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private final class Cache {
|
||||
private final double[] cacheX = new double[ConfigUtil.cacheSize];
|
||||
private final double[] cacheZ = new double[ConfigUtil.cacheSize];
|
||||
private final double[] cacheValues = new double[ConfigUtil.cacheSize];
|
||||
public double get(double x, double z) {
|
||||
for(int i = 0; i < cacheX.length; i++) {
|
||||
if(cacheX[i] == x && cacheZ[i] == z) return cacheValues[i];
|
||||
}
|
||||
cacheX[0] = x;
|
||||
cacheZ[0] = z;
|
||||
cacheValues[0] = gen.getNoise(x, z);
|
||||
for(int i = 0; i < cacheX.length-1; i++) {
|
||||
cacheX[i+1] = cacheX[i];
|
||||
cacheZ[i+1] = cacheZ[i];
|
||||
cacheValues[i+1] = cacheValues[i];
|
||||
}
|
||||
return cacheValues[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class NoiseFunction3 implements Function {
|
||||
|
||||
@Override
|
||||
public double eval(List<Expression> list) {
|
||||
return gen.getNoise((float) list.get(0).evaluate(), (float) list.get(1).evaluate(), (float) list.get(2).evaluate());
|
||||
return gen.getNoise(list.get(0).evaluate(), list.get(1).evaluate(), list.get(2).evaluate());
|
||||
}
|
||||
|
||||
public void setNoise(FastNoiseLite gen) {
|
||||
|
||||
@@ -3,5 +3,6 @@ data-save: PT6M
|
||||
language: "en_us"
|
||||
fail-type: SHUTDOWN
|
||||
dump-default: true
|
||||
cache-size: 8
|
||||
master-disable:
|
||||
caves: false
|
||||
@@ -1,7 +1,7 @@
|
||||
name: "Terra"
|
||||
depend: [ "Gaea" ]
|
||||
main: "com.dfsek.terra.Terra"
|
||||
version: "1.0.4-BETA"
|
||||
version: "1.0.5-BETA"
|
||||
load: "STARTUP"
|
||||
api-version: "1.16"
|
||||
softdepend: [ "WorldEdit" ]
|
||||
|
||||
Reference in New Issue
Block a user