diff --git a/src/main/java/com/volmit/iris/gen/v2/IrisTerrainGenerator.java b/src/main/java/com/volmit/iris/gen/v2/IrisTerrainGenerator.java index fee979f8d..b6cf4fa89 100644 --- a/src/main/java/com/volmit/iris/gen/v2/IrisTerrainGenerator.java +++ b/src/main/java/com/volmit/iris/gen/v2/IrisTerrainGenerator.java @@ -3,32 +3,23 @@ package com.volmit.iris.gen.v2; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; -import com.volmit.iris.Iris; -import com.volmit.iris.gen.v2.scaffold.Hunk; +import com.volmit.iris.gen.v2.scaffold.hunk.Hunk; import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; -import com.volmit.iris.gen.v2.scaffold.multicore.MultiBurst; import com.volmit.iris.manager.IrisDataManager; import com.volmit.iris.object.IrisDimension; -import com.volmit.iris.util.KMap; -import com.volmit.iris.util.M; import com.volmit.iris.util.PrecisionStopwatch; -import com.volmit.iris.util.RollingSequence; public class IrisTerrainGenerator { private long seed; - private MultiBurst burster; private IrisDataManager data; private IrisDimension dimension; private IrisComplex complex; - private int parallelism; public IrisTerrainGenerator(long seed, IrisDimension dimension, IrisDataManager data) { this.seed = seed; complex = new IrisComplex(); - parallelism = 6; - burster = new MultiBurst((parallelism * parallelism) * 4); this.data = data; this.dimension = dimension; @@ -42,28 +33,17 @@ public class IrisTerrainGenerator private void fill2D(ProceduralStream t, Hunk h, double x, double z, ProceduralStream v) { - if(parallelism <= 1) - { - t.fill2D(h, x * 16, z * 16, v); - } - - else - { - t.fill2DParallel(burster.burst(parallelism * parallelism), parallelism, h, x * 16, z * 16, v); - } + t.fill2D(h, x * 16, z * 16, v); } private void fill2DYLock(ProceduralStream t, Hunk h, double x, double z, ProceduralStream v) { - if(parallelism <= 1) - { - t.fill2DYLocked(h, x * 16, z * 16, v); - } + t.fill2DYLocked(h, x * 16, z * 16, v); + } + + public void generateDecorations(int x, int z, Hunk blocks) + { - else - { - t.fill2DParallelYLocked(burster.burst(parallelism * parallelism), parallelism, h, x * 16, z * 16, v); - } } public void generateTerrain(int x, int z, Hunk blocks) diff --git a/src/main/java/com/volmit/iris/gen/v2/TestGen.java b/src/main/java/com/volmit/iris/gen/v2/TestGen.java index 38e5cf9eb..b82e92765 100644 --- a/src/main/java/com/volmit/iris/gen/v2/TestGen.java +++ b/src/main/java/com/volmit/iris/gen/v2/TestGen.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; import org.bukkit.generator.ChunkGenerator; import com.volmit.iris.Iris; -import com.volmit.iris.gen.v2.scaffold.Hunk; +import com.volmit.iris.gen.v2.scaffold.hunk.Hunk; import com.volmit.iris.util.Form; import com.volmit.iris.util.PrecisionStopwatch; @@ -32,7 +32,7 @@ public class TestGen { PrecisionStopwatch p = PrecisionStopwatch.start(); ChunkData c = createChunkData(world); - Hunk b = Hunk.create(16, 256, 16); + Hunk b = Hunk.newHunk(16, 256, 16); tg.generate(x, z, Hunk.view(c), b); for(int i = 0; i < 16; i++) diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/layer/ProceduralStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/layer/ProceduralStream.java index b1f7dc3fe..d2ac4e448 100644 --- a/src/main/java/com/volmit/iris/gen/v2/scaffold/layer/ProceduralStream.java +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/layer/ProceduralStream.java @@ -3,8 +3,8 @@ package com.volmit.iris.gen.v2.scaffold.layer; import java.util.List; import java.util.function.Function; -import com.volmit.iris.gen.v2.scaffold.Hunk; import com.volmit.iris.gen.v2.scaffold.Significance; +import com.volmit.iris.gen.v2.scaffold.hunk.Hunk; import com.volmit.iris.gen.v2.scaffold.multicore.BurstExecutor; import com.volmit.iris.gen.v2.scaffold.stream.AddingStream; import com.volmit.iris.gen.v2.scaffold.stream.AwareConversionStream2D; @@ -293,163 +293,142 @@ public interface ProceduralStream extends ProceduralLayer, Interpolated return new FittedStream(this, inMin, inMax, min, max); } - default void fill(Hunk h, double x, double y, double z) + default void fill(Hunk h, double x, double y, double z, int parallelism) { - for(int i = 0; i < h.getWidth(); i++) + h.compute3D(parallelism, (xx, yy, zz, hh) -> hh.iterate((xv, yv, zv) -> hh.set(xv, yv, zv, get(xx + xv + x, yy + yv + y, zz + zv + z)))); + } + + default void fill2D(Hunk h, double x, double z, V v, int parallelism) + { + h.compute2D(parallelism, (xx, __, zz, hh) -> { - for(int j = 0; j < h.getHeight(); j++) + for(int i = 0; i < hh.getWidth(); i++) { - for(int k = 0; k < h.getDepth(); k++) + for(int k = 0; k < hh.getDepth(); k++) { - h.set(i, j, k, get(i + x, j + y, k + z)); + double n = getDouble(i + x + xx, k + z + zz); + + for(int j = 0; j < Math.min(h.getHeight(), n); j++) + { + hh.set(i, j, k, v); + } } } - } + }); + } + + default void fill2D(Hunk h, double x, double z, ProceduralStream v, int parallelism) + { + h.compute2D(parallelism, (xx, yy, zz, hh) -> + { + for(int i = 0; i < hh.getWidth(); i++) + { + for(int k = 0; k < hh.getDepth(); k++) + { + double n = getDouble(i + x + xx, k + z + zz); + + for(int j = 0; j < Math.min(h.getHeight(), n); j++) + { + hh.set(i, j, k, v.get(i + x + xx, j + yy, k + z + zz)); + } + } + } + }); + } + + default void fill2DYLocked(Hunk h, double x, double z, V v, int parallelism) + { + h.compute2D(parallelism, (xx, yy, zz, hh) -> + { + for(int i = 0; i < hh.getWidth(); i++) + { + for(int k = 0; k < hh.getDepth(); k++) + { + double n = getDouble(i + x + xx, k + z + zz); + + for(int j = 0; j < Math.min(h.getHeight(), n); j++) + { + hh.set(i, j, k, v); + } + } + } + }); + } + + default void fill2DYLocked(Hunk h, double x, double z, ProceduralStream v, int parallelism) + { + h.compute2D(parallelism, (xx, yy, zz, hh) -> + { + for(int i = 0; i < hh.getWidth(); i++) + { + for(int k = 0; k < hh.getDepth(); k++) + { + double n = getDouble(i + x + xx, k + z + zz); + + for(int j = 0; j < Math.min(h.getHeight(), n); j++) + { + hh.set(i, j, k, v.get(i + x + xx, k + z + zz)); + } + } + } + }); + } + + default void fill3D(Hunk h, double x, int y, double z, V v, int parallelism) + { + h.compute3D(parallelism, (xx, yy, zz, hh) -> hh.iterate((xv, yv, zv) -> + { + if(getDouble(xx + xv + x, yy + yv + y, zz + zv + z) > 0.5) + { + hh.set(xv, yv, zv, v); + } + })); + } + + default void fill3D(Hunk h, double x, int y, double z, ProceduralStream v, int parallelism) + { + h.compute3D(parallelism, (xx, yy, zz, hh) -> hh.iterate((xv, yv, zv) -> + { + if(getDouble(xx + xv + x, yy + yv + y, zz + zv + z) > 0.5) + { + hh.set(xv, yv, zv, v.get(xx + xv + x, yy + yv + y, zz + zv + z)); + } + })); + } + + default void fill(Hunk h, double x, double y, double z) + { + fill(h, x, z, 4); } default void fill2D(Hunk h, double x, double z, V v) { - for(int i = 0; i < h.getWidth(); i++) - { - for(int k = 0; k < h.getDepth(); k++) - { - double n = getDouble(i + x, k + z); - - for(int j = 0; j < Math.min(h.getHeight(), n); j++) - { - h.set(i, j, k, v); - } - } - } - } - - default void fill3D(Hunk h, double x, int y, double z, V v) - { - for(int i = 0; i < h.getWidth(); i++) - { - for(int k = 0; k < h.getDepth(); k++) - { - - for(int j = 0; j < h.getHeight(); j++) - { - double n = getDouble(i + x, j + y, k + z); - - if(n >= 0.5) - { - h.set(i, j, k, v); - } - } - } - } - } - - default void fill3D(Hunk h, double x, int y, double z, ProceduralStream v) - { - for(int i = 0; i < h.getWidth(); i++) - { - for(int k = 0; k < h.getDepth(); k++) - { - for(int j = 0; j < h.getHeight(); j++) - { - double n = getDouble(i + x, j + y, k + z); - - if(n >= 0.5) - { - h.set(i, j, k, v.get(i + x, j + y, k + z)); - } - } - } - } + fill2D(h, x, z, v, 4); } default void fill2D(Hunk h, double x, double z, ProceduralStream v) { - for(int i = 0; i < h.getWidth(); i++) - { - for(int k = 0; k < h.getDepth(); k++) - { - double n = getDouble(i + x, k + z); + fill2D(h, x, z, v, 4); + } - for(int j = 0; j < Math.min(h.getHeight(), n); j++) - { - h.set(i, j, k, v.get(i + x, j, k + z)); - } - } - } + default void fill2DYLocked(Hunk h, double x, double z, V v) + { + fill2DYLocked(h, x, z, v, 4); } default void fill2DYLocked(Hunk h, double x, double z, ProceduralStream v) { - for(int i = 0; i < h.getWidth(); i++) - { - for(int k = 0; k < h.getDepth(); k++) - { - double n = getDouble(i + x, k + z); - V yy = v.get(i + x, k + z); - for(int j = 0; j < Math.min(h.getHeight(), n); j++) - { - h.set(i, j, k, yy); - } - } - } + fill2DYLocked(h, x, z, v, 4); } - default void fill2DParallel(BurstExecutor burster, int parallelismRooted, Hunk h, double x, double z, ProceduralStream v) + default void fill3D(Hunk h, double x, int y, double z, V v) { - parallelismRooted = parallelismRooted % 2 != 0 ? parallelismRooted + 1 : parallelismRooted; - KList future = new KList<>(); - int w = h.getWidth() / parallelismRooted; - int d = h.getDepth() / parallelismRooted; - int i, j; - - for(i = 0; i < h.getWidth(); i += w) - { - int ii = i; - - for(j = 0; j < h.getDepth(); j += d) - { - int jj = j; - Hunk mh = h.crop(i, 0, j, i + w, h.getHeight(), j + d); - burster.queue(() -> fill2D(mh, x + ii, z + jj, v)); - future.add(() -> h.insert(ii, 0, jj, mh)); - } - } - - burster.complete(); - - for(Runnable vx : future) - { - vx.run(); - } + fill3D(h, x, y, z, v, 4); } - default void fill2DParallelYLocked(BurstExecutor burster, int parallelismRooted, Hunk h, double x, double z, ProceduralStream v) + default void fill3D(Hunk h, double x, int y, double z, ProceduralStream v) { - parallelismRooted = parallelismRooted % 2 != 0 ? parallelismRooted + 1 : parallelismRooted; - KList future = new KList<>(); - int w = h.getWidth() / parallelismRooted; - int d = h.getDepth() / parallelismRooted; - int i, j; - - for(i = 0; i < h.getWidth(); i += w) - { - int ii = i; - - for(j = 0; j < h.getDepth(); j += d) - { - int jj = j; - Hunk mh = h.crop(i, 0, j, i + w, h.getHeight(), j + d); - burster.queue(() -> fill2DYLocked(mh, x + ii, z + jj, v)); - future.add(() -> h.insert(ii, 0, jj, mh)); - } - } - - burster.complete(); - - for(Runnable vx : future) - { - vx.run(); - } + fill3D(h, x, y, z, v, 4); } public T get(double x, double z); diff --git a/src/main/java/com/volmit/iris/util/Consumer4.java b/src/main/java/com/volmit/iris/util/Consumer4.java new file mode 100644 index 000000000..4520cd93e --- /dev/null +++ b/src/main/java/com/volmit/iris/util/Consumer4.java @@ -0,0 +1,8 @@ +package com.volmit.iris.util; + +@SuppressWarnings("hiding") +@FunctionalInterface +public interface Consumer4 +{ + public void accept(A a, B b, C c, D d); +} diff --git a/src/main/java/com/volmit/iris/util/Consumer5.java b/src/main/java/com/volmit/iris/util/Consumer5.java new file mode 100644 index 000000000..66c9154ec --- /dev/null +++ b/src/main/java/com/volmit/iris/util/Consumer5.java @@ -0,0 +1,8 @@ +package com.volmit.iris.util; + +@SuppressWarnings("hiding") +@FunctionalInterface +public interface Consumer5 +{ + public void accept(A a, B b, C c, D d, E e); +}