From 75d9bf458aa02c1a2388c06cd56801d30678461d Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Thu, 16 Jan 2020 03:55:54 -0500 Subject: [PATCH] Fixes? --- .../java/ninja/bytecode/iris/Settings.java | 10 +- .../iris/generator/IrisGenerator.java | 29 ++++- .../iris/generator/layer/GenLayerBiome.java | 10 +- .../iris/generator/layer/GenLayerCaves.java | 6 +- .../ninja/bytecode/iris/pack/IrisBiome.java | 9 +- .../ninja/bytecode/iris/pack/IrisRegion.java | 16 ++- .../bytecode/iris/util/MaxingGenerator.java | 122 ------------------ .../iris/util/MulticoreChunkGenerator.java | 15 +++ .../iris/util/ParallelChunkGenerator.java | 27 +++- .../bytecode/iris/util/PolygonGenerator.java | 36 ++++++ .../bytecode/iris/util/PrepackagedChunk.java | 35 +++++ 11 files changed, 163 insertions(+), 152 deletions(-) delete mode 100644 src/main/java/ninja/bytecode/iris/util/MaxingGenerator.java create mode 100644 src/main/java/ninja/bytecode/iris/util/MulticoreChunkGenerator.java create mode 100644 src/main/java/ninja/bytecode/iris/util/PrepackagedChunk.java diff --git a/src/main/java/ninja/bytecode/iris/Settings.java b/src/main/java/ninja/bytecode/iris/Settings.java index b6929625d..c083f06da 100644 --- a/src/main/java/ninja/bytecode/iris/Settings.java +++ b/src/main/java/ninja/bytecode/iris/Settings.java @@ -9,11 +9,11 @@ public class Settings public static class PerformanceSettings { - public PerformanceMode performanceMode = PerformanceMode.MATCH_CPU; + public PerformanceMode performanceMode = PerformanceMode.UNLIMITED; public boolean fastDecoration = true; - public int threadPriority = Thread.MIN_PRIORITY; - public int compilerPriority = Thread.MIN_PRIORITY; - public int threadCount = 1; + public int threadPriority = Thread.MAX_PRIORITY; + public int compilerPriority = Thread.MAX_PRIORITY; + public int threadCount = 4; public boolean debugMode = true; public int compilerThreads = 12; public int decorationAccuracy = 1; @@ -39,7 +39,7 @@ public class Settings public int seaLevel = 63; public double caveDensity = 4; public double caveScale = 1.45; - public double biomeScale = 2; + public double biomeScale = 2.5; public boolean flatBedrock = true; public boolean genObjects = true; public boolean genCarving = true; diff --git a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java b/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java index bea22957c..89ad00f29 100644 --- a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java +++ b/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java @@ -2,7 +2,6 @@ package ninja.bytecode.iris.generator; import java.util.List; import java.util.Random; -import java.util.concurrent.locks.ReentrantLock; import org.bukkit.Material; import org.bukkit.World; @@ -62,6 +61,8 @@ public class IrisGenerator extends ParallelChunkGenerator private CNG scatter; public GMap biomeCache = new GMap<>(); private MB WATER = new MB(Material.STATIONARY_WATER); + private MB ICE = new MB(Material.ICE); + private MB PACKED_ICE = new MB(Material.PACKED_ICE); private MB BEDROCK = new MB(Material.BEDROCK); private GList internal; private GenLayerLayeredNoise glLNoise; @@ -190,6 +191,15 @@ public class IrisGenerator extends ParallelChunkGenerator public IrisBiome getOcean(IrisBiome biome, int height) { + IrisRegion region = glBiome.getRegion(biome.getRegion()); + if(region != null) + { + if(region.isFrozen()) + { + return biome("Frozen Ocean"); + } + } + if(height < 36) { return biome("Deep Ocean"); @@ -237,6 +247,11 @@ public class IrisGenerator extends ParallelChunkGenerator return hv; } + public IrisRegion getRegion(IrisBiome biome) + { + return glBiome.getRegion(biome.getRegion()); + } + @Override public Biome genColumn(int wxx, int wzx, int x, int z, ChunkPlan plan) { @@ -245,22 +260,28 @@ public class IrisGenerator extends ParallelChunkGenerator double wx = getOffsetX(wxx); double wz = getOffsetZ(wzx); IrisBiome biome = getBiome(wxx, wzx); + boolean frozen = getRegion(biome) != null ? getRegion(biome).isFrozen() : false; int height = computeHeight(wxx, wzx, plan, biome); int max = Math.max(height, seaLevel); - biome = height > 61 && height < 65 ? getBeach(biome) : biome; - biome = height < 63 ? getOcean(biome, height) : biome; + IrisBiome nbiome = height < 63 ? getOcean(biome, height) : biome; + biome = nbiome; + biome = height > 61 && height < 65 ? frozen ? biome : getBeach(biome) : biome; for(int i = 0; i < max; i++) { MB mb = ROCK.get(scatterInt(wzx, i, wxx, ROCK.size())); boolean underwater = i >= height && i < seaLevel; + boolean someunderwater = i >= height && i < seaLevel - (1 + scatterInt(x, i, z, 1)); + boolean wayunderwater = i >= height && i < seaLevel - (3 + scatterInt(x, i, z, 2)); boolean underground = i < height; int dheight = biome.getDirtDepth(); int rheight = biome.getRockDepth(); boolean dirt = (height - 1) - i < (dheight > 0 ? scatterInt(x, i, z, 4) : 0) + dheight; boolean rocky = i > height - rheight && !dirt; boolean bedrock = i == 0 || !Iris.settings.gen.flatBedrock ? i <= 2 : i < scatterInt(x, i, z, 3); - mb = underwater ? WATER : mb; + mb = underwater ? frozen ? PACKED_ICE : WATER : mb; + mb = someunderwater ? frozen ? ICE : WATER : mb; + mb = wayunderwater ? WATER : mb; mb = underground && dirt ? biome.getSubSurface(wxx, i, wzx, rTerrain) : mb; mb = underground && rocky ? biome.getRock(wxx, i, wzx, rTerrain) : mb; mb = bedrock ? BEDROCK : mb; diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerBiome.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerBiome.java index 349f15458..f748898ee 100644 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerBiome.java +++ b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerBiome.java @@ -10,7 +10,7 @@ import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.iris.pack.IrisRegion; import ninja.bytecode.iris.util.GenLayer; -import ninja.bytecode.iris.util.MaxingGenerator.EnumMaxingGenerator; +import ninja.bytecode.iris.util.PolygonGenerator.EnumPolygonGenerator; import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.collections.GMap; import ninja.bytecode.shuriken.math.CNG; @@ -19,7 +19,7 @@ import ninja.bytecode.shuriken.math.RNG; public class GenLayerBiome extends GenLayer { - private EnumMaxingGenerator regionGenerator; + private EnumPolygonGenerator regionGenerator; private GMap regions; private Function factory; private CNG fracture; @@ -54,16 +54,16 @@ public class GenLayerBiome extends GenLayer } int v = 85034; - regionGenerator = new EnumMaxingGenerator(rng.nextParallelRNG(v), 0.00522 * Iris.settings.gen.biomeScale * 0.189, 1, regions.v().toArray(new IrisRegion[regions.v().size()]), factory); + regionGenerator = new EnumPolygonGenerator(rng.nextParallelRNG(v), 0.00522 * Iris.settings.gen.biomeScale * 0.189, 1, regions.v().toArray(new IrisRegion[regions.v().size()]), factory); for(IrisRegion i : regions.v()) { v += 13 - i.getName().length(); - i.setGen(new EnumMaxingGenerator(rng.nextParallelRNG(33 + v), 0.000255 * i.getBiomes().size() * Iris.settings.gen.biomeScale, 1, i.getBiomes().toArray(new IrisBiome[i.getBiomes().size()]), factory)); + i.setGen(new EnumPolygonGenerator(rng.nextParallelRNG(33 + v), 0.000255 * i.getBiomes().size() * Iris.settings.gen.biomeScale, 1, i.getBiomes().toArray(new IrisBiome[i.getBiomes().size()]), factory)); } } - public EnumMaxingGenerator getRegionGenerator(double xx, double zz) + public EnumPolygonGenerator getRegionGenerator(double xx, double zz) { return regionGenerator.getChoice(xx, zz).getGen(); } diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaves.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaves.java index 3211b59fe..4edd67100 100644 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaves.java +++ b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaves.java @@ -8,7 +8,7 @@ import org.bukkit.World; import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.util.GenLayer; -import ninja.bytecode.iris.util.MaxingGenerator; +import ninja.bytecode.iris.util.PolygonGenerator; import ninja.bytecode.shuriken.math.CNG; import ninja.bytecode.shuriken.math.RNG; @@ -17,7 +17,7 @@ public class GenLayerCaves extends GenLayer private CNG caveHeight; private CNG caveGirth; private CNG caveClamp; - private MaxingGenerator caveVeins; + private PolygonGenerator caveVeins; public GenLayerCaves(IrisGenerator iris, World world, Random random, RNG rng) { @@ -25,7 +25,7 @@ public class GenLayerCaves extends GenLayer caveHeight = new CNG(rng.nextParallelRNG(-100001), 1D, 3).scale(0.00222); caveGirth = new CNG(rng.nextParallelRNG(-100002), 1D, 3).scale(0.03); caveClamp = new CNG(rng.nextParallelRNG(-10000), 1D, 3).scale(0.1422); - caveVeins = new MaxingGenerator(rng.nextParallelRNG(-99999), 4, 0.002 * Iris.settings.gen.caveScale, 1, (g) -> g.fractureWith(new CNG(rng.nextParallelRNG(-5555), 1D, 4).scale(0.02), 70)); + caveVeins = new PolygonGenerator(rng.nextParallelRNG(-99999), 4, 0.002 * Iris.settings.gen.caveScale, 1, (g) -> g.fractureWith(new CNG(rng.nextParallelRNG(-5555), 1D, 4).scale(0.02), 70)); } public void genCaves(double wxx, double wzx, int x, int z, int s, IrisGenerator g) diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java b/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java index 35a3f93fa..4b63f8662 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java @@ -26,12 +26,17 @@ public class IrisBiome //@builder private static final IrisBiome OCEAN = new IrisBiome("Ocean", Biome.OCEAN) - .height(-0.5) + .height(-0.2) + .coreBiome() + .surface(MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.CLAY), MB.of(Material.GRAVEL)) + .simplexSurface(); + private static final IrisBiome FROZEN_OCEAN = new IrisBiome("Frozen Ocean", Biome.FROZEN_OCEAN) + .height(-0.16) .coreBiome() .surface(MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.CLAY), MB.of(Material.GRAVEL)) .simplexSurface(); private static final IrisBiome DEEP_OCEAN = new IrisBiome("Deep Ocean", Biome.DEEP_OCEAN) - .height(-0.88) + .height(-0.4) .coreBiome() .surface(MB.of(Material.SAND), MB.of(Material.CLAY), MB.of(Material.GRAVEL)) .simplexSurface(); diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java b/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java index cb167cace..bfe2a8213 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java @@ -2,7 +2,7 @@ package ninja.bytecode.iris.pack; import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.controller.PackController; -import ninja.bytecode.iris.util.MaxingGenerator.EnumMaxingGenerator; +import ninja.bytecode.iris.util.PolygonGenerator.EnumPolygonGenerator; import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.execution.J; import ninja.bytecode.shuriken.json.JSONObject; @@ -11,12 +11,14 @@ public class IrisRegion { private String name; private GList biomes; - private EnumMaxingGenerator gen; + private EnumPolygonGenerator gen; private double rarity; + private boolean frozen; private IrisBiome beach; public IrisRegion(String name) { + frozen = false; this.name = name; this.biomes = new GList<>(); rarity = 1; @@ -28,18 +30,19 @@ public class IrisRegion J.attempt(() -> { JSONObject o = Iris.getController(PackController.class).loadJSON("pack/regions/" + name + ".json"); + J.attempt(() -> frozen = o.getBoolean("frozen")); J.attempt(() -> name = o.getString("name")); J.attempt(() -> rarity = o.getDouble("rarity")); J.attempt(() -> beach = Iris.getController(PackController.class).getBiomeById(o.getString("beach"))); }); } - public EnumMaxingGenerator getGen() + public EnumPolygonGenerator getGen() { return gen; } - public void setGen(EnumMaxingGenerator gen) + public void setGen(EnumPolygonGenerator gen) { this.gen = gen; } @@ -141,4 +144,9 @@ public class IrisRegion return false; return true; } + + public boolean isFrozen() + { + return frozen; + } } diff --git a/src/main/java/ninja/bytecode/iris/util/MaxingGenerator.java b/src/main/java/ninja/bytecode/iris/util/MaxingGenerator.java deleted file mode 100644 index 964504312..000000000 --- a/src/main/java/ninja/bytecode/iris/util/MaxingGenerator.java +++ /dev/null @@ -1,122 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.function.Function; - -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.RNG; - -public class MaxingGenerator -{ - private CNG[] gen; - private int possibilities; - - public MaxingGenerator(RNG rng, int possibilities, double scale, int octaves, Function factory) - { - this.possibilities = possibilities; - gen = new CNG[possibilities]; - - for(int i = 0; i < possibilities; i++) - { - gen[i] = new CNG(rng.nextParallelRNG((i * 15000) + 11285), 1D, 1).scale(scale); - gen[i] = factory.apply(gen[i]); - } - } - - public double getEdge(double... dim) - { - double b = 0; - - for(int i = 0; i < gen.length; i++) - { - double g = Math.pow(gen[i].noise(dim), gen.length); - - if(g > b) - { - b = g; - } - } - - return b; - } - - public int getIndex(double... dim) - { - double b = 0; - int index = 0; - - for(int i = 0; i < gen.length; i++) - { - double g = Math.pow(gen[i].noise(dim), gen.length); - - if(g > b) - { - b = g; - index = i; - } - } - - return index % possibilities; - } - - public boolean hasBorder(int checks, double distance, double... dims) - { - int current = getIndex(dims); - double ajump = 360D / (double) checks; - - if(dims.length == 2) - { - for(int i = 0; i < checks; i++) - { - double dx = Math.sin(Math.toRadians(ajump * i)); - double dz = Math.cos(Math.toRadians(ajump * i)); - if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1])) - { - return true; - } - } - } - - if(dims.length == 3) - { - for(int i = 0; i < checks; i++) - { - double dx = Math.sin(Math.toRadians(ajump * i)); - double dz = Math.cos(Math.toRadians(ajump * i)); - double dy = Math.tan(Math.toRadians(ajump * i)); - if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1], (dy * distance) + dims[2])) - { - return true; - } - } - } - - return false; - } - - public static class EnumMaxingGenerator extends MaxingGenerator - { - private T[] choices; - - public EnumMaxingGenerator(RNG rng, double scale, int octaves, T[] choices, Function factory) - { - super(rng, choices.length, scale / (double) choices.length, octaves, factory); - - if(choices.length == 0) - { - throw new RuntimeException("Must contain more than 0 choices!"); - } - - this.choices = choices; - } - - public T getChoice(double... dim) - { - if(choices.length == 1) - { - return choices[0]; - } - - return choices[super.getIndex(dim)]; - } - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/MulticoreChunkGenerator.java b/src/main/java/ninja/bytecode/iris/util/MulticoreChunkGenerator.java new file mode 100644 index 000000000..d224d4539 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/util/MulticoreChunkGenerator.java @@ -0,0 +1,15 @@ +package ninja.bytecode.iris.util; + +import org.bukkit.generator.ChunkGenerator; + +import ninja.bytecode.shuriken.collections.GList; + +public class MulticoreChunkGenerator extends ChunkGenerator +{ + private GList generators; + + public MulticoreChunkGenerator(int tc) + { + + } +} diff --git a/src/main/java/ninja/bytecode/iris/util/ParallelChunkGenerator.java b/src/main/java/ninja/bytecode/iris/util/ParallelChunkGenerator.java index e05f932e7..cec77c617 100644 --- a/src/main/java/ninja/bytecode/iris/util/ParallelChunkGenerator.java +++ b/src/main/java/ninja/bytecode/iris/util/ParallelChunkGenerator.java @@ -14,6 +14,7 @@ import ninja.bytecode.shuriken.execution.ChronoLatch; import ninja.bytecode.shuriken.execution.TaskExecutor; import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; import ninja.bytecode.shuriken.execution.TaskExecutor.TaskResult; +import ninja.bytecode.shuriken.logging.L; import ninja.bytecode.shuriken.math.RollingSequence; import ninja.bytecode.shuriken.reaction.O; @@ -37,9 +38,9 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator return world; } - public void generateFullColumn(int a, int b, int c, int d, BiomeGrid g, ChunkPlan p) + public Biome generateFullColumn(int a, int b, int c, int d, ChunkPlan p) { - g.setBiome(c, d, genColumn(a, b, c, d, p)); + return genColumn(a, b, c, d, p); } public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) @@ -51,6 +52,20 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator { genPool = Iris.getController(ExecutionController.class).getExecutor(world); } + + if(this.world != null && world.getSeed() != this.world.getSeed()) + { + for(int i = 0; i < 16; i++) + { + for(int j = 0; j < 16; j++) + { + data.setBlock(i, 0, j, Material.YELLOW_GLAZED_TERRACOTTA); + } + } + + return data.toChunkData(); + } + this.world = world; data = new AtomicChunkData(world); if(!ready) @@ -61,6 +76,7 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator tg = genPool.startWork(); O plan = new O(); + for(i = 0; i < 16; i++) { wx = (x * 16) + i; @@ -72,7 +88,7 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator int b = wz; int c = i; int d = j; - tg.queue(() -> generateFullColumn(a, b, c, d, biome, plan.get())); + tg.queue(() -> biome.setBiome(c, d, generateFullColumn(a, b, c, d, plan.get()))); } } @@ -86,10 +102,7 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator catch(Throwable e) { - if(cl.flip()) - { - e.printStackTrace(); - } + e.printStackTrace(); for(int i = 0; i < 16; i++) { diff --git a/src/main/java/ninja/bytecode/iris/util/PolygonGenerator.java b/src/main/java/ninja/bytecode/iris/util/PolygonGenerator.java index b880088b4..921f46187 100644 --- a/src/main/java/ninja/bytecode/iris/util/PolygonGenerator.java +++ b/src/main/java/ninja/bytecode/iris/util/PolygonGenerator.java @@ -3,6 +3,7 @@ package ninja.bytecode.iris.util; import java.util.function.Function; import ninja.bytecode.shuriken.math.CNG; +import ninja.bytecode.shuriken.math.M; import ninja.bytecode.shuriken.math.RNG; public class PolygonGenerator @@ -32,6 +33,41 @@ public class PolygonGenerator } } + public boolean hasBorder(int checks, double distance, double... dims) + { + int current = getIndex(dims); + double ajump = 360D / (double) checks; + + if(dims.length == 2) + { + for(int i = 0; i < checks; i++) + { + double dx = M.sin((float)Math.toRadians(ajump * i)); + double dz = M.cos((float)Math.toRadians(ajump * i)); + if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1])) + { + return true; + } + } + } + + if(dims.length == 3) + { + for(int i = 0; i < checks; i++) + { + double dx = M.sin((float)Math.toRadians(ajump * i)); + double dz = M.cos((float)Math.toRadians(ajump * i)); + double dy = Math.tan(Math.toRadians(ajump * i)); + if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1], (dy * distance) + dims[2])) + { + return true; + } + } + } + + return false; + } + /** * Returns 0.0 to 1.0 where 0.0 is directly on the border of another region and 1.0 is perfectly in the center of a region * @param x the x diff --git a/src/main/java/ninja/bytecode/iris/util/PrepackagedChunk.java b/src/main/java/ninja/bytecode/iris/util/PrepackagedChunk.java new file mode 100644 index 000000000..0d5692e66 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/util/PrepackagedChunk.java @@ -0,0 +1,35 @@ +package ninja.bytecode.iris.util; + +import org.bukkit.block.Biome; + +public class PrepackagedChunk +{ + private AtomicChunkData data; + private Biome[] biome; + + public PrepackagedChunk(AtomicChunkData data, Biome[] biome) + { + this.data = data; + this.biome = biome; + } + + public AtomicChunkData getData() + { + return data; + } + + public void setData(AtomicChunkData data) + { + this.data = data; + } + + public Biome[] getBiome() + { + return biome; + } + + public void setBiome(Biome[] biome) + { + this.biome = biome; + } +}