carver speedup finalization

This commit is contained in:
dfsek
2020-12-05 03:19:39 -07:00
parent 4e647620f0
commit 3d7796d8c3
2 changed files with 5 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ package com.dfsek.terra.carving;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import com.dfsek.terra.config.base.PluginConfig;
import org.bukkit.World;
import org.bukkit.util.Vector;
import org.polydev.gaea.biome.Biome;
@@ -21,17 +22,18 @@ import java.util.Random;
public class CarverCache {
private final Map<ChunkCoordinate, List<Worm.WormPoint>> carvers = new HashMap<>();
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, World w, ChunkCoordinate look, UserDefinedCarver carver) {
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, World w, UserDefinedCarver carver) {
ChunkCoordinate req = new ChunkCoordinate(chunkX, chunkZ, w.getUID());
if(carvers.size() > PluginConfig.getCacheSize() * 2) carvers.clear();
return carvers.computeIfAbsent(req, key -> {
TerraBiomeGrid grid = TerraWorld.getWorld(w).getGrid();
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
carver.getSeedVar().setValue(seed);
Random r = new FastRandom(seed);
Worm carving = carver.getWorm(seed, new Vector((chunkX << 4) + r.nextInt(16), carver.getConfig().getHeight().get(r), (chunkZ << 4) + r.nextInt(16)));
Vector origin = carving.getOrigin();
List<Worm.WormPoint> points = new GlueList<>();
for(int i = 0; i < carving.getLength(); i++) {
carving.step();

View File

@@ -2,7 +2,6 @@ package com.dfsek.terra.carving;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.config.templates.CarverTemplate;
import com.dfsek.terra.math.RandomFunction;
@@ -12,7 +11,6 @@ import org.bukkit.util.Vector;
import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.math.Range;
import org.polydev.gaea.population.ChunkCoordinate;
import org.polydev.gaea.util.FastRandom;
import org.polydev.gaea.world.carving.Carver;
import org.polydev.gaea.world.carving.Worm;
@@ -105,12 +103,10 @@ public class UserDefinedCarver extends Carver {
@Override
public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector, CarvingType> consumer) {
int carvingRadius = getCarvingRadius();
TerraBiomeGrid grid = TerraWorld.getWorld(w).getGrid();
for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) {
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, new ChunkCoordinate(chunkX, chunkZ, w.getUID()), this).forEach(point -> {
cache.getPoints(x, z, w, this).forEach(point -> {
Vector origin = point.getOrigin();
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ)
return;