Performance improvements

This commit is contained in:
dfsek
2020-09-30 21:18:30 -07:00
parent ca5accafa2
commit 0f29a506d0
20 changed files with 281 additions and 109 deletions

View File

@@ -0,0 +1,50 @@
package com.dfsek.terra.carving;
import com.dfsek.terra.procgen.GridSpawn;
import com.dfsek.terra.procgen.voxel.DeformedSphere;
import com.dfsek.terra.procgen.voxel.Tube;
import com.dfsek.terra.procgen.voxel.VoxelGeometry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.util.Vector;
import org.polydev.gaea.math.FastNoise;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.world.carving.CarvingData;
import java.util.Random;
public class Cavern {
private final Node node;
private final long seed;
public Cavern(World w) {
this.node = new Node(w);
this.seed = w.getSeed();
}
public VoxelGeometry carveChunk(int chunkX, int chunkZ) {
long seedC = MathUtil.getCarverChunkSeed(chunkX, chunkZ, seed);
Random chunk = new Random(seedC);
Vector org = node.getNodeLocation((chunkX << 4)+8, (chunkZ << 4)+8).clone().setY(chunk.nextInt(128));
VoxelGeometry carve = VoxelGeometry.getBlank();
FastNoise smpl = new FastNoise((int) seedC);
smpl.setFrequency(0.01f);
smpl.setNoiseType(FastNoise.NoiseType.Simplex);
Bukkit.getLogger().info("Cavern: " + org.toString());
carve.merge(new DeformedSphere(org.clone(), chunk.nextInt(4)+3, 0.75, smpl));
Vector _00 = new Vector(org.getX()+16, new Random(MathUtil.getCarverChunkSeed(chunkX+1, chunkZ, seed)).nextInt(128), org.getZ());
carve.merge(new Tube(org, _00, 4));
return carve;
}
public static class Node {
private final long seed;
private final GridSpawn spawn = new GridSpawn(16, 0);
public Node(World w) {
this.seed = w.getSeed();
}
public Vector getNodeLocation(int x, int z) {
return spawn.getNearestSpawn(x, z, seed);
}
}
}

View File

@@ -10,6 +10,8 @@ import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.world.carving.Carver;
import org.polydev.gaea.world.carving.Worm;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class UserDefinedCarver extends Carver {
@@ -21,6 +23,7 @@ public class UserDefinedCarver extends Carver {
private final int hash;
private final int topCut;
private final int bottomCut;
public UserDefinedCarver(Range height, Range radius, Range length, double[] start, double[] mutate, double[] radiusMultiplier, int hash, int topCut, int bottomCut) {
super(height.getMin(), height.getMax());
this.radius = radius;
@@ -36,7 +39,7 @@ public class UserDefinedCarver extends Carver {
@Override
public Worm getWorm(long l, Vector vector) {
Random r = new Random(l+hash);
return new UserDefinedWorm(length.get(r), r, vector, radius.getMax(), topCut, bottomCut);
return new UserDefinedWorm((int) (length.get(r)/2), r, vector, radius.getMax(), topCut, bottomCut);
}
@Override
@@ -54,7 +57,7 @@ public class UserDefinedCarver extends Carver {
super.setBottomCut(bottomCut);
runningRadius = radius.get(r);
this.maxRad = maxRad;
direction = new Vector((r.nextDouble()-0.5D)*start[0], (r.nextDouble()-0.5D)*start[1], (r.nextDouble()-0.5D)*start[2]).normalize();
direction = new Vector((r.nextDouble()-0.5D)*start[0], (r.nextDouble()-0.5D)*start[1], (r.nextDouble()-0.5D)*start[2]).normalize().multiply(2);
}
@Override
@@ -62,9 +65,9 @@ public class UserDefinedCarver extends Carver {
setRadius(new int[] {(int) (runningRadius*radiusMultiplier[0]), (int) (runningRadius*radiusMultiplier[1]), (int) (runningRadius*radiusMultiplier[2])});
runningRadius += (getRandom().nextDouble()-0.5)*mutate[3];
runningRadius = Math.max(Math.min(runningRadius, maxRad), 1);
direction.rotateAroundX(Math.toRadians(getRandom().nextDouble()*mutate[0]));
direction.rotateAroundY(Math.toRadians(getRandom().nextDouble()*mutate[1]));
direction.rotateAroundZ(Math.toRadians(getRandom().nextDouble()*mutate[2]));
direction.rotateAroundX(Math.toRadians(getRandom().nextDouble()*mutate[0]*2));
direction.rotateAroundY(Math.toRadians(getRandom().nextDouble()*mutate[1]*2));
direction.rotateAroundZ(Math.toRadians(getRandom().nextDouble()*mutate[2]*2));
getRunning().add(direction);
}
}