From 0d5e3a080c0024f86cff0035d0b0633625d40ee4 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Sat, 24 Jul 2021 09:42:19 -0400 Subject: [PATCH] Parallax fixes --- .../framework/EngineAssignedWorldManager.java | 10 +-- .../framework/EngineParallaxManager.java | 72 +++++++++---------- .../iris/engine/parallax/ParallaxRegion.java | 4 +- .../com/volmit/iris/util/math/Position2.java | 4 ++ 4 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java index ebd0794f4..353268453 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java @@ -39,35 +39,35 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent @EventHandler public void on(WorldSaveEvent e) { - if (e.getWorld().equals(getTarget().getWorld())) { + if (e.getWorld().equals(getTarget().getWorld().realWorld())) { onSave(); } } @EventHandler public void on(WorldUnloadEvent e) { - if (e.getWorld().equals(getTarget().getWorld())) { + if (e.getWorld().equals(getTarget().getWorld().realWorld())) { getEngine().close(); } } @EventHandler public void on(EntitySpawnEvent e) { - if (e.getEntity().getWorld().equals(getTarget().getWorld())) { + if (e.getEntity().getWorld().equals(getTarget().getWorld().realWorld())) { onEntitySpawn(e); } } @EventHandler public void on(BlockBreakEvent e) { - if (e.getPlayer().getWorld().equals(getTarget().getWorld())) { + if (e.getPlayer().getWorld().equals(getTarget().getWorld().realWorld())) { onBlockBreak(e); } } @EventHandler public void on(BlockPlaceEvent e) { - if (e.getPlayer().getWorld().equals(getTarget().getWorld())) { + if (e.getPlayer().getWorld().equals(getTarget().getWorld().realWorld())) { onBlockPlace(e); } } diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineParallaxManager.java b/src/main/java/com/volmit/iris/engine/framework/EngineParallaxManager.java index f9f8ef5f5..c83a62a31 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineParallaxManager.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineParallaxManager.java @@ -37,13 +37,16 @@ import com.volmit.iris.engine.parallel.BurstExecutor; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; +import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.function.Consumer4; +import com.volmit.iris.util.math.Position2; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.IrisLock; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.PrecisionStopwatch; +import io.lumine.xikage.mythicmobs.utils.serialize.ChunkPosition; import org.bukkit.Chunk; import org.bukkit.ChunkSnapshot; import org.bukkit.block.TileState; @@ -203,55 +206,44 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer { IrisLock getFeatureLock(); + @BlockCoordinates default void forEachFeature(double x, double z, Consumer f) { if (!getEngine().getDimension().hasFeatures(getEngine())) { return; } - long key = Cache.key(((int) x) >> 4, ((int) z) >> 4); + KList pos = new KList<>(); - for (IrisFeaturePositional ipf : getFeatureCache().compute(key, (ke, v) -> { - if (v != null) { - return v; + for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) { + if (i.shouldFilter(x, z)) { + pos.add(i); } + } - getFeatureLock().lock(); - KList pos = new KList<>(); + int s = (int) Math.ceil(getParallaxSize() / 2D); + int i, j; + int cx = (int) x >> 4; + int cz = (int) z >> 4; - for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) { - if (i.shouldFilter(x, z)) { - pos.add(i); - } - } + for (i = -s; i <= s; i++) { + for (j = -s; j <= s; j++) { + ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz); - int s = (int) Math.ceil(getParallaxSize() / 2D); - int i, j; - int cx = (int) x >> 4; - int cz = (int) z >> 4; - - for (i = -s; i <= s; i++) { - for (j = -s; j <= s; j++) { - ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz); - - synchronized (m) { - try { - for (IrisFeaturePositional k : m.getFeatures()) { - if (k.shouldFilter(x, z)) { - pos.add(k); - } - } - } catch (Throwable e) { - Iris.error("FILTER ERROR" + " AT " + (cx + i) + " " + (j + cz)); - e.printStackTrace(); - Iris.reportError(e); + try { + for (IrisFeaturePositional k : m.getFeatures()) { + if (k.shouldFilter(x, z)) { + pos.add(k); } } + } catch (Throwable e) { + Iris.error("FILTER ERROR" + " AT " + (cx + i) + " " + (j + cz)); + e.printStackTrace(); + Iris.reportError(e); } } - getFeatureLock().unlock(); + } - return pos; - })) { + for (IrisFeaturePositional ipf : pos) { f.accept(ipf); } } @@ -269,7 +261,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer { int i, j; KList after = new KList<>(); int bs = (int) Math.pow((s * 2) + 1, 2); - BurstExecutor burst = getEngine().getTarget().getBurster().burst(bs); + BurstExecutor burst = getEngine().getTarget().getParallaxBurster().burst(bs); for (i = -s; i <= s; i++) { for (j = -s; j <= s; j++) { int xx = i + x; @@ -277,8 +269,8 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer { int xxx = xx << 4; int zzz = zz << 4; if (!getParallaxAccess().isFeatureGenerated(xx, zz)) { + getParallaxAccess().setFeatureGenerated(xx, zz); burst.queue(() -> { - getParallaxAccess().setFeatureGenerated(xx, zz); RNG rng = new RNG(Cache.key(xx, zz)).nextParallelRNG(getEngine().getTarget().getWorld().seed()); IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz); @@ -291,7 +283,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer { burst.complete(); if (getEngine().getDimension().isPlaceObjects()) { - burst = getEngine().getTarget().getBurster().burst(bs); + burst = getEngine().getTarget().getParallaxBurster().burst(bs); for (i = -s; i <= s; i++) { int ii = i; @@ -307,7 +299,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer { } burst.complete(); - burst = getEngine().getTarget().getBurster().burst(bs); + burst = getEngine().getTarget().getParallaxBurster().burst(bs); for (i = -s; i <= s; i++) { int ii = i; @@ -320,7 +312,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer { burst.complete(); } - getEngine().getTarget().getBurster().burst(after); + getEngine().getTarget().getParallaxBurster().burst(after); getParallaxAccess().setChunkGenerated(x, z); p.end(); getEngine().getMetrics().getParallax().put(p.getMilliseconds()); @@ -674,7 +666,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer { } Iris.verbose("Checking sizes for " + Form.f(objects.size()) + " referenced objects."); - BurstExecutor e = getEngine().getTarget().getBurster().burst(objects.size()); + BurstExecutor e = getEngine().getTarget().getParallaxBurster().burst(objects.size()); KMap sizeCache = new KMap<>(); for (String i : objects) { e.queue(() -> { diff --git a/src/main/java/com/volmit/iris/engine/parallax/ParallaxRegion.java b/src/main/java/com/volmit/iris/engine/parallax/ParallaxRegion.java index d131a508b..8426737ec 100644 --- a/src/main/java/com/volmit/iris/engine/parallax/ParallaxRegion.java +++ b/src/main/java/com/volmit/iris/engine/parallax/ParallaxRegion.java @@ -121,7 +121,7 @@ public class ParallaxRegion extends HunkRegion { if ((t instanceof ByteArrayTag)) { try { - meta = metaAdapter.read((x, y, z) -> Hunk.newArrayHunk(32, 1, 32), (ByteArrayTag) t); + meta = metaAdapter.read((x, y, z) -> Hunk.newAtomicHunk(32, 1, 32), (ByteArrayTag) t); } catch (IOException e) { Iris.reportError(e); e.printStackTrace(); @@ -129,7 +129,7 @@ public class ParallaxRegion extends HunkRegion { } if (meta == null) { - meta = Hunk.newArrayHunk(32, 1, 32); + meta = Hunk.newAtomicHunk(32, 1, 32); } } diff --git a/src/main/java/com/volmit/iris/util/math/Position2.java b/src/main/java/com/volmit/iris/util/math/Position2.java index 835f1e448..96e2746a8 100644 --- a/src/main/java/com/volmit/iris/util/math/Position2.java +++ b/src/main/java/com/volmit/iris/util/math/Position2.java @@ -83,4 +83,8 @@ public class Position2 { public Position2 add(int x, int z) { return new Position2(this.x + x, this.z + z); } + + public Position2 blockToChunk() { + return new Position2(x >> 4, z >> 4); + } }