From 7b94d753b853d1dee8a8447d39ff98b48d7b9cce Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Thu, 20 Aug 2020 22:44:16 -0400 Subject: [PATCH] Block Updates --- src/main/java/com/volmit/iris/Iris.java | 1 + .../iris/gen/ParallaxChunkGenerator.java | 6 +- .../iris/gen/ParallelChunkGenerator.java | 4 +- .../iris/gen/TerrainChunkGenerator.java | 11 ++-- .../volmit/iris/gen/atomics/AtomicSliver.java | 58 ++++++++++++++----- 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index b56533dba..c4f56c5d6 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -168,6 +168,7 @@ public class Iris extends MortarPlugin implements BoardProvider 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); + lines.add(ChatColor.GREEN + "Heightmap" + ChatColor.GRAY + ": " + (int) g.getTerrainHeight(x, z)); if(er != null && b != null) { diff --git a/src/main/java/com/volmit/iris/gen/ParallaxChunkGenerator.java b/src/main/java/com/volmit/iris/gen/ParallaxChunkGenerator.java index 172f9b263..effe61814 100644 --- a/src/main/java/com/volmit/iris/gen/ParallaxChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/ParallaxChunkGenerator.java @@ -164,14 +164,14 @@ 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) + protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap, AtomicSliverMap map) { if(getSliverCache().size() > 20000) { getSliverCache().clear(); } - super.onPostGenerate(random, x, z, data, grid, height, biomeMap); + super.onPostGenerate(random, x, z, data, grid, height, biomeMap, map); PrecisionStopwatch p = PrecisionStopwatch.start(); if(getDimension().isPlaceObjects()) @@ -185,7 +185,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple p.end(); getMetrics().getParallax().put(p.getMilliseconds()); - super.onPostParallaxPostGenerate(random, x, z, data, grid, height, biomeMap); + super.onPostParallaxPostGenerate(random, x, z, data, grid, height, biomeMap, map); getParallaxMap().clean(ticks); getData().getObjectLoader().clean(); } diff --git a/src/main/java/com/volmit/iris/gen/ParallelChunkGenerator.java b/src/main/java/com/volmit/iris/gen/ParallelChunkGenerator.java index af82c9150..53b09e28c 100644 --- a/src/main/java/com/volmit/iris/gen/ParallelChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/ParallelChunkGenerator.java @@ -55,7 +55,7 @@ public abstract class ParallelChunkGenerator extends DimensionChunkGenerator 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, AtomicSliverMap map); protected int sampleHeight(int x, int z) { @@ -96,7 +96,7 @@ public abstract class ParallelChunkGenerator extends DimensionChunkGenerator map.write(data, grid, height); getMetrics().getTerrain().put(p.getMilliseconds()); p = PrecisionStopwatch.start(); - onPostGenerate(random, x, z, data, grid, height, biomeMap); + onPostGenerate(random, x, z, data, grid, height, biomeMap, map); } protected void onClose() diff --git a/src/main/java/com/volmit/iris/gen/TerrainChunkGenerator.java b/src/main/java/com/volmit/iris/gen/TerrainChunkGenerator.java index 11ad4a71e..0e7f9f5b6 100644 --- a/src/main/java/com/volmit/iris/gen/TerrainChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/TerrainChunkGenerator.java @@ -9,6 +9,7 @@ import org.bukkit.block.data.BlockData; import com.volmit.iris.Iris; import com.volmit.iris.gen.atomics.AtomicSliver; +import com.volmit.iris.gen.atomics.AtomicSliverMap; import com.volmit.iris.gen.layer.GenLayerBiome; import com.volmit.iris.gen.layer.GenLayerCarve; import com.volmit.iris.gen.layer.GenLayerCave; @@ -88,7 +89,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator try { - int highestPlaced = 0; BlockData block; int fluidHeight = getDimension().getFluidHeight(); double ox = getModifiedX(rx, rz); @@ -198,7 +198,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator // Set block and update heightmaps sliver.set(k, block); - highestPlaced = Math.max(highestPlaced, k); // Decorate underwater surface if(!cavernSurface && (k == height && B.isSolid(block.getMaterial()) && k < fluidHeight)) @@ -479,17 +478,17 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator } @Override - protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap) + protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap, AtomicSliverMap map) { - onPreParallaxPostGenerate(random, x, z, data, grid, height, biomeMap); + onPreParallaxPostGenerate(random, x, z, data, grid, height, biomeMap, map); } - protected void onPreParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap) + protected void onPreParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap, AtomicSliverMap map) { } - protected void onPostParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap) + protected void onPostParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap, AtomicSliverMap map) { } diff --git a/src/main/java/com/volmit/iris/gen/atomics/AtomicSliver.java b/src/main/java/com/volmit/iris/gen/atomics/AtomicSliver.java index 1d85537d0..4b46f672d 100644 --- a/src/main/java/com/volmit/iris/gen/atomics/AtomicSliver.java +++ b/src/main/java/com/volmit/iris/gen/atomics/AtomicSliver.java @@ -16,6 +16,7 @@ import com.volmit.iris.util.HeightMap; import com.volmit.iris.util.IrisLock; import com.volmit.iris.util.KList; import com.volmit.iris.util.KMap; +import com.volmit.iris.util.KSet; import com.volmit.iris.util.M; import lombok.Data; @@ -27,6 +28,7 @@ public class AtomicSliver private KMap block; private KMap truebiome; private KMap biome; + private KSet update; private IrisLock lock = new IrisLock("Sliver"); private int highestBlock = 0; private int highestBiome = 0; @@ -40,6 +42,7 @@ public class AtomicSliver lock.setDisabled(true); this.x = x; this.z = z; + update = new KSet<>(); this.block = new KMap<>(); this.biome = new KMap<>(); this.truebiome = new KMap<>(); @@ -50,6 +53,21 @@ public class AtomicSliver return get(h).getMaterial(); } + public KSet getUpdatables() + { + return update; + } + + public void update(int y) + { + update.add(y); + } + + public void dontUpdate(int y) + { + update.remove(y); + } + public BlockData get(int h) { BlockData b = block.get(h); @@ -65,21 +83,8 @@ public class AtomicSliver public void set(int h, BlockData d) { - if(d == null) - { - return; - } - - lock.lock(); - block.put(h, d); - lock.unlock(); + setSilently(h, d); modified = true; - - if(d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(B.mat("CAVE_AIR"))) - { - return; - } - lock.lock(); highestBlock = h > highestBlock ? h : highestBlock; lock.unlock(); @@ -95,6 +100,17 @@ public class AtomicSliver lock.lock(); modified = true; block.put(h, d); + + if(B.isLit(d)) + { + update(h); + } + + else + { + dontUpdate(h); + } + lock.unlock(); } @@ -176,7 +192,9 @@ public class AtomicSliver this.block = new KMap(); int h = din.readByte() - Byte.MIN_VALUE; int p = din.readByte() - Byte.MIN_VALUE; + int u = din.readByte() - Byte.MIN_VALUE; KList palette = new KList(); + getUpdatables().clear(); highestBlock = h; for(int i = 0; i < p; i++) @@ -188,6 +206,12 @@ public class AtomicSliver { block.put(i, palette.get(din.readByte() - Byte.MIN_VALUE).clone()); } + + for(int i = 0; i <= u; i++) + { + update(din.readByte() - Byte.MIN_VALUE); + } + modified = false; lock.unlock(); } @@ -210,6 +234,7 @@ public class AtomicSliver } dos.writeByte(palette.size() + Byte.MIN_VALUE); + dos.writeByte(update.size() + Byte.MIN_VALUE); for(String i : palette) { @@ -223,6 +248,11 @@ public class AtomicSliver dos.writeByte(palette.indexOf(d) + Byte.MIN_VALUE); } + for(Integer i : getUpdatables()) + { + dos.writeByte(i + Byte.MIN_VALUE); + } + lock.unlock(); }