Carving is now very much optimized

This commit is contained in:
dfsek
2020-12-05 16:11:56 -07:00
parent 0e4df43ddb
commit 5b17d87a97
2 changed files with 13 additions and 10 deletions
@@ -25,7 +25,7 @@ public class CarverCache {
if(carvers.size() > PluginConfig.getCacheSize() * 2) carvers.clear(); if(carvers.size() > PluginConfig.getCacheSize() * 2) carvers.clear();
return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL) ^ w.getSeed(), key -> { return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL) ^ w.getSeed(), key -> {
TerraBiomeGrid grid = TerraWorld.getWorld(w).getGrid(); TerraBiomeGrid grid = TerraWorld.getWorld(w).getGrid();
if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.hashToLong(this.getClass().getName() + "_" + chunkX + "&" + chunkZ)))) { if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.hashToLong(carver.getClass().getName() + "_" + chunkX + "&" + chunkZ)))) {
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed()); long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
carver.getSeedVar().setValue(seed); carver.getSeedVar().setValue(seed);
Random r = new FastRandom(seed); Random r = new FastRandom(seed);
@@ -9,6 +9,7 @@ import net.jafama.FastMath;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.polydev.gaea.generation.GenerationPhase; import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
import org.polydev.gaea.util.FastRandom; import org.polydev.gaea.util.FastRandom;
import org.polydev.gaea.world.carving.Carver; import org.polydev.gaea.world.carving.Carver;
@@ -30,6 +31,9 @@ public class UserDefinedCarver extends Carver {
private final int hash; private final int hash;
private final int topCut; private final int topCut;
private final int bottomCut; private final int bottomCut;
private double step = 2;
private Range recalc = new Range(8, 10);
private double recalcMagnitude = 3;
private final CarverTemplate config; private final CarverTemplate config;
private final Expression xRad; private final Expression xRad;
private final Expression yRad; private final Expression yRad;
@@ -40,9 +44,6 @@ public class UserDefinedCarver extends Carver {
private final Range height; private final Range height;
private final double sixtyFourSq = FastMath.pow(64, 2); private final double sixtyFourSq = FastMath.pow(64, 2);
private final CarverCache cache = new CarverCache(); private final CarverCache cache = new CarverCache();
private double step = 2;
private Range recalc = new Range(8, 10);
private double recalcMagnitude = 3;
public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, int hash, int topCut, int bottomCut, CarverTemplate config) throws ParseException { public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, int hash, int topCut, int bottomCut, CarverTemplate config) throws ParseException {
super(height.getMin(), height.getMax()); super(height.getMin(), height.getMax());
@@ -104,6 +105,7 @@ public class UserDefinedCarver extends Carver {
int carvingRadius = getCarvingRadius(); int carvingRadius = getCarvingRadius();
for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) { for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) {
for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) { for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) {
if(isChunkCarved(w, x, z, new FastRandom(MathUtil.hashToLong(this.getClass().getName() + "_" + x + "&" + z)))) {
cache.getPoints(x, z, w, this).forEach(point -> { cache.getPoints(x, z, w, this).forEach(point -> {
Vector origin = point.getOrigin(); Vector origin = point.getOrigin();
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ) if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ)
@@ -113,6 +115,7 @@ public class UserDefinedCarver extends Carver {
} }
} }
} }
}
public void setRecalcMagnitude(double recalcMagnitude) { public void setRecalcMagnitude(double recalcMagnitude) {
this.recalcMagnitude = recalcMagnitude; this.recalcMagnitude = recalcMagnitude;