From 948317c27a9a9071a66b194375db9020f7676f8f Mon Sep 17 00:00:00 2001 From: Dan Macbook Date: Fri, 14 Aug 2020 03:39:35 -0400 Subject: [PATCH] No Caching --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 2 + src/main/java/com/volmit/iris/Iris.java | 111 ++++---- src/main/java/com/volmit/iris/NoiseView.java | 21 +- .../volmit/iris/gen/BiomeChunkGenerator.java | 177 +++++-------- .../iris/gen/ContextualChunkGenerator.java | 2 +- .../volmit/iris/gen/IrisChunkGenerator.java | 4 - .../iris/gen/ParallaxChunkGenerator.java | 236 +++++++----------- .../iris/gen/ParallelChunkGenerator.java | 60 ++--- .../iris/gen/PostBlockChunkGenerator.java | 116 ++++----- .../iris/gen/TerrainChunkGenerator.java | 56 +---- .../iris/gen/atomics/AtomicBiomeMap.java | 7 + .../iris/gen/atomics/AtomicDoubleMap.java | 23 ++ .../volmit/iris/gen/atomics/AtomicIntMap.java | 19 ++ .../iris/gen/atomics/AtomicObjectMap.java | 19 ++ .../iris/gen/atomics/AtomicRegionMap.java | 7 + .../java/com/volmit/iris/noise/FlatNoise.java | 22 ++ .../java/com/volmit/iris/noise/NoiseType.java | 1 + .../iris/object/IrisObjectTranslate.java | 8 +- .../com/volmit/iris/object/NoiseStyle.java | 4 + 20 files changed, 397 insertions(+), 498 deletions(-) delete mode 100644 .DS_Store create mode 100644 src/main/java/com/volmit/iris/gen/atomics/AtomicBiomeMap.java create mode 100644 src/main/java/com/volmit/iris/gen/atomics/AtomicDoubleMap.java create mode 100644 src/main/java/com/volmit/iris/gen/atomics/AtomicIntMap.java create mode 100644 src/main/java/com/volmit/iris/gen/atomics/AtomicObjectMap.java create mode 100644 src/main/java/com/volmit/iris/gen/atomics/AtomicRegionMap.java create mode 100644 src/main/java/com/volmit/iris/noise/FlatNoise.java diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 638b0d7026a296895fb31efe27e5047a6d991ff3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ8l9o5S<|it(0a9^us9E~@hB50G26hv>N@w3PC zZ21*CJ0hapdG{vLibw-Dl#2~hvwic4%`&1uIL_G1u>0B`K90x3B>U%paThYkMo#ki zoo^d7DnJFO02QDDRN&zXWQlEFAAT|qqykjn*%h$wLxCIC#4*r69T>a?0L~G1!`yob zV6gzOCXRuKz%;19plY@l8g#@<=GDY8FzBM$d}!XR*`cW4j`NGBi`GDnRDcTHEASG_ z*6RNX{!9OVPvVLSP=SA?fX@5(zQdEUwoV>rwYI?5aLc*E%`kTg1~11zFUMF|IbM2F bPDkA7K>iGvE;K6e*9zPK5X%*r diff --git a/.gitignore b/.gitignore index 1d896823b..b209698dd 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ lint/in.jar lint/out.jar lint/mapping.txt + +.DS_Store diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index e2f2e0216..bfd31ef4e 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -41,8 +41,7 @@ import com.volmit.iris.util.Permission; import com.volmit.iris.util.RollingSequence; import com.volmit.iris.util.ScoreDirection; -public class Iris extends MortarPlugin implements BoardProvider -{ +public class Iris extends MortarPlugin implements BoardProvider { public static KList executors = new KList<>(); public static Iris instance; public static IrisDataManager globaldata; @@ -66,31 +65,27 @@ public class Iris extends MortarPlugin implements BoardProvider @com.volmit.iris.util.Command public CommandIris commandIris; - public Iris() - { + public Iris() { IO.delete(new File("iris")); } @Override - public void start() - { + public void start() { } @Override - public void stop() - { + public void stop() { } @Override - public String getTag(String subTag) - { - return ChatColor.BOLD + "" + ChatColor.DARK_GRAY + "[" + ChatColor.BOLD + "" + ChatColor.GREEN + "Iris" + ChatColor.BOLD + ChatColor.DARK_GRAY + "]" + ChatColor.RESET + "" + ChatColor.GRAY + ": "; + public String getTag(String subTag) { + return ChatColor.BOLD + "" + ChatColor.DARK_GRAY + "[" + ChatColor.BOLD + "" + ChatColor.GREEN + "Iris" + + ChatColor.BOLD + ChatColor.DARK_GRAY + "]" + ChatColor.RESET + "" + ChatColor.GRAY + ": "; } - public void onEnable() - { + public void onEnable() { lock = new IrisLock("Iris"); instance = this; hotloader = new IrisHotloadManager(); @@ -98,25 +93,22 @@ public class Iris extends MortarPlugin implements BoardProvider wand = new WandController(); postProcessors = loadPostProcessors(); proj = new ProjectManager(); - manager = new BoardManager(this, BoardSettings.builder().boardProvider(this).scoreDirection(ScoreDirection.UP).build()); + manager = new BoardManager(this, + BoardSettings.builder().boardProvider(this).scoreDirection(ScoreDirection.UP).build()); super.onEnable(); } - public void onDisable() - { + public void onDisable() { lock.unlock(); proj.close(); - for(GroupedExecutor i : executors) - { + for (GroupedExecutor i : executors) { i.close(); } - for(World i : Bukkit.getWorlds()) - { - if(i.getGenerator() instanceof IrisChunkGenerator) - { + for (World i : Bukkit.getWorlds()) { + if (i.getGenerator() instanceof IrisChunkGenerator) { ((IrisChunkGenerator) i).close(); } } @@ -129,28 +121,23 @@ public class Iris extends MortarPlugin implements BoardProvider } @Override - public String getTitle(Player player) - { + public String getTitle(Player player) { return ChatColor.GREEN + "Iris"; } @Override - public List getLines(Player player) - { - if(!clf.flip()) - { + public List getLines(Player player) { + if (!clf.flip()) { return lines; } World world = player.getWorld(); lines.clear(); - if(world.getGenerator() instanceof IrisChunkGenerator) - { + if (world.getGenerator() instanceof IrisChunkGenerator) { IrisChunkGenerator g = (IrisChunkGenerator) world.getGenerator(); - if(cl.flip()) - { + if (cl.flip()) { mem = Form.memSize(g.guessMemoryUsage(), 2); } @@ -163,21 +150,23 @@ public class Iris extends MortarPlugin implements BoardProvider tp.put(g.getMetrics().getSpeed()); lines.add("&7&m-----------------"); - lines.add(ChatColor.GREEN + "Speed" + ChatColor.GRAY + ": " + ChatColor.BOLD + "" + ChatColor.GRAY + Form.f(g.getMetrics().getPerSecond().getAverage(), 0) + "/s " + Form.duration(g.getMetrics().getTotal().getAverage(), 1) + ""); + lines.add(ChatColor.GREEN + "Speed" + ChatColor.GRAY + ": " + ChatColor.BOLD + "" + ChatColor.GRAY + + Form.f(g.getMetrics().getPerSecond().getAverage(), 0) + "/s " + + Form.duration(g.getMetrics().getTotal().getAverage(), 1) + ""); lines.add(ChatColor.GREEN + "Generators" + ChatColor.GRAY + ": " + Form.f(CNG.creates)); lines.add(ChatColor.GREEN + "Noise" + ChatColor.GRAY + ": " + Form.f((int) hits.getAverage())); - lines.add(ChatColor.GREEN + "Parallax Chunks" + ChatColor.GRAY + ": " + Form.f((int) g.getParallaxMap().getLoadedChunks().size())); - lines.add(ChatColor.GREEN + "Objects" + ChatColor.GRAY + ": " + Form.f(g.getData().getObjectLoader().count())); + lines.add(ChatColor.GREEN + "Parallax Chunks" + ChatColor.GRAY + ": " + + Form.f((int) g.getParallaxMap().getLoadedChunks().size())); + lines.add(ChatColor.GREEN + "Objects" + ChatColor.GRAY + ": " + + Form.f(g.getData().getObjectLoader().count())); lines.add(ChatColor.GREEN + "Memory" + ChatColor.GRAY + ": " + mem); - if(er != null && b != null) - { + if (er != null && b != null) { lines.add(ChatColor.GREEN + "Biome" + ChatColor.GRAY + ": " + b.getName()); lines.add(ChatColor.GREEN + "File" + ChatColor.GRAY + ": " + b.getLoadKey()); } - if(st != null) - { + if (st != null) { lines.add(ChatColor.GREEN + "Structure" + ChatColor.GRAY + ": " + st.getStructure().getName()); lines.add(ChatColor.GREEN + "Tile" + ChatColor.GRAY + ": " + st.getTile().toString()); } @@ -185,16 +174,14 @@ public class Iris extends MortarPlugin implements BoardProvider lines.add("&7&m-----------------"); } - else - { + else { lines.add(ChatColor.GREEN + "Join an Iris World!"); } return lines; } - private static KList> loadPostProcessors() - { + private static KList> loadPostProcessors() { KList> g = new KList>(); g.add(PostFloatingNibDeleter.class); @@ -208,65 +195,55 @@ public class Iris extends MortarPlugin implements BoardProvider } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) - { + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { return super.onCommand(sender, command, label, args); } - public void imsg(CommandSender s, String msg) - { - s.sendMessage(ChatColor.GREEN + "[" + ChatColor.DARK_GRAY + "Iris" + ChatColor.GREEN + "]" + ChatColor.GRAY + ": " + msg); + public void imsg(CommandSender s, String msg) { + s.sendMessage(ChatColor.GREEN + "[" + ChatColor.DARK_GRAY + "Iris" + ChatColor.GREEN + "]" + ChatColor.GRAY + + ": " + msg); } @Override - public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) - { + public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { return new IrisChunkGenerator(16); } - public static void msg(String string) - { + public static void msg(String string) { lock.lock(); String msg = ChatColor.GREEN + "[Iris]: " + ChatColor.GRAY + string; - if(last.equals(msg)) - { + if (last.equals(msg)) { lock.unlock(); return; } last = msg; - Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> Bukkit.getConsoleSender().sendMessage(msg)); + Bukkit.getConsoleSender().sendMessage(msg); lock.unlock(); } - public static void warn(String string) - { + public static void warn(String string) { msg(ChatColor.YELLOW + string); } - public static void error(String string) - { + public static void error(String string) { msg(ChatColor.RED + string); } - public static void verbose(String string) - { + public static void verbose(String string) { msg(ChatColor.GRAY + string); } - public static void success(String string) - { + public static void success(String string) { msg(ChatColor.GREEN + string); } - public static void info(String string) - { + public static void info(String string) { msg(ChatColor.WHITE + string); } - public void hit(long hits2) - { + public void hit(long hits2) { hits.put(hits2); } } diff --git a/src/main/java/com/volmit/iris/NoiseView.java b/src/main/java/com/volmit/iris/NoiseView.java index dc46715f5..d13be0b17 100644 --- a/src/main/java/com/volmit/iris/NoiseView.java +++ b/src/main/java/com/volmit/iris/NoiseView.java @@ -56,6 +56,8 @@ public class NoiseView extends JPanel implements MouseWheelListener { double lx = Double.MAX_VALUE; double lz = Double.MAX_VALUE; + double tz = 1D; + double t = 1D; public NoiseView() { @@ -82,7 +84,13 @@ public class NoiseView extends JPanel implements MouseWheelListener { } public void mouseWheelMoved(MouseWheelEvent e) { + int notches = e.getWheelRotation(); + if (e.isControlDown()) { + t = t + ((0.001 * t) * notches); + return; + } + scale = scale + ((0.044 * scale) * notches); scale = scale < 0.00001 ? 0.00001 : scale; } @@ -98,6 +106,14 @@ public class NoiseView extends JPanel implements MouseWheelListener { ascale += Math.abs(ascale - scale) * 0.16; } + if (t < tz) { + tz -= Math.abs(t - tz) * 0.29; + } + + if (t > tz) { + tz += Math.abs(tz - t) * 0.29; + } + if (ox < oxp) { oxp -= Math.abs(ox - oxp) * 0.16; } @@ -134,8 +150,7 @@ public class NoiseView extends JPanel implements MouseWheelListener { int xx = x; gx.queue("a", () -> { for (int z = 0; z < getParent().getHeight(); z += accuracy) { - double n = cng.noise((xx * ascale) + oxp, Math.sin((double) M.ms() / 20000D) * 800D, - (z * ascale) + ozp); + double n = cng.noise((xx * ascale) + oxp, tz, (z * ascale) + ozp); if (n > 1 || n < 0) { System.out.println("EXCEEDED " + n); @@ -162,6 +177,8 @@ public class NoiseView extends JPanel implements MouseWheelListener { } p.end(); + + t += 1D; r.put(p.getMilliseconds()); EventQueue.invokeLater(() -> { repaint(); diff --git a/src/main/java/com/volmit/iris/gen/BiomeChunkGenerator.java b/src/main/java/com/volmit/iris/gen/BiomeChunkGenerator.java index 5ac43a217..5a7d16584 100644 --- a/src/main/java/com/volmit/iris/gen/BiomeChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/BiomeChunkGenerator.java @@ -13,7 +13,6 @@ import com.volmit.iris.object.IrisGenerator; import com.volmit.iris.object.IrisRegion; import com.volmit.iris.util.BiomeResult; import com.volmit.iris.util.ChronoLatch; -import com.volmit.iris.util.ChunkPosition; import com.volmit.iris.util.IrisInterpolation; import com.volmit.iris.util.IrisLock; import com.volmit.iris.util.KList; @@ -26,68 +25,39 @@ import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) -public abstract class BiomeChunkGenerator extends DimensionChunkGenerator -{ +public abstract class BiomeChunkGenerator extends DimensionChunkGenerator { protected IrisLock regLock; private KMap generators; private KMap ceilingGenerators; protected GenLayerBiome glBiome; protected CNG masterFracture; - private KMap biomeHitCache; - private KMap ceilingBiomeHitCache; protected ChronoLatch cwarn = new ChronoLatch(1000); - private IrisBiome[] biomeCache; - public BiomeChunkGenerator(String dimensionName) - { + public BiomeChunkGenerator(String dimensionName) { super(dimensionName); generators = new KMap<>(); ceilingGenerators = new KMap<>(); regLock = new IrisLock("BiomeChunkGenerator"); - biomeHitCache = new KMap<>(); - ceilingBiomeHitCache = new KMap<>(); - biomeCache = new IrisBiome[256]; } - public void onInit(World world, RNG rng) - { + public void onInit(World world, RNG rng) { super.onInit(world, rng); loadGenerators(); glBiome = new GenLayerBiome(this, masterRandom.nextParallelRNG(1)); masterFracture = CNG.signature(rng.nextParallelRNG(13)).scale(0.12); } - protected IrisBiome getCachedInternalBiome(int x, int z) - { - return biomeCache[(z << 4) | x]; - } - - protected void cacheInternalBiome(int x, int z, IrisBiome b) - { - biomeCache[(z << 4) | x] = b; - } - - public KMap getBiomeHitCache() - { - return getDimension().isInverted() ? ceilingBiomeHitCache : biomeHitCache; - } - @Override - public void onHotload() - { + public void onHotload() { super.onHotload(); - biomeHitCache = new KMap<>(); - ceilingBiomeHitCache = new KMap<>(); loadGenerators(); } - public void registerGenerator(IrisGenerator g, IrisDimension dim) - { + public void registerGenerator(IrisGenerator g, IrisDimension dim) { KMap generators = dim.isInverted() ? ceilingGenerators : this.generators; regLock.lock(); - if(g.getLoadKey() == null || generators.containsKey(g.getLoadKey())) - { + if (g.getLoadKey() == null || generators.containsKey(g.getLoadKey())) { regLock.unlock(); return; } @@ -96,98 +66,83 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator generators.put(g.getLoadKey(), g); } - protected KMap getGenerators() - { + protected KMap getGenerators() { return getDimension().isInverted() ? ceilingGenerators : generators; } - protected double getBiomeHeight(double rx, double rz, int x, int z) - { + protected double getBiomeHeight(double rx, double rz, int x, int z) { double h = 0; - for(IrisGenerator i : getGenerators().values()) - { + for (IrisGenerator i : getGenerators().values()) { h += interpolateGenerator(rx, rz, i); } return h; } - protected double interpolateGenerator(double rx, double rz, IrisGenerator gen) - { - double hi = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> - { - try - { - IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome(); + protected double interpolateGenerator(double rx, double rz, IrisGenerator gen) { + double hi = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), + (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> { + try { + IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome(); + + for (IrisBiomeGeneratorLink i : b.getGenerators()) { + if (i.getGenerator().equals(gen.getLoadKey())) { + return i.getMax(); + } + } - for(IrisBiomeGeneratorLink i : b.getGenerators()) - { - if(i.getGenerator().equals(gen.getLoadKey())) - { - return i.getMax(); } - } - } - - catch(Throwable e) - { - Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " + gen.getLoadKey()); - } - return 0; - }); - - double lo = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> - { - try - { - IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome(); - - for(IrisBiomeGeneratorLink i : b.getGenerators()) - { - if(i.getGenerator().equals(gen.getLoadKey())) - { - return i.getMin(); + catch (Throwable e) { + Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " + + gen.getLoadKey()); } - } - } + return 0; + }); - catch(Throwable e) - { - Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " + gen.getLoadKey()); - } + double lo = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), + (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> { + try { + IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome(); - return 0; - }); + for (IrisBiomeGeneratorLink i : b.getGenerators()) { + if (i.getGenerator().equals(gen.getLoadKey())) { + return i.getMin(); + } + } + } + + catch (Throwable e) { + Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " + + gen.getLoadKey()); + } + + return 0; + }); return M.lerp(lo, hi, gen.getHeight(rx, rz, world.getSeed() + 239945)); } - protected void loadGenerators() - { + protected void loadGenerators() { generators.clear(); ceilingGenerators.clear(); loadGenerators(((CeilingChunkGenerator) this).getFloorDimension()); loadGenerators(((CeilingChunkGenerator) this).getCeilingDimension()); } - protected void loadGenerators(IrisDimension dim) - { - if(dim == null) - { + protected void loadGenerators(IrisDimension dim) { + if (dim == null) { return; } KList touch = new KList<>(); KList loadQueue = new KList<>(); - for(String i : dim.getRegions()) - { + for (String i : dim.getRegions()) { IrisRegion r = loadRegion(i); - if(r != null) - { + if (r != null) { loadQueue.addAll(r.getLandBiomes()); loadQueue.addAll(r.getSeaBiomes()); loadQueue.addAll(r.getShoreBiomes()); @@ -196,12 +151,10 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator } } - while(!loadQueue.isEmpty()) - { + while (!loadQueue.isEmpty()) { String next = loadQueue.pop(); - if(!touch.contains(next)) - { + if (!touch.contains(next)) { touch.add(next); IrisBiome biome = loadBiome(next); biome.getGenerators().forEach((i) -> registerGenerator(i.getCachedGenerator(this), dim)); @@ -210,37 +163,31 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator } } - public IrisRegion sampleRegion(int x, int z) - { + public IrisRegion sampleRegion(int x, int z) { + double wx = getModifiedX(x, z); double wz = getModifiedZ(x, z); return glBiome.getRegion(wx, wz); } - public BiomeResult sampleBiome(int x, int z) - { - if(!getDimension().getFocus().equals("")) - { + public BiomeResult sampleBiome(int x, int z) { + if (!getDimension().getFocus().equals("")) { IrisBiome biome = loadBiome(getDimension().getFocus()); - for(String i : getDimension().getRegions()) - { + for (String i : getDimension().getRegions()) { IrisRegion reg = loadRegion(i); - if(reg.getLandBiomes().contains(biome.getLoadKey())) - { + if (reg.getLandBiomes().contains(biome.getLoadKey())) { biome.setInferredType(InferredType.LAND); break; } - if(reg.getSeaBiomes().contains(biome.getLoadKey())) - { + if (reg.getSeaBiomes().contains(biome.getLoadKey())) { biome.setInferredType(InferredType.SEA); break; } - if(reg.getShoreBiomes().contains(biome.getLoadKey())) - { + if (reg.getShoreBiomes().contains(biome.getLoadKey())) { biome.setInferredType(InferredType.SHORE); break; } @@ -249,18 +196,10 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator return new BiomeResult(biome, 0); } - ChunkPosition pos = new ChunkPosition(x, z); - - if(getBiomeHitCache().containsKey(pos)) - { - return getBiomeHitCache().get(pos); - } - double wx = getModifiedX(x, z); double wz = getModifiedZ(x, z); IrisRegion region = glBiome.getRegion(wx, wz); BiomeResult res = glBiome.generateRegionData(wx, wz, x, z, region); - getBiomeHitCache().put(pos, res); return res; } diff --git a/src/main/java/com/volmit/iris/gen/ContextualChunkGenerator.java b/src/main/java/com/volmit/iris/gen/ContextualChunkGenerator.java index 82b4eed19..71e983ef5 100644 --- a/src/main/java/com/volmit/iris/gen/ContextualChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/ContextualChunkGenerator.java @@ -270,7 +270,7 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements @Override public ChunkData generateChunkData(World world, Random no, int x, int z, BiomeGrid biomeGrid) { - hlock.getLock(); + hlock.lock(); if (!dev) { pregenDone = true; fastPregen = false; diff --git a/src/main/java/com/volmit/iris/gen/IrisChunkGenerator.java b/src/main/java/com/volmit/iris/gen/IrisChunkGenerator.java index 5f463b220..1953d6f91 100644 --- a/src/main/java/com/volmit/iris/gen/IrisChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/IrisChunkGenerator.java @@ -123,11 +123,7 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon e.printStackTrace(); } - setBiomeCache(null); setAvailableFilters(null); - setBiomeHitCache(null); - setCacheTrueBiome(null); - setCacheHeightMap(null); setCeilingSliverCache(null); setSliverCache(null); Iris.info("Closing Iris Dimension " + getWorld().getName()); diff --git a/src/main/java/com/volmit/iris/gen/ParallaxChunkGenerator.java b/src/main/java/com/volmit/iris/gen/ParallaxChunkGenerator.java index 41af24270..a052aabba 100644 --- a/src/main/java/com/volmit/iris/gen/ParallaxChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/ParallaxChunkGenerator.java @@ -33,8 +33,7 @@ import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) -public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator implements IObjectPlacer -{ +public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator implements IObjectPlacer { protected KMap sliverCache; protected AtomicWorldData parallaxMap; protected KMap ceilingSliverCache; @@ -44,8 +43,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple private IrisLock lockq = new IrisLock("ParallaxQueueLock"); private int sliverBuffer; - public ParallaxChunkGenerator(String dimensionName, int threads) - { + public ParallaxChunkGenerator(String dimensionName, int threads) { super(dimensionName, threads); sliverCache = new KMap<>(); ceilingSliverCache = new KMap<>(); @@ -53,49 +51,40 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple masterLock = new MasterLock(); } - public void onInit(World world, RNG rng) - { + public void onInit(World world, RNG rng) { super.onInit(world, rng); parallaxMap = new AtomicWorldData(world, "floor"); ceilingParallaxMap = new AtomicWorldData(world, "ceiling"); } - protected KMap getSliverCache() - { + protected KMap getSliverCache() { return getDimension().isInverted() ? ceilingSliverCache : sliverCache; } - protected void onClose() - { + protected void onClose() { super.onClose(); - try - { + try { parallaxMap.unloadAll(true); ceilingParallaxMap.unloadAll(true); } - catch(IOException e) - { + catch (IOException e) { e.printStackTrace(); } } @Override - public int getHighest(int x, int z) - { + public int getHighest(int x, int z) { return getHighest(x, z, false); } @Override - public int getHighest(int x, int z, boolean ignoreFluid) - { + public int getHighest(int x, int z, boolean ignoreFluid) { int h = (int) Math.round(ignoreFluid ? getTerrainHeight(x, z) : getTerrainWaterHeight(x, z)); - if(getDimension().isCarving() && h >= getDimension().getCarvingMin()) - { - while(getGlCarve().isCarved(x, h, z)) - { + if (getDimension().isCarving() && h >= getDimension().getCarvingMin()) { + while (getGlCarve().isCarved(x, h, z)) { h--; } @@ -106,28 +95,24 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple } @Override - public void set(int x, int y, int z, BlockData d) - { + public void set(int x, int y, int z, BlockData d) { getMasterLock().lock((x >> 4) + "." + (z >> 4)); getParallaxSliver(x, z).set(y, d); getMasterLock().unlock((x >> 4) + "." + (z >> 4)); } @Override - public BlockData get(int x, int y, int z) - { + public BlockData get(int x, int y, int z) { BlockData b = sampleSliver(x, z).getBlock().get(y); return b == null ? AIR : b; } @Override - public boolean isSolid(int x, int y, int z) - { + public boolean isSolid(int x, int y, int z) { return get(x, y, z).getMaterial().isSolid(); } - public AtomicSliver getParallaxSliver(int wx, int wz) - { + public AtomicSliver getParallaxSliver(int wx, int wz) { getMasterLock().lock("gpc"); getMasterLock().lock((wx >> 4) + "." + (wz >> 4)); AtomicSliverMap map = getParallaxChunk(wx >> 4, wz >> 4); @@ -138,30 +123,24 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple return sliver; } - public boolean isParallaxGenerated(int x, int z) - { + public boolean isParallaxGenerated(int x, int z) { return getParallaxChunk(x, z).isParallaxGenerated(); } - public boolean isWorldGenerated(int x, int z) - { + public boolean isWorldGenerated(int x, int z) { return getParallaxChunk(x, z).isWorldGenerated(); } - public AtomicWorldData getParallaxMap() - { + public AtomicWorldData getParallaxMap() { return getDimension().isInverted() ? ceilingParallaxMap : parallaxMap; } - public AtomicSliverMap getParallaxChunk(int x, int z) - { - try - { + public AtomicSliverMap getParallaxChunk(int x, int z) { + try { return getParallaxMap().loadChunk(x, z); } - catch(IOException e) - { + catch (IOException e) { fail(e); } @@ -169,19 +148,16 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple } @Override - protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap) - { - if(getSliverCache().size() > 20000) - { + protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, + BiomeMap biomeMap) { + if (getSliverCache().size() > 20000) { getSliverCache().clear(); } super.onPostGenerate(random, x, z, data, grid, height, biomeMap); PrecisionStopwatch p = PrecisionStopwatch.start(); - getBiomeHitCache().clear(); - if(getDimension().isPlaceObjects()) - { + if (getDimension().isPlaceObjects()) { onGenerateParallax(random, x, z); getParallaxChunk(x, z).inject(data); setSliverBuffer(getSliverCache().size()); @@ -196,58 +172,50 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple getData().getObjectLoader().clean(); } - public IrisStructureResult getStructure(int x, int y, int z) - { + public IrisStructureResult getStructure(int x, int y, int z) { IrisBiome b = sampleTrueBiome(x, z).getBiome(); IrisRegion r = sampleRegion(x, z); RNG ro = getMasterRandom().nextParallelRNG(496888 + (x >> 4) + (z >> 4)); int h = (int) Math.round(getTerrainHeight(x, z)); KList p = new KList<>(); - for(IrisStructurePlacement i : r.getStructures()) - { - if(i.getHeight() > -1) - { - if(y >= i.getHeight() && y <= i.getHeight() + (i.getStructure(this).getGridHeight() * i.getStructure(this).getMaxLayers())) - { + for (IrisStructurePlacement i : r.getStructures()) { + if (i.getHeight() > -1) { + if (y >= i.getHeight() && y <= i.getHeight() + + (i.getStructure(this).getGridHeight() * i.getStructure(this).getMaxLayers())) { p.add(i); } } - else if(y >= h && y <= i.getStructure(this).getGridHeight() + h) - { + else if (y >= h && y <= i.getStructure(this).getGridHeight() + h) { p.add(i); } } - for(IrisStructurePlacement i : b.getStructures()) - { - if(i.getHeight() > -1) - { - if(y >= i.getHeight() && y <= i.getHeight() + (i.getStructure(this).getGridHeight() * i.getStructure(this).getMaxLayers())) - { + for (IrisStructurePlacement i : b.getStructures()) { + if (i.getHeight() > -1) { + if (y >= i.getHeight() && y <= i.getHeight() + + (i.getStructure(this).getGridHeight() * i.getStructure(this).getMaxLayers())) { p.add(i); } } - else if(y >= h && y <= i.getStructure(this).getGridHeight() + h) - { + else if (y >= h && y <= i.getStructure(this).getGridHeight() + h) { p.add(i); } } - for(IrisStructurePlacement i : p) - { - if(!i.hasStructure(ro, x, y, z)) - { + for (IrisStructurePlacement i : p) { + if (!i.hasStructure(ro, x, y, z)) { continue; } - int hv = (i.getHeight() == -1 ? 0 : i.getHeight()) + (Math.floorDiv(y, i.getStructure(this).getGridHeight()) * i.getStructure(this).getGridHeight()); - TileResult tile = i.getStructure(this).getTile(ro, Math.floorDiv(i.gridSize(this), x) * i.gridSize(this), hv, Math.floorDiv(i.gridSize(this), z) * i.gridSize(this)); + int hv = (i.getHeight() == -1 ? 0 : i.getHeight()) + + (Math.floorDiv(y, i.getStructure(this).getGridHeight()) * i.getStructure(this).getGridHeight()); + TileResult tile = i.getStructure(this).getTile(ro, Math.floorDiv(i.gridSize(this), x) * i.gridSize(this), + hv, Math.floorDiv(i.gridSize(this), z) * i.gridSize(this)); - if(tile != null && tile.getTile() != null) - { + if (tile != null && tile.getTile() != null) { return new IrisStructureResult(tile.getTile(), i.getStructure(this)); } } @@ -255,58 +223,52 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple return null; } - protected void onGenerateParallax(RNG random, int x, int z) - { + protected void onGenerateParallax(RNG random, int x, int z) { String key = "par." + x + "." + "z"; ChunkPosition rad = getDimension().getParallaxSize(this); KList q = new KList<>(); - for(int ii = x - (rad.getX() / 2); ii <= x + (rad.getX() / 2); ii++) - { + for (int ii = x - (rad.getX() / 2); ii <= x + (rad.getX() / 2); ii++) { int i = ii; - for(int jj = z - (rad.getZ() / 2); jj <= z + (rad.getZ() / 2); jj++) - { + for (int jj = z - (rad.getZ() / 2); jj <= z + (rad.getZ() / 2); jj++) { int j = jj; - if(isParallaxGenerated(ii, jj)) - { + if (isParallaxGenerated(ii, jj)) { continue; } - if(isWorldGenerated(ii, jj)) - { + if (isWorldGenerated(ii, jj)) { continue; } - getAccelerant().queue(key, () -> - { + getAccelerant().queue(key, () -> { IrisBiome b = sampleTrueBiome((i * 16) + 7, (j * 16) + 7).getBiome(); RNG ro = getMasterRandom().nextParallelRNG(496888 + i + j); int g = 1; - searching: for(IrisBiomeMutation k : getDimension().getMutations()) - { - for(int l = 0; l < k.getChecks(); l++) - { - IrisBiome sa = sampleTrueBiome(((i * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius()), ((j * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius())).getBiome(); - IrisBiome sb = sampleTrueBiome(((i * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius()), ((j * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius())).getBiome(); + searching: for (IrisBiomeMutation k : getDimension().getMutations()) { + for (int l = 0; l < k.getChecks(); l++) { + IrisBiome sa = sampleTrueBiome( + ((i * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius()), + ((j * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius())).getBiome(); + IrisBiome sb = sampleTrueBiome( + ((i * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius()), + ((j * 16) + ro.nextInt(16)) + ro.i(-k.getRadius(), k.getRadius())).getBiome(); - if(sa.getLoadKey().equals(sb.getLoadKey())) - { + if (sa.getLoadKey().equals(sb.getLoadKey())) { continue; } - if(k.getRealSideA(this).contains(sa.getLoadKey()) && k.getRealSideB(this).contains(sb.getLoadKey())) - { - for(IrisObjectPlacement m : k.getObjects()) - { + if (k.getRealSideA(this).contains(sa.getLoadKey()) + && k.getRealSideB(this).contains(sb.getLoadKey())) { + for (IrisObjectPlacement m : k.getObjects()) { int gg = g++; lockq.lock(); - q.add(() -> - { - placeObject(m, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1569962)); + q.add(() -> { + placeObject(m, i, j, random.nextParallelRNG( + (34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1569962)); }); lockq.unlock(); } @@ -318,61 +280,52 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple IrisRegion r = sampleRegion((i * 16) + 7, (j * 16) + 7); - for(IrisStructurePlacement k : r.getStructures()) - { + for (IrisStructurePlacement k : r.getStructures()) { lockq.lock(); - q.add(() -> - { + q.add(() -> { k.place(this, random.nextParallelRNG(2228), i, j); }); lockq.unlock(); } - for(IrisStructurePlacement k : b.getStructures()) - { + for (IrisStructurePlacement k : b.getStructures()) { lockq.lock(); - q.add(() -> - { + q.add(() -> { k.place(this, random.nextParallelRNG(-22228), i, j); }); lockq.unlock(); } - for(IrisObjectPlacement k : b.getObjects()) - { + for (IrisObjectPlacement k : b.getObjects()) { int gg = g++; lockq.lock(); - q.add(() -> - { - placeObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 3569222)); + q.add(() -> { + placeObject(k, i, j, random + .nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 3569222)); }); lockq.unlock(); } - if(getDimension().isCaves()) - { + if (getDimension().isCaves()) { int bx = (i * 16) + ro.nextInt(16); int bz = (j * 16) + ro.nextInt(16); IrisBiome biome = sampleCaveBiome(bx, bz).getBiome(); - if(biome == null) - { + if (biome == null) { return; } - if(biome.getObjects().isEmpty()) - { + if (biome.getObjects().isEmpty()) { return; } - for(IrisObjectPlacement k : biome.getObjects()) - { + for (IrisObjectPlacement k : biome.getObjects()) { int gg = g++; lockq.lock(); - q.add(() -> - { - placeCaveObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1869322)); + q.add(() -> { + placeCaveObject(k, i, j, random + .nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1869322)); }); lockq.unlock(); } @@ -386,8 +339,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple getAccelerant().waitFor(key); lockq.lock(); - for(NastyRunnable i : q) - { + for (NastyRunnable i : q) { getAccelerant().queue(key + "-obj", i); } lockq.unlock(); @@ -395,39 +347,34 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple getAccelerant().waitFor(key + "-obj"); } - public void placeObject(IrisObjectPlacement o, int x, int z, RNG rng) - { - for(int i = 0; i < o.getTriesForChunk(rng); i++) - { + public void placeObject(IrisObjectPlacement o, int x, int z, RNG rng) { + for (int i = 0; i < o.getTriesForChunk(rng); i++) { rng = rng.nextParallelRNG((i * 3 + 8) - 23040); o.getSchematic(this, rng).place((x * 16) + rng.nextInt(16), (z * 16) + rng.nextInt(16), this, o, rng); } } - public void placeCaveObject(IrisObjectPlacement o, int x, int z, RNG rng) - { - for(int i = 0; i < o.getTriesForChunk(rng); i++) - { + public void placeCaveObject(IrisObjectPlacement o, int x, int z, RNG rng) { + for (int i = 0; i < o.getTriesForChunk(rng); i++) { rng = rng.nextParallelRNG((i * 3 + 8) - 23040); int xx = (x * 16) + rng.nextInt(16); int zz = (z * 16) + rng.nextInt(16); KList res = getCaves(xx, zz); - if(res.isEmpty()) - { + if (res.isEmpty()) { continue; } - o.getSchematic(this, rng).place(xx, res.get(rng.nextParallelRNG(29345 * (i + 234)).nextInt(res.size())).getFloor() + 2, zz, this, o, rng); + o.getSchematic(this, rng).place(xx, + res.get(rng.nextParallelRNG(29345 * (i + 234)).nextInt(res.size())).getFloor() + 2, zz, this, o, + rng); } } - public AtomicSliver sampleSliver(int x, int z) - { + public AtomicSliver sampleSliver(int x, int z) { ChunkPosition key = new ChunkPosition(x, z); - if(getSliverCache().containsKey(key)) - { + if (getSliverCache().containsKey(key)) { return getSliverCache().get(key); } @@ -439,8 +386,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple } @Override - public boolean isPreventingDecay() - { + public boolean isPreventingDecay() { return getDimension().isPreventLeafDecay(); } } diff --git a/src/main/java/com/volmit/iris/gen/ParallelChunkGenerator.java b/src/main/java/com/volmit/iris/gen/ParallelChunkGenerator.java index 71cf3db19..96becef7d 100644 --- a/src/main/java/com/volmit/iris/gen/ParallelChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/ParallelChunkGenerator.java @@ -17,57 +17,54 @@ import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) -public abstract class ParallelChunkGenerator extends BiomeChunkGenerator -{ +public abstract class ParallelChunkGenerator extends BiomeChunkGenerator { private GroupedExecutor accelerant; private int threads; - protected boolean unsafe; + protected boolean safe; protected int cacheX; protected int cacheZ; private IrisLock genlock; protected boolean cachingAllowed; - public ParallelChunkGenerator(String dimensionName, int threads) - { + public ParallelChunkGenerator(String dimensionName, int threads) { super(dimensionName); - unsafe = false; + safe = false; cacheX = 0; cacheZ = 0; this.threads = threads; genlock = new IrisLock("ParallelGenLock"); + cachingAllowed = false; } - public void changeThreadCount(int tc) - { + public void changeThreadCount(int tc) { threads = tc; GroupedExecutor e = accelerant; accelerant = new GroupedExecutor(threads, Thread.NORM_PRIORITY, "Iris Generator - " + world.getName()); Iris.executors.add(accelerant); - if(e != null) - { + if (e != null) { e.close(); } } - protected abstract void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled); + protected abstract void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, + BiomeMap biomeMap, boolean sampled); - protected void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap) - { + protected void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, + BiomeMap biomeMap) { onGenerateColumn(cx, cz, wx, wz, x, z, sliver, biomeMap, false); } protected abstract int onSampleColumnHeight(int cx, int cz, int wx, int wz, int x, int z); - protected abstract void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap); + protected abstract void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, + BiomeMap biomeMap); - protected int sampleHeight(int x, int z) - { + protected int sampleHeight(int x, int z) { return onSampleColumnHeight(x >> 4, z >> 4, x, z, x & 15, z & 15); } - protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) - { + protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) { genlock.lock(); cacheX = x; cacheZ = z; @@ -78,28 +75,25 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator BiomeMap biomeMap = new BiomeMap(); int ii, jj; - for(ii = 0; ii < 16; ii++) - { + for (ii = 0; ii < 16; ii++) { int i = ii; int wx = (x * 16) + i; - for(jj = 0; jj < 16; jj++) - { + for (jj = 0; jj < 16; jj++) { int j = jj; int wz = (z * 16) + j; AtomicSliver sliver = map.getSliver(i, j); - accelerant.queue(key, () -> - { + accelerant.queue(key, () -> { onGenerateColumn(x, z, wx, wz, i, j, sliver, biomeMap); }); } } setCachingAllowed(true); - setUnsafe(true); + setSafe(false); accelerant.waitFor(key); - setUnsafe(false); + setSafe(true); setCachingAllowed(false); map.write(data, grid, height); getMetrics().getTerrain().put(p.getMilliseconds()); @@ -108,26 +102,18 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator genlock.unlock(); } - protected void onClose() - { + protected void onClose() { accelerant.close(); Iris.executors.remove(accelerant); } - public void onInit(World world, RNG rng) - { + public void onInit(World world, RNG rng) { super.onInit(world, rng); changeThreadCount(threads); } - public boolean isSafe() - { - return !unsafe; - } - @Override - public boolean isParallelCapable() - { + public boolean isParallelCapable() { return false; } } diff --git a/src/main/java/com/volmit/iris/gen/PostBlockChunkGenerator.java b/src/main/java/com/volmit/iris/gen/PostBlockChunkGenerator.java index 0c08a4416..4b23b20a4 100644 --- a/src/main/java/com/volmit/iris/gen/PostBlockChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/PostBlockChunkGenerator.java @@ -18,8 +18,7 @@ import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) -public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator implements IPostBlockAccess -{ +public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator implements IPostBlockAccess { protected boolean generatingCeiling = false; protected boolean ceilingCached = false; protected IrisDimension cacheCeiling = null; @@ -33,27 +32,22 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp private int minPhase; private int maxPhase; - public PostBlockChunkGenerator(String dimensionName, int threads) - { + public PostBlockChunkGenerator(String dimensionName, int threads) { super(dimensionName, threads); availableFilters = new KList<>(); postKey = "post-" + dimensionName; lock = new IrisLock("PostChunkGenerator"); } - public void onInit(World world, RNG rng) - { + public void onInit(World world, RNG rng) { super.onInit(world, rng); - for(Class i : Iris.postProcessors) - { - try - { + for (Class i : Iris.postProcessors) { + try { availableFilters.add(i.getConstructor(PostBlockChunkGenerator.class).newInstance(this)); } - catch(Throwable e) - { + catch (Throwable e) { Iris.error("Failed to initialize post processor: " + i.getCanonicalName()); fail(e); } @@ -61,12 +55,10 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp } @Override - protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) - { + protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) { super.onGenerate(random, x, z, data, grid); - if(!getDimension().isPostProcessing()) - { + if (!getDimension().isPostProcessing()) { return; } @@ -77,24 +69,18 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp int rx, i, j; PrecisionStopwatch p = PrecisionStopwatch.start(); - for(int h = getMinPhase(); h <= getMaxPhase(); h++) - { - for(i = 0; i < 16; i++) - { + for (int h = getMinPhase(); h <= getMaxPhase(); h++) { + for (i = 0; i < 16; i++) { rx = (x << 4) + i; - for(j = 0; j < 16; j++) - { + for (j = 0; j < 16; j++) { int rxx = rx; int rzz = (z << 4) + j; int hh = h; - getAccelerant().queue("post", () -> - { - for(IrisPostBlockFilter f : filters) - { - if(f.getPhase() == hh) - { + getAccelerant().queue("post", () -> { + for (IrisPostBlockFilter f : filters) { + if (f.getPhase() == hh) { f.onPost(rxx, rzz); } } @@ -104,19 +90,14 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp getAccelerant().waitFor("post"); - for(IrisPostBlockFilter f : filters) - { - if(f.getPhase() == h) - { - while(f.getQueue().size() > 0) - { - try - { + for (IrisPostBlockFilter f : filters) { + if (f.getPhase() == h) { + while (f.getQueue().size() > 0) { + try { f.getQueue().pop().run(); } - catch(Throwable e) - { + catch (Throwable e) { } } @@ -128,19 +109,15 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp getMetrics().getPost().put(p.getMilliseconds()); } - public IrisPostBlockFilter createProcessor(String processor, int phase) - { - for(IrisPostBlockFilter i : availableFilters) - { - if(i.getKey().equals(processor)) - { - try - { - return i.getClass().getConstructor(PostBlockChunkGenerator.class, int.class).newInstance(this, phase); + public IrisPostBlockFilter createProcessor(String processor, int phase) { + for (IrisPostBlockFilter i : availableFilters) { + if (i.getKey().equals(processor)) { + try { + return i.getClass().getConstructor(PostBlockChunkGenerator.class, int.class).newInstance(this, + phase); } - catch(Throwable e) - { + catch (Throwable e) { Iris.error("Failed initialize find post processor: " + processor); fail(e); } @@ -153,24 +130,20 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp } @Override - public void updateHeight(int x, int z, int h) - { - if(x >> 4 == currentPostX && z >> 4 == currentPostZ) - { - getCacheHeightMap()[((z & 15) << 4) | (x & 15)] = h; + public void updateHeight(int x, int z, int h) { + if (x >> 4 == currentPostX && z >> 4 == currentPostZ) { + //cacheHeight(x, z, h); } - else - { - Iris.error("Invalid Heightmap set! Chunk Currently at " + currentPostX + "," + currentPostZ + ". Attempted to place at " + (x >> 4) + " " + (z >> 4) + " which is bad."); + else { + Iris.error("Invalid Heightmap set! Chunk Currently at " + currentPostX + "," + currentPostZ + + ". Attempted to place at " + (x >> 4) + " " + (z >> 4) + " which is bad."); } } @Override - public BlockData getPostBlock(int x, int y, int z) - { - if(x >> 4 == currentPostX && z >> 4 == currentPostZ) - { + public BlockData getPostBlock(int x, int y, int z) { + if (x >> 4 == currentPostX && z >> 4 == currentPostZ) { lock.lock(); BlockData d = currentData.getBlockData(x & 15, y, z & 15); lock.unlock(); @@ -181,36 +154,31 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp } @Override - public void setPostBlock(int x, int y, int z, BlockData d) - { - if(x >> 4 == currentPostX && z >> 4 == currentPostZ) - { + public void setPostBlock(int x, int y, int z, BlockData d) { + if (x >> 4 == currentPostX && z >> 4 == currentPostZ) { lock.lock(); currentData.setBlock(x & 15, y, z & 15, d); lock.unlock(); } - else - { - Iris.warn("Post Block Overdraw: " + currentPostX + "," + currentPostZ + " into " + (x >> 4) + ", " + (z >> 4)); + else { + Iris.warn("Post Block Overdraw: " + currentPostX + "," + currentPostZ + " into " + (x >> 4) + ", " + + (z >> 4)); } } @Override - public int highestTerrainOrFluidBlock(int x, int z) - { + public int highestTerrainOrFluidBlock(int x, int z) { return getHighest(x, z, false); } @Override - public int highestTerrainBlock(int x, int z) - { + public int highestTerrainBlock(int x, int z) { return getHighest(x, z, true); } @Override - public KList caveFloors(int x, int z) - { + public KList caveFloors(int x, int z) { return getCaves(x, z); } } diff --git a/src/main/java/com/volmit/iris/gen/TerrainChunkGenerator.java b/src/main/java/com/volmit/iris/gen/TerrainChunkGenerator.java index b3d5327d8..f0e3fc87b 100644 --- a/src/main/java/com/volmit/iris/gen/TerrainChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/TerrainChunkGenerator.java @@ -6,7 +6,6 @@ import org.bukkit.block.data.Bisected; import org.bukkit.block.data.Bisected.Half; import org.bukkit.block.data.BlockData; -import com.volmit.iris.Iris; import com.volmit.iris.gen.atomics.AtomicSliver; import com.volmit.iris.gen.layer.GenLayerCarve; import com.volmit.iris.gen.layer.GenLayerCave; @@ -16,12 +15,11 @@ import com.volmit.iris.object.IrisBiome; import com.volmit.iris.object.IrisBiomeDecorator; import com.volmit.iris.object.IrisDepositGenerator; import com.volmit.iris.object.IrisRegion; +import com.volmit.iris.util.B; import com.volmit.iris.util.BiomeMap; import com.volmit.iris.util.BiomeResult; -import com.volmit.iris.util.B; import com.volmit.iris.util.CaveResult; import com.volmit.iris.util.HeightMap; -import com.volmit.iris.util.IrisLock; import com.volmit.iris.util.KList; import com.volmit.iris.util.M; import com.volmit.iris.util.RNG; @@ -37,16 +35,9 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator { private GenLayerCave glCave; private GenLayerCarve glCarve; private RNG rockRandom; - private int[] cacheHeightMap; - private BiomeResult[] cacheTrueBiome; - private IrisLock cacheLock; public TerrainChunkGenerator(String dimensionName, int threads) { super(dimensionName, threads); - cacheHeightMap = new int[256]; - cacheTrueBiome = new BiomeResult[256]; - cachingAllowed = true; - cacheLock = new IrisLock("TerrainCacheLock"); } public void onInit(World world, RNG rng) { @@ -68,6 +59,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator { } try { + int highestPlaced = 0; BlockData block; int fluidHeight = getDimension().getFluidHeight(); @@ -87,8 +79,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator { throw new RuntimeException("Null Biome!"); } - cacheBiome(cachingAllowed && !sampled, x, z, biomeResult, height); - cacheInternalBiome(cachingAllowed && !sampled, x, z, biome); KList layers = biome.generateLayers(rx, rz, masterRandom, height, height - getFluidHeight()); KList seaLayers = biome.isSea() ? biome.generateSeaLayers(rx, rz, masterRandom, fluidHeight - height) @@ -213,11 +203,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator { if (block.getMaterial().isSolid()) { decorateLand(biome, sliver, wx, Math.max(height, fluidHeight), wz, rx, rz, block); } - - // Update Height Map - if (!sampled && cachingAllowed && highestPlaced < height) { - cacheHeightMap[(z << 4) | x] = highestPlaced; - } } catch (Throwable e) { @@ -225,25 +210,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator { } } - protected void cacheInternalBiome(boolean b, int x, int z, IrisBiome bv) { - if (b) { - cacheInternalBiome(x, z, bv); - } - } - - private void cacheBiome(boolean b, int x, int z, BiomeResult biomeResult, int height) { - if (b) { - try { - cacheTrueBiome[(z << 4) | x] = biomeResult; - cacheHeightMap[(z << 4) | x] = height; - } - - catch (Throwable e) { - Iris.error("Failed to write cache at " + x + " " + z); - } - } - } - @Override protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) { super.onGenerate(random, x, z, data, grid); @@ -446,8 +412,9 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator { protected double getNoiseHeight(int rx, int rz) { double wx = getZoomed(rx); double wz = getZoomed(rz); + double h = getBiomeHeight(wx, wz, rx, rz); - return getBiomeHeight(wx, wz, rx, rz); + return h; } public BiomeResult sampleTrueBiomeBase(int x, int z, int height) { @@ -508,15 +475,18 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator { return sampleTrueBiome(x, z, getTerrainHeight(x, z)); } + @Override + public IrisRegion sampleRegion(int x, int z) { + IrisRegion r = super.sampleRegion(x, z); + + return r; + } + public BiomeResult sampleTrueBiome(int x, int z, double noise) { if (!getDimension().getFocus().equals("")) { return focus(); } - if (isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ) { - return cacheTrueBiome[((z & 15) << 4) | (x & 15)]; - } - double wx = getModifiedX(x, z); double wz = getModifiedZ(x, z); IrisRegion region = sampleRegion(x, z); @@ -558,10 +528,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator { } public double getTerrainHeight(int x, int z) { - if (isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ) { - return cacheHeightMap[((z & 15) << 4) | (x & 15)]; - } - return getNoiseHeight(x, z) + getFluidHeight(); } diff --git a/src/main/java/com/volmit/iris/gen/atomics/AtomicBiomeMap.java b/src/main/java/com/volmit/iris/gen/atomics/AtomicBiomeMap.java new file mode 100644 index 000000000..78c6c2566 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/atomics/AtomicBiomeMap.java @@ -0,0 +1,7 @@ +package com.volmit.iris.gen.atomics; + +import com.volmit.iris.object.IrisBiome; + +public class AtomicBiomeMap extends AtomicObjectMap { + +} diff --git a/src/main/java/com/volmit/iris/gen/atomics/AtomicDoubleMap.java b/src/main/java/com/volmit/iris/gen/atomics/AtomicDoubleMap.java new file mode 100644 index 000000000..b9575b245 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/atomics/AtomicDoubleMap.java @@ -0,0 +1,23 @@ +package com.volmit.iris.gen.atomics; + +import com.google.common.util.concurrent.AtomicDoubleArray; + +public class AtomicDoubleMap { + private final AtomicDoubleArray data; + + public AtomicDoubleMap() { + data = new AtomicDoubleArray(256); + } + + public double get(int x, int z) { + return data.get((z << 4) | x); + } + + public int getInt(int x, int z) { + return (int) Math.round(get(x, z)); + } + + public void set(int x, int z, double v) { + data.set((z << 4) | x, v); + } +} diff --git a/src/main/java/com/volmit/iris/gen/atomics/AtomicIntMap.java b/src/main/java/com/volmit/iris/gen/atomics/AtomicIntMap.java new file mode 100644 index 000000000..52fdc4d85 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/atomics/AtomicIntMap.java @@ -0,0 +1,19 @@ +package com.volmit.iris.gen.atomics; + +import java.util.concurrent.atomic.AtomicIntegerArray; + +public class AtomicIntMap { + private final AtomicIntegerArray data; + + public AtomicIntMap() { + data = new AtomicIntegerArray(256); + } + + public int get(int x, int z) { + return data.get((z << 4) | x); + } + + public void set(int x, int z, int v) { + data.set((z << 4) | x, v); + } +} diff --git a/src/main/java/com/volmit/iris/gen/atomics/AtomicObjectMap.java b/src/main/java/com/volmit/iris/gen/atomics/AtomicObjectMap.java new file mode 100644 index 000000000..f62da1a6a --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/atomics/AtomicObjectMap.java @@ -0,0 +1,19 @@ +package com.volmit.iris.gen.atomics; + +import java.util.concurrent.atomic.AtomicReferenceArray; + +public class AtomicObjectMap { + private final AtomicReferenceArray data; + + public AtomicObjectMap() { + data = new AtomicReferenceArray(256); + } + + public T get(int x, int z) { + return data.get((z << 4) | x); + } + + public void set(int x, int z, T v) { + data.set((z << 4) | x, v); + } +} diff --git a/src/main/java/com/volmit/iris/gen/atomics/AtomicRegionMap.java b/src/main/java/com/volmit/iris/gen/atomics/AtomicRegionMap.java new file mode 100644 index 000000000..669836046 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/atomics/AtomicRegionMap.java @@ -0,0 +1,7 @@ +package com.volmit.iris.gen.atomics; + +import com.volmit.iris.object.IrisRegion; + +public class AtomicRegionMap extends AtomicObjectMap { + +} diff --git a/src/main/java/com/volmit/iris/noise/FlatNoise.java b/src/main/java/com/volmit/iris/noise/FlatNoise.java new file mode 100644 index 000000000..b7c37a93d --- /dev/null +++ b/src/main/java/com/volmit/iris/noise/FlatNoise.java @@ -0,0 +1,22 @@ +package com.volmit.iris.noise; + +public class FlatNoise implements NoiseGenerator { + public FlatNoise(long seed) { + + } + + @Override + public double noise(double x) { + return 0.5; + } + + @Override + public double noise(double x, double z) { + return 0.5; + } + + @Override + public double noise(double x, double y, double z) { + return 0.5; + } +} diff --git a/src/main/java/com/volmit/iris/noise/NoiseType.java b/src/main/java/com/volmit/iris/noise/NoiseType.java index 6386fa36d..c789e799a 100644 --- a/src/main/java/com/volmit/iris/noise/NoiseType.java +++ b/src/main/java/com/volmit/iris/noise/NoiseType.java @@ -8,6 +8,7 @@ public enum NoiseType { FRACTAL_BILLOW_PERLIN(seed -> new FractalBillowPerlinNoise(seed)), FRACTAL_FBM_SIMPLEX(seed -> new FractalFBMSimplexNoise(seed)), FRACTAL_RIGID_MULTI_SIMPLEX(seed -> new FractalRigidMultiSimplexNoise(seed)), + FLAT(seed -> new FlatNoise(seed)), CELLULAR(seed -> new CellularNoise(seed)), GLOB(seed -> new GlobNoise(seed)), CUBIC(seed -> new CubicNoise(seed)), diff --git a/src/main/java/com/volmit/iris/object/IrisObjectTranslate.java b/src/main/java/com/volmit/iris/object/IrisObjectTranslate.java index 9840a0057..72d58b084 100644 --- a/src/main/java/com/volmit/iris/object/IrisObjectTranslate.java +++ b/src/main/java/com/volmit/iris/object/IrisObjectTranslate.java @@ -14,8 +14,8 @@ import lombok.Data; @Data public class IrisObjectTranslate { - @MinNumber(-8) - @MaxNumber(8) + @MinNumber(-128) + @MaxNumber(128) @DontObfuscate @Desc("The x shift in blocks") private int x = 0; @@ -27,8 +27,8 @@ public class IrisObjectTranslate @Desc("The x shift in blocks") private int y = 0; - @MinNumber(-8) - @MaxNumber(8) + @MinNumber(-128) + @MaxNumber(128) @DontObfuscate @Desc("The x shift in blocks") private int z = 0; diff --git a/src/main/java/com/volmit/iris/object/NoiseStyle.java b/src/main/java/com/volmit/iris/object/NoiseStyle.java index 7fa70e538..79c308ade 100644 --- a/src/main/java/com/volmit/iris/object/NoiseStyle.java +++ b/src/main/java/com/volmit/iris/object/NoiseStyle.java @@ -391,6 +391,10 @@ public enum NoiseStyle { @Desc("Vascular noise gets higher as the position nears a cell border.") @DontObfuscate VASCULAR(rng -> new CNG(rng, NoiseType.VASCULAR, 1D, 1)), + + @Desc("It always returns 0.5") + @DontObfuscate + FLAT(rng -> new CNG(rng, NoiseType.FLAT, 1D, 1)), @Desc("Vascular noise gets higher as the position nears a cell border. Cells are distorted using Iris styled wispy noise.") @DontObfuscate