mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-09 09:16:34 +00:00
Slightly improve performance of NoiseFunction2
This commit is contained in:
@@ -18,7 +18,6 @@ import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.Duration;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@@ -29,7 +28,6 @@ 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 void loadConfig(JavaPlugin main) {
|
||||
main.saveDefaultConfig();
|
||||
@@ -38,7 +36,6 @@ 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);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.dfsek.terra.math;
|
||||
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
import parsii.eval.Expression;
|
||||
@@ -8,7 +7,6 @@ import parsii.eval.Expression;
|
||||
import java.util.List;
|
||||
|
||||
public class NoiseFunction2 implements NoiseFunction {
|
||||
private final Cache cache = new Cache();
|
||||
private final FastNoiseLite gen;
|
||||
|
||||
public NoiseFunction2(long seed, NoiseBuilder builder) {
|
||||
@@ -22,32 +20,11 @@ public class NoiseFunction2 implements NoiseFunction {
|
||||
|
||||
@Override
|
||||
public double eval(List<Expression> list) {
|
||||
return cache.get(list.get(0).evaluate(), list.get(1).evaluate());
|
||||
return gen.getNoise(list.get(0).evaluate(), list.get(1).evaluate());
|
||||
}
|
||||
|
||||
@Override
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user