From 60324c041cd0e2f9785e6d4cd487ddd80e327fcf Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Fri, 7 Aug 2020 01:29:05 -0400 Subject: [PATCH] Structures --- .../com/volmit/iris/object/IrisStructure.java | 48 ++++------------ .../iris/object/IrisStructurePlacement.java | 57 +++++++++++-------- 2 files changed, 43 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/volmit/iris/object/IrisStructure.java b/src/main/java/com/volmit/iris/object/IrisStructure.java index 2b1f42c09..be703edc6 100644 --- a/src/main/java/com/volmit/iris/object/IrisStructure.java +++ b/src/main/java/com/volmit/iris/object/IrisStructure.java @@ -1,6 +1,7 @@ package com.volmit.iris.object; import com.volmit.iris.gen.atomics.AtomicCache; +import com.volmit.iris.util.BlockPosition; import com.volmit.iris.util.CNG; import com.volmit.iris.util.Desc; import com.volmit.iris.util.DontObfuscate; @@ -44,14 +45,6 @@ public class IrisStructure extends IrisRegistrant @Desc("The tiles") private KList tiles = new KList<>(); - @DontObfuscate - @Desc("This is the wall chance zoom") - private double wallChanceZoom = 1D; - - @DontObfuscate - @Desc("The dispersion of walls") - private Dispersion dispersion = Dispersion.SCATTER; - private transient AtomicCache wallGenerator = new AtomicCache<>(); public TileResult getTile(RNG rng, double x, double y, double z) @@ -117,20 +110,8 @@ public class IrisStructure extends IrisRegistrant return true; } - int gs = getGridSize() + 1; - int gh = getGridHeight() + 1; - int gx = getTileHorizon(x); - int gy = getTileVertical(y); - int gz = getTileHorizon(z); - int hx = face.x(); - int hy = face.y(); - int hz = face.z(); - - int tx = (gx * 2) + (hx * gs); - int ty = (gy * 2) + (hy * gh); - int tz = (gz * 2) + (hz * gs); - - return getWallGenerator(rng).fitDoubleD(0, 1, (tx) / wallChanceZoom, ty / wallChanceZoom, tz / wallChanceZoom) < getWallChance(); + BlockPosition p = asTileHorizon(new BlockPosition((int) x, (int) y, (int) z), face); + return (getWallGenerator(rng).fitDoubleD(0, 1, p.getX(), p.getY(), p.getZ()) < getWallChance()); } public int getTileHorizon(double v) @@ -138,29 +119,20 @@ public class IrisStructure extends IrisRegistrant return (int) Math.floor(v / gridSize); } - public int getTileVertical(double v) + public BlockPosition asTileHorizon(BlockPosition b, StructureTileFace face) { - return (int) Math.floor(v / gridHeight); + b.setX((int) (Math.floor((b.getX() * 2) / gridSize) + face.x())); + b.setY((int) (Math.floor((b.getY() * 2) / gridHeight) + face.y())); + b.setZ((int) (Math.floor((b.getZ() * 2) / gridSize) + face.z())); + return b; } public CNG getWallGenerator(RNG rng) { return wallGenerator.aquire(() -> { - CNG wallGenerator = new CNG(rng); - RNG rngx = rng.nextParallelRNG((int) ((wallChance * 102005) + gridHeight - gridSize + maxLayers + tiles.size())); - - switch(dispersion) - { - case SCATTER: - wallGenerator = CNG.signature(rngx).freq(1000000); - break; - case WISPY: - wallGenerator = CNG.signature(rngx); - break; - } - - return wallGenerator; + RNG rngx = rng.nextParallelRNG((int) (name.hashCode() + gridHeight - gridSize + maxLayers + tiles.size())); + return CNG.signature(rngx).scale(0.8); }); } diff --git a/src/main/java/com/volmit/iris/object/IrisStructurePlacement.java b/src/main/java/com/volmit/iris/object/IrisStructurePlacement.java index 985fdc166..f4e4ae046 100644 --- a/src/main/java/com/volmit/iris/object/IrisStructurePlacement.java +++ b/src/main/java/com/volmit/iris/object/IrisStructurePlacement.java @@ -46,13 +46,11 @@ public class IrisStructurePlacement } - public void place(ParallaxChunkGenerator g, RNG rng, int cx, int cz) + public void place(ParallaxChunkGenerator g, RNG rngno, int cx, int cz) { try { - TileResult t; - IrisObject o; - int h; + RNG rng = g.getMasterRandom().nextParallelRNG(-88738456); RNG rnp = rng.nextParallelRNG(cx - (cz * cz)); int s = gridSize() - (getStructure().isMergeEdges() ? 1 : 0); int sh = gridHeight() - (getStructure().isMergeEdges() ? 1 : 0); @@ -61,26 +59,15 @@ public class IrisStructurePlacement { for(int j = cz << 4; j < (cz << 4) + 15; j += Math.max(s / 2, 1)) { + if(getStructure().getMaxLayers() <= 1) + { + placeLayer(g, rng, rnp, i, 0, j, s, sh); + continue; + } + for(int k = 0; k < s * getStructure().getMaxLayers(); k += Math.max(sh, 1)) { - if(!hasStructure(rng, i, k, j)) - { - continue; - } - - h = (height == -1 ? 0 : height) + (Math.floorDiv(k, sh) * sh); - t = getStructure().getTile(rng, i / zoom, h / zoom, j / zoom); - - if(t != null) - { - if(height >= 0) - { - t.getPlacement().setBore(true); - } - - o = load(t.getTile().getObjects().get(rnp.nextInt(t.getTile().getObjects().size()))); - o.place(Math.floorDiv(i, s) * s, height == -1 ? -1 : h, Math.floorDiv(j, s) * s, g, t.getPlacement(), rng); - } + placeLayer(g, rng, rnp, i, k, j, s, sh); } } } @@ -92,6 +79,28 @@ public class IrisStructurePlacement } } + public void placeLayer(ParallaxChunkGenerator g, RNG rng, RNG rnp, int i, int k, int j, int s, int sh) + { + if(!hasStructure(rng, i, k, j)) + { + return; + } + + int h = (height == -1 ? 0 : height) + (Math.floorDiv(k, sh) * sh); + TileResult t = getStructure().getTile(rng, i, h, j); + + if(t != null) + { + if(height >= 0) + { + t.getPlacement().setBore(true); + } + + IrisObject o = load(t.getTile().getObjects().get(rnp.nextInt(t.getTile().getObjects().size()))); + o.place(Math.floorDiv(i, s) * s, height == -1 ? -1 : h, Math.floorDiv(j, s) * s, g, t.getPlacement(), rng); + } + } + private IrisObjectPlacement getConfig() { return config.aquire(() -> new IrisObjectPlacement()); @@ -119,9 +128,9 @@ public class IrisStructurePlacement public boolean hasStructure(RNG random, double x, double y, double z) { - if(getChanceGenerator(random).getIndex(x, y, z, getRarity()) == getRarity() / 2) + if(getChanceGenerator(random).getIndex(x / zoom, y / zoom, z / zoom, getRarity()) == getRarity() / 2) { - return ratio > 0 ? getChanceGenerator(random).getDistance(x, z) > ratio : getChanceGenerator(random).getDistance(x, z) < Math.abs(ratio); + return ratio > 0 ? getChanceGenerator(random).getDistance(x / zoom, z / zoom) > ratio : getChanceGenerator(random).getDistance(x / zoom, z / zoom) < Math.abs(ratio); } return false;