From 0d3d0a8da1840b5c3226e83fec21e33ae5f88c7d Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:06:24 -0400 Subject: [PATCH 01/36] Mantle components --- .../engine/mantle/IrisMantleComponent.java | 28 +++++++ .../iris/engine/mantle/MantleComponent.java | 75 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 src/main/java/com/volmit/iris/engine/mantle/IrisMantleComponent.java create mode 100644 src/main/java/com/volmit/iris/engine/mantle/MantleComponent.java diff --git a/src/main/java/com/volmit/iris/engine/mantle/IrisMantleComponent.java b/src/main/java/com/volmit/iris/engine/mantle/IrisMantleComponent.java new file mode 100644 index 000000000..b7e24aeeb --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/mantle/IrisMantleComponent.java @@ -0,0 +1,28 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.mantle; + +import com.volmit.iris.util.mantle.MantleFlag; +import lombok.Data; + +@Data +public abstract class IrisMantleComponent implements MantleComponent{ + private final EngineMantle engineMantle; + private final MantleFlag flag; +} diff --git a/src/main/java/com/volmit/iris/engine/mantle/MantleComponent.java b/src/main/java/com/volmit/iris/engine/mantle/MantleComponent.java new file mode 100644 index 000000000..accbdc4f1 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/mantle/MantleComponent.java @@ -0,0 +1,75 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.mantle; + +import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.engine.IrisComplex; +import com.volmit.iris.engine.object.dimensional.IrisDimension; +import com.volmit.iris.util.documentation.ChunkCoordinates; +import com.volmit.iris.util.mantle.Mantle; +import com.volmit.iris.util.mantle.MantleFlag; +import com.volmit.iris.util.parallel.BurstExecutor; + +import java.util.function.Consumer; +import java.util.function.Supplier; + +public interface MantleComponent +{ + default int getRadius() + { + return getEngineMantle().getRealRadius(); + } + + default IrisData getData() + { + return getEngineMantle().getData(); + } + + default IrisDimension getDimension() + { + return getEngineMantle().getEngine().getDimension(); + } + + default IrisComplex getComplex() + { + return getEngineMantle().getComplex(); + } + + default long seed() + { + return getEngineMantle().getEngine().getTarget().getWorld().seed(); + } + + default BurstExecutor burst() + { + return getEngineMantle().getEngine().burst().burst(); + } + + EngineMantle getEngineMantle(); + + default Mantle getMantle() + { + return getEngineMantle().getMantle(); + } + + MantleFlag getFlag(); + + @ChunkCoordinates + void generateLayer(int x, int z, Consumer post); +} From 0d8cb7393c3a03db4e87059ba77710e7f1c5d581 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:06:31 -0400 Subject: [PATCH 02/36] Jigsaw Mantle Components --- .../components/MantleJigsawComponent.java | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java new file mode 100644 index 000000000..2b0f3af05 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java @@ -0,0 +1,132 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.mantle.components; + +import com.volmit.iris.engine.data.cache.Cache; +import com.volmit.iris.engine.jigsaw.PlannedStructure; +import com.volmit.iris.engine.mantle.EngineMantle; +import com.volmit.iris.engine.mantle.IrisMantleComponent; +import com.volmit.iris.engine.object.basic.IrisPosition; +import com.volmit.iris.engine.object.biome.IrisBiome; +import com.volmit.iris.engine.object.feature.IrisFeaturePositional; +import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructure; +import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement; +import com.volmit.iris.engine.object.regional.IrisRegion; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.mantle.MantleFlag; +import com.volmit.iris.util.math.Position2; +import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.parallel.BurstExecutor; + +import java.util.List; +import java.util.function.Consumer; + +public class MantleJigsawComponent extends IrisMantleComponent +{ + public MantleJigsawComponent(EngineMantle engineMantle) { + super(engineMantle, MantleFlag.JIGSAW); + } + + @Override + public void generateLayer(int x, int z, Consumer post) { + int s = getRadius(); + BurstExecutor burst = burst(); + + for (int i = -s; i <= s; i++) { + int xx = i+x; + int xxx = 8 + (xx << 4); + for (int j = -s; j <= s; j++) { + int zz = j + z; + int zzz = 8 + (zz << 4); + burst.queue(() -> { + RNG rng = new RNG(Cache.key(xx, zz) + seed()); + IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); + IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); + generateParallaxJigsaw(rng, xx, zz, biome, region, post); + }); + } + } + + burst.complete(); + } + + private void generateParallaxJigsaw(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer post) { + boolean placed = false; + + if (getDimension().getStronghold() != null) { + List poss = getDimension().getStrongholds(seed()); + + if (poss != null) { + for (Position2 pos : poss) { + if (x == pos.getX() >> 4 && z == pos.getZ() >> 4) { + IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(getDimension().getStronghold()); + placeStructure(pos.toIris(), structure, rng, post); + placed = true; + } + } + } + } + + if (!placed) { + for (IrisJigsawStructurePlacement i : biome.getJigsawStructures()) { + if (rng.nextInt(i.getRarity()) == 0) { + IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15)); + IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure()); + placeStructure(position, structure, rng, post); + placed = true; + } + } + } + + if (!placed) { + for (IrisJigsawStructurePlacement i : region.getJigsawStructures()) { + if (rng.nextInt(i.getRarity()) == 0) { + IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15)); + IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure()); + placeStructure(position, structure, rng, post); + placed = true; + } + } + } + + if (!placed) { + for (IrisJigsawStructurePlacement i : getDimension().getJigsawStructures()) { + if (rng.nextInt(i.getRarity()) == 0) { + IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15)); + IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure()); + placeStructure(position, structure, rng, post); + } + } + } + } + + + private void placeStructure(IrisPosition position, IrisJigsawStructure structure, RNG rng, Consumer post) { + if (structure.getFeature() != null) { + if (structure.getFeature().getBlockRadius() == 32) { + structure.getFeature().setBlockRadius((double) structure.getMaxDimension() / 3); + } + + getMantle().set(position.getX(), 0, position.getZ(), + new IrisFeaturePositional(position.getX(), position.getZ(), structure.getFeature())); + } + + post.accept(() -> new PlannedStructure(structure, position, rng).place(getEngineMantle(), getMantle(), post)); + } +} From 4ee31db7a03904570f4aea9f72647fd268e18b18 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:06:45 -0400 Subject: [PATCH 03/36] Mantle flagging --- .../iris/util/collection/StateList.java | 126 ++++++++++++++++++ .../com/volmit/iris/util/mantle/Mantle.java | 43 ++++++ .../volmit/iris/util/mantle/MantleChunk.java | 34 ++--- .../volmit/iris/util/mantle/MantleFlag.java | 33 +++++ 4 files changed, 220 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/volmit/iris/util/collection/StateList.java create mode 100644 src/main/java/com/volmit/iris/util/mantle/MantleFlag.java diff --git a/src/main/java/com/volmit/iris/util/collection/StateList.java b/src/main/java/com/volmit/iris/util/collection/StateList.java new file mode 100644 index 000000000..62490d7f2 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/collection/StateList.java @@ -0,0 +1,126 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.util.collection; + +public class StateList +{ + private final KList states; + + public StateList(String... states) + { + this.states = new KList(states); + + if(getBits() > 64) + { + throw new RuntimeException("StateLists cannot exceed 64 bits! You are trying to use " + getBits() + " bits!"); + } + } + + public StateList(Enum... states) + { + this.states = new KList>().convert(Enum::name); + + if(getBits() > 64) + { + throw new RuntimeException("StateLists cannot exceed 64 bits! You are trying to use " + getBits() + " bits!"); + } + } + + public long max() + { + return (long) (Math.pow(2, getBits()) - 1); + } + + public KList getEnabled(long list) + { + KList f = new KList<>(); + + for(String i : states) + { + if(is(list, i)) + { + f.add(i); + } + } + + return f; + } + + public long of(String... enabledStates) + { + long b = 0; + + for(String i : enabledStates) + { + b |= getBit(i); + } + + return b; + } + + public long set(long list, String state, boolean enabled) + { + long bit = getBit(state); + boolean is = is(list, state); + + if(enabled && !is) + { + return list | bit; + } + + else if(!enabled && is) + { + return list ^ bit; + } + + return list; + } + + public boolean is(long list, String state) + { + long bit = getBit(state); + + return bit > 0 && (list & bit) == bit; + } + + public boolean hasBit(String state) + { + return getBit(state) > 0; + } + + public long getBit(String state) + { + return getBit(states.indexOf(state)); + } + + public long getBit(int index) + { + return (long) (index < 0 ? -1 : Math.pow(2, index)); + } + + public int getBytes() + { + return getBits() == 0 ? 0 : ((getBits() >> 2) + 1); + } + + public int getBits() + { + return states.size(); + } +} diff --git a/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/src/main/java/com/volmit/iris/util/mantle/Mantle.java index f2026c452..f607a530d 100644 --- a/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -23,6 +23,7 @@ import com.volmit.iris.engine.data.cache.Cache; 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.documentation.RegionCoordinates; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; @@ -77,6 +78,48 @@ public class Mantle { Iris.debug("Opened The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath()); } + @ChunkCoordinates + public void raiseFlag(int x, int z, MantleFlag flag, Runnable r) + { + if(!hasFlag(x, z, flag)) + { + flag(x, z, flag, true); + r.run(); + } + } + + @ChunkCoordinates + public void lowerFlag(int x, int z, MantleFlag flag, Runnable r) + { + if(hasFlag(x, z, flag)) + { + flag(x, z, flag, false); + r.run(); + } + } + + @ChunkCoordinates + public void flag(int x, int z, MantleFlag flag, boolean flagged) + { + try { + get(x >> 5, z >> 5).get().get(x & 31, z & 31).flag(flag, flagged); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } + + @ChunkCoordinates + public boolean hasFlag(int x, int z, MantleFlag flag) + { + try { + get(x >> 5, z >> 5).get().get(x & 31, z & 31).isFlagged(flag); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + + return false; + } + /** * Set data T at the given block position. This method will attempt to find a * Tectonic Plate either by loading it or creating a new one. This method uses diff --git a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java index ebbd93916..28fd95243 100644 --- a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java +++ b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java @@ -19,6 +19,8 @@ package com.volmit.iris.util.mantle; import com.volmit.iris.util.collection.KSet; +import com.volmit.iris.util.collection.StateList; +import com.volmit.iris.util.data.Varint; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.matter.IrisMatter; import com.volmit.iris.util.matter.Matter; @@ -26,6 +28,7 @@ import com.volmit.iris.util.matter.Matter; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.concurrent.atomic.AtomicIntegerArray; import java.util.concurrent.atomic.AtomicReferenceArray; /** @@ -33,7 +36,8 @@ import java.util.concurrent.atomic.AtomicReferenceArray; * Mantle Chunks are fully atomic & thread safe */ public class MantleChunk { - private final KSet flags; + private static final StateList state = MantleFlag.getStateList(); + private final AtomicIntegerArray flags; private final AtomicReferenceArray sections; /** @@ -44,7 +48,7 @@ public class MantleChunk { @ChunkCoordinates public MantleChunk(int sectionHeight) { sections = new AtomicReferenceArray<>(sectionHeight); - flags = new KSet<>(); + flags = new AtomicIntegerArray(MantleFlag.values().length); } /** @@ -58,10 +62,10 @@ public class MantleChunk { public MantleChunk(int sectionHeight, DataInputStream din) throws IOException, ClassNotFoundException { this(sectionHeight); int s = din.readByte(); - int f = din.readByte(); - for (int i = 0; i < f; i++) { - flags.add(din.readUTF()); + for(String i : state.getEnabled(Varint.readUnsignedVarLong(din))) + { + flags.set(MantleFlag.valueOf(i).ordinal(), 1); } for (int i = 0; i < s; i++) { @@ -71,16 +75,12 @@ public class MantleChunk { } } - public void flag(String s, boolean f) { - if (f) { - flags.add(s); - } else { - flags.remove(s); - } + public void flag(MantleFlag flag, boolean f) { + flags.set(flag.ordinal(), f ? 1 : 0); } - public boolean isFlagged(String s) { - return flags.contains(s); + public boolean isFlagged(MantleFlag flag) { + return flags.get(flags.get(flag.ordinal())) == 1; } /** @@ -150,12 +150,14 @@ public class MantleChunk { */ public void write(DataOutputStream dos) throws IOException { dos.writeByte(sections.length()); - dos.writeByte(flags.size()); + long data = 0; - for (String i : flags) { - dos.writeUTF(i); + for (int i = 0; i < flags.length(); i++) { + state.set(data, MantleFlag.values()[i].name(), flags.get(i) == 1); } + Varint.writeUnsignedVarLong(data, dos); + for (int i = 0; i < sections.length(); i++) { if (exists(i)) { dos.writeBoolean(true); diff --git a/src/main/java/com/volmit/iris/util/mantle/MantleFlag.java b/src/main/java/com/volmit/iris/util/mantle/MantleFlag.java new file mode 100644 index 000000000..128773092 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/mantle/MantleFlag.java @@ -0,0 +1,33 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.util.mantle; + +import com.volmit.iris.util.collection.StateList; + +public enum MantleFlag { + OBJECT, + VACUUM, + JIGSAW, + FEATURE + ; + static StateList getStateList() + { + return new StateList(MantleFlag.values()); + } +} From 7c3fa7aef526ab518c07f829e20d8b3b6dfabac9 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:06:49 -0400 Subject: [PATCH 04/36] Player Matter --- .../iris/util/matter/slices/PlayerMatter.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/java/com/volmit/iris/util/matter/slices/PlayerMatter.java diff --git a/src/main/java/com/volmit/iris/util/matter/slices/PlayerMatter.java b/src/main/java/com/volmit/iris/util/matter/slices/PlayerMatter.java new file mode 100644 index 000000000..41eeb2401 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/matter/slices/PlayerMatter.java @@ -0,0 +1,54 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.util.matter.slices; + +import com.volmit.iris.util.data.Varint; +import com.volmit.iris.util.matter.Sliced; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.UUID; + +@Sliced +public class PlayerMatter extends RawMatter { + public PlayerMatter() { + this(1, 1, 1); + } + + public PlayerMatter(int width, int height, int depth) { + super(width, height, depth, Player.class); + } + + @Override + public void writeNode(Player b, DataOutputStream dos) throws IOException { + Varint.writeSignedVarLong(b.getUniqueId().getMostSignificantBits(), dos); + Varint.writeSignedVarLong(b.getUniqueId().getLeastSignificantBits(), dos); + } + + @Override + public Player readNode(DataInputStream din) throws IOException { + UUID id = new UUID(Varint.readSignedVarLong(din), Varint.readSignedVarLong(din)); + + return Bukkit.getPlayer(id); + } +} From 3723c5dae55c6552946f1c5960fd7864df91751b Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:06:57 -0400 Subject: [PATCH 05/36] Replace placeObjects with useMantle --- .../volmit/iris/engine/object/dimensional/IrisDimension.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java index a908c4dd4..f9d5ee6fb 100644 --- a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java +++ b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java @@ -294,8 +294,8 @@ public class IrisDimension extends IrisRegistrant { @Desc("The configuration for island mode dimensions") private IrisTerrainIsland islandMode = new IrisTerrainIsland(); - @Desc("Disable this to stop placing schematics in biomes") - private boolean placeObjects = true; + @Desc("Disable this to stop placing objects, entities, features & updates") + private boolean useMantle = true; @Desc("Prevent Leaf decay as if placed in creative mode") private boolean preventLeafDecay = false; From d5b99316e5a005ca67b34852b07a338c05e35800 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:07:13 -0400 Subject: [PATCH 06/36] Mantle & Engine Mantle & Engine changes --- .../com/volmit/iris/engine/IrisEngine.java | 10 +-- .../volmit/iris/engine/IrisEngineMantle.java | 19 +++++ .../iris/engine/mantle/EngineMantle.java | 79 +++++++++++++++++-- 3 files changed, 98 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 9895a8b1c..ae9ac20f4 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -29,6 +29,7 @@ import com.volmit.iris.engine.actuator.IrisTerrainIslandActuator; import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.*; +import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.modifier.IrisCaveModifier; import com.volmit.iris.engine.modifier.IrisDepositModifier; import com.volmit.iris.engine.modifier.IrisPostModifier; @@ -83,6 +84,7 @@ public class IrisEngine extends BlockPopulator implements Engine { private final EngineTarget target; private final IrisContext context; private final EngineEffects effects; + private final EngineMantle mantle; private final ChronoLatch perSecondLatch; private final EngineExecutionEnvironment execution; private final EngineWorldManager worldManager; @@ -99,7 +101,6 @@ public class IrisEngine extends BlockPopulator implements Engine { private double maxBiomeLayerDensity; private double maxBiomeDecoratorDensity; private final IrisComplex complex; - private final EngineParallaxManager engineParallax; private final EngineActuator terrainNormalActuator; private final EngineActuator terrainIslandActuator; private final EngineActuator decorantActuator; @@ -121,6 +122,7 @@ public class IrisEngine extends BlockPopulator implements Engine { lastGPS = new AtomicLong(M.ms()); generated = new AtomicInteger(0); execution = new IrisExecutionEnvironment(this); + mantle = new IrisEngineMantle(this); // TODO: HEIGHT ------------------------------------------------------------------------------------------------------> Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + 256+ " height)"); metrics = new EngineMetrics(32); @@ -138,7 +140,6 @@ public class IrisEngine extends BlockPopulator implements Engine { context = new IrisContext(this); context.touch(); this.complex = new IrisComplex(this); - this.engineParallax = new IrisEngineParallax(this); this.terrainNormalActuator = new IrisTerrainNormalActuator(this); this.terrainIslandActuator = new IrisTerrainIslandActuator(this); this.decorantActuator = new IrisDecorantActuator(this); @@ -340,7 +341,6 @@ public class IrisEngine extends BlockPopulator implements Engine { cleaning.lazySet(false); } - public EngineActuator getTerrainActuator() { return switch (getDimension().getTerrainMode()) { case NORMAL -> getTerrainNormalActuator(); @@ -371,14 +371,14 @@ public class IrisEngine extends BlockPopulator implements Engine { switch (getDimension().getTerrainMode()) { case NORMAL -> { - getEngineParallax().generateParallaxArea(x >> 4, z >> 4); + getMantle().generateMatter(x>>4, z>>4); getTerrainActuator().actuate(x, z, vblocks, multicore); getBiomeActuator().actuate(x, z, vbiomes, multicore); getCaveModifier().modify(x, z, vblocks, multicore); getRavineModifier().modify(x, z, vblocks, multicore); getPostModifier().modify(x, z, vblocks, multicore); getDecorantActuator().actuate(x, z, blocks, multicore); - getEngineParallax().insertParallax(x >> 4, z >> 4, blocks); + getMantle().insertMatter(x>>4, z>>4, blocks); getDepositModifier().modify(x, z, blocks, multicore); } case ISLANDS -> { diff --git a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java index 2b7017b48..13f818482 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java @@ -20,18 +20,37 @@ package com.volmit.iris.engine; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.EngineMantle; +import com.volmit.iris.engine.mantle.IrisMantleComponent; +import com.volmit.iris.engine.mantle.MantleComponent; +import com.volmit.iris.engine.mantle.components.MantleFeatureComponent; +import com.volmit.iris.engine.mantle.components.MantleJigsawComponent; +import com.volmit.iris.engine.mantle.components.MantleVacuumComponent; +import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.mantle.Mantle; import lombok.Data; import java.io.File; +import java.util.concurrent.CompletableFuture; @Data public class IrisEngineMantle implements EngineMantle { private final Engine engine; private final Mantle mantle; + private final KList components; + private final CompletableFuture radius; public IrisEngineMantle(Engine engine) { this.engine = engine; this.mantle = new Mantle(new File(engine.getWorld().worldFolder(), "mantle"), engine.getTarget().getHeight()); + radius = CompletableFuture.completedFuture(0); // TODO + components = new KList<>(); + registerComponent(new MantleFeatureComponent(this)); + registerComponent(new MantleJigsawComponent(this)); + registerComponent(new MantleVacuumComponent(this)); + } + + @Override + public void registerComponent(MantleComponent c) { + components.add(c); } } diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 5dc36b852..90c191125 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -21,17 +21,35 @@ package com.volmit.iris.engine.mantle; import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.IrisComplex; +import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.EngineParallaxManager; import com.volmit.iris.engine.framework.EngineTarget; +import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.common.IObjectPlacer; import com.volmit.iris.engine.object.dimensional.IrisDimension; +import com.volmit.iris.engine.object.feature.IrisFeaturePositional; +import com.volmit.iris.engine.object.feature.IrisFeaturePotential; +import com.volmit.iris.engine.object.regional.IrisRegion; import com.volmit.iris.engine.object.tile.TileData; -import com.volmit.iris.engine.parallax.ParallaxAccess; +import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.B; +import com.volmit.iris.util.documentation.ChunkCoordinates; +import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.mantle.Mantle; +import com.volmit.iris.util.mantle.MantleFlag; +import com.volmit.iris.util.mantle.TectonicPlate; +import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.parallel.BurstExecutor; +import org.bukkit.Bukkit; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.function.Consumer; + +// TODO: MOVE PLACER OUT OF MATTER INTO ITS OWN THING public interface EngineMantle extends IObjectPlacer { BlockData AIR = B.get("AIR"); @@ -39,6 +57,12 @@ public interface EngineMantle extends IObjectPlacer { Engine getEngine(); + CompletableFuture getRadius(); + + KList getComponents(); + + void registerComponent(MantleComponent c); + default int getHighest(int x, int z) { return getHighest(x, z, getData()); } @@ -116,10 +140,6 @@ public interface EngineMantle extends IObjectPlacer { return getEngine().getData(); } - default ParallaxAccess getParallax() { - return getEngine().getParallax(); - } - default EngineTarget getTarget() { return getEngine().getTarget(); } @@ -135,4 +155,53 @@ public interface EngineMantle extends IObjectPlacer { default void close() { getMantle().close(); } + + default void saveAllNow() + { + + } + + default void save() + { + + } + + default void trim() + { + getMantle().trim(60000); + } + + default int getRealRadius() + { + getMantle().set(0, 34, 292393, Bukkit.getPlayer("cyberpwn")); + try { + return (int) Math.ceil(getRadius().get() / 2D); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + + return 0; + } + + + @ChunkCoordinates + default void generateMatter(int x, int z) + { + if (!getEngine().getDimension().isUseMantle()) { + return; + } + + KList post = new KList<>(); + Consumer c = post::add; + getComponents().forEach((i) -> getMantle().raiseFlag(x, z, i.getFlag(), () -> i.generateLayer(x, z, c))); + post.forEach(Runnable::run); + } + + @ChunkCoordinates + default void insertMatter(int x, int z, Hunk blocks) + { + + } } From 832bad1fee5062f6b399c37741796c5597208b94 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:07:22 -0400 Subject: [PATCH 07/36] Planned Structure support mantle --- .../iris/engine/jigsaw/PlannedStructure.java | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java index 2ba155748..ac52e8a35 100644 --- a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java +++ b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java @@ -36,6 +36,7 @@ import com.volmit.iris.engine.object.objects.*; import com.volmit.iris.engine.parallax.ParallaxChunkMeta; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.interpolation.InterpolationMethod; +import com.volmit.iris.util.mantle.Mantle; import com.volmit.iris.util.math.RNG; import lombok.Data; import org.bukkit.Axis; @@ -43,6 +44,8 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Entity; +import java.util.function.Consumer; + @Data public class PlannedStructure { private KList pieces; @@ -80,24 +83,21 @@ public class PlannedStructure { } } - public KList place(IObjectPlacer placer, EngineParallaxManager e) { - KList after = new KList<>(); + public void place(IObjectPlacer placer, Mantle e, Consumer post) { IrisObjectPlacement options = new IrisObjectPlacement(); options.getRotation().setEnabled(false); int startHeight = pieces.get(0).getPosition().getY(); for (PlannedPiece i : pieces) { - if (i.getPiece().getPlaceMode().equals(ObjectPlaceMode.VACUUM)) { + if (i.getPiece().getPlacementOptions().usesFeatures()) { place(i, startHeight, options, placer, e); } else { - after.add(() -> place(i, startHeight, options, placer, e)); + post.accept(() -> place(i, startHeight, options, placer, e)); } } - - return after; } - public void place(PlannedPiece i, int startHeight, IrisObjectPlacement o, IObjectPlacer placer, EngineParallaxManager e) { + public void place(PlannedPiece i, int startHeight, IrisObjectPlacement o, IObjectPlacer placer, Mantle e) { IrisObjectPlacement options = o; if (i.getPiece().getPlacementOptions() != null) { @@ -121,17 +121,8 @@ public class PlannedStructure { } int id = rng.i(0, Integer.MAX_VALUE); - - int h = vo.place(xx, height, zz, placer, options, rng, (b) -> { - int xf = b.getX(); - int yf = b.getY(); - int zf = b.getZ(); - e.getParallaxAccess().setObject(xf, yf, zf, v.getLoadKey() + "@" + id); - ParallaxChunkMeta meta = e.getParallaxAccess().getMetaRW(xf >> 4, zf >> 4); - meta.setObjects(true); - meta.setMinObject(Math.min(Math.max(meta.getMinObject(), 0), yf)); - meta.setMaxObject(Math.max(Math.max(meta.getMaxObject(), 0), yf)); - }, null, getData()); + int h = vo.place(xx, height, zz, placer, options, rng, (b) + -> e.set(b.getX(), b.getY(), b.getZ(), v.getLoadKey() + "@" + id), null, getData()); for (IrisJigsawPieceConnector j : i.getAvailableConnectors()) { @@ -149,13 +140,10 @@ public class PlannedStructure { } else { p.setY(height); } - for (int k = 0; k < j.getEntityCount(); k++) { - e.getParallaxAccess().setEntity(p.getX(), p.getY(), p.getZ(), j.getSpawnEntity()); - } } } - if (options.isVacuum()) { + if (options.usesFeatures()) { double a = Math.max(v.getW(), v.getD()); IrisFeature f = new IrisFeature(); f.setConvergeToHeight(h - (v.getH() >> 1) - 1); @@ -163,9 +151,7 @@ public class PlannedStructure { f.setInterpolationRadius(a / 4); f.setInterpolator(InterpolationMethod.BILINEAR_STARCAST_9); f.setStrength(1D); - e.getParallaxAccess().getMetaRW(xx >> 4, zz >> 4) - .getFeatures() - .add(new IrisFeaturePositional(xx, zz, f)); + e.set(xx, 0, zz, new IrisFeaturePositional(xx, zz, f)); } } From 252d289a8d16f73df94a228557302007469a9b66 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:07:31 -0400 Subject: [PATCH 08/36] Framework remove parallax --- .../volmit/iris/engine/framework/Engine.java | 22 +++++++------------ .../iris/engine/framework/EngineTarget.java | 10 --------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/framework/Engine.java b/src/main/java/com/volmit/iris/engine/framework/Engine.java index b816573c6..bf87a7433 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -24,6 +24,7 @@ import com.volmit.iris.core.gui.components.Renderer; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.IrisComplex; import com.volmit.iris.engine.data.cache.Cache; +import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.object.basic.IrisColor; import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.engine.object.biome.IrisBiome; @@ -80,9 +81,9 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro void printMetrics(CommandSender sender); - void recycle(); + EngineMantle getMantle(); - EngineParallaxManager getEngineParallax(); + void recycle(); EngineActuator getTerrainActuator(); @@ -143,13 +144,13 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro EngineMetrics getMetrics(); default void save() { - getParallax().saveAll(); + getMantle().save(); getWorldManager().onSave(); saveEngineData(); } default void saveNow() { - getParallax().saveAllNOW(); + getMantle().saveAllNow(); saveEngineData(); } @@ -171,10 +172,6 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro return getTarget().getDimension(); } - default ParallaxAccess getParallax() { - return getTarget().getParallaxWorld(); - } - @BlockCoordinates default Color draw(double x, double z) { IrisRegion region = getRegion((int) x, (int) z); @@ -196,11 +193,6 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro return getComplex().getRegionStream().get(x, z); } - @Override - default ParallaxAccess getParallaxAccess() { - return getParallax(); - } - @BlockCoordinates @Override default IrisBiome getCaveBiome(int x, int z) { @@ -232,6 +224,7 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro } if (B.isUpdatable(data)) { + // TODO: BLOCK UPDATES getParallax().updateBlock(x, y, z); getParallax().getMetaRW(x >> 4, z >> 4).setUpdates(true); } @@ -246,6 +239,7 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro @Override default void updateChunk(Chunk c) { PrecisionStopwatch p = PrecisionStopwatch.start(); + // TODO: Mantle block updates if (getParallax().getMetaR(c.getX(), c.getZ()).isUpdates()) { Hunk b = getParallax().getUpdatesR(c.getX(), c.getZ()); @@ -423,7 +417,7 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro } default void clean() { - burst().lazy(() -> getParallax().cleanup()); + burst().lazy(() -> getMantle().trim()); } @BlockCoordinates diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java b/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java index ae41fd725..8e1b647da 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java @@ -22,21 +22,15 @@ import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.object.common.IrisWorld; import com.volmit.iris.engine.object.dimensional.IrisDimension; -import com.volmit.iris.engine.parallax.ParallaxWorld; import com.volmit.iris.util.parallel.MultiBurst; -import lombok.Builder; import lombok.Data; -import java.io.File; - @Data public class EngineTarget { - private final MultiBurst parallaxBurster; private final MultiBurst burster; private final IrisDimension dimension; private IrisWorld world; private final IrisData data; - private final ParallaxWorld parallaxWorld; public EngineTarget(IrisWorld world, IrisDimension dimension, IrisData data) { this.world = world; @@ -45,9 +39,6 @@ public class EngineTarget { this.burster = new MultiBurst("Iris Engine " + dimension.getName(), IrisSettings.get().getConcurrency().getEngineThreadPriority(), IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getEngineThreadCount())); - this.parallaxBurster = new MultiBurst("Iris Parallax Engine " + dimension.getName(), 3, 4); - this.parallaxWorld = new ParallaxWorld(parallaxBurster, 256, new File(world.worldFolder(), - "iris/" + dimension.getLoadKey() + "/parallax")); } public int getHeight() @@ -56,7 +47,6 @@ public class EngineTarget { } public void close() { - parallaxBurster.shutdownLater(); burster.shutdownLater(); } } From 9ed3c8a6bb29cf05aa1f3c80f1168d15a4d53282 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:07:42 -0400 Subject: [PATCH 09/36] Mantle Feature Components --- .../components/MantleFeatureComponent.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/main/java/com/volmit/iris/engine/mantle/components/MantleFeatureComponent.java diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleFeatureComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleFeatureComponent.java new file mode 100644 index 000000000..58bcbfe40 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleFeatureComponent.java @@ -0,0 +1,88 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.mantle.components; + +import com.volmit.iris.engine.data.cache.Cache; +import com.volmit.iris.engine.mantle.EngineMantle; +import com.volmit.iris.engine.mantle.IrisMantleComponent; +import com.volmit.iris.engine.object.biome.IrisBiome; +import com.volmit.iris.engine.object.feature.IrisFeaturePositional; +import com.volmit.iris.engine.object.feature.IrisFeaturePotential; +import com.volmit.iris.engine.object.regional.IrisRegion; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.documentation.ChunkCoordinates; +import com.volmit.iris.util.mantle.MantleFlag; +import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.parallel.BurstExecutor; + +import java.util.function.Consumer; + +public class MantleFeatureComponent extends IrisMantleComponent { + public MantleFeatureComponent(EngineMantle engineMantle) { + super(engineMantle, MantleFlag.FEATURE); + } + + @Override + public void generateLayer(int x, int z, Consumer post) { + int s = getRadius(); + BurstExecutor burst = burst(); + + for (int i = -s; i <= s; i++) { + int xx = i + x; + int xxx = 8 + (xx << 4); + for (int j = -s; j <= s; j++) { + int zz = j + z; + int zzz = 8 + (zz << 4); + burst.queue(() -> { + RNG rng = new RNG(Cache.key(xx, zz) + seed()); + IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); + IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); + generateFeatures(rng, xx, zz, region, biome); + }); + } + } + + burst.complete(); + } + + @ChunkCoordinates + private void generateFeatures(RNG rng, int cx, int cz, IrisRegion region, IrisBiome biome) { + for (IrisFeaturePotential i : getFeatures()) { + placeZone(rng, cx, cz, i); + } + + for (IrisFeaturePotential i : region.getFeatures()) { + placeZone(rng, cx, cz, i); + } + + for (IrisFeaturePotential i : biome.getFeatures()) { + placeZone(rng, cx, cz, i); + } + } + + private void placeZone(RNG rng, int cx, int cz, IrisFeaturePotential i) { + int x = (cx << 4) + rng.nextInt(16); + int z = (cz << 4) + rng.nextInt(16); + getMantle().set(x, 0, z, new IrisFeaturePositional(x, z, i.getZone())); + } + + private KList getFeatures() { + return getEngineMantle().getEngine().getDimension().getFeatures(); + } +} From 4cdac76ca5191c2be09cceb11943240c1825064b Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:09:45 -0400 Subject: [PATCH 10/36] Fixes --- src/main/java/com/volmit/iris/engine/IrisEngineMantle.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java index 13f818482..c6052d1f1 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java @@ -24,7 +24,6 @@ import com.volmit.iris.engine.mantle.IrisMantleComponent; import com.volmit.iris.engine.mantle.MantleComponent; import com.volmit.iris.engine.mantle.components.MantleFeatureComponent; import com.volmit.iris.engine.mantle.components.MantleJigsawComponent; -import com.volmit.iris.engine.mantle.components.MantleVacuumComponent; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.mantle.Mantle; import lombok.Data; @@ -46,7 +45,6 @@ public class IrisEngineMantle implements EngineMantle { components = new KList<>(); registerComponent(new MantleFeatureComponent(this)); registerComponent(new MantleJigsawComponent(this)); - registerComponent(new MantleVacuumComponent(this)); } @Override From 378f735e9f27d5f160161a1e952b17e97305ff44 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:11:09 -0400 Subject: [PATCH 11/36] Drop support for mutations --- .../object/biome/IrisBiomeMutation.java | 104 ------------------ .../object/dimensional/IrisDimension.java | 5 - 2 files changed, 109 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/engine/object/biome/IrisBiomeMutation.java diff --git a/src/main/java/com/volmit/iris/engine/object/biome/IrisBiomeMutation.java b/src/main/java/com/volmit/iris/engine/object/biome/IrisBiomeMutation.java deleted file mode 100644 index b0b01981c..000000000 --- a/src/main/java/com/volmit/iris/engine/object/biome/IrisBiomeMutation.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.engine.object.biome; - -import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; -import com.volmit.iris.engine.object.objects.IrisObject; -import com.volmit.iris.engine.object.objects.IrisObjectPlacement; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.collection.KSet; -import com.volmit.iris.util.data.DataProvider; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("A biome mutation if a condition is met") -@Data -public class IrisBiomeMutation { - @RegistryListResource(IrisBiome.class) - @Required - @ArrayType(min = 1, type = String.class) - @Desc("One of The following biomes or regions must show up") - private KList sideA = new KList<>(); - - @RegistryListResource(IrisBiome.class) - @Required - @ArrayType(min = 1, type = String.class) - @Desc("One of The following biomes or regions must show up") - private KList sideB = new KList<>(); - - @Required - @MinNumber(1) - @MaxNumber(1024) - @Desc("The scan radius for placing this mutator") - private int radius = 16; - - @Required - @MinNumber(1) - @MaxNumber(32) - @Desc("How many tries per chunk to check for this mutation") - private int checks = 2; - - @RegistryListResource(IrisObject.class) - @ArrayType(min = 1, type = IrisObjectPlacement.class) - @Desc("Objects define what schematics (iob files) iris will place in this biome mutation") - private KList objects = new KList<>(); - - private final transient AtomicCache> sideACache = new AtomicCache<>(); - private final transient AtomicCache> sideBCache = new AtomicCache<>(); - - public KList getRealSideA(DataProvider xg) { - return sideACache.aquire(() -> processList(xg, getSideA())); - } - - public KList getRealSideB(DataProvider xg) { - return sideBCache.aquire(() -> processList(xg, getSideB())); - } - - public KList processList(DataProvider xg, KList s) { - KSet r = new KSet<>(); - - for (String i : s) { - - if (i.startsWith("^")) { - r.addAll(xg.getData().getRegionLoader().load(i.substring(1)).getLandBiomes()); - } else if (i.startsWith("*")) { - String name = i.substring(1); - r.addAll(xg.getData().getBiomeLoader().load(name).getAllChildren(xg, 7)); - } else if (i.startsWith("!")) { - r.remove(i.substring(1)); - } else if (i.startsWith("!*")) { - String name = i.substring(2); - - for (String g : xg.getData().getBiomeLoader().load(name).getAllChildren(xg, 7)) { - r.remove(g); - } - } else { - r.add(i); - } - } - - return new KList<>(r); - } -} diff --git a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java index f9d5ee6fb..35ce5e094 100644 --- a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java +++ b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java @@ -26,7 +26,6 @@ import com.volmit.iris.engine.object.annotations.*; import com.volmit.iris.engine.object.biome.InferredType; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.biome.IrisBiomeCustom; -import com.volmit.iris.engine.object.biome.IrisBiomeMutation; import com.volmit.iris.engine.object.block.IrisBlockDrops; import com.volmit.iris.engine.object.block.IrisMaterialPalette; import com.volmit.iris.engine.object.carve.IrisCarveLayer; @@ -330,10 +329,6 @@ public class IrisDimension extends IrisRegistrant { @Desc("The palette of blocks for 'water'") private IrisMaterialPalette fluidPalette = new IrisMaterialPalette().qclear().qadd("water"); - @ArrayType(min = 1, type = IrisBiomeMutation.class) - @Desc("Define biome mutations for this dimension") - private KList mutations = new KList<>(); - @Desc("Cartographer map trade overrides") private IrisVillagerOverride patchCartographers = new IrisVillagerOverride().setDisableTrade(false); From 037473f2e15f91e7167a8b710bc469aa3d4d685c Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:26:22 -0400 Subject: [PATCH 12/36] Cleanup components --- .../volmit/iris/engine/IrisEngineMantle.java | 2 + .../iris/engine/mantle/EngineMantle.java | 20 ++- .../components/MantleJigsawComponent.java | 20 +-- .../components/MantleObjectComponent.java | 145 ++++++++++++++++++ .../iris/util/parallel/BurstExecutor.java | 3 +- .../volmit/iris/util/parallel/MultiBurst.java | 3 +- 6 files changed, 179 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java diff --git a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java index c6052d1f1..8c2b6279e 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java @@ -24,6 +24,7 @@ import com.volmit.iris.engine.mantle.IrisMantleComponent; import com.volmit.iris.engine.mantle.MantleComponent; import com.volmit.iris.engine.mantle.components.MantleFeatureComponent; import com.volmit.iris.engine.mantle.components.MantleJigsawComponent; +import com.volmit.iris.engine.mantle.components.MantleObjectComponent; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.mantle.Mantle; import lombok.Data; @@ -45,6 +46,7 @@ public class IrisEngineMantle implements EngineMantle { components = new KList<>(); registerComponent(new MantleFeatureComponent(this)); registerComponent(new MantleJigsawComponent(this)); + registerComponent(new MantleObjectComponent(this)); } @Override diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 90c191125..f025eea32 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -41,10 +41,14 @@ import com.volmit.iris.util.mantle.MantleFlag; import com.volmit.iris.util.mantle.TectonicPlate; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.BurstExecutor; +import com.volmit.iris.util.parallel.MultiBurst; import org.bukkit.Bukkit; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; @@ -171,6 +175,11 @@ public interface EngineMantle extends IObjectPlacer { getMantle().trim(60000); } + default MultiBurst burst() + { + return getEngine().burst(); + } + default int getRealRadius() { getMantle().set(0, 34, 292393, Bukkit.getPlayer("cyberpwn")); @@ -193,10 +202,15 @@ public interface EngineMantle extends IObjectPlacer { return; } - KList post = new KList<>(); + List post = Collections.synchronizedList(new KList<>()); Consumer c = post::add; - getComponents().forEach((i) -> getMantle().raiseFlag(x, z, i.getFlag(), () -> i.generateLayer(x, z, c))); - post.forEach(Runnable::run); + getComponents().forEach((i) -> generateMantleComponent(x, z, i, c)); + burst().burst(post); + } + + default void generateMantleComponent(int x, int z, MantleComponent i, Consumer post) + { + getMantle().raiseFlag(x, z, i.getFlag(), () -> i.generateLayer(x, z, post)); } @ChunkCoordinates diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java index 2b0f3af05..ebf225890 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java @@ -28,7 +28,8 @@ import com.volmit.iris.engine.object.feature.IrisFeaturePositional; import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructure; import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement; import com.volmit.iris.engine.object.regional.IrisRegion; -import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.documentation.BlockCoordinates; +import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.mantle.MantleFlag; import com.volmit.iris.util.math.Position2; import com.volmit.iris.util.math.RNG; @@ -58,7 +59,7 @@ public class MantleJigsawComponent extends IrisMantleComponent RNG rng = new RNG(Cache.key(xx, zz) + seed()); IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); - generateParallaxJigsaw(rng, xx, zz, biome, region, post); + generateJigsaw(rng, xx, zz, biome, region, post); }); } } @@ -66,7 +67,8 @@ public class MantleJigsawComponent extends IrisMantleComponent burst.complete(); } - private void generateParallaxJigsaw(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer post) { + @ChunkCoordinates + private void generateJigsaw(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer post) { boolean placed = false; if (getDimension().getStronghold() != null) { @@ -76,7 +78,7 @@ public class MantleJigsawComponent extends IrisMantleComponent for (Position2 pos : poss) { if (x == pos.getX() >> 4 && z == pos.getZ() >> 4) { IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(getDimension().getStronghold()); - placeStructure(pos.toIris(), structure, rng, post); + place(pos.toIris(), structure, rng, post); placed = true; } } @@ -88,7 +90,7 @@ public class MantleJigsawComponent extends IrisMantleComponent if (rng.nextInt(i.getRarity()) == 0) { IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15)); IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure()); - placeStructure(position, structure, rng, post); + place(position, structure, rng, post); placed = true; } } @@ -99,7 +101,7 @@ public class MantleJigsawComponent extends IrisMantleComponent if (rng.nextInt(i.getRarity()) == 0) { IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15)); IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure()); - placeStructure(position, structure, rng, post); + place(position, structure, rng, post); placed = true; } } @@ -110,14 +112,14 @@ public class MantleJigsawComponent extends IrisMantleComponent if (rng.nextInt(i.getRarity()) == 0) { IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15)); IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure()); - placeStructure(position, structure, rng, post); + place(position, structure, rng, post); } } } } - - private void placeStructure(IrisPosition position, IrisJigsawStructure structure, RNG rng, Consumer post) { + @BlockCoordinates + private void place(IrisPosition position, IrisJigsawStructure structure, RNG rng, Consumer post) { if (structure.getFeature() != null) { if (structure.getFeature().getBlockRadius() == 32) { structure.getFeature().setBlockRadius((double) structure.getMaxDimension() / 3); diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java new file mode 100644 index 000000000..7a2a11bd2 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java @@ -0,0 +1,145 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.mantle.components; + +import com.volmit.iris.Iris; +import com.volmit.iris.engine.data.cache.Cache; +import com.volmit.iris.engine.mantle.EngineMantle; +import com.volmit.iris.engine.mantle.IrisMantleComponent; +import com.volmit.iris.engine.object.biome.IrisBiome; +import com.volmit.iris.engine.object.feature.IrisFeature; +import com.volmit.iris.engine.object.feature.IrisFeaturePositional; +import com.volmit.iris.engine.object.feature.IrisFeaturePotential; +import com.volmit.iris.engine.object.objects.IrisObject; +import com.volmit.iris.engine.object.objects.IrisObjectPlacement; +import com.volmit.iris.engine.object.regional.IrisRegion; +import com.volmit.iris.util.documentation.ChunkCoordinates; +import com.volmit.iris.util.mantle.MantleFlag; +import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.parallel.BurstExecutor; + +import java.util.function.Consumer; + +public class MantleObjectComponent extends IrisMantleComponent { + public MantleObjectComponent(EngineMantle engineMantle) { + super(engineMantle, MantleFlag.FEATURE); + } + + @Override + public void generateLayer(int x, int z, Consumer post) { + int s = getRadius(); + BurstExecutor burst = burst(); + + for (int i = -s; i <= s; i++) { + int xx = i + x; + int xxx = 8 + (xx << 4); + for (int j = -s; j <= s; j++) { + int zz = j + z; + int zzz = 8 + (zz << 4); + burst.queue(() -> { + RNG rng = new RNG(Cache.key(xx, zz) + seed()); + IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); + IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); + placeObjects(rng, xx, zz, biome, region, post); + }); + } + } + + burst.complete(); + } + + @ChunkCoordinates + private void placeObjects(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer post) { + + for (IrisObjectPlacement i : biome.getSurfaceObjects()) { + if (rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && rng.chance(getComplex().getObjectChanceStream().get(x << 4, z << 4))) { + try { + placeObject(rng, x << 4, z << 4, i, post); + } catch (Throwable e) { + Iris.reportError(e); + Iris.error("Failed to place objects in the following biome: " + biome.getName()); + Iris.error("Object(s) " + i.getPlace().toString(", ") + " (" + e.getClass().getSimpleName() + ")."); + Iris.error("Are these objects missing?"); + e.printStackTrace(); + } + } + } + + for (IrisObjectPlacement i : region.getSurfaceObjects()) { + if (rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && rng.chance(getComplex().getObjectChanceStream().get(x << 4, z << 4))) { + try { + placeObject(rng, x << 4, z << 4, i, post); + } catch (Throwable e) { + Iris.reportError(e); + Iris.error("Failed to place objects in the following region: " + region.getName()); + Iris.error("Object(s) " + i.getPlace().toString(", ") + " (" + e.getClass().getSimpleName() + ")."); + Iris.error("Are these objects missing?"); + e.printStackTrace(); + } + } + } + } + + private void placeObject(RNG rng, int x, int z, IrisObjectPlacement objectPlacement, Consumer post) { + for (int i = 0; i < objectPlacement.getDensity(); i++) { + IrisObject v = objectPlacement.getScale().get(rng, objectPlacement.getObject(getComplex(), rng)); + if (v == null) { + return; + } + int xx = rng.i(x, x + 16); + int zz = rng.i(z, z + 16); + int id = rng.i(0, Integer.MAX_VALUE); + + Runnable r = () -> { + int h = v.place(xx, -1, zz, getEngineMantle(), objectPlacement, rng, + (b) -> getMantle().set(b.getX(), b.getY(), b.getZ(), + v.getLoadKey() + "@" + id), null, getData()); + + if (objectPlacement.usesFeatures()) { + if (objectPlacement.isVacuum()) { + + double a = Math.max(v.getW(), v.getD()); + IrisFeature f = new IrisFeature(); + f.setConvergeToHeight(h - (v.getH() >> 1)); + f.setBlockRadius(a); + f.setInterpolationRadius(objectPlacement.getVacuumInterpolationRadius()); + f.setInterpolator(objectPlacement.getVacuumInterpolationMethod()); + f.setStrength(1D); + getMantle().set(xx,0,zz,new IrisFeaturePositional(xx, zz, f)); + } + + for (IrisFeaturePotential j : objectPlacement.getAddFeatures()) { + if (j.hasZone(rng, xx >> 4, zz >> 4)) { + getMantle().set(xx,0,zz,new IrisFeaturePositional(xx, zz, j.getZone())); + } + } + } + }; + + if (objectPlacement.usesFeatures()) { + r.run(); + } + + else + { + post.accept(r); + } + } + } +} diff --git a/src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java b/src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java index 7e43908fe..9129a0c3f 100644 --- a/src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java +++ b/src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java @@ -21,6 +21,7 @@ package com.volmit.iris.util.parallel; import com.volmit.iris.Iris; import com.volmit.iris.util.collection.KList; +import java.util.List; import java.util.concurrent.*; @SuppressWarnings("ALL") @@ -42,7 +43,7 @@ public class BurstExecutor { } } - public BurstExecutor queue(KList r) { + public BurstExecutor queue(List r) { synchronized (futures) { for (Runnable i : r) { CompletableFuture c = CompletableFuture.runAsync(i, executor); diff --git a/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java b/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java index 61a07ec12..5e81d74da 100644 --- a/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java +++ b/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java @@ -26,6 +26,7 @@ import com.volmit.iris.util.math.M; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.Looper; +import java.util.List; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Supplier; @@ -99,7 +100,7 @@ public class MultiBurst { burst(r.length).queue(r).complete(); } - public void burst(KList r) { + public void burst(List r) { burst(r.size()).queue(r).complete(); } From a99f2b78a1804272b1caab22ee8394682e31a387 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:38:43 -0400 Subject: [PATCH 13/36] Drop gen access & merge with engine --- .../com/volmit/iris/engine/IrisEngine.java | 4 +- .../volmit/iris/engine/framework/Engine.java | 80 +- .../framework/EngineParallaxManager.java | 941 ------------------ .../engine/framework/GeneratorAccess.java | 80 -- 4 files changed, 56 insertions(+), 1049 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/engine/framework/EngineParallaxManager.java delete mode 100644 src/main/java/com/volmit/iris/engine/framework/GeneratorAccess.java diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index ae9ac20f4..f73e67d02 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -301,7 +301,7 @@ public class IrisEngine extends BlockPopulator implements Engine { getWorldManager().close(); getTarget().close(); saveEngineData(); - getEngineParallax().close(); + getMantle().close(); getTerrainActuator().close(); getDecorantActuator().close(); getBiomeActuator().close(); @@ -330,7 +330,7 @@ public class IrisEngine extends BlockPopulator implements Engine { cleaning.set(true); try { - getParallax().cleanup(); + getMantle().trim(); getData().getObjectLoader().clean(); } catch (Throwable e) { Iris.reportError(e); diff --git a/src/main/java/com/volmit/iris/engine/framework/Engine.java b/src/main/java/com/volmit/iris/engine/framework/Engine.java index bf87a7433..209d08770 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -35,6 +35,7 @@ import com.volmit.iris.engine.object.loot.IrisLootMode; import com.volmit.iris.engine.object.loot.IrisLootReference; import com.volmit.iris.engine.object.loot.IrisLootTable; import com.volmit.iris.engine.object.meta.InventorySlotType; +import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.engine.object.regional.IrisRegion; import com.volmit.iris.engine.parallax.ParallaxAccess; import com.volmit.iris.engine.scripting.EngineExecutionEnvironment; @@ -47,6 +48,8 @@ import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.function.Function2; import com.volmit.iris.util.hunk.Hunk; +import com.volmit.iris.util.mantle.Mantle; +import com.volmit.iris.util.mantle.MantleFlag; import com.volmit.iris.util.math.BlockPosition; import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RNG; @@ -76,7 +79,7 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootProvider, BlockUpdater, Renderer { +public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdater, Renderer { IrisComplex getComplex(); void printMetrics(CommandSender sender); @@ -188,32 +191,28 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro } @BlockCoordinates - @Override default IrisRegion getRegion(int x, int z) { return getComplex().getRegionStream().get(x, z); } @BlockCoordinates - @Override default IrisBiome getCaveBiome(int x, int z) { return getComplex().getCaveBiomeStream().get(x, z); } @BlockCoordinates - @Override default IrisBiome getSurfaceBiome(int x, int z) { return getComplex().getTrueBiomeStream().get(x, z); } @BlockCoordinates - @Override default int getHeight(int x, int z) { return getHeight(x, z, true); } @BlockCoordinates default int getHeight(int x, int z, boolean ignoreFluid) { - return getEngineParallax().getHighest(x, z, getData(), ignoreFluid); + return getMantle().getHighest(x, z, getData(), ignoreFluid); } @BlockCoordinates @@ -224,9 +223,7 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro } if (B.isUpdatable(data)) { - // TODO: BLOCK UPDATES - getParallax().updateBlock(x, y, z); - getParallax().getMetaRW(x >> 4, z >> 4).setUpdates(true); + getMantle().updateBlock(x, y, z); } } @@ -239,24 +236,17 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro @Override default void updateChunk(Chunk c) { PrecisionStopwatch p = PrecisionStopwatch.start(); - // TODO: Mantle block updates - if (getParallax().getMetaR(c.getX(), c.getZ()).isUpdates()) { - Hunk b = getParallax().getUpdatesR(c.getX(), c.getZ()); + getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), Boolean.class, (x, y, z, v) -> { + if (v != null && v) { + int vx = x & 15; + int vz = z & 15; + update(x, y, z, c, new RNG(Cache.key(c.getX(), c.getZ()))); - b.iterateSync((x, y, z, v) -> { - - if (v != null && v) { - int vx = x & 15; - int vz = z & 15; - update(x, y, z, c, new RNG(Cache.key(c.getX(), c.getZ()))); - - if (vx > 0 && vx < 15 && vz > 0 && vz < 15) { - updateLighting(x, y, z, c); - } + if (vx > 0 && vx < 15 && vz > 0 && vz < 15) { + updateLighting(x, y, z, c); } - }); - } - + } + }, MantleFlag.UPDATE); getMetrics().getUpdates().put(p.getMilliseconds()); } @@ -271,7 +261,6 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro block.setBlockData(data, true); } catch (Exception e) { Iris.reportError(e); - // Issue when adding block data. Suppress massive warnings and stack-traces to console. } } } @@ -636,4 +625,43 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro } boolean isStudio(); + + default IrisBiome getBiome(int x, int y, int z) { + if (y <= getHeight(x, z) - 2) { + return getCaveBiome(x, z); + } + + return getSurfaceBiome(x, z); + } + + default PlacedObject getObjectPlacement(int x, int y, int z) { + String objectAt = getMantle().getMantle().get(x,y,z, String.class); + + if (objectAt == null || objectAt.isEmpty()) { + return null; + } + + String[] v = objectAt.split("\\Q@\\E"); + String object = v[0]; + int id = Integer.parseInt(v[1]); + IrisRegion region = getRegion(x, z); + + for (IrisObjectPlacement i : region.getObjects()) { + if (i.getPlace().contains(object)) { + return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z); + } + } + + IrisBiome biome = getBiome(x, y, z); + + for (IrisObjectPlacement i : biome.getObjects()) { + if (i.getPlace().contains(object)) { + return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z); + } + } + + return new PlacedObject(null, getData().getObjectLoader().load(object), id, x, z); + } + + int getCacheID(); } diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineParallaxManager.java b/src/main/java/com/volmit/iris/engine/framework/EngineParallaxManager.java deleted file mode 100644 index 7c4a729f8..000000000 --- a/src/main/java/com/volmit/iris/engine/framework/EngineParallaxManager.java +++ /dev/null @@ -1,941 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.engine.framework; - -import com.volmit.iris.Iris; -import com.volmit.iris.core.project.loader.IrisData; -import com.volmit.iris.engine.IrisComplex; -import com.volmit.iris.engine.data.cache.Cache; -import com.volmit.iris.engine.jigsaw.PlannedStructure; -import com.volmit.iris.engine.object.basic.IrisPosition; -import com.volmit.iris.engine.object.biome.IrisBiome; -import com.volmit.iris.engine.object.biome.IrisBiomeMutation; -import com.volmit.iris.engine.object.common.IObjectPlacer; -import com.volmit.iris.engine.object.deposits.IrisDepositGenerator; -import com.volmit.iris.engine.object.feature.IrisFeature; -import com.volmit.iris.engine.object.feature.IrisFeaturePositional; -import com.volmit.iris.engine.object.feature.IrisFeaturePotential; -import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructure; -import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement; -import com.volmit.iris.engine.object.objects.IrisObject; -import com.volmit.iris.engine.object.objects.IrisObjectPlacement; -import com.volmit.iris.engine.object.objects.IrisObjectScale; -import com.volmit.iris.engine.object.regional.IrisRegion; -import com.volmit.iris.engine.object.tile.TileData; -import com.volmit.iris.engine.parallax.ParallaxAccess; -import com.volmit.iris.engine.parallax.ParallaxChunkMeta; -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.data.B; -import com.volmit.iris.util.data.DataProvider; -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.hunk.Hunk; -import com.volmit.iris.util.math.Position2; -import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.parallel.BurstExecutor; -import com.volmit.iris.util.scheduling.J; -import com.volmit.iris.util.scheduling.PrecisionStopwatch; -import org.bukkit.Chunk; -import org.bukkit.ChunkSnapshot; -import org.bukkit.block.TileState; -import org.bukkit.block.data.BlockData; -import org.bukkit.util.BlockVector; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -public interface EngineParallaxManager extends DataProvider, IObjectPlacer { - BlockData AIR = B.get("AIR"); - - Engine getEngine(); - - int getParallaxSize(); - - default ParallaxAccess getParallaxAccess() { - return getEngine().getParallax(); - } - - default IrisData getData() { - return getEngine().getData(); - } - - default IrisComplex getComplex() { - return getEngine().getComplex(); - } - - default KList getAllRegions() { - KList r = new KList<>(); - - for (String i : getEngine().getDimension().getRegions()) { - r.add(getEngine().getData().getRegionLoader().load(i)); - } - - return r; - } - - default KList getAllFeatures() { - KList r = new KList<>(); - r.addAll(getEngine().getDimension().getFeatures()); - getAllRegions().forEach((i) -> r.addAll(i.getFeatures())); - getAllBiomes().forEach((i) -> r.addAll(i.getFeatures())); - return r; - } - - default KList getAllBiomes() { - KList r = new KList<>(); - - for (IrisRegion i : getAllRegions()) { - r.addAll(i.getAllBiomes(this)); - } - - return r; - } - - /** - * Verifies the chunk correctly has all the parallax objects it should. - * This method should not have to be written but why not. - * Thread Safe, Designed to run async - * - * @param c the bukkit chunk - */ - default int repairChunk(Chunk c) { - ParallaxChunkMeta m = getParallaxAccess().getMetaR(c.getX(), c.getZ()); - Hunk o = getParallaxAccess().getObjectsR(c.getX(), c.getZ()); - Hunk b = getParallaxAccess().getBlocksR(c.getX(), c.getZ()); - ChunkSnapshot snapshot = c.getChunkSnapshot(false, false, false); - KList queue = new KList<>(); - - o.iterateSync((x, y, z, s) -> { - if (s != null) { - - BlockData bd = b.get(x, y, z); - if (bd != null) { - BlockData bdx = snapshot.getBlockData(x, y, z); - - if (!bdx.getMaterial().equals(bd.getMaterial())) { - queue.add(() -> c.getBlock(x, y, z).setBlockData(bd, false)); - } - } - } - }); - - AtomicBoolean bx = new AtomicBoolean(false); - J.s(() -> { - queue.forEach(Runnable::run); - bx.set(true); - }); - - while (!bx.get()) { - J.sleep(50); - } - - return queue.size(); - } - - default void insertTileEntities(int x, int z, Consumer4> consumer) { - ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(x >> 4, z >> 4); - - if (meta.isTilesGenerated()) { - return; - } - - meta.setTilesGenerated(true); - - getParallaxAccess().getTilesRW(x >> 4, z >> 4).iterateSync((a, b, c, d) -> { - if (d != null) { - consumer.accept(a, b, c, d); - } - }); - } - - @ChunkCoordinates - default void insertParallax(int x, int z, Hunk data) { - if (!getEngine().getDimension().isPlaceObjects()) { - return; - } - - try { - PrecisionStopwatch p = PrecisionStopwatch.start(); - ParallaxChunkMeta meta = getParallaxAccess().getMetaR(x, z); - - if (!meta.isParallaxGenerated()) { - generateParallaxLayer(x, z, true); - meta = getParallaxAccess().getMetaR(x, z); - } - - if (!meta.isObjects()) { - getEngine().getMetrics().getParallaxInsert().put(p.getMilliseconds()); - return; - } - - getParallaxAccess().getBlocksR(x, z).iterateSync((a, b, c, d) -> { - if (d != null) { - data.set(a, b, c, d); - } - }); - - getEngine().getMetrics().getParallaxInsert().put(p.getMilliseconds()); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("Failed to insert parallax at chunk " + x + " " + z); - e.printStackTrace(); - } - } - - @ChunkCoordinates - default KList getFeaturesInChunk(int x, int z) { - KList pos = new KList<>(); - - for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) { - if (i.shouldFilter((x << 4) + 8, (z << 4) + 8, getEngine().getComplex().getRng(), getData())) { - pos.add(i); - } - } - - for (IrisFeaturePositional i : getParallaxAccess().getMetaR(x, z).getFeatures()) { - if (i.shouldFilter((x << 4) + 8, (z << 4) + 8, getEngine().getComplex().getRng(), getData())) { - pos.add(i); - } - } - - pos.add(forEachFeature(x << 4, z << 4)); - pos.add(forEachFeature(((x + 1) << 4) - 1, z << 4)); - pos.add(forEachFeature(x << 4, ((z + 1) << 4) - 1)); - pos.add(forEachFeature(((x + 1) << 4) - 1, ((z + 1) << 4) - 1)); - pos.removeDuplicates(); - return pos; - } - - @BlockCoordinates - default KList forEachFeature(double x, double z) { - KList pos = new KList<>(); - - if (!getEngine().getDimension().hasFeatures(getEngine())) { - return pos; - } - - for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) { - if (i.shouldFilter(x, z, getEngine().getComplex().getRng(), getData())) { - pos.add(i); - } - } - - 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); - - try { - for (IrisFeaturePositional k : m.getFeatures()) { - if (k.shouldFilter(x, z, getEngine().getComplex().getRng(), getData())) { - pos.add(k); - } - } - } catch (Throwable e) { - Iris.error("FILTER ERROR" + " AT " + (cx + i) + " " + (j + cz)); - e.printStackTrace(); - Iris.reportError(e); - } - } - } - - return pos; - } - - @ChunkCoordinates - @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") - default void generateParallaxArea(int x, int z) { - if (!getEngine().getDimension().isPlaceObjects()) { - return; - } - - try { - PrecisionStopwatch p = PrecisionStopwatch.start(); - - int s = (int) Math.ceil(getParallaxSize() / 2D); - int i, j; - KList after = new KList<>(); - int bs = (int) Math.pow((s * 2) + 1, 2); - BurstExecutor burst = getEngine().getTarget().getBurster().burst(bs); - for (i = -s; i <= s; i++) { - for (j = -s; j <= s; j++) { - int xx = i + x; - int zz = j + z; - int xxx = xx << 4; - int zzz = zz << 4; - if (!getParallaxAccess().isFeatureGenerated(xx, zz)) { - getParallaxAccess().setFeatureGenerated(xx, zz); - burst.queue(() -> { - RNG rng = new RNG(Cache.key(xx, zz) + getEngine().getTarget().getWorld().seed()); - IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); - IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); - generateParallaxFeatures(rng, xx, zz, region, biome); - }); - } - } - } - - burst.complete(); - - if (getEngine().getDimension().isPlaceObjects()) { - burst = getEngine().getTarget().getBurster().burst(bs); - - for (i = -s; i <= s; i++) { - int ii = i; - for (j = -s; j <= s; j++) { - int jj = j; - burst.queue(() -> { - KList a = generateParallaxVacuumLayer(ii + x, jj + z); - synchronized (a) { - after.addAll(a); - } - }); - } - } - - burst.complete(); - burst = getEngine().getTarget().getBurster().burst(bs); - - for (i = -s; i <= s; i++) { - int ii = i; - for (j = -s; j <= s; j++) { - int jj = j; - burst.queue(() -> generateParallaxLayer(ii + x, jj + z)); - } - } - - burst.complete(); - } - - getEngine().getTarget().getBurster().burst(after); - getParallaxAccess().setChunkGenerated(x, z); - p.end(); - getEngine().getMetrics().getParallax().put(p.getMilliseconds()); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("Failed to generate parallax in " + x + " " + z); - e.printStackTrace(); - } - } - - @ChunkCoordinates - default KList generateParallaxVacuumLayer(int x, int z) { - KList after = new KList<>(); - if (getParallaxAccess().isParallaxGenerated(x, z)) { - return after; - } - - if (getEngine().getDimension().isPlaceObjects()) { - int xx = x << 4; - int zz = z << 4; - RNG rng = new RNG(Cache.key(x, z)).nextParallelRNG(getEngine().getTarget().getWorld().seed()); - IrisRegion region = getComplex().getRegionStream().get(xx + 8, zz + 8); - IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xx + 8, zz + 8); - after.addAll(generateParallaxJigsaw(rng, x, z, biome, region)); - generateParallaxSurface(rng, x, z, biome, region, true); - generateParallaxMutations(rng, x, z, true); - } - - return after; - } - - default void generateParallaxLayer(int x, int z, boolean force) { - if (!force && getParallaxAccess().isParallaxGenerated(x, z)) { - return; - } - - int xx = x << 4; - int zz = z << 4; - getParallaxAccess().setParallaxGenerated(x, z); - RNG rng = new RNG(Cache.key(x, z)).nextParallelRNG(getEngine().getTarget().getWorld().seed()); - IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xx + 8, zz + 8); - IrisRegion region = getComplex().getRegionStream().get(xx + 8, zz + 8); - generateParallaxSurface(rng, x, z, biome, region, false); - generateParallaxMutations(rng, x, z, false); - } - - @ChunkCoordinates - default void generateParallaxFeatures(RNG rng, int cx, int cz, IrisRegion region, IrisBiome biome) { - for (IrisFeaturePotential i : getEngine().getDimension().getFeatures()) { - placeZone(rng, cx, cz, i); - } - - for (IrisFeaturePotential i : region.getFeatures()) { - placeZone(rng, cx, cz, i); - } - - for (IrisFeaturePotential i : biome.getFeatures()) { - placeZone(rng, cx, cz, i); - } - } - - default void placeZone(RNG rng, int cx, int cz, IrisFeaturePotential i) { - if (i.hasZone(rng, cx, cz)) { - getParallaxAccess().getMetaRW(cx, cz).getFeatures() - .add(new IrisFeaturePositional( - (cx << 4) + rng.nextInt(16), - (cz << 4) + rng.nextInt(16), - i.getZone())); - } - } - - default void generateParallaxLayer(int x, int z) { - generateParallaxLayer(x, z, false); - } - - default KList placeStructure(IrisPosition position, IrisJigsawStructure structure, RNG rng) { - KList placeAfter = new KList<>(); - - if (structure == null) { - return null; - } - - if (structure.getFeature() != null) { - if (structure.getFeature().getBlockRadius() == 32) { - structure.getFeature().setBlockRadius((double) structure.getMaxDimension() / 3); - } - - getParallaxAccess().getMetaRW(position.getX() >> 4, position.getZ() >> 4).getFeatures() - .add(new IrisFeaturePositional(position.getX(), position.getZ(), structure.getFeature())); - } - - placeAfter.addAll(new PlannedStructure(structure, position, rng).place(this, this)); - return placeAfter; - } - - default KList generateParallaxJigsaw(RNG rng, int x, int z, IrisBiome biome, IrisRegion region) { - KList placeAfter = new KList<>(); - - if (getEngine().getDimension().isPlaceObjects()) { - boolean placed = false; - - if (getEngine().getDimension().getStronghold() != null) { - List poss = getEngine().getDimension().getStrongholds(getEngine().getWorld().seed()); - - if (poss != null) { - for (Position2 pos : poss) { - if (x == pos.getX() >> 4 && z == pos.getZ() >> 4) { - IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(getEngine().getDimension().getStronghold()); - placeAfter.addAll(placeStructure(pos.toIris(), structure, rng)); - placed = true; - } - } - } - } - - if (!placed) { - for (IrisJigsawStructurePlacement i : biome.getJigsawStructures()) { - if (rng.nextInt(i.getRarity()) == 0) { - IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15)); - IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure()); - placeAfter.addAll(placeStructure(position, structure, rng)); - placed = true; - } - } - } - - if (!placed) { - for (IrisJigsawStructurePlacement i : region.getJigsawStructures()) { - if (rng.nextInt(i.getRarity()) == 0) { - IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15)); - IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure()); - placeAfter.addAll(placeStructure(position, structure, rng)); - placed = true; - } - } - } - - if (!placed) { - for (IrisJigsawStructurePlacement i : getEngine().getDimension().getJigsawStructures()) { - if (rng.nextInt(i.getRarity()) == 0) { - IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15)); - IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure()); - placeAfter.addAll(placeStructure(position, structure, rng)); - placed = true; - } - } - } - } - - return placeAfter; - } - - default void generateParallaxSurface(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, boolean useFeatures) { - - for (IrisObjectPlacement i : biome.getSurfaceObjects()) { - if (i.usesFeatures() != useFeatures) { - continue; - } - - if (rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && rng.chance(getComplex().getObjectChanceStream().get(x << 4, z << 4))) { - try { - place(rng, x << 4, z << 4, i); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("Failed to place objects in the following biome: " + biome.getName()); - Iris.error("Object(s) " + i.getPlace().toString(", ") + " (" + e.getClass().getSimpleName() + ")."); - Iris.error("Are these objects missing?"); - e.printStackTrace(); - } - } - } - - for (IrisObjectPlacement i : region.getSurfaceObjects()) { - if (i.usesFeatures() != useFeatures) { - continue; - } - - if (rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && rng.chance(getComplex().getObjectChanceStream().get(x << 4, z << 4))) { - try { - place(rng, x << 4, z << 4, i); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("Failed to place objects in the following region: " + region.getName()); - Iris.error("Object(s) " + i.getPlace().toString(", ") + " (" + e.getClass().getSimpleName() + ")."); - Iris.error("Are these objects missing?"); - e.printStackTrace(); - } - } - } - } - - default void generateParallaxMutations(RNG rng, int x, int z, boolean useFeatures) { - if (getEngine().getDimension().getMutations().isEmpty()) { - return; - } - - searching: - for (IrisBiomeMutation k : getEngine().getDimension().getMutations()) { - for (int l = 0; l < k.getChecks(); l++) { - IrisBiome sa = getComplex().getTrueBiomeStreamNoFeatures().get(((x * 16) + rng.nextInt(16)) + rng.i(-k.getRadius(), k.getRadius()), ((z * 16) + rng.nextInt(16)) + rng.i(-k.getRadius(), k.getRadius())); - IrisBiome sb = getComplex().getTrueBiomeStreamNoFeatures().get(((x * 16) + rng.nextInt(16)) + rng.i(-k.getRadius(), k.getRadius()), ((z * 16) + rng.nextInt(16)) + rng.i(-k.getRadius(), k.getRadius())); - - 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 (m.usesFeatures() != useFeatures) { - continue; - } - - place(rng.nextParallelRNG((34 * ((x * 30) + (z * 30)) * x * z) + x - z + 1569962), x, z, m); - } - - continue searching; - } - } - } - } - - default void place(RNG rng, int x, int z, IrisObjectPlacement objectPlacement) { - place(rng, x, -1, z, objectPlacement); - } - - default void placePiece(RNG rng, int xx, int forceY, int zz, IrisObject v, IrisObjectPlacement p) { - int id = rng.i(0, Integer.MAX_VALUE); - int maxf = 10000; - AtomicBoolean pl = new AtomicBoolean(false); - AtomicInteger max = new AtomicInteger(-1); - AtomicInteger min = new AtomicInteger(maxf); - int h = v.place(xx, forceY, zz, this, p, rng, (b) -> { - int xf = b.getX(); - int yf = b.getY(); - int zf = b.getZ(); - getParallaxAccess().setObject(xf, yf, zf, v.getLoadKey() + "@" + id); - ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(xf >> 4, zf >> 4); - meta.setObjects(true); - meta.setMinObject(Math.min(Math.max(meta.getMinObject(), 0), yf)); - meta.setMaxObject(Math.max(Math.max(meta.getMaxObject(), 0), yf)); - - }, null, getData()); - - if (p.usesFeatures()) { - if (p.isVacuum()) { - ParallaxChunkMeta rw = getParallaxAccess().getMetaRW(xx >> 4, zz >> 4); - double a = Math.max(v.getW(), v.getD()); - IrisFeature f = new IrisFeature(); - f.setConvergeToHeight(h - (v.getH() >> 1)); - f.setBlockRadius(a); - f.setInterpolationRadius(p.getVacuumInterpolationRadius()); - f.setInterpolator(p.getVacuumInterpolationMethod()); - f.setStrength(1D); - - rw.getFeatures().add(new IrisFeaturePositional(xx, zz, f)); - } - - for (IrisFeaturePotential j : p.getAddFeatures()) { - if (j.hasZone(rng, xx >> 4, zz >> 4)) { - ParallaxChunkMeta rw = getParallaxAccess().getMetaRW(xx >> 4, zz >> 4); - rw.getFeatures().add(new IrisFeaturePositional(xx + 1, zz - 1, j.getZone())); - } - } - } - - - } - - default void place(RNG rng, int x, int forceY, int z, IrisObjectPlacement objectPlacement) { - placing: - for (int i = 0; i < objectPlacement.getDensity(); i++) { - IrisObject v = objectPlacement.getScale().get(rng, objectPlacement.getObject(getComplex(), rng)); - if (v == null) { - return; - } - int xx = rng.i(x, x + 16); - int zz = rng.i(z, z + 16); - int id = rng.i(0, Integer.MAX_VALUE); - - int h = v.place(xx, forceY, zz, this, objectPlacement, rng, (b) -> { - int xf = b.getX(); - int yf = b.getY(); - int zf = b.getZ(); - getParallaxAccess().setObject(xf, yf, zf, v.getLoadKey() + "@" + id); - ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(xf >> 4, zf >> 4); - meta.setObjects(true); - meta.setMinObject(Math.min(Math.max(meta.getMinObject(), 0), yf)); - meta.setMaxObject(Math.max(Math.max(meta.getMaxObject(), 0), yf)); - - }, null, getData()); - - if (objectPlacement.usesFeatures()) { - if (objectPlacement.isVacuum()) { - ParallaxChunkMeta rw = getParallaxAccess().getMetaRW(xx >> 4, zz >> 4); - double a = Math.max(v.getW(), v.getD()); - IrisFeature f = new IrisFeature(); - f.setConvergeToHeight(h - (v.getH() >> 1)); - f.setBlockRadius(a); - f.setInterpolationRadius(objectPlacement.getVacuumInterpolationRadius()); - f.setInterpolator(objectPlacement.getVacuumInterpolationMethod()); - f.setStrength(1D); - rw.getFeatures().add(new IrisFeaturePositional(xx, zz, f)); - } - - for (IrisFeaturePotential j : objectPlacement.getAddFeatures()) { - if (j.hasZone(rng, xx >> 4, zz >> 4)) { - ParallaxChunkMeta rw = getParallaxAccess().getMetaRW(xx >> 4, zz >> 4); - rw.getFeatures().add(new IrisFeaturePositional(xx + 1, zz - 1, j.getZone())); - } - } - } - } - } - - default void updateParallaxChunkObjectData(int minY, int maxY, int x, int z, IrisObject v) { - ParallaxChunkMeta meta = getParallaxAccess().getMetaRW(x >> 4, z >> 4); - meta.setObjects(true); - meta.setMaxObject(Math.max(maxY, meta.getMaxObject())); - meta.setMinObject(Math.min(minY, Math.max(meta.getMinObject(), 0))); - } - - default int computeParallaxSize() { - Iris.verbose("Calculating the Parallax Size in Parallel"); - AtomicInteger xg = new AtomicInteger(0); - AtomicInteger zg = new AtomicInteger(); - xg.set(0); - zg.set(0); - int jig = 0; - KSet objects = new KSet<>(); - KMap> scalars = new KMap<>(); - int x = xg.get(); - int z = zg.get(); - - if (getEngine().getDimension().isPlaceObjects()) { - KList r = getAllRegions(); - KList b = getAllBiomes(); - - for (IrisBiome i : b) { - for (IrisObjectPlacement j : i.getObjects()) { - if (j.getScale().canScaleBeyond()) { - scalars.put(j.getScale(), j.getPlace()); - } else { - objects.addAll(j.getPlace()); - } - } - - for (IrisJigsawStructurePlacement j : i.getJigsawStructures()) { - jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension()); - } - } - - for (IrisRegion i : r) { - for (IrisObjectPlacement j : i.getObjects()) { - if (j.getScale().canScaleBeyond()) { - scalars.put(j.getScale(), j.getPlace()); - } else { - objects.addAll(j.getPlace()); - } - } - - for (IrisJigsawStructurePlacement j : i.getJigsawStructures()) { - jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension()); - } - } - - for (IrisJigsawStructurePlacement j : getEngine().getDimension().getJigsawStructures()) { - jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension()); - } - - if (getEngine().getDimension().getStronghold() != null) { - try { - jig = Math.max(jig, getData().getJigsawStructureLoader().load(getEngine().getDimension().getStronghold()).getMaxDimension()); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("THIS IS THE ONE"); - e.printStackTrace(); - } - } - - Iris.verbose("Checking sizes for " + Form.f(objects.size()) + " referenced objects."); - BurstExecutor e = getEngine().getTarget().getBurster().burst(objects.size()); - KMap sizeCache = new KMap<>(); - for (String i : objects) { - e.queue(() -> { - try { - BlockVector bv = sizeCache.compute(i, (k, v) -> { - if (v != null) { - return v; - } - - try { - return IrisObject.sampleSize(getData().getObjectLoader().findFile(i)); - } catch (IOException ex) { - Iris.reportError(ex); - ex.printStackTrace(); - } - - return null; - }); - - if (bv == null) { - throw new RuntimeException(); - } - - warn(i, bv); - - synchronized (xg) { - xg.getAndSet(Math.max(bv.getBlockX(), xg.get())); - } - - synchronized (zg) { - zg.getAndSet(Math.max(bv.getBlockZ(), zg.get())); - } - } catch (Throwable ed) { - Iris.reportError(ed); - - } - }); - } - - for (Map.Entry> entry : scalars.entrySet()) { - double ms = entry.getKey().getMaximumScale(); - for (String j : entry.getValue()) { - e.queue(() -> { - try { - BlockVector bv = sizeCache.compute(j, (k, v) -> { - if (v != null) { - return v; - } - - try { - return IrisObject.sampleSize(getData().getObjectLoader().findFile(j)); - } catch (IOException ioException) { - Iris.reportError(ioException); - ioException.printStackTrace(); - } - - return null; - }); - - if (bv == null) { - throw new RuntimeException(); - } - - warnScaled(j, bv, ms); - - synchronized (xg) { - xg.getAndSet((int) Math.max(Math.ceil(bv.getBlockX() * ms), xg.get())); - } - - synchronized (zg) { - zg.getAndSet((int) Math.max(Math.ceil(bv.getBlockZ() * ms), zg.get())); - } - } catch (Throwable ee) { - Iris.reportError(ee); - - } - }); - } - } - - e.complete(); - - x = xg.get(); - z = zg.get(); - - for (IrisDepositGenerator i : getEngine().getDimension().getDeposits()) { - int max = i.getMaxDimension(); - x = Math.max(max, x); - z = Math.max(max, z); - } - - for (IrisRegion v : r) { - for (IrisDepositGenerator i : v.getDeposits()) { - int max = i.getMaxDimension(); - x = Math.max(max, x); - z = Math.max(max, z); - } - } - - for (IrisBiome v : b) { - for (IrisDepositGenerator i : v.getDeposits()) { - int max = i.getMaxDimension(); - x = Math.max(max, x); - z = Math.max(max, z); - } - } - } - - x = Math.max(z, x); - int u = x; - int v = computeFeatureRange(); - x = Math.max(jig, x); - x = Math.max(x, v); - x = (Math.max(x, 16) + 16) >> 4; - x = x % 2 == 0 ? x + 1 : x; - Iris.info("Parallax Size: " + x + " Chunks"); - Iris.info(" Object Parallax Size: " + u + " (" + ((Math.max(u, 16) + 16) >> 4) + ")"); - Iris.info(" Jigsaw Parallax Size: " + jig + " (" + ((Math.max(jig, 16) + 16) >> 4) + ")"); - Iris.info(" Feature Parallax Size: " + v + " (" + ((Math.max(v, 16) + 16) >> 4) + ")"); - - return x; - } - - default int computeFeatureRange() { - int m = 0; - - for (IrisFeaturePotential i : getAllFeatures()) { - m = Math.max(m, i.getZone().getRealSize()); - } - - return m; - } - - default void warn(String ob, BlockVector bv) { - if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) { - Iris.warn("Object " + ob + " has a large size (" + bv + ") and may increase memory usage!"); - } - } - - default void warnScaled(String ob, BlockVector bv, double ms) { - if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) { - Iris.warn("Object " + ob + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")"); - } - } - - default int getHighest(int x, int z) { - return getHighest(x, z, getData()); - } - - default int getHighest(int x, int z, boolean ignoreFluid) { - return getHighest(x, z, getData(), ignoreFluid); - } - - @Override - default int getHighest(int x, int z, IrisData data) { - return getHighest(x, z, data, false); - } - - @Override - default int getHighest(int x, int z, IrisData data, boolean ignoreFluid) { - return ignoreFluid ? trueHeight(x, z) : Math.max(trueHeight(x, z), getEngine().getDimension().getFluidHeight()); - } - - default int trueHeight(int x, int z) { - return getComplex().getTrueHeightStream().get(x, z); - } - - @Override - default void set(int x, int y, int z, BlockData d) { - getParallaxAccess().setBlock(x, y, z, d); - } - - @Override - default void setTile(int x, int y, int z, TileData d) { - getParallaxAccess().setTile(x, y, z, d); - } - - @Override - default BlockData get(int x, int y, int z) { - BlockData block = getParallaxAccess().getBlock(x, y, z); - - if (block == null) { - return AIR; - } - - return block; - } - - @Override - default boolean isPreventingDecay() { - return getEngine().getDimension().isPreventLeafDecay(); - } - - @Override - default boolean isSolid(int x, int y, int z) { - return B.isSolid(get(x, y, z)); - } - - @Override - default boolean isUnderwater(int x, int z) { - return getHighest(x, z, true) <= getFluidHeight(); - } - - @Override - default int getFluidHeight() { - return getEngine().getDimension().getFluidHeight(); - } - - @Override - default boolean isDebugSmartBore() { - return getEngine().getDimension().isDebugSmartBore(); - } - - default void close() { - - } - - @ChunkCoordinates - default KList getFeaturesInChunk(Chunk c) { - return getFeaturesInChunk(c.getX(), c.getZ()); - } -} diff --git a/src/main/java/com/volmit/iris/engine/framework/GeneratorAccess.java b/src/main/java/com/volmit/iris/engine/framework/GeneratorAccess.java deleted file mode 100644 index 7c5cabf85..000000000 --- a/src/main/java/com/volmit/iris/engine/framework/GeneratorAccess.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.engine.framework; - -import com.volmit.iris.core.gui.components.Renderer; -import com.volmit.iris.core.project.loader.IrisData; -import com.volmit.iris.engine.object.biome.IrisBiome; -import com.volmit.iris.engine.object.objects.IrisObjectPlacement; -import com.volmit.iris.engine.object.regional.IrisRegion; -import com.volmit.iris.engine.parallax.ParallaxAccess; -import com.volmit.iris.util.data.DataProvider; - -public interface GeneratorAccess extends DataProvider, Renderer { - IrisRegion getRegion(int x, int z); - - ParallaxAccess getParallaxAccess(); - - IrisData getData(); - - IrisBiome getCaveBiome(int x, int z); - - IrisBiome getSurfaceBiome(int x, int z); - - int getHeight(int x, int z); - - default IrisBiome getBiome(int x, int y, int z) { - if (y <= getHeight(x, z) - 2) { - return getCaveBiome(x, z); - } - - return getSurfaceBiome(x, z); - } - - default PlacedObject getObjectPlacement(int x, int y, int z) { - String objectAt = getParallaxAccess().getObject(x, y, z); - - if (objectAt == null || objectAt.isEmpty()) { - return null; - } - - String[] v = objectAt.split("\\Q@\\E"); - String object = v[0]; - int id = Integer.parseInt(v[1]); - IrisRegion region = getRegion(x, z); - - for (IrisObjectPlacement i : region.getObjects()) { - if (i.getPlace().contains(object)) { - return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z); - } - } - - IrisBiome biome = getBiome(x, y, z); - - for (IrisObjectPlacement i : biome.getObjects()) { - if (i.getPlace().contains(object)) { - return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z); - } - } - - return new PlacedObject(null, getData().getObjectLoader().load(object), id, x, z); - } - - int getCacheID(); -} From 734847db68fa50aff9b8db18e8ec833e457c0847 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:38:52 -0400 Subject: [PATCH 14/36] Object tweaks & mantle fixes --- .../java/com/volmit/iris/engine/mantle/EngineMantle.java | 8 ++++++++ .../engine/mantle/components/MantleObjectComponent.java | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index f025eea32..604b709e4 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -34,6 +34,7 @@ import com.volmit.iris.engine.object.regional.IrisRegion; import com.volmit.iris.engine.object.tile.TileData; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.B; +import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.mantle.Mantle; @@ -218,4 +219,11 @@ public interface EngineMantle extends IObjectPlacer { { } + + @BlockCoordinates + default void updateBlock(int x, int y, int z) + { + getMantle().flag(x>>4, z>>4, MantleFlag.UPDATE, true); + getMantle().set(x,y,z,true); + } } diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java index 7a2a11bd2..0624fc793 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java @@ -29,6 +29,7 @@ import com.volmit.iris.engine.object.feature.IrisFeaturePotential; import com.volmit.iris.engine.object.objects.IrisObject; import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.engine.object.regional.IrisRegion; +import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.mantle.MantleFlag; import com.volmit.iris.util.math.RNG; @@ -66,7 +67,6 @@ public class MantleObjectComponent extends IrisMantleComponent { @ChunkCoordinates private void placeObjects(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer post) { - for (IrisObjectPlacement i : biome.getSurfaceObjects()) { if (rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && rng.chance(getComplex().getObjectChanceStream().get(x << 4, z << 4))) { try { @@ -95,7 +95,8 @@ public class MantleObjectComponent extends IrisMantleComponent { } } } - + + @BlockCoordinates private void placeObject(RNG rng, int x, int z, IrisObjectPlacement objectPlacement, Consumer post) { for (int i = 0; i < objectPlacement.getDensity(); i++) { IrisObject v = objectPlacement.getScale().get(rng, objectPlacement.getObject(getComplex(), rng)); From 075aec3ac0b6702136c8f663de65bd510d6c18ab Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:39:01 -0400 Subject: [PATCH 15/36] Mantle optimized iteration --- .../com/volmit/iris/util/mantle/Mantle.java | 19 +++++++++++++++++++ .../volmit/iris/util/mantle/MantleChunk.java | 19 +++++++++++++++++++ .../volmit/iris/util/mantle/MantleFlag.java | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/src/main/java/com/volmit/iris/util/mantle/Mantle.java index f607a530d..de7ea75d9 100644 --- a/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -27,6 +27,7 @@ import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.documentation.RegionCoordinates; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; +import com.volmit.iris.util.function.Consumer4; import com.volmit.iris.util.math.M; import com.volmit.iris.util.matter.Matter; import com.volmit.iris.util.parallel.BurstExecutor; @@ -108,6 +109,24 @@ public class Mantle { } } + @ChunkCoordinates + public void iterateChunk(int x, int z, Class type, Consumer4 iterator, MantleFlag... requiredFlags) + { + for(MantleFlag i : requiredFlags) + { + if(!hasFlag(x, z, i)) + { + return; + } + } + + try { + get(x >> 5, z >> 5).get().get(x & 31, z & 31).iterate(type, iterator); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } + @ChunkCoordinates public boolean hasFlag(int x, int z, MantleFlag flag) { diff --git a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java index 28fd95243..9b9db5e49 100644 --- a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java +++ b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java @@ -22,8 +22,10 @@ import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.collection.StateList; import com.volmit.iris.util.data.Varint; import com.volmit.iris.util.documentation.ChunkCoordinates; +import com.volmit.iris.util.function.Consumer4; import com.volmit.iris.util.matter.IrisMatter; import com.volmit.iris.util.matter.Matter; +import com.volmit.iris.util.matter.MatterSlice; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -168,4 +170,21 @@ public class MantleChunk { } } } + + public void iterate(Class type, Consumer4 iterator) { + for(int i = 0; i < sections.length(); i++) + { + Matter matter = get(i); + + if(matter != null) + { + MatterSlice t = matter.getSlice(type); + + if(t != null) + { + t.iterateSync(iterator); + } + } + } + } } diff --git a/src/main/java/com/volmit/iris/util/mantle/MantleFlag.java b/src/main/java/com/volmit/iris/util/mantle/MantleFlag.java index 128773092..e14e19806 100644 --- a/src/main/java/com/volmit/iris/util/mantle/MantleFlag.java +++ b/src/main/java/com/volmit/iris/util/mantle/MantleFlag.java @@ -22,7 +22,7 @@ import com.volmit.iris.util.collection.StateList; public enum MantleFlag { OBJECT, - VACUUM, + UPDATE, JIGSAW, FEATURE ; From 65690387778a710f9d1c79cda9ff70035e0ef01e Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:43:15 -0400 Subject: [PATCH 16/36] Drop par manager --- .../volmit/iris/core/project/IrisProject.java | 40 ------------------- .../iris/engine/IrisEngineParallax.java | 36 ----------------- .../iris/engine/mantle/EngineMantle.java | 1 - .../iris/engine/object/meta/IrisEffect.java | 5 ++- 4 files changed, 3 insertions(+), 79 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/engine/IrisEngineParallax.java diff --git a/src/main/java/com/volmit/iris/core/project/IrisProject.java b/src/main/java/com/volmit/iris/core/project/IrisProject.java index 7c0de8c13..227201dac 100644 --- a/src/main/java/com/volmit/iris/core/project/IrisProject.java +++ b/src/main/java/com/volmit/iris/core/project/IrisProject.java @@ -30,7 +30,6 @@ import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.core.tools.IrisWorldCreator; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.biome.IrisBiome; -import com.volmit.iris.engine.object.biome.IrisBiomeMutation; import com.volmit.iris.engine.object.biome.IrisBiomePaletteLayer; import com.volmit.iris.engine.object.block.IrisBlockData; import com.volmit.iris.engine.object.dimensional.IrisDimension; @@ -411,27 +410,6 @@ public class IrisProject { } } - for (IrisBiomeMutation i : dimension.getMutations()) { - for (IrisObjectPlacement j : i.getObjects()) { - b.append(j.hashCode()); - KList newNames = new KList<>(); - - for (String k : j.getPlace()) { - if (renameObjects.containsKey(k)) { - newNames.add(renameObjects.get(k)); - continue; - } - - String name = !obfuscate ? k : UUID.randomUUID().toString().replaceAll("-", ""); - b.append(name); - newNames.add(name); - renameObjects.put(k, name); - } - - j.setPlace(newNames); - } - } - KMap> lookupObjects = renameObjects.flip(); StringBuilder gb = new StringBuilder(); ChronoLatch cl = new ChronoLatch(1000); @@ -455,24 +433,6 @@ public class IrisProject { } }))); - dimension.getMutations().forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) -> - { - try { - File f = dm.getObjectLoader().findFile(lookupObjects.get(k).get(0)); - IO.copyFile(f, new File(folder, "objects/" + k + ".iob")); - gb.append(IO.hash(f)); - ggg.set(ggg.get() + 1); - - if (cl.flip()) { - int g = ggg.get(); - ggg.set(0); - sender.sendMessage("Wrote another " + g + " Objects"); - } - } catch (Throwable e) { - Iris.reportError(e); - } - }))); - b.append(IO.hash(gb.toString())); c.append(IO.hash(b.toString())); b = new StringBuilder(); diff --git a/src/main/java/com/volmit/iris/engine/IrisEngineParallax.java b/src/main/java/com/volmit/iris/engine/IrisEngineParallax.java deleted file mode 100644 index f5ce791ca..000000000 --- a/src/main/java/com/volmit/iris/engine/IrisEngineParallax.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.engine; - -import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.framework.EngineParallaxManager; -import lombok.Getter; - -public class IrisEngineParallax implements EngineParallaxManager { - @Getter - private final Engine engine; - - @Getter - private final int parallaxSize; - - public IrisEngineParallax(Engine engine) { - this.engine = engine; - parallaxSize = computeParallaxSize(); - } -} diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 604b709e4..36f07ac07 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -23,7 +23,6 @@ import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.IrisComplex; import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.framework.EngineParallaxManager; import com.volmit.iris.engine.framework.EngineTarget; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.common.IObjectPlacer; diff --git a/src/main/java/com/volmit/iris/engine/object/meta/IrisEffect.java b/src/main/java/com/volmit/iris/engine/object/meta/IrisEffect.java index 3573dfb92..5146d97d5 100644 --- a/src/main/java/com/volmit/iris/engine/object/meta/IrisEffect.java +++ b/src/main/java/com/volmit/iris/engine/object/meta/IrisEffect.java @@ -20,7 +20,7 @@ package com.volmit.iris.engine.object.meta; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.framework.GeneratorAccess; +import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.annotations.*; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.ChronoLatch; @@ -29,6 +29,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; +import net.minecraft.world.level.GeneratorAccess; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.Sound; @@ -202,7 +203,7 @@ public class IrisEffect { }); } - public void apply(Player p, GeneratorAccess g) { + public void apply(Player p, Engine g) { if (!canTick()) { return; } From de51d4860e586e07e7be526be99e64f3e1ed9552 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:43:30 -0400 Subject: [PATCH 17/36] Drop parallax core --- .../iris/engine/parallax/ParallaxAccess.java | 202 ------------- .../engine/parallax/ParallaxChunkMeta.java | 100 ------- .../iris/engine/parallax/ParallaxRegion.java | 223 --------------- .../iris/engine/parallax/ParallaxWorld.java | 270 ------------------ 4 files changed, 795 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/engine/parallax/ParallaxAccess.java delete mode 100644 src/main/java/com/volmit/iris/engine/parallax/ParallaxChunkMeta.java delete mode 100644 src/main/java/com/volmit/iris/engine/parallax/ParallaxRegion.java delete mode 100644 src/main/java/com/volmit/iris/engine/parallax/ParallaxWorld.java diff --git a/src/main/java/com/volmit/iris/engine/parallax/ParallaxAccess.java b/src/main/java/com/volmit/iris/engine/parallax/ParallaxAccess.java deleted file mode 100644 index 146ce0772..000000000 --- a/src/main/java/com/volmit/iris/engine/parallax/ParallaxAccess.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.engine.parallax; - -import com.volmit.iris.engine.object.tile.TileData; -import com.volmit.iris.util.documentation.BlockCoordinates; -import com.volmit.iris.util.documentation.ChunkCoordinates; -import com.volmit.iris.util.hunk.Hunk; -import org.bukkit.block.TileState; -import org.bukkit.block.data.BlockData; - -public interface ParallaxAccess { - @BlockCoordinates - default BlockData getBlock(int x, int y, int z) { - return getBlocksR(x >> 4, z >> 4).get(x & 15, y, z & 15); - } - - @BlockCoordinates - default void setBlock(int x, int y, int z, BlockData d) { - getBlocksRW(x >> 4, z >> 4).set(x & 15, y, z & 15, d); - } - - @BlockCoordinates - default TileData getTile(int x, int y, int z) { - return getTilesR(x >> 4, z >> 4).get(x & 15, y, z & 15); - } - - @BlockCoordinates - default void setTile(int x, int y, int z, TileData d) { - getTilesRW(x >> 4, z >> 4).set(x & 15, y, z & 15, d); - } - - @BlockCoordinates - default String getObject(int x, int y, int z) { - return getObjectsR(x >> 4, z >> 4).get(x & 15, y, z & 15); - } - - @BlockCoordinates - default void setObject(int x, int y, int z, String d) { - getObjectsRW(x >> 4, z >> 4).set(x & 15, y, z & 15, d); - } - - @BlockCoordinates - default String getEntity(int x, int y, int z) { - return getEntitiesR(x >> 4, z >> 4).get(x & 15, y, z & 15); - } - - @BlockCoordinates - default void setEntity(int x, int y, int z, String d) { - getEntitiesRW(x >> 4, z >> 4).set(x & 15, y, z & 15, d); - } - - @BlockCoordinates - default Boolean isUpdate(int x, int y, int z) { - return getUpdatesR(x >> 4, z >> 4).get(x & 15, y, z & 15); - } - - @BlockCoordinates - default void updateBlock(int x, int y, int z) { - setUpdate(x, y, z, true); - } - - @BlockCoordinates - default void setUpdate(int x, int y, int z, boolean d) { - getUpdatesRW(x >> 4, z >> 4).set(x & 15, y, z & 15, d); - } - - @ChunkCoordinates - default boolean isParallaxGenerated(int x, int z) { - return getMetaR(x, z).isParallaxGenerated(); - } - - @ChunkCoordinates - default boolean isChunkGenerated(int x, int z) { - return getMetaR(x, z).isGenerated(); - } - - @ChunkCoordinates - default boolean isFeatureGenerated(int x, int z) { - return getMetaR(x, z).isFeatureGenerated(); - } - - @ChunkCoordinates - default void setParallaxGenerated(int x, int z) { - setParallaxGenerated(x, z, true); - } - - @ChunkCoordinates - default void setChunkGenerated(int x, int z) { - setChunkGenerated(x, z, true); - } - - @ChunkCoordinates - default void setFeatureGenerated(int x, int z) { - setFeatureGenerated(x, z, true); - } - - @ChunkCoordinates - default void setParallaxGenerated(int x, int z, boolean v) { - getMetaRW(x, z).setParallaxGenerated(v); - } - - @ChunkCoordinates - default void maxMin(int x, int z, int value) { - ParallaxChunkMeta meat = getMetaRW(x, z); - - if (value > meat.getMaxObject()) { - meat.setMaxObject(value); - } - - if (meat.getMinObject() <= -1) { - meat.setMinObject(value); - } - - if (value < meat.getMinObject()) { - meat.setMinObject(value); - } - } - - @ChunkCoordinates - default void setChunkGenerated(int x, int z, boolean v) { - getMetaRW(x, z).setGenerated(v); - } - - @ChunkCoordinates - default void setFeatureGenerated(int x, int z, boolean v) { - getMetaRW(x, z).setFeatureGenerated(v); - } - - @ChunkCoordinates - Hunk> getTilesR(int x, int z); - - @ChunkCoordinates - Hunk> getTilesRW(int x, int z); - - @ChunkCoordinates - Hunk getBlocksR(int x, int z); - - @ChunkCoordinates - Hunk getBlocksRW(int x, int z); - - @ChunkCoordinates - Hunk getObjectsR(int x, int z); - - @ChunkCoordinates - Hunk getObjectsRW(int x, int z); - - @ChunkCoordinates - Hunk getEntitiesRW(int x, int z); - - @ChunkCoordinates - Hunk getEntitiesR(int x, int z); - - @ChunkCoordinates - Hunk getUpdatesR(int x, int z); - - @ChunkCoordinates - Hunk getUpdatesRW(int x, int z); - - @ChunkCoordinates - ParallaxChunkMeta getMetaR(int x, int z); - - @ChunkCoordinates - ParallaxChunkMeta getMetaRW(int x, int z); - - void cleanup(long regionIdle, long chunkIdle); - - void cleanup(); - - void saveAll(); - - void saveAllNOW(); - - int getRegionCount(); - - int getChunkCount(); - - @ChunkCoordinates - default void delete(int x, int z) { - getUpdatesRW(x, z).empty(false); - getBlocksRW(x, z).empty(null); - getTilesRW(x, z).empty(null); - getEntitiesRW(x, z).empty(null); - getObjectsRW(x, z).empty(null); - } -} diff --git a/src/main/java/com/volmit/iris/engine/parallax/ParallaxChunkMeta.java b/src/main/java/com/volmit/iris/engine/parallax/ParallaxChunkMeta.java deleted file mode 100644 index 27e4c3589..000000000 --- a/src/main/java/com/volmit/iris/engine/parallax/ParallaxChunkMeta.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.engine.parallax; - -import com.google.gson.Gson; -import com.volmit.iris.engine.object.feature.IrisFeaturePositional; -import com.volmit.iris.util.hunk.io.HunkIOAdapter; -import com.volmit.iris.util.hunk.io.PaletteHunkIOAdapter; -import com.volmit.iris.util.oldnbt.CompoundTag; -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.function.Function; - -@AllArgsConstructor -@Data -public class ParallaxChunkMeta { - private static final Gson gson = new Gson(); - public static final Function> adapter = (c) -> new PaletteHunkIOAdapter<>() { - @Override - public void write(ParallaxChunkMeta parallaxChunkMeta, DataOutputStream dos) throws IOException { - dos.writeBoolean(parallaxChunkMeta.updates); - dos.writeBoolean(parallaxChunkMeta.generated); - dos.writeBoolean(parallaxChunkMeta.tilesGenerated); - dos.writeBoolean(parallaxChunkMeta.parallaxGenerated); - dos.writeBoolean(parallaxChunkMeta.featureGenerated); - dos.writeBoolean(parallaxChunkMeta.objects); - dos.writeInt(parallaxChunkMeta.maxObject); - dos.writeInt(parallaxChunkMeta.minObject); - dos.writeInt(parallaxChunkMeta.count); - dos.writeInt(parallaxChunkMeta.features.size()); - - for (IrisFeaturePositional i : parallaxChunkMeta.features) { - dos.writeUTF(gson.toJson(i)); - } - } - - @Override - public ParallaxChunkMeta read(DataInputStream din) throws IOException { - ParallaxChunkMeta pcm = new ParallaxChunkMeta(); - pcm.setUpdates(din.readBoolean()); - pcm.setGenerated(din.readBoolean()); - pcm.setTilesGenerated(din.readBoolean()); - pcm.setParallaxGenerated(din.readBoolean()); - pcm.setFeatureGenerated(din.readBoolean()); - pcm.setObjects(din.readBoolean()); - pcm.setMaxObject(din.readInt()); - pcm.setMinObject(din.readInt()); - pcm.setCount(din.readInt()); - pcm.setFeatures(newSet()); - int c = din.readInt(); - - for (int i = 0; i < c; i++) { - pcm.getFeatures().add(gson.fromJson(din.readUTF(), IrisFeaturePositional.class)); - } - - return pcm; - } - }; - - private boolean updates; - private boolean generated; - private boolean tilesGenerated; - private boolean parallaxGenerated; - private boolean featureGenerated; - private boolean objects; - private int maxObject = -1; - private int minObject = -1; - private int count; - private Set features; - - private static Set newSet() { - return new CopyOnWriteArraySet<>(); - } - - public ParallaxChunkMeta() { - this(false, false, false, false, false, false, -1, -1, 0, newSet()); - } -} diff --git a/src/main/java/com/volmit/iris/engine/parallax/ParallaxRegion.java b/src/main/java/com/volmit/iris/engine/parallax/ParallaxRegion.java deleted file mode 100644 index 3e917b9cc..000000000 --- a/src/main/java/com/volmit/iris/engine/parallax/ParallaxRegion.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.engine.parallax; - -import com.volmit.iris.Iris; -import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.engine.object.tile.TileData; -import com.volmit.iris.util.format.C; -import com.volmit.iris.util.hunk.Hunk; -import com.volmit.iris.util.hunk.io.HunkIOAdapter; -import com.volmit.iris.util.hunk.io.HunkRegion; -import com.volmit.iris.util.hunk.io.HunkRegionSlice; -import com.volmit.iris.util.math.M; -import com.volmit.iris.util.oldnbt.ByteArrayTag; -import com.volmit.iris.util.oldnbt.CompoundTag; -import com.volmit.iris.util.oldnbt.Tag; -import com.volmit.iris.util.parallel.GridLock; -import com.volmit.iris.util.parallel.MultiBurst; -import com.volmit.iris.util.parallel.NOOPGridLock; -import org.bukkit.block.TileState; -import org.bukkit.block.data.BlockData; - -import java.io.File; -import java.io.IOException; - -public class ParallaxRegion extends HunkRegion { - private boolean dirtyMeta; - private Hunk meta; - private HunkIOAdapter metaAdapter; - private HunkRegionSlice blockSlice; - private HunkRegionSlice> tileSlice; - private HunkRegionSlice objectSlice; - private HunkRegionSlice entitySlice; - private HunkRegionSlice updateSlice; - private final GridLock lock; - private long lastUse; - private final int height; - private final MultiBurst burst; - - public ParallaxRegion(MultiBurst burst, int height, File folder, int x, int z, CompoundTag compound) { - super(folder, x, z, compound); - this.burst = burst; - this.height = height; - setupSlices(); - lock = newGridLock(); - } - - public ParallaxRegion(MultiBurst burst, int height, File folder, int x, int z) { - super(folder, x, z); - this.burst = burst; - this.height = height; - setupSlices(); - lock = newGridLock(); - } - - private GridLock newGridLock() { - return IrisSettings.get().getConcurrency().isUnstableLockingHeuristics() ? new NOOPGridLock(1, 1) : new GridLock(32, 32); - } - - private void setupSlices() { - blockSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound()); - tileSlice = HunkRegionSlice.TILE.apply(height, getCompound()); - objectSlice = HunkRegionSlice.STRING.apply(height, getCompound(), "objects"); - entitySlice = HunkRegionSlice.STRING.apply(height, getCompound(), "entities"); - updateSlice = HunkRegionSlice.BOOLEAN.apply(height, getCompound(), "updates"); - metaAdapter = ParallaxChunkMeta.adapter.apply(getCompound()); - dirtyMeta = false; - meta = null; - lastUse = M.ms(); - } - - public boolean hasBeenIdleLongerThan(long time) { - return M.ms() - lastUse > time; - } - - public ParallaxChunkMeta getMetaR(int x, int z) { - return lock.withResult(x, z, () -> getMetaHunkR().getOr(x, 0, z, new ParallaxChunkMeta())); - } - - public ParallaxChunkMeta getMetaRW(int x, int z) { - return lock.withResult(x, z, () -> { - lastUse = M.ms(); - dirtyMeta = true; - ParallaxChunkMeta p = getMetaHunkRW().get(x, 0, z); - if (p == null) { - p = new ParallaxChunkMeta(); - getMetaHunkRW().set(x, 0, z, p); - } - - return p; - }); - } - - private Hunk getMetaHunkR() { - if (meta == null) { - meta = loadMetaHunk(); - } - - return meta; - } - - private Hunk getMetaHunkRW() { - dirtyMeta = true; - return getMetaHunkR(); - } - - private Hunk loadMetaHunk() { - lastUse = M.ms(); - if (meta == null) { - Tag t = getCompound().getValue().get("meta"); - - if ((t instanceof ByteArrayTag)) { - try { - meta = metaAdapter.read((x, y, z) -> Hunk.newAtomicHunk(32, 1, 32), (ByteArrayTag) t); - } catch (IOException e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - - if (meta == null) { - meta = Hunk.newAtomicHunk(32, 1, 32); - } - } - - return meta; - } - - public void unloadMetaHunk() { - if (dirtyMeta) { - saveMetaHunk(); - dirtyMeta = false; - } - - meta = null; - } - - public void saveMetaHunk() { - if (meta != null && dirtyMeta) { - try { - getCompound().getValue().put("meta", meta.writeByteArrayTag(metaAdapter, "meta")); - dirtyMeta = false; - } catch (IOException e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - } - - @Override - public synchronized void save() throws IOException { - blockSlice.save(burst); - objectSlice.save(burst); - entitySlice.save(burst); - tileSlice.save(burst); - updateSlice.save(burst); - saveMetaHunk(); - Iris.debug("Saved Parallax Region " + C.GOLD + getX() + " " + getZ()); - super.save(); - } - - public int unload() { - unloadMetaHunk(); - return blockSlice.unloadAll() + - objectSlice.unloadAll() + - entitySlice.unloadAll() + - tileSlice.unloadAll() + - updateSlice.unloadAll(); - } - - public HunkRegionSlice getBlockSlice() { - lastUse = M.ms(); - return blockSlice; - } - - public HunkRegionSlice getEntitySlice() { - lastUse = M.ms(); - return entitySlice; - } - - public HunkRegionSlice> getTileSlice() { - lastUse = M.ms(); - return tileSlice; - } - - public HunkRegionSlice getObjectSlice() { - lastUse = M.ms(); - return objectSlice; - } - - public HunkRegionSlice getUpdateSlice() { - lastUse = M.ms(); - return updateSlice; - } - - public synchronized int cleanup(long c) { - return blockSlice.cleanup(c) + - objectSlice.cleanup(c) + - entitySlice.cleanup(c) + - tileSlice.cleanup(c) + - updateSlice.cleanup(c); - } - - public int getChunkCount() { - return blockSlice.getLoadCount() + objectSlice.getLoadCount() + entitySlice.getLoadCount() + tileSlice.getLoadCount() + updateSlice.getLoadCount(); - } -} diff --git a/src/main/java/com/volmit/iris/engine/parallax/ParallaxWorld.java b/src/main/java/com/volmit/iris/engine/parallax/ParallaxWorld.java deleted file mode 100644 index a8892ecab..000000000 --- a/src/main/java/com/volmit/iris/engine/parallax/ParallaxWorld.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.engine.parallax; - -import com.volmit.iris.Iris; -import com.volmit.iris.core.IrisSettings; -import com.volmit.iris.engine.object.tile.TileData; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.collection.KMap; -import com.volmit.iris.util.documentation.ChunkCoordinates; -import com.volmit.iris.util.documentation.RegionCoordinates; -import com.volmit.iris.util.format.C; -import com.volmit.iris.util.hunk.Hunk; -import com.volmit.iris.util.parallel.MultiBurst; -import org.bukkit.block.TileState; -import org.bukkit.block.data.BlockData; - -import java.io.File; -import java.io.IOException; - -@SuppressWarnings("ALL") -public class ParallaxWorld implements ParallaxAccess { - private final KMap loadedRegions; - private final KList save; - private final File folder; - private final MultiBurst burst; - private final int height; - - public ParallaxWorld(MultiBurst burst, int height, File folder) { - this.height = height; - this.burst = burst; - this.folder = folder; - save = new KList<>(); - loadedRegions = new KMap<>(); - folder.mkdirs(); - } - - public int getRegionCount() { - return loadedRegions.size(); - } - - public int getChunkCount() { - int m = 0; - - try { - for (ParallaxRegion i : loadedRegions.values()) { - m += i.getChunkCount(); - } - } catch (Throwable e) { - Iris.reportError(e); - - } - - return m; - } - - public void close() { - for (ParallaxRegion i : loadedRegions.v()) { - unload(i.getX(), i.getZ()); - } - - save.clear(); - loadedRegions.clear(); - } - - public void save(ParallaxRegion region) { - try { - region.save(); - } catch (IOException e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - - @RegionCoordinates - public boolean isLoaded(int x, int z) { - return loadedRegions.containsKey(key(x, z)); - } - - @RegionCoordinates - public void save(int x, int z) { - if (isLoaded(x, z)) { - save(getR(x, z)); - } - } - - @RegionCoordinates - public int unload(int x, int z) { - long key = key(x, z); - int v = 0; - if (isLoaded(x, z)) { - if (save.contains(key)) { - save(x, z); - save.remove(key); - } - - ParallaxRegion lr = loadedRegions.remove(key); - - if (lr != null) { - v += lr.unload(); - Iris.debug("Unloaded Parallax Region " + C.RED + x + " " + z); - } - } - - return v; - } - - @RegionCoordinates - public ParallaxRegion load(int x, int z) { - if (isLoaded(x, z)) { - return loadedRegions.get(key(x, z)); - } - - ParallaxRegion v = new ParallaxRegion(burst, height, folder, x, z); - loadedRegions.put(key(x, z), v); - Iris.debug("Loaded Parallax Region " + C.RED + x + " " + z); - - return v; - } - - @RegionCoordinates - public ParallaxRegion getR(int x, int z) { - long key = key(x, z); - - ParallaxRegion region = loadedRegions.get(key); - - if (region == null) { - region = load(x, z); - } - - return region; - } - - @RegionCoordinates - public ParallaxRegion getRW(int x, int z) { - save.addIfMissing(key(x, z)); - return getR(x, z); - } - - @RegionCoordinates - private long key(int x, int z) { - return (((long) x) << 32) | (((long) z) & 0xffffffffL); - } - - @ChunkCoordinates - @Override - public Hunk getBlocksR(int x, int z) { - return getR(x >> 5, z >> 5).getBlockSlice().getR(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public Hunk getBlocksRW(int x, int z) { - return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public Hunk> getTilesR(int x, int z) { - return getR(x >> 5, z >> 5).getTileSlice().getR(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public Hunk> getTilesRW(int x, int z) { - return getRW(x >> 5, z >> 5).getTileSlice().getRW(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public Hunk getObjectsR(int x, int z) { - return getR(x >> 5, z >> 5).getObjectSlice().getR(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public Hunk getObjectsRW(int x, int z) { - return getRW(x >> 5, z >> 5).getObjectSlice().getRW(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public Hunk getEntitiesRW(int x, int z) { - return getRW(x >> 5, z >> 5).getEntitySlice().getRW(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public Hunk getEntitiesR(int x, int z) { - return getRW(x >> 5, z >> 5).getEntitySlice().getR(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public Hunk getUpdatesR(int x, int z) { - return getR(x >> 5, z >> 5).getUpdateSlice().getR(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public Hunk getUpdatesRW(int x, int z) { - return getRW(x >> 5, z >> 5).getUpdateSlice().getRW(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public ParallaxChunkMeta getMetaR(int x, int z) { - return getR(x >> 5, z >> 5).getMetaR(x & 31, z & 31); - } - - @ChunkCoordinates - @Override - public ParallaxChunkMeta getMetaRW(int x, int z) { - return getRW(x >> 5, z >> 5).getMetaRW(x & 31, z & 31); - } - - public void cleanup() { - cleanup(IrisSettings.get().getParallaxRegionEvictionMS(), IrisSettings.get().getParallax().getParallaxChunkEvictionMS()); - } - - @Override - public synchronized void cleanup(long r, long c) { - try { - int rr = 0; - for (ParallaxRegion i : loadedRegions.v()) { - burst.lazy(() -> { - if (i.hasBeenIdleLongerThan(r)) { - unload(i.getX(), i.getZ()); - } else { - i.cleanup(c); - } - }); - } - } catch (Throwable e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - - @Override - public void saveAll() { - burst.lazy(this::saveAllNOW); - } - - @Override - public void saveAllNOW() { - Iris.debug("Saving " + C.GREEN + loadedRegions.size() + " Parallax Regions"); - for (ParallaxRegion i : loadedRegions.v()) { - if (save.contains(key(i.getX(), i.getZ()))) { - save(i.getX(), i.getZ()); - } - } - } -} From 831143427d5aade08c8ebd4729893150af311339 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:45:04 -0400 Subject: [PATCH 18/36] Strip engine components of parallax --- src/main/java/com/volmit/iris/engine/framework/Engine.java | 1 - .../com/volmit/iris/engine/framework/EngineComponent.java | 5 ----- 2 files changed, 6 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/framework/Engine.java b/src/main/java/com/volmit/iris/engine/framework/Engine.java index 209d08770..d4521f51a 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -37,7 +37,6 @@ import com.volmit.iris.engine.object.loot.IrisLootTable; import com.volmit.iris.engine.object.meta.InventorySlotType; import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.engine.object.regional.IrisRegion; -import com.volmit.iris.engine.parallax.ParallaxAccess; import com.volmit.iris.engine.scripting.EngineExecutionEnvironment; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineComponent.java b/src/main/java/com/volmit/iris/engine/framework/EngineComponent.java index 6903159b5..389f52910 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineComponent.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineComponent.java @@ -22,7 +22,6 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.IrisComplex; import com.volmit.iris.engine.object.dimensional.IrisDimension; -import com.volmit.iris.engine.parallax.ParallaxAccess; import com.volmit.iris.util.math.RollingSequence; import org.bukkit.event.Listener; @@ -56,10 +55,6 @@ public interface EngineComponent { return getEngine().getData(); } - default ParallaxAccess getParallax() { - return getEngine().getParallax(); - } - default EngineTarget getTarget() { return getEngine().getTarget(); } From 059ff25d8ec6eaee4a54fa6596e861a83cd3a96c Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 09:59:12 -0400 Subject: [PATCH 19/36] Fix dust --- .../volmit/iris/core/edit/DustRevealer.java | 23 ++++++++++--------- .../volmit/iris/engine/framework/Engine.java | 12 ++++++++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/edit/DustRevealer.java b/src/main/java/com/volmit/iris/core/edit/DustRevealer.java index 1f7fda4e6..58c226c6d 100644 --- a/src/main/java/com/volmit/iris/core/edit/DustRevealer.java +++ b/src/main/java/com/volmit/iris/core/edit/DustRevealer.java @@ -21,7 +21,9 @@ package com.volmit.iris.core.edit; import com.volmit.iris.Iris; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.parallax.ParallaxAccess; +import com.volmit.iris.engine.framework.PlacedObject; +import com.volmit.iris.engine.mantle.EngineMantle; +import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.BlockPosition; import com.volmit.iris.util.math.RNG; @@ -34,7 +36,7 @@ import org.bukkit.block.Block; @SuppressWarnings("ALL") @Data public class DustRevealer { - private final ParallaxAccess parallax; + private final Engine engine; private final World world; private final BlockPosition block; private final String key; @@ -45,20 +47,19 @@ public class DustRevealer { Engine access = IrisToolbelt.access(world).getEngine(); if (access != null) { - ParallaxAccess a = access.getParallaxAccess(); + String a = access.getObjectPlacementKey(block.getX(), block.getY(), block.getZ()); - if (a.getObject(block.getX(), block.getY(), block.getZ()) != null) { - sender.sendMessage("Found object " + a.getObject(block.getX(), block.getY(), block.getZ())); - Iris.info(sender.getName() + " found object " + a.getObject(block.getX(), block.getY(), block.getZ())); + if (a != null) { + sender.sendMessage("Found object " + a); J.a(() -> { - new DustRevealer(a, world, new BlockPosition(block.getX(), block.getY(), block.getZ()), a.getObject(block.getX(), block.getY(), block.getZ()), new KList<>()); + new DustRevealer(access, world, new BlockPosition(block.getX(), block.getY(), block.getZ()), a, new KList<>()); }); } } } - public DustRevealer(ParallaxAccess parallax, World world, BlockPosition block, String key, KList hits) { - this.parallax = parallax; + public DustRevealer(Engine engine, World world, BlockPosition block, String key, KList hits) { + this.engine = engine; this.world = world; this.block = block; this.key = key; @@ -103,9 +104,9 @@ public class DustRevealer { } private boolean is(BlockPosition a) { - if (isValidTry(a) && parallax.getObject(a.getX(), a.getY(), a.getZ()) != null && parallax.getObject(a.getX(), a.getY(), a.getZ()).equals(key)) { + if (isValidTry(a) && engine.getObjectPlacementKey(a.getX(), a.getY(), a.getZ()) != null && engine.getObjectPlacementKey(a.getX(), a.getY(), a.getZ()).equals(key)) { hits.add(a); - new DustRevealer(parallax, world, a, key, hits); + new DustRevealer(engine, world, a, key, hits); return true; } diff --git a/src/main/java/com/volmit/iris/engine/framework/Engine.java b/src/main/java/com/volmit/iris/engine/framework/Engine.java index d4521f51a..78aa8134e 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -633,6 +633,18 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat return getSurfaceBiome(x, z); } + default String getObjectPlacementKey(int x, int y, int z) + { + PlacedObject o = getObjectPlacement(x,y,z); + + if(o != null && o.getObject() != null) + { + return o.getObject().getLoadKey() + "@" + o.getId(); + } + + return null; + } + default PlacedObject getObjectPlacement(int x, int y, int z) { String objectAt = getMantle().getMantle().get(x,y,z, String.class); From 5b8171a71905585311ea60d070e1d27ed5b0889a Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 9 Aug 2021 16:28:10 -0400 Subject: [PATCH 20/36] Fix structure imports --- .../java/com/volmit/iris/engine/jigsaw/PlannedStructure.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java index ac52e8a35..a44549c1d 100644 --- a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java +++ b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java @@ -23,7 +23,6 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.framework.EngineParallaxManager; import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.engine.object.common.IObjectPlacer; import com.volmit.iris.engine.object.entity.IrisEntity; @@ -33,7 +32,6 @@ import com.volmit.iris.engine.object.jigsaw.IrisJigsawPiece; import com.volmit.iris.engine.object.jigsaw.IrisJigsawPieceConnector; import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructure; import com.volmit.iris.engine.object.objects.*; -import com.volmit.iris.engine.parallax.ParallaxChunkMeta; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.interpolation.InterpolationMethod; import com.volmit.iris.util.mantle.Mantle; From 099b50dbfa52db2a2258adc6df63b0528381910e Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 03:23:28 -0400 Subject: [PATCH 21/36] Drop fix command --- .../volmit/iris/core/command/CommandIris.java | 3 - .../core/command/world/CommandIrisFix.java | 76 ------------------- 2 files changed, 79 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/core/command/world/CommandIrisFix.java diff --git a/src/main/java/com/volmit/iris/core/command/CommandIris.java b/src/main/java/com/volmit/iris/core/command/CommandIris.java index d88d7fadc..17c816806 100644 --- a/src/main/java/com/volmit/iris/core/command/CommandIris.java +++ b/src/main/java/com/volmit/iris/core/command/CommandIris.java @@ -43,9 +43,6 @@ public class CommandIris extends MortarCommand { @Command private CommandIrisDebug debug; - @Command - private CommandIrisFix fix; - @Command private CommandIrisStudio studio; diff --git a/src/main/java/com/volmit/iris/core/command/world/CommandIrisFix.java b/src/main/java/com/volmit/iris/core/command/world/CommandIrisFix.java deleted file mode 100644 index 167431724..000000000 --- a/src/main/java/com/volmit/iris/core/command/world/CommandIrisFix.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.core.command.world; - -import com.volmit.iris.Iris; -import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.format.Form; -import com.volmit.iris.util.math.Spiraler; -import com.volmit.iris.util.plugin.MortarCommand; -import com.volmit.iris.util.plugin.VolmitSender; -import com.volmit.iris.util.scheduling.J; - -import java.util.concurrent.atomic.AtomicInteger; - -public class CommandIrisFix extends MortarCommand { - public CommandIrisFix() { - super("fix"); - requiresPermission(Iris.perm.studio); - setDescription("Fix nearby chunks"); - setCategory("Studio"); - } - - @Override - public void addTabOptions(VolmitSender sender, String[] args, KList list) { - - } - - @Override - public boolean handle(VolmitSender sender, String[] args) { - try { - Engine a = IrisToolbelt.access(sender.player().getWorld()).getEngine(); - - int viewDistance = args.length > 0 ? Integer.parseInt(args[0]) : -1; - if (viewDistance <= 1) { - J.a(() -> { - int fixed = a.getEngineParallax().repairChunk(sender.player().getLocation().getChunk()); - sender.sendMessage("Fixed " + Form.f(fixed) + " blocks!"); - }); - } else { - AtomicInteger v = new AtomicInteger(); - J.a(() -> { - new Spiraler(viewDistance, viewDistance, (x, z) -> v.set(v.get() + a.getEngineParallax().repairChunk(sender.player().getWorld().getChunkAt(x, z)))).drain(); - sender.sendMessage("Fixed " + Form.f(v.get()) + " blocks in " + (viewDistance * viewDistance) + " chunks!"); - }); - } - } catch (Throwable e) { - Iris.reportError(e); - sender.sendMessage("Not a valid Iris World (or bad argument)"); - } - - return true; - } - - @Override - protected String getArgsUsage() { - return "[view-distance]"; - } -} From 2f450b7ea07cd623d024d81e6743dce666c8158c Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 03:29:27 -0400 Subject: [PATCH 22/36] Iterate features --- .../com/volmit/iris/core/command/CommandIris.java | 1 - .../command/what/CommandIrisWhatFeatures.java | 2 +- .../volmit/iris/engine/mantle/EngineMantle.java | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/command/CommandIris.java b/src/main/java/com/volmit/iris/core/command/CommandIris.java index 17c816806..c54885676 100644 --- a/src/main/java/com/volmit/iris/core/command/CommandIris.java +++ b/src/main/java/com/volmit/iris/core/command/CommandIris.java @@ -25,7 +25,6 @@ import com.volmit.iris.core.command.pregen.CommandIrisPregen; import com.volmit.iris.core.command.studio.CommandIrisStudio; import com.volmit.iris.core.command.what.CommandIrisWhat; import com.volmit.iris.core.command.world.CommandIrisCreate; -import com.volmit.iris.core.command.world.CommandIrisFix; import com.volmit.iris.core.command.world.CommandIrisUpdateWorld; import com.volmit.iris.core.command.world.CommandIrisVerify; import com.volmit.iris.util.collection.KList; diff --git a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatFeatures.java b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatFeatures.java index b766d4630..f4589db46 100644 --- a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatFeatures.java +++ b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatFeatures.java @@ -53,7 +53,7 @@ public class CommandIrisWhatFeatures extends MortarCommand { if (IrisToolbelt.isIrisWorld(c.getWorld())) { int m = 1; - for (IrisFeaturePositional i : ((Engine) IrisToolbelt.access(c.getWorld()).getEngine()).getEngineParallax().getFeaturesInChunk(c)) { + for (IrisFeaturePositional i : ((Engine) IrisToolbelt.access(c.getWorld()).getEngine()).getMantle().getFeaturesInChunk(c)) { sender.sendMessage("#" + m++ + " " + new JSONObject(new Gson().toJson(i)).toString(4)); } } else { diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 36f07ac07..5fda1dfc0 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -43,6 +43,7 @@ import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; @@ -225,4 +226,18 @@ public interface EngineMantle extends IObjectPlacer { getMantle().flag(x>>4, z>>4, MantleFlag.UPDATE, true); getMantle().set(x,y,z,true); } + + @ChunkCoordinates + default KList getFeaturesInChunk(Chunk c) + { + return getFeaturesInChunk(c.getX(), c.getZ()); + } + + @ChunkCoordinates + default KList getFeaturesInChunk(int x, int z) + { + KList pos = new KList<>(); + getMantle().iterateChunk(x, z, IrisFeaturePositional.class, (a,b,c,f) -> pos.add(f), MantleFlag.FEATURE); + return pos; + } } From 98ffa0a2563848656255664ed930a06a286fe658 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 03:33:16 -0400 Subject: [PATCH 23/36] Feature looping --- .../com/volmit/iris/engine/IrisComplex.java | 12 +++--- .../iris/engine/mantle/EngineMantle.java | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisComplex.java b/src/main/java/com/volmit/iris/engine/IrisComplex.java index 83b8bf3bd..6888284d3 100644 --- a/src/main/java/com/volmit/iris/engine/IrisComplex.java +++ b/src/main/java/com/volmit/iris/engine/IrisComplex.java @@ -230,7 +230,7 @@ public class IrisComplex implements DataProvider { objectChanceStream = ProceduralStream.ofDouble((x, z) -> { if (engine.getDimension().hasFeatures(engine)) { AtomicDouble str = new AtomicDouble(1D); - for (IrisFeaturePositional i : engine.getEngineParallax().forEachFeature(x, z)) { + for (IrisFeaturePositional i : engine.getMantle().forEachFeature(x, z)) { str.set(Math.min(str.get(), i.getObjectChanceModifier(x, z, rng, getData()))); } @@ -241,7 +241,7 @@ public class IrisComplex implements DataProvider { }); trueBiomeStream = focus != null ? ProceduralStream.of((x, y) -> focus, Interpolated.of(a -> 0D, b -> focus)).convertAware2D((b, x, z) -> { - for (IrisFeaturePositional i : engine.getEngineParallax().forEachFeature(x, z)) { + for (IrisFeaturePositional i : engine.getMantle().forEachFeature(x, z)) { IrisBiome bx = i.filter(x, z, b, rng); if (bx != null) { @@ -257,7 +257,7 @@ public class IrisComplex implements DataProvider { fixBiomeType(h, baseBiomeStream.get(x, z), regionStream.get(x, z), x, z, fluidHeight)) .convertAware2D((b, x, z) -> { - for (IrisFeaturePositional i : engine.getEngineParallax().forEachFeature(x, z)) { + for (IrisFeaturePositional i : engine.getMantle().forEachFeature(x, z)) { IrisBiome bx = i.filter(x, z, b, rng); if (bx != null) { @@ -271,7 +271,7 @@ public class IrisComplex implements DataProvider { .cache2D(cacheSize); trueBiomeStream = focus != null ? ProceduralStream.of((x, y) -> focus, Interpolated.of(a -> 0D, b -> focus)).convertAware2D((b, x, z) -> { - for (IrisFeaturePositional i : engine.getEngineParallax().forEachFeature(x, z)) { + for (IrisFeaturePositional i : engine.getMantle().forEachFeature(x, z)) { IrisBiome bx = i.filter(x, z, b, rng); if (bx != null) { @@ -287,7 +287,7 @@ public class IrisComplex implements DataProvider { fixBiomeType(h, baseBiomeStream.get(x, z), regionStream.get(x, z), x, z, fluidHeight)) .convertAware2D((b, x, z) -> { - for (IrisFeaturePositional i : engine.getEngineParallax().forEachFeature(x, z)) { + for (IrisFeaturePositional i : engine.getMantle().forEachFeature(x, z)) { IrisBiome bx = i.filter(x, z, b, rng); if (bx != null) { @@ -458,7 +458,7 @@ public class IrisComplex implements DataProvider { AtomicDouble noise = new AtomicDouble(h + fluidHeight + overlayStream.get(x, z)); if (features) { - List p = engine.getEngineParallax().forEachFeature(x, z); + List p = engine.getMantle().forEachFeature(x, z); for (IrisFeaturePositional i : p) { noise.set(i.filter(x, z, noise.get(), rng, getData())); diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 5fda1dfc0..33af3cebd 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -240,4 +240,42 @@ public interface EngineMantle extends IObjectPlacer { getMantle().iterateChunk(x, z, IrisFeaturePositional.class, (a,b,c,f) -> pos.add(f), MantleFlag.FEATURE); return pos; } + + @BlockCoordinates + default KList forEachFeature(double x, double z) { + KList pos = new KList<>(); + + if (!getEngine().getDimension().hasFeatures(getEngine())) { + return pos; + } + + for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) { + if (i.shouldFilter(x, z, getEngine().getComplex().getRng(), getData())) { + pos.add(i); + } + } + + int s = getRealRadius(); + 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++) { + try { + for (IrisFeaturePositional k : getFeaturesInChunk(i + cx, j + cx)) { + if (k.shouldFilter(x, z, getEngine().getComplex().getRng(), getData())) { + pos.add(k); + } + } + } catch (Throwable e) { + Iris.error("FILTER ERROR" + " AT " + (cx + i) + " " + (j + cz)); + e.printStackTrace(); + Iris.reportError(e); + } + } + } + + return pos; + } } From ee240ca20151a0db96839fc86b72d3febfa8a83d Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 03:35:21 -0400 Subject: [PATCH 24/36] Fix post --- .../volmit/iris/engine/modifier/IrisPostModifier.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisPostModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisPostModifier.java index 91c23922f..d2a5bd818 100644 --- a/src/main/java/com/volmit/iris/engine/modifier/IrisPostModifier.java +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisPostModifier.java @@ -62,11 +62,11 @@ public class IrisPostModifier extends EngineAssignedModifier { @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") private void post(int currentPostX, int currentPostZ, Hunk currentData, int x, int z) { - int h = getEngine().getEngineParallax().trueHeight(x, z); - int ha = getEngine().getEngineParallax().trueHeight(x + 1, z); - int hb = getEngine().getEngineParallax().trueHeight(x, z + 1); - int hc = getEngine().getEngineParallax().trueHeight(x - 1, z); - int hd = getEngine().getEngineParallax().trueHeight(x, z - 1); + int h = getEngine().getMantle().trueHeight(x, z); + int ha = getEngine().getMantle().trueHeight(x + 1, z); + int hb = getEngine().getMantle().trueHeight(x, z + 1); + int hc = getEngine().getMantle().trueHeight(x - 1, z); + int hd = getEngine().getMantle().trueHeight(x, z - 1); // Floating Nibs int g = 0; From 5410cda18299cdb8e73eab0f06e9a1e0577daae0 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 03:35:31 -0400 Subject: [PATCH 25/36] World manager fixes --- src/main/java/com/volmit/iris/engine/IrisWorldManager.java | 4 ++-- src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisWorldManager.java b/src/main/java/com/volmit/iris/engine/IrisWorldManager.java index 7ab760407..070366de0 100644 --- a/src/main/java/com/volmit/iris/engine/IrisWorldManager.java +++ b/src/main/java/com/volmit/iris/engine/IrisWorldManager.java @@ -206,7 +206,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager { getData().getSpawnerLoader() .loadAll(getDimension().getEntitySpawners()) .shuffleCopy(RNG.r).stream().filter(this::canSpawn), - getData().getSpawnerLoader().streamAll(getEngine().getEngineParallax() + getData().getSpawnerLoader().streamAll(getEngine().getMantle() .getFeaturesInChunk(c).stream() .flatMap((o) -> o.getFeature().getEntitySpawners().stream())) .filter(this::canSpawn)) @@ -333,7 +333,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager { @Override public void onSave() { - getEngine().getParallax().saveAll(); + getEngine().getMantle().save(); } @Override diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 33af3cebd..1cd41688e 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -240,7 +240,7 @@ public interface EngineMantle extends IObjectPlacer { getMantle().iterateChunk(x, z, IrisFeaturePositional.class, (a,b,c,f) -> pos.add(f), MantleFlag.FEATURE); return pos; } - + @BlockCoordinates default KList forEachFeature(double x, double z) { KList pos = new KList<>(); From 87e1e55da7af2b04d9d154d59e8200d8d3189fee Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 03:35:37 -0400 Subject: [PATCH 26/36] Fix the board --- src/main/java/com/volmit/iris/core/IrisBoardManager.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/IrisBoardManager.java b/src/main/java/com/volmit/iris/core/IrisBoardManager.java index d560842ce..16bb7e6ab 100644 --- a/src/main/java/com/volmit/iris/core/IrisBoardManager.java +++ b/src/main/java/com/volmit/iris/core/IrisBoardManager.java @@ -122,8 +122,6 @@ public class IrisBoardManager implements BoardProvider, Listener { long memoryGuess = 0; int loadedObjects = 0; - parallaxRegions +=engine.getParallax().getRegionCount(); - parallaxChunks += engine.getParallax().getChunkCount(); loadedObjects += engine.getData().getObjectLoader().getSize(); memoryGuess += engine.getData().getObjectLoader().getTotalStorage() * 225L; memoryGuess += parallaxChunks * 3500L; @@ -139,7 +137,7 @@ public class IrisBoardManager implements BoardProvider, Listener { if (engine != null) { v.add("&7&m------------------"); KList f = new KList<>(); - f.add(engine.getEngineParallax().forEachFeature(x, z)); + f.add(engine.getMantle().forEachFeature(x, z)); v.add(C.AQUA + "Region" + C.GRAY + ": " + engine.getRegion(x, z).getName()); v.add(C.AQUA + "Biome" + C.GRAY + ": " + engine.getBiome(x, y, z).getName()); v.add(C.AQUA + "Height" + C.GRAY + ": " + Math.round(engine.getHeight(x, z))); From 97a62752c6fec9cf31b5e89a1a2a3afabc540031 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 03:43:24 -0400 Subject: [PATCH 27/36] Compiles --- src/main/java/com/volmit/iris/engine/IrisEngine.java | 2 +- .../java/com/volmit/iris/engine/mantle/EngineMantle.java | 7 ++++++- src/main/java/com/volmit/iris/util/mantle/MantleChunk.java | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index f73e67d02..d8f06649d 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -378,7 +378,7 @@ public class IrisEngine extends BlockPopulator implements Engine { getRavineModifier().modify(x, z, vblocks, multicore); getPostModifier().modify(x, z, vblocks, multicore); getDecorantActuator().actuate(x, z, blocks, multicore); - getMantle().insertMatter(x>>4, z>>4, blocks); + getMantle().insertMatter(x>>4, z>>4, BlockData.class, blocks); getDepositModifier().modify(x, z, blocks, multicore); } case ISLANDS -> { diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 1cd41688e..2b8dbc20c 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -42,6 +42,7 @@ import com.volmit.iris.util.mantle.TectonicPlate; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; +import com.volmit.iris.util.scheduling.PrecisionStopwatch; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.block.TileState; @@ -215,9 +216,13 @@ public interface EngineMantle extends IObjectPlacer { } @ChunkCoordinates - default void insertMatter(int x, int z, Hunk blocks) + default void insertMatter(int x, int z, Class t, Hunk blocks) { + if (!getEngine().getDimension().isUseMantle()) { + return; + } + getMantle().iterateChunk(x, z, t, blocks::set); } @BlockCoordinates diff --git a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java index 9b9db5e49..df3014dc9 100644 --- a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java +++ b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java @@ -174,6 +174,7 @@ public class MantleChunk { public void iterate(Class type, Consumer4 iterator) { for(int i = 0; i < sections.length(); i++) { + int bs = (i << 4); Matter matter = get(i); if(matter != null) @@ -182,7 +183,7 @@ public class MantleChunk { if(t != null) { - t.iterateSync(iterator); + t.iterateSync((a, b, c, f) -> iterator.accept(a,b + bs, c, f)); } } } From fc4377abafa97a8b2ecb370b1cd054ec7a4092dd Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 06:06:32 -0400 Subject: [PATCH 28/36] Fix IO --- .../com/volmit/iris/util/mantle/Mantle.java | 39 ++++++++++++++++--- .../volmit/iris/util/mantle/MantleChunk.java | 18 +++++---- .../iris/util/mantle/TectonicPlate.java | 1 + 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/src/main/java/com/volmit/iris/util/mantle/Mantle.java index de7ea75d9..4f917c107 100644 --- a/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -44,6 +44,7 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.zip.GZIPInputStream; /** * The mantle can store any type of data slice anywhere and manage regions & IO on it's own. @@ -103,7 +104,7 @@ public class Mantle { public void flag(int x, int z, MantleFlag flag, boolean flagged) { try { - get(x >> 5, z >> 5).get().get(x & 31, z & 31).flag(flag, flagged); + get(x >> 5, z >> 5).get().getOrCreate(x & 31, z & 31).flag(flag, flagged); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } @@ -121,7 +122,7 @@ public class Mantle { } try { - get(x >> 5, z >> 5).get().get(x & 31, z & 31).iterate(type, iterator); + get(x >> 5, z >> 5).get().getOrCreate(x & 31, z & 31).iterate(type, iterator); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } @@ -131,7 +132,7 @@ public class Mantle { public boolean hasFlag(int x, int z, MantleFlag flag) { try { - get(x >> 5, z >> 5).get().get(x & 31, z & 31).isFlagged(flag); + return get(x >> 5, z >> 5).get().getOrCreate(x & 31, z & 31).isFlagged(flag); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } @@ -297,8 +298,15 @@ public class Mantle { */ @RegionCoordinates private CompletableFuture get(int x, int z) { + Long k = key(x, z); + TectonicPlate p = loadedRegions.get(k); + + if(p != null) + { + return CompletableFuture.completedFuture(p); + } + return ioBurst.completeValue(() -> hyperLock.withResult(x, z, () -> { - Long k = key(x, z); lastUse.put(k, M.ms()); TectonicPlate region = loadedRegions.get(k); @@ -330,7 +338,7 @@ public class Mantle { region = new TectonicPlate(worldHeight); loadedRegions.put(k, region); - Iris.debug("Created new Tectonic Plate (Due to Load Failure) " + C.DARK_GREEN + x + " " + z); + Iris.debug("Created new Tectonic Plate " + C.DARK_GREEN + x + " " + z); return region; })); } @@ -349,4 +357,25 @@ public class Mantle { public static Long key(int x, int z) { return Cache.key(x, z); } + + public void saveAll() { + Iris.debug("Saving The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath()); + if (closed.get()) { + throw new RuntimeException("The Mantle is closed"); + } + + BurstExecutor b = ioBurst.burst(loadedRegions.size()); + for (Long i : loadedRegions.keySet()) { + b.queue(() -> { + try { + loadedRegions.get(i).write(fileForRegion(dataFolder, i)); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } + + b.complete(); + Iris.debug("The Mantle has Saved " + C.DARK_AQUA + dataFolder.getAbsolutePath()); + } } diff --git a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java index df3014dc9..f677550d5 100644 --- a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java +++ b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java @@ -18,6 +18,7 @@ package com.volmit.iris.util.mantle; +import com.volmit.iris.Iris; import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.collection.StateList; import com.volmit.iris.util.data.Varint; @@ -38,7 +39,6 @@ import java.util.concurrent.atomic.AtomicReferenceArray; * Mantle Chunks are fully atomic & thread safe */ public class MantleChunk { - private static final StateList state = MantleFlag.getStateList(); private final AtomicIntegerArray flags; private final AtomicReferenceArray sections; @@ -51,6 +51,11 @@ public class MantleChunk { public MantleChunk(int sectionHeight) { sections = new AtomicReferenceArray<>(sectionHeight); flags = new AtomicIntegerArray(MantleFlag.values().length); + + for (int i = 0; i < flags.length(); i++) + { + flags.set(i, 0); + } } /** @@ -65,9 +70,9 @@ public class MantleChunk { this(sectionHeight); int s = din.readByte(); - for(String i : state.getEnabled(Varint.readUnsignedVarLong(din))) + for(int i = 0; i < flags.length(); i++) { - flags.set(MantleFlag.valueOf(i).ordinal(), 1); + flags.set(i, din.readBoolean() ? 1 : 0); } for (int i = 0; i < s; i++) { @@ -82,7 +87,7 @@ public class MantleChunk { } public boolean isFlagged(MantleFlag flag) { - return flags.get(flags.get(flag.ordinal())) == 1; + return flags.get(flag.ordinal()) == 1; } /** @@ -152,14 +157,11 @@ public class MantleChunk { */ public void write(DataOutputStream dos) throws IOException { dos.writeByte(sections.length()); - long data = 0; for (int i = 0; i < flags.length(); i++) { - state.set(data, MantleFlag.values()[i].name(), flags.get(i) == 1); + dos.writeBoolean(flags.get(i) == 1); } - Varint.writeUnsignedVarLong(data, dos); - for (int i = 0; i < sections.length(); i++) { if (exists(i)) { dos.writeBoolean(true); diff --git a/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java b/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java index a09d18299..cbaa79549 100644 --- a/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java +++ b/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java @@ -24,6 +24,7 @@ import com.volmit.iris.util.format.C; import java.io.*; import java.util.concurrent.atomic.AtomicReferenceArray; +import java.util.zip.GZIPOutputStream; /** * Tectonic Plates are essentially representations of regions in minecraft. From d0fb3dde66545bec7abe7b813bebf57125c5aca5 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 06:06:39 -0400 Subject: [PATCH 29/36] Locks --- .../com/volmit/iris/util/matter/Matter.java | 28 +++++++++++-------- .../volmit/iris/util/parallel/HyperLock.java | 15 ++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/matter/Matter.java b/src/main/java/com/volmit/iris/util/matter/Matter.java index d81cbe08a..e80fa288d 100644 --- a/src/main/java/com/volmit/iris/util/matter/Matter.java +++ b/src/main/java/com/volmit/iris/util/matter/Matter.java @@ -186,18 +186,19 @@ public interface Matter { } default MatterSlice slice(Class c) { - if (!hasSlice(c)) { - MatterSlice s = createSlice(c, this); + MatterSlice slice = (MatterSlice) getSlice(c); + if (slice == null) { + slice = (MatterSlice) createSlice(c, this); - if (s == null) { + if (slice == null) { Iris.error("Unable to find a slice for class " + C.DARK_RED + c.getCanonicalName()); return null; } - putSlice(c, (MatterSlice) s); + putSlice(c, slice); } - return (MatterSlice) getSlice(c); + return slice; } /** @@ -254,11 +255,15 @@ public interface Matter { */ Map, MatterSlice> getSliceMap(); + default void write(File f) throws IOException { - FileOutputStream out = new FileOutputStream(f); - GZIPOutputStream gzo = new GZIPOutputStream(out); - write(gzo); - gzo.close(); + write(f, true); + } + + default void write(File f, boolean compression) throws IOException { + OutputStream out = new FileOutputStream(f); + write(out); + out.close(); } /** @@ -310,9 +315,8 @@ public interface Matter { static Matter read(File f) throws IOException, ClassNotFoundException { FileInputStream in = new FileInputStream(f); - GZIPInputStream gzi = new GZIPInputStream(in); - Matter m = read(gzi); - gzi.close(); + Matter m = read(in); + in.close(); return m; } diff --git a/src/main/java/com/volmit/iris/util/parallel/HyperLock.java b/src/main/java/com/volmit/iris/util/parallel/HyperLock.java index f93358a29..660bb9c9f 100644 --- a/src/main/java/com/volmit/iris/util/parallel/HyperLock.java +++ b/src/main/java/com/volmit/iris/util/parallel/HyperLock.java @@ -33,6 +33,7 @@ import java.util.function.Supplier; public class HyperLock { private final ConcurrentLinkedHashMap locks; private final BiFunction accessor; + private boolean enabled = true; public HyperLock() { this(1024, false); @@ -120,10 +121,24 @@ public class HyperLock { } public void lock(int x, int z) { + if(!enabled) + { + return; + } + getLock(x, z).lock(); } public void unlock(int x, int z) { + if(!enabled) + { + return; + } + getLock(x, z).unlock(); } + + public void disable() { + enabled = false; + } } From fca189ee4c9b47be55112e75b14ba8ae4ff142d6 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 06:06:55 -0400 Subject: [PATCH 30/36] Component writers merged --- .../iris/engine/mantle/EngineMantle.java | 33 +++++++++++-------- .../components/MantleFeatureComponent.java | 25 ++++---------- .../components/MantleJigsawComponent.java | 25 ++++---------- .../components/MantleObjectComponent.java | 29 +++++----------- 4 files changed, 41 insertions(+), 71 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 2b8dbc20c..225d2ce1b 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -21,38 +21,32 @@ package com.volmit.iris.engine.mantle; import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.IrisComplex; -import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineTarget; -import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.common.IObjectPlacer; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.engine.object.feature.IrisFeaturePositional; -import com.volmit.iris.engine.object.feature.IrisFeaturePotential; -import com.volmit.iris.engine.object.regional.IrisRegion; import com.volmit.iris.engine.object.tile.TileData; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.B; 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.hunk.Hunk; import com.volmit.iris.util.mantle.Mantle; import com.volmit.iris.util.mantle.MantleFlag; -import com.volmit.iris.util.mantle.TectonicPlate; -import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.scheduling.PrecisionStopwatch; -import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; // TODO: MOVE PLACER OUT OF MATTER INTO ITS OWN THING @@ -164,7 +158,7 @@ public interface EngineMantle extends IObjectPlacer { default void saveAllNow() { - + getMantle().saveAll(); } default void save() @@ -184,7 +178,6 @@ public interface EngineMantle extends IObjectPlacer { default int getRealRadius() { - getMantle().set(0, 34, 292393, Bukkit.getPlayer("cyberpwn")); try { return (int) Math.ceil(getRadius().get() / 2D); } catch (InterruptedException e) { @@ -204,15 +197,29 @@ public interface EngineMantle extends IObjectPlacer { return; } + PrecisionStopwatch p = PrecisionStopwatch.start(); List post = Collections.synchronizedList(new KList<>()); Consumer c = post::add; - getComponents().forEach((i) -> generateMantleComponent(x, z, i, c)); + int s = getRealRadius(); + BurstExecutor burst = burst().burst(); + + for (int i = -s; i <= s; i++) { + int xx = i + x; + for (int j = -s; j <= s; j++) { + int zz = j + z; + burst.queue(() -> { + getComponents().forEach((f) -> generateMantleComponent(xx, zz, f, c)); + }); + } + } + + burst.complete(); burst().burst(post); } - default void generateMantleComponent(int x, int z, MantleComponent i, Consumer post) + default void generateMantleComponent(int x, int z, MantleComponent c, Consumer post) { - getMantle().raiseFlag(x, z, i.getFlag(), () -> i.generateLayer(x, z, post)); + getMantle().raiseFlag(x, z, c.getFlag(), () -> c.generateLayer(x, z, post)); } @ChunkCoordinates diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleFeatureComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleFeatureComponent.java index 58bcbfe40..340be30c8 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleFeatureComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleFeatureComponent.java @@ -40,25 +40,12 @@ public class MantleFeatureComponent extends IrisMantleComponent { @Override public void generateLayer(int x, int z, Consumer post) { - int s = getRadius(); - BurstExecutor burst = burst(); - - for (int i = -s; i <= s; i++) { - int xx = i + x; - int xxx = 8 + (xx << 4); - for (int j = -s; j <= s; j++) { - int zz = j + z; - int zzz = 8 + (zz << 4); - burst.queue(() -> { - RNG rng = new RNG(Cache.key(xx, zz) + seed()); - IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); - IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); - generateFeatures(rng, xx, zz, region, biome); - }); - } - } - - burst.complete(); + RNG rng = new RNG(Cache.key(x, z) + seed()); + int xxx = 8 + (x << 4); + int zzz = 8 + (z << 4); + IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); + IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); + generateFeatures(rng, x, z, region, biome); } @ChunkCoordinates diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java index ebf225890..2e7d474f6 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java @@ -46,25 +46,12 @@ public class MantleJigsawComponent extends IrisMantleComponent @Override public void generateLayer(int x, int z, Consumer post) { - int s = getRadius(); - BurstExecutor burst = burst(); - - for (int i = -s; i <= s; i++) { - int xx = i+x; - int xxx = 8 + (xx << 4); - for (int j = -s; j <= s; j++) { - int zz = j + z; - int zzz = 8 + (zz << 4); - burst.queue(() -> { - RNG rng = new RNG(Cache.key(xx, zz) + seed()); - IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); - IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); - generateJigsaw(rng, xx, zz, biome, region, post); - }); - } - } - - burst.complete(); + RNG rng = new RNG(Cache.key(x, z) + seed()); + int xxx = 8 + (x << 4); + int zzz = 8 + (z << 4); + IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); + IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); + generateJigsaw(rng, x, z, biome, region, post); } @ChunkCoordinates diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java index 0624fc793..bb119a9c9 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java @@ -31,38 +31,27 @@ import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.engine.object.regional.IrisRegion; 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.mantle.MantleFlag; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.BurstExecutor; +import com.volmit.iris.util.scheduling.PrecisionStopwatch; import java.util.function.Consumer; public class MantleObjectComponent extends IrisMantleComponent { public MantleObjectComponent(EngineMantle engineMantle) { - super(engineMantle, MantleFlag.FEATURE); + super(engineMantle, MantleFlag.OBJECT); } @Override public void generateLayer(int x, int z, Consumer post) { - int s = getRadius(); - BurstExecutor burst = burst(); - - for (int i = -s; i <= s; i++) { - int xx = i + x; - int xxx = 8 + (xx << 4); - for (int j = -s; j <= s; j++) { - int zz = j + z; - int zzz = 8 + (zz << 4); - burst.queue(() -> { - RNG rng = new RNG(Cache.key(xx, zz) + seed()); - IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); - IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); - placeObjects(rng, xx, zz, biome, region, post); - }); - } - } - - burst.complete(); + RNG rng = new RNG(Cache.key(x, z) + seed()); + int xxx = 8 + (x << 4); + int zzz = 8 + (z << 4); + IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); + IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz); + placeObjects(rng, x, z, biome, region, post); } @ChunkCoordinates From 8928b35f3056935fb5af57d316adb83f2f6ec4a9 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 06:07:02 -0400 Subject: [PATCH 31/36] Mantle tweaks --- .../volmit/iris/engine/IrisEngineMantle.java | 257 +++++++++++++++++- 1 file changed, 256 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java index 8c2b6279e..92ad6ee35 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java @@ -18,6 +18,7 @@ package com.volmit.iris.engine; +import com.volmit.iris.Iris; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.mantle.IrisMantleComponent; @@ -25,12 +26,28 @@ import com.volmit.iris.engine.mantle.MantleComponent; import com.volmit.iris.engine.mantle.components.MantleFeatureComponent; import com.volmit.iris.engine.mantle.components.MantleJigsawComponent; import com.volmit.iris.engine.mantle.components.MantleObjectComponent; +import com.volmit.iris.engine.object.biome.IrisBiome; +import com.volmit.iris.engine.object.deposits.IrisDepositGenerator; +import com.volmit.iris.engine.object.feature.IrisFeaturePotential; +import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement; +import com.volmit.iris.engine.object.objects.IrisObject; +import com.volmit.iris.engine.object.objects.IrisObjectPlacement; +import com.volmit.iris.engine.object.objects.IrisObjectScale; +import com.volmit.iris.engine.object.regional.IrisRegion; 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.format.Form; import com.volmit.iris.util.mantle.Mantle; +import com.volmit.iris.util.parallel.BurstExecutor; import lombok.Data; +import org.bukkit.util.BlockVector; import java.io.File; +import java.io.IOException; +import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; @Data public class IrisEngineMantle implements EngineMantle { @@ -42,7 +59,7 @@ public class IrisEngineMantle implements EngineMantle { public IrisEngineMantle(Engine engine) { this.engine = engine; this.mantle = new Mantle(new File(engine.getWorld().worldFolder(), "mantle"), engine.getTarget().getHeight()); - radius = CompletableFuture.completedFuture(0); // TODO + radius = burst().completeValue(this::computeParallaxSize); components = new KList<>(); registerComponent(new MantleFeatureComponent(this)); registerComponent(new MantleJigsawComponent(this)); @@ -53,4 +70,242 @@ public class IrisEngineMantle implements EngineMantle { public void registerComponent(MantleComponent c) { components.add(c); } + + private KList getAllRegions() { + KList r = new KList<>(); + + for (String i : getEngine().getDimension().getRegions()) { + r.add(getEngine().getData().getRegionLoader().load(i)); + } + + return r; + } + + private KList getAllFeatures() { + KList r = new KList<>(); + r.addAll(getEngine().getDimension().getFeatures()); + getAllRegions().forEach((i) -> r.addAll(i.getFeatures())); + getAllBiomes().forEach((i) -> r.addAll(i.getFeatures())); + return r; + } + + private KList getAllBiomes() { + KList r = new KList<>(); + + for (IrisRegion i : getAllRegions()) { + r.addAll(i.getAllBiomes(getEngine())); + } + + return r; + } + + private void warn(String ob, BlockVector bv) { + if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) { + Iris.warn("Object " + ob + " has a large size (" + bv + ") and may increase memory usage!"); + } + } + + private void warnScaled(String ob, BlockVector bv, double ms) { + if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) { + Iris.warn("Object " + ob + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")"); + } + } + + private int computeFeatureRange() { + int m = 0; + + for (IrisFeaturePotential i : getAllFeatures()) { + m = Math.max(m, i.getZone().getRealSize()); + } + + return m; + } + + private int computeParallaxSize() { + Iris.verbose("Calculating the Parallax Size in Parallel"); + AtomicInteger xg = new AtomicInteger(0); + AtomicInteger zg = new AtomicInteger(); + xg.set(0); + zg.set(0); + int jig = 0; + KSet objects = new KSet<>(); + KMap> scalars = new KMap<>(); + int x = xg.get(); + int z = zg.get(); + + if (getEngine().getDimension().isUseMantle()) { + KList r = getAllRegions(); + KList b = getAllBiomes(); + + for (IrisBiome i : b) { + for (IrisObjectPlacement j : i.getObjects()) { + if (j.getScale().canScaleBeyond()) { + scalars.put(j.getScale(), j.getPlace()); + } else { + objects.addAll(j.getPlace()); + } + } + + for (IrisJigsawStructurePlacement j : i.getJigsawStructures()) { + jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension()); + } + } + + for (IrisRegion i : r) { + for (IrisObjectPlacement j : i.getObjects()) { + if (j.getScale().canScaleBeyond()) { + scalars.put(j.getScale(), j.getPlace()); + } else { + objects.addAll(j.getPlace()); + } + } + + for (IrisJigsawStructurePlacement j : i.getJigsawStructures()) { + jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension()); + } + } + + for (IrisJigsawStructurePlacement j : getEngine().getDimension().getJigsawStructures()) { + jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension()); + } + + if (getEngine().getDimension().getStronghold() != null) { + try { + jig = Math.max(jig, getData().getJigsawStructureLoader().load(getEngine().getDimension().getStronghold()).getMaxDimension()); + } catch (Throwable e) { + Iris.reportError(e); + Iris.error("THIS IS THE ONE"); + e.printStackTrace(); + } + } + + Iris.verbose("Checking sizes for " + Form.f(objects.size()) + " referenced objects."); + BurstExecutor e = getEngine().getTarget().getBurster().burst(objects.size()); + KMap sizeCache = new KMap<>(); + for (String i : objects) { + e.queue(() -> { + try { + BlockVector bv = sizeCache.compute(i, (k, v) -> { + if (v != null) { + return v; + } + + try { + return IrisObject.sampleSize(getData().getObjectLoader().findFile(i)); + } catch (IOException ex) { + Iris.reportError(ex); + ex.printStackTrace(); + } + + return null; + }); + + if (bv == null) { + throw new RuntimeException(); + } + + warn(i, bv); + + synchronized (xg) { + xg.getAndSet(Math.max(bv.getBlockX(), xg.get())); + } + + synchronized (zg) { + zg.getAndSet(Math.max(bv.getBlockZ(), zg.get())); + } + } catch (Throwable ed) { + Iris.reportError(ed); + + } + }); + } + + for (Map.Entry> entry : scalars.entrySet()) { + double ms = entry.getKey().getMaximumScale(); + for (String j : entry.getValue()) { + e.queue(() -> { + try { + BlockVector bv = sizeCache.compute(j, (k, v) -> { + if (v != null) { + return v; + } + + try { + return IrisObject.sampleSize(getData().getObjectLoader().findFile(j)); + } catch (IOException ioException) { + Iris.reportError(ioException); + ioException.printStackTrace(); + } + + return null; + }); + + if (bv == null) { + throw new RuntimeException(); + } + + warnScaled(j, bv, ms); + + synchronized (xg) { + xg.getAndSet((int) Math.max(Math.ceil(bv.getBlockX() * ms), xg.get())); + } + + synchronized (zg) { + zg.getAndSet((int) Math.max(Math.ceil(bv.getBlockZ() * ms), zg.get())); + } + } catch (Throwable ee) { + Iris.reportError(ee); + + } + }); + } + } + + e.complete(); + + x = xg.get(); + z = zg.get(); + + for (IrisDepositGenerator i : getEngine().getDimension().getDeposits()) { + int max = i.getMaxDimension(); + x = Math.max(max, x); + z = Math.max(max, z); + } + + for (IrisRegion v : r) { + for (IrisDepositGenerator i : v.getDeposits()) { + int max = i.getMaxDimension(); + x = Math.max(max, x); + z = Math.max(max, z); + } + } + + for (IrisBiome v : b) { + for (IrisDepositGenerator i : v.getDeposits()) { + int max = i.getMaxDimension(); + x = Math.max(max, x); + z = Math.max(max, z); + } + } + } + + else + { + return 0; + } + + x = Math.max(z, x); + int u = x; + int v = computeFeatureRange(); + x = Math.max(jig, x); + x = Math.max(x, v); + x = (Math.max(x, 16) + 16) >> 4; + x = x % 2 == 0 ? x + 1 : x; + Iris.info("Parallax Size: " + x + " Chunks"); + Iris.info(" Object Parallax Size: " + u + " (" + ((Math.max(u, 16) + 16) >> 4) + ")"); + Iris.info(" Jigsaw Parallax Size: " + jig + " (" + ((Math.max(jig, 16) + 16) >> 4) + ")"); + Iris.info(" Feature Parallax Size: " + v + " (" + ((Math.max(v, 16) + 16) >> 4) + ")"); + + return x; + } } From 4442d9a706052df60fb659faf2b48e893cf2a3ce Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 06:07:08 -0400 Subject: [PATCH 32/36] Fix gens --- .../com/volmit/iris/engine/IrisEngine.java | 22 ++++++++++--------- .../engine/platform/BukkitChunkGenerator.java | 3 +-- .../iris/engine/platform/EngineProvider.java | 13 ++++++++--- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index d8f06649d..e6e20bfcf 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -122,7 +122,6 @@ public class IrisEngine extends BlockPopulator implements Engine { lastGPS = new AtomicLong(M.ms()); generated = new AtomicInteger(0); execution = new IrisExecutionEnvironment(this); - mantle = new IrisEngineMantle(this); // TODO: HEIGHT ------------------------------------------------------------------------------------------------------> Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + 256+ " height)"); metrics = new EngineMetrics(32); @@ -151,7 +150,7 @@ public class IrisEngine extends BlockPopulator implements Engine { cleaning = new AtomicBoolean(false); cleanLatch = new ChronoLatch(Math.max(10000, Math.min(IrisSettings.get().getParallax() .getParallaxChunkEvictionMS(), IrisSettings.get().getParallax().getParallaxRegionEvictionMS()))); - + mantle = new IrisEngineMantle(this); } @Override @@ -329,14 +328,16 @@ public class IrisEngine extends BlockPopulator implements Engine { cleaning.set(true); - try { - getMantle().trim(); - getData().getObjectLoader().clean(); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("Cleanup failed!"); - e.printStackTrace(); - } + J.a(() -> { + try { + getMantle().trim(); + getData().getObjectLoader().clean(); + } catch (Throwable e) { + Iris.reportError(e); + Iris.error("Cleanup failed!"); + e.printStackTrace(); + } + }); cleaning.lazySet(false); } @@ -388,6 +389,7 @@ public class IrisEngine extends BlockPopulator implements Engine { getMetrics().getTotal().put(p.getMilliseconds()); generated.incrementAndGet(); + recycle(); } catch (Throwable e) { Iris.reportError(e); fail("Failed to generate " + x + ", " + z, e); diff --git a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java index 4c3120b6a..f051e5f9c 100644 --- a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java @@ -51,7 +51,6 @@ import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChunkGenerator { - private static final BlockData ERROR_BLOCK = Material.RED_GLAZED_TERRACOTTA.createBlockData(); private final EngineProvider provider; private final IrisWorld world; private final File dataLocation; @@ -150,7 +149,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { - d.setBlock(i, 0, j, ERROR_BLOCK); + d.setBlock(i, 0, j, Material.RED_GLAZED_TERRACOTTA.createBlockData()); } } diff --git a/src/main/java/com/volmit/iris/engine/platform/EngineProvider.java b/src/main/java/com/volmit/iris/engine/platform/EngineProvider.java index c3996af3f..76c70ed23 100644 --- a/src/main/java/com/volmit/iris/engine/platform/EngineProvider.java +++ b/src/main/java/com/volmit/iris/engine/platform/EngineProvider.java @@ -54,14 +54,21 @@ public class EngineProvider { public Engine getEngine() { try { - return engine.get().get(); + Engine e = engine.get().get(); + + if(e == null) + { + throw new RuntimeException("NULL"); + } + + return e; } catch (InterruptedException e) { e.printStackTrace(); + throw new RuntimeException("INTERRUPTED"); } catch (ExecutionException e) { e.printStackTrace(); + throw new RuntimeException("EXECUTION ERROR"); } - - return null; } public void close() { From 3728c59f1d77e9c9d9984c8a1e384fa30fb2e030 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 07:18:55 -0400 Subject: [PATCH 33/36] Async trimming --- .../com/volmit/iris/engine/IrisEngine.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index e6e20bfcf..e61da4ed6 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -328,18 +328,18 @@ public class IrisEngine extends BlockPopulator implements Engine { cleaning.set(true); - J.a(() -> { - try { - getMantle().trim(); - getData().getObjectLoader().clean(); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("Cleanup failed!"); - e.printStackTrace(); - } - }); + J.a(() -> { + try { + getMantle().trim(); + getData().getObjectLoader().clean(); + } catch (Throwable e) { + Iris.reportError(e); + Iris.error("Cleanup failed!"); + e.printStackTrace(); + } - cleaning.lazySet(false); + cleaning.lazySet(false); + }); } public EngineActuator getTerrainActuator() { From ec780b7b936f41276e58eea4f10ddc11c868188c Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 07:18:59 -0400 Subject: [PATCH 34/36] Fixes --- src/main/java/com/volmit/iris/Iris.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 4ddcd1219..995545809 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -48,7 +48,6 @@ import com.volmit.iris.util.io.InstanceState; import com.volmit.iris.util.io.JarScanner; import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.noise.CNG; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.plugin.Metrics; import com.volmit.iris.util.plugin.Permission; From 7637905de2f88201cea07ae726f98798584c6d0c Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 07:19:10 -0400 Subject: [PATCH 35/36] Safe saving / trimming --- .../com/volmit/iris/util/mantle/Mantle.java | 56 +++++++------------ .../volmit/iris/util/mantle/MantleChunk.java | 22 ++++++++ .../iris/util/mantle/TectonicPlate.java | 26 ++++++++- 3 files changed, 64 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/src/main/java/com/volmit/iris/util/mantle/Mantle.java index 4f917c107..c96c4f5c7 100644 --- a/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -266,25 +266,26 @@ public class Mantle { unload.clear(); for (Long i : lastUse.keySet()) { - if (M.ms() - lastUse.get(i) >= idleDuration) { - unload.add(i); - } + hyperLock.withLong(i, () -> { + if (M.ms() - lastUse.get(i) >= idleDuration) { + unload.add(i); + } + }); } for (Long i : unload) { - TectonicPlate m = loadedRegions.remove(i); - lastUse.remove(i); - Iris.debug("Unloaded Tectonic Plate " + C.DARK_GREEN + i); + hyperLock.withLong(i, () ->{ + TectonicPlate m = loadedRegions.remove(i); + lastUse.remove(i); - if (m != null) { - ioBurst.lazy(() -> { - try { - m.write(fileForRegion(dataFolder, i)); - } catch (IOException e) { - e.printStackTrace(); - } - }); - } + try { + m.write(fileForRegion(dataFolder, i)); + } catch (IOException e) { + e.printStackTrace(); + } + + Iris.debug("Unloaded Tectonic Plate " + C.DARK_GREEN + Cache.keyX(i) + " " + Cache.keyZ(i)); + }); } } @@ -297,12 +298,13 @@ public class Mantle { * @return the future of a tectonic plate. */ @RegionCoordinates - private CompletableFuture get(int x, int z) { + private synchronized CompletableFuture get(int x, int z) { Long k = key(x, z); TectonicPlate p = loadedRegions.get(k); if(p != null) { + lastUse.put(k, M.ms()); return CompletableFuture.completedFuture(p); } @@ -318,10 +320,7 @@ public class Mantle { if (file.exists()) { try { - FileInputStream fin = new FileInputStream(file); - DataInputStream din = new DataInputStream(fin); - region = new TectonicPlate(worldHeight, din); - din.close(); + region = TectonicPlate.read(worldHeight, file); loadedRegions.put(k, region); Iris.debug("Loaded Tectonic Plate " + C.DARK_GREEN + x + " " + z + C.DARK_AQUA + " " + file.getName()); } catch (Throwable e) { @@ -359,23 +358,6 @@ public class Mantle { } public void saveAll() { - Iris.debug("Saving The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath()); - if (closed.get()) { - throw new RuntimeException("The Mantle is closed"); - } - BurstExecutor b = ioBurst.burst(loadedRegions.size()); - for (Long i : loadedRegions.keySet()) { - b.queue(() -> { - try { - loadedRegions.get(i).write(fileForRegion(dataFolder, i)); - } catch (IOException e) { - e.printStackTrace(); - } - }); - } - - b.complete(); - Iris.debug("The Mantle has Saved " + C.DARK_AQUA + dataFolder.getAbsolutePath()); } } diff --git a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java index f677550d5..fa8712dde 100644 --- a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java +++ b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java @@ -163,6 +163,8 @@ public class MantleChunk { } for (int i = 0; i < sections.length(); i++) { + trimSlice(i); + if (exists(i)) { dos.writeBoolean(true); Matter matter = get(i); @@ -173,6 +175,26 @@ public class MantleChunk { } } + private void trimSlice(int i) { + if(exists(i)) + { + Matter m = get(i); + + if(m.getSliceMap().isEmpty()) + { + sections.set(i, null); + } + + else{ + m.trimSlices(); + if(m.getSliceMap().isEmpty()) + { + sections.set(i, null); + } + } + } + } + public void iterate(Class type, Consumer4 iterator) { for(int i = 0; i < sections.length(); i++) { diff --git a/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java b/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java index cbaa79549..76f390d7f 100644 --- a/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java +++ b/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java @@ -21,9 +21,12 @@ package com.volmit.iris.util.mantle; import com.volmit.iris.Iris; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.format.C; +import com.volmit.iris.util.format.Form; +import com.volmit.iris.util.scheduling.PrecisionStopwatch; import java.io.*; import java.util.concurrent.atomic.AtomicReferenceArray; +import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; /** @@ -62,6 +65,16 @@ public class TectonicPlate { } } + public static TectonicPlate read(int worldHeight, File file) throws IOException, ClassNotFoundException { + FileInputStream fin = new FileInputStream(file); + GZIPInputStream gzi = new GZIPInputStream(fin); + DataInputStream din = new DataInputStream(gzi); + TectonicPlate p = new TectonicPlate(worldHeight, din); + din.close(); + + return p; + } + /** * Check if a chunk exists in this plate or not (same as get(x, z) != null) * @@ -137,11 +150,13 @@ public class TectonicPlate { * @throws IOException shit happens */ public void write(File file) throws IOException { + PrecisionStopwatch p = PrecisionStopwatch.start(); FileOutputStream fos = new FileOutputStream(file); - DataOutputStream dos = new DataOutputStream(fos); + GZIPOutputStream gzo = new GZIPOutputStream(fos); + DataOutputStream dos = new DataOutputStream(gzo); write(dos); dos.close(); - Iris.debug("Saved Tectonic Plate " + C.DARK_GREEN + file.getName().split("\\Q.\\E")[0]); + Iris.debug("Saved Tectonic Plate " + C.DARK_GREEN + file.getName().split("\\Q.\\E")[0] + C.RED + " in " + Form.duration(p.getMilliseconds(), 2)); } /** @@ -153,11 +168,16 @@ public class TectonicPlate { public void write(DataOutputStream dos) throws IOException { for (int i = 0; i < chunks.length(); i++) { MantleChunk chunk = chunks.get(i); - dos.writeBoolean(chunk != null); if (chunk != null) { + dos.writeBoolean(true); chunk.write(dos); } + + else + { + dos.writeBoolean(false); + } } } } From c5c1a9b25b850984a2914cbe9fcb02bdf2673307 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 10 Aug 2021 07:19:17 -0400 Subject: [PATCH 36/36] Fixes --- .../java/com/volmit/iris/util/matter/Matter.java | 1 - .../com/volmit/iris/util/matter/MatterHeader.java | 2 +- .../com/volmit/iris/util/matter/MatterSlice.java | 15 +++++++++++++++ .../com/volmit/iris/util/parallel/HyperLock.java | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/matter/Matter.java b/src/main/java/com/volmit/iris/util/matter/Matter.java index e80fa288d..84aefb1b9 100644 --- a/src/main/java/com/volmit/iris/util/matter/Matter.java +++ b/src/main/java/com/volmit/iris/util/matter/Matter.java @@ -255,7 +255,6 @@ public interface Matter { */ Map, MatterSlice> getSliceMap(); - default void write(File f) throws IOException { write(f, true); } diff --git a/src/main/java/com/volmit/iris/util/matter/MatterHeader.java b/src/main/java/com/volmit/iris/util/matter/MatterHeader.java index 3548439f3..a00a53d75 100644 --- a/src/main/java/com/volmit/iris/util/matter/MatterHeader.java +++ b/src/main/java/com/volmit/iris/util/matter/MatterHeader.java @@ -28,7 +28,7 @@ import java.io.IOException; @Data public class MatterHeader { - private String author = "anonymous"; + private String author = ""; private long createdAt = M.ms(); private int version = Matter.VERSION; diff --git a/src/main/java/com/volmit/iris/util/matter/MatterSlice.java b/src/main/java/com/volmit/iris/util/matter/MatterSlice.java index e05194d56..2b3aa44c3 100644 --- a/src/main/java/com/volmit/iris/util/matter/MatterSlice.java +++ b/src/main/java/com/volmit/iris/util/matter/MatterSlice.java @@ -18,7 +18,9 @@ package com.volmit.iris.util.matter; +import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.Cache; +import com.volmit.iris.util.data.NibbleDataPalette; import com.volmit.iris.util.data.Varint; import com.volmit.iris.util.hunk.Hunk; import org.bukkit.Location; @@ -106,6 +108,19 @@ public interface MatterSlice extends Hunk { return readFrom(mediumType) != null; } + default int getBitsPer(int needed) + { + int target = 1; + for (int i = 1; i < 8; i++) { + if (Math.pow(2, i) > needed) { + target = i; + break; + } + } + + return target; + } + default void write(DataOutputStream dos) throws IOException { int w = getWidth(); int h = getHeight(); diff --git a/src/main/java/com/volmit/iris/util/parallel/HyperLock.java b/src/main/java/com/volmit/iris/util/parallel/HyperLock.java index 660bb9c9f..03138b339 100644 --- a/src/main/java/com/volmit/iris/util/parallel/HyperLock.java +++ b/src/main/java/com/volmit/iris/util/parallel/HyperLock.java @@ -63,6 +63,12 @@ public class HyperLock { unlock(x, z); } + public void withLong(long k, Runnable r) { + lock(Cache.keyX(k), Cache.keyZ(k)); + r.run(); + unlock(Cache.keyX(k), Cache.keyZ(k)); + } + public void withNasty(int x, int z, NastyRunnable r) throws Throwable { lock(x, z); Throwable ee = null;