carvers go brrrrrrr

This commit is contained in:
dfsek committed 2020-12-05 15:59:48 -07:00
1 parent 3d7796d8c3
commit 0e4df43ddb
6 files changed
+52 -56

No files matched your search

@@ -9,7 +9,6 @@ import org.bukkit.util.Vector;
import org.polydev.gaea.biome.Biome; import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.generation.GenerationPhase; import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.math.MathUtil; import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.population.ChunkCoordinate;
import org.polydev.gaea.util.FastRandom; import org.polydev.gaea.util.FastRandom;
import org.polydev.gaea.util.GlueList; import org.polydev.gaea.util.GlueList;
import org.polydev.gaea.world.carving.Worm; import org.polydev.gaea.world.carving.Worm;
@@ -20,31 +19,29 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
public class CarverCache { public class CarverCache {
private final Map<ChunkCoordinate, List<Worm.WormPoint>> carvers = new HashMap<>(); private final Map<Long, List<Worm.WormPoint>> carvers = new HashMap<>();
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, World w, 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(); if(carvers.size() > PluginConfig.getCacheSize() * 2) carvers.clear();
return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL) ^ w.getSeed(), key -> {
return carvers.computeIfAbsent(req, key -> {
TerraBiomeGrid grid = TerraWorld.getWorld(w).getGrid(); TerraBiomeGrid grid = TerraWorld.getWorld(w).getGrid();
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed()); if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.hashToLong(this.getClass().getName() + "_" + chunkX + "&" + chunkZ)))) {
carver.getSeedVar().setValue(seed); long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
Random r = new FastRandom(seed); carver.getSeedVar().setValue(seed);
Worm carving = carver.getWorm(seed, new Vector((chunkX << 4) + r.nextInt(16), carver.getConfig().getHeight().get(r), (chunkZ << 4) + r.nextInt(16))); Random r = new FastRandom(seed);
List<Worm.WormPoint> points = new GlueList<>(); Worm carving = carver.getWorm(seed, new Vector((chunkX << 4) + r.nextInt(16), carver.getConfig().getHeight().get(r), (chunkZ << 4) + r.nextInt(16)));
for(int i = 0; i < carving.getLength(); i++) { List<Worm.WormPoint> points = new GlueList<>();
carving.step(); for(int i = 0; i < carving.getLength(); i++) {
Biome biome = grid.getBiome(carving.getRunning().toLocation(w), GenerationPhase.POPULATE); carving.step();
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(carver)) { // Stop if we enter a biome this carver is not present in Biome biome = grid.getBiome(carving.getRunning().toLocation(w), GenerationPhase.POPULATE);
return new GlueList<>(); if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(carver)) { // Stop if we enter a biome this carver is not present in
return new GlueList<>();
}
points.add(carving.getPoint());
} }
points.add(carving.getPoint()); return points;
} }
return new GlueList<>();
return points;
}); });
} }
} }
@@ -9,7 +9,6 @@ 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;
@@ -31,9 +30,6 @@ 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;
@@ -44,6 +40,9 @@ 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());
@@ -105,14 +104,12 @@ 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) return;
return; point.carve(chunkX, chunkZ, consumer);
point.carve(chunkX, chunkZ, consumer); });
});
}
} }
} }
} }
@@ -38,7 +38,7 @@ public class PacksCommand extends Command {
LangUtil.send("command.packs.main", commandSender); LangUtil.send("command.packs.main", commandSender);
registry.entries().forEach(entry -> { registry.entries().forEach(entry -> {
ConfigPackTemplate template = entry.getTemplate(); ConfigPackTemplate template = entry.getTemplate();
LangUtil.send("command.packs.pack", commandSender, template.getID(), template.getAuthor()); LangUtil.send("command.packs.pack", commandSender, template.getID(), template.getAuthor(), template.getVersion());
}); });
return true; return true;
@@ -6,7 +6,6 @@ import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.image.ImageLoader; import com.dfsek.terra.image.ImageLoader;
import com.dfsek.terra.registry.ConfigRegistry; import com.dfsek.terra.registry.ConfigRegistry;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@@ -80,7 +79,7 @@ public class WorldConfig implements ConfigTemplate {
} catch(IllegalArgumentException | NullPointerException e) { } catch(IllegalArgumentException | NullPointerException e) {
throw new InvalidConfigurationException(e.getCause()); throw new InvalidConfigurationException(e.getCause());
} }
Bukkit.getLogger().log(Level.INFO, "Loaded {0} BiomeGrids from list.", tConfig.getTemplate().getGrids().size()); Debug.info("Loaded " + tConfig.getTemplate().getGrids().size() + " BiomeGrids from list.");
} catch(IOException | InvalidConfigurationException e) { } catch(IOException | InvalidConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
LangUtil.log("world-config.error", Level.SEVERE, worldID); LangUtil.log("world-config.error", Level.SEVERE, worldID);
@@ -16,7 +16,6 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.profiler.ProfileFuture; import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.world.carving.Carver;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -44,26 +43,30 @@ public class CavePopulator extends BlockPopulator {
c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> { c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> {
Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ()); Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
Material m = b.getType(); Material m = b.getType();
if(type.equals(Carver.CarvingType.CENTER) && template.getInner().canReplace(m)) { switch(type) {
if(template.getShift().containsKey(b.getType())) case CENTER:
shiftCandidate.put(b.getLocation(), b.getType()); if(template.getInner().canReplace(m)) {
b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false); b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false);
} else if(type.equals(Carver.CarvingType.WALL) && template.getOuter().canReplace(m)) { }
if(template.getShift().containsKey(b.getType())) break;
shiftCandidate.put(b.getLocation(), b.getType()); case WALL:
b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false); if(template.getOuter().canReplace(m)) {
} else if(type.equals(Carver.CarvingType.TOP) && template.getTop().canReplace(m)) { b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false);
if(template.getShift().containsKey(b.getType())) }
shiftCandidate.put(b.getLocation(), b.getType()); break;
b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false); case TOP:
} else if(type.equals(Carver.CarvingType.BOTTOM) && template.getBottom().canReplace(m)) { if(template.getTop().canReplace(m)) {
if(template.getShift().containsKey(b.getType())) b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false);
shiftCandidate.put(b.getLocation(), b.getType()); }
b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false); break;
} case BOTTOM:
if(template.getUpdate().contains(m)) { if(template.getBottom().canReplace(m)) {
updateNeeded.add(b); b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false);
}
break;
} }
if(template.getShift().containsKey(b.getType())) shiftCandidate.put(b.getLocation(), b.getType());
if(template.getUpdate().contains(m)) updateNeeded.add(b);
}); });
for(Map.Entry<Location, Material> entry : shiftCandidate.entrySet()) { for(Map.Entry<Location, Material> entry : shiftCandidate.entrySet()) {
Location l = entry.getKey(); Location l = entry.getKey();
+1 -1
View File
@@ -30,7 +30,7 @@ command:
in: "You are in \"%s\"" in: "You are in \"%s\""
packs: packs:
main: "Currently installed config packs:" main: "Currently installed config packs:"
pack: " - %1$s by %2$s" pack: " - %1$s v%3$s by %2$s"
none: "No config packs are installed." none: "No config packs are installed."
ore: ore:
main-menu: main-menu: