diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 4ef3a0910..a8ff713e7 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -31,12 +31,14 @@ import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineEffects; import com.volmit.iris.engine.framework.EngineMetrics; +import com.volmit.iris.engine.framework.EngineMode; import com.volmit.iris.engine.framework.EngineStage; import com.volmit.iris.engine.framework.EngineTarget; import com.volmit.iris.engine.framework.EngineWorldManager; import com.volmit.iris.engine.framework.SeedManager; import com.volmit.iris.engine.framework.WrongEngineBroException; import com.volmit.iris.engine.mantle.EngineMantle; +import com.volmit.iris.engine.mode.ModeOverworld; import com.volmit.iris.engine.modifier.IrisCarveModifier; import com.volmit.iris.engine.modifier.IrisDepositModifier; import com.volmit.iris.engine.modifier.IrisPerfectionModifier; @@ -94,6 +96,7 @@ public class IrisEngine implements Engine { private final KList stages; private final AtomicRollingSequence wallClock; private final int art; + private EngineMode mode; private final AtomicCache engineData = new AtomicCache<>(); private final AtomicBoolean cleaning; private final ChronoLatch cleanLatch; @@ -167,6 +170,8 @@ public class IrisEngine implements Engine { stages.forEach(EngineStage::close); stages.clear(); effects.close(); + mode.close(); + J.a(() -> new IrisProject(getData().getDataFolder()).updateWorkspace()); } @@ -178,7 +183,7 @@ public class IrisEngine implements Engine { complex = new IrisComplex(this); execution = new IrisExecutionEnvironment(this); effects = new IrisEngineEffects(this); - setupStages(); + setupMode(); J.a(this::computeBiomeMaxes); } catch (Throwable e) { Iris.error("FAILED TO SETUP ENGINE!"); @@ -188,25 +193,13 @@ public class IrisEngine implements Engine { Iris.debug("Engine Setup Complete " + getCacheID()); } - private void setupStages() { - var terrain = new IrisTerrainNormalActuator(this); - var biome = new IrisBiomeActuator(this); - var decorant = new IrisDecorantActuator(this); - var cave = new IrisCarveModifier(this); - var post = new IrisPostModifier(this); - var deposit = new IrisDepositModifier(this); - var perfection = new IrisPerfectionModifier(this); + private void setupMode() { + if(mode != null) + { + mode.close(); + } - registerStage((x, z, k, p, m) -> warmupChunk(x >> 4, z >> 4)); - registerStage((x, z, k, p, m) -> generateMatter(x >> 4, z >> 4, m)); - registerStage((x, z, k, p, m) -> terrain.actuate(x, z, k, m)); - registerStage((x, z, k, p, m) -> biome.actuate(x, z, p, m)); - registerStage((x, z, k, p, m) -> cave.modify(x >> 4, z >> 4, k, m)); - registerStage((x, z, k, p, m) -> decorant.actuate(x, z, k, m)); - registerStage((x, z, k, p, m) -> post.modify(x, z, k, m)); - registerStage((x, z, k, p, m) -> deposit.modify(x, z, k, m)); - registerStage((x, z, K, p, m) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m)); - registerStage((x, z, k, p, m) -> perfection.modify(x, z, k, m)); + mode = getDimension().getMode().getType().create(this); } @Override @@ -335,11 +328,6 @@ public class IrisEngine implements Engine { } } - @Override - public void registerStage(EngineStage stage) { - stages.add(stage); - } - @Override public int getBlockUpdatesPerSecond() { return buds.get(); 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 f4731da6c..81e8e1619 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -93,12 +93,10 @@ import java.util.function.Consumer; import java.util.stream.Collectors; public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdater, Renderer, Hotloadable { - KList getStages(); - - void registerStage(EngineStage stage); - IrisComplex getComplex(); + EngineMode getMode(); + int getBlockUpdatesPerSecond(); void printMetrics(CommandSender sender); diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineMode.java b/src/main/java/com/volmit/iris/engine/framework/EngineMode.java index 5f59b1090..22018a963 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineMode.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineMode.java @@ -18,16 +18,59 @@ package com.volmit.iris.engine.framework; +import com.volmit.iris.engine.IrisComplex; +import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.hunk.Hunk; +import com.volmit.iris.util.parallel.BurstExecutor; +import com.volmit.iris.util.parallel.MultiBurst; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; -public interface EngineMode { +public interface EngineMode extends Staged { void close(); Engine getEngine(); + default MultiBurst burst() + { + return getEngine().burst(); + } + + default EngineStage burst(EngineStage... stages) + { + return (x, z, blocks, biomes, multicore) -> { + BurstExecutor e = burst().burst(stages.length); + e.setMulticore(multicore); + + for(EngineStage i : stages) + { + e.queue(() -> i.generate(x, z, blocks, biomes, multicore)); + } + + e.complete(); + }; + } + + default IrisComplex getComplex() + { + return getEngine().getComplex(); + } + + default EngineMantle getMantle() + { + return getEngine().getMantle(); + } + + default void generateMatter(int x, int z, boolean multicore) { + getMantle().generateMatter(x, z, multicore); + } + @BlockCoordinates - void generate(int x, int z, Hunk blocks, Hunk biomes, boolean multicore); + default void generate(int x, int z, Hunk blocks, Hunk biomes, boolean multicore) + { + for (EngineStage i : getStages()) { + i.generate(x, z, blocks, biomes, multicore); + } + } } diff --git a/src/main/java/com/volmit/iris/engine/framework/IrisEngineMode.java b/src/main/java/com/volmit/iris/engine/framework/IrisEngineMode.java new file mode 100644 index 000000000..f0b9d17fa --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/framework/IrisEngineMode.java @@ -0,0 +1,61 @@ +/* + * 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.util.collection.KList; + +public abstract class IrisEngineMode implements EngineMode { + private final Engine engine; + private final KList stages; + private boolean closed; + + public IrisEngineMode(Engine engine) + { + this.engine = engine; + this.stages = new KList<>(); + this.closed = false; + } + + @Override + public synchronized void close() + { + if(closed) + { + return; + } + + closed = true; + dump(); + } + + @Override + public Engine getEngine() { + return engine; + } + + @Override + public KList getStages() { + return stages; + } + + @Override + public void registerStage(EngineStage stage) { + stages.add(stage); + } +} diff --git a/src/main/java/com/volmit/iris/engine/framework/Staged.java b/src/main/java/com/volmit/iris/engine/framework/Staged.java new file mode 100644 index 000000000..069d8af77 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/framework/Staged.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.engine.framework; + +import com.volmit.iris.util.collection.KList; + +public interface Staged { + KList getStages(); + + void registerStage(EngineStage stage); + + default void dump() + { + getStages().forEach(EngineStage::close); + getStages().clear(); + } +} diff --git a/src/main/java/com/volmit/iris/engine/mode/ModeEnclosure.java b/src/main/java/com/volmit/iris/engine/mode/ModeEnclosure.java new file mode 100644 index 000000000..24def0438 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/mode/ModeEnclosure.java @@ -0,0 +1,39 @@ +/* + * 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.mode; + +import com.volmit.iris.engine.actuator.IrisBiomeActuator; +import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.EngineMode; +import com.volmit.iris.engine.framework.IrisEngineMode; + +public class ModeEnclosure extends IrisEngineMode implements EngineMode { + public ModeEnclosure(Engine engine) + { + super(engine); + var terrain = new IrisTerrainNormalActuator(getEngine()); + var biome = new IrisBiomeActuator(getEngine()); + + registerStage(burst( + (x, z, k, p, m) -> terrain.actuate(x, z, k, m), + (x, z, k, p, m) -> biome.actuate(x, z, p, m) + )); + } +} diff --git a/src/main/java/com/volmit/iris/engine/mode/ModeIslands.java b/src/main/java/com/volmit/iris/engine/mode/ModeIslands.java new file mode 100644 index 000000000..5dd557b52 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/mode/ModeIslands.java @@ -0,0 +1,39 @@ +/* + * 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.mode; + +import com.volmit.iris.engine.actuator.IrisBiomeActuator; +import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.EngineMode; +import com.volmit.iris.engine.framework.IrisEngineMode; + +public class ModeIslands extends IrisEngineMode implements EngineMode { + public ModeIslands(Engine engine) + { + super(engine); + var terrain = new IrisTerrainNormalActuator(getEngine()); + var biome = new IrisBiomeActuator(getEngine()); + + registerStage(burst( + (x, z, k, p, m) -> terrain.actuate(x, z, k, m), + (x, z, k, p, m) -> biome.actuate(x, z, p, m) + )); + } +} diff --git a/src/main/java/com/volmit/iris/engine/mode/ModeOverworld.java b/src/main/java/com/volmit/iris/engine/mode/ModeOverworld.java new file mode 100644 index 000000000..e7c5ba046 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/mode/ModeOverworld.java @@ -0,0 +1,59 @@ +/* + * 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.mode; + +import com.volmit.iris.engine.actuator.IrisBiomeActuator; +import com.volmit.iris.engine.actuator.IrisDecorantActuator; +import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.EngineMode; +import com.volmit.iris.engine.framework.IrisEngineMode; +import com.volmit.iris.engine.modifier.IrisCarveModifier; +import com.volmit.iris.engine.modifier.IrisDepositModifier; +import com.volmit.iris.engine.modifier.IrisPerfectionModifier; +import com.volmit.iris.engine.modifier.IrisPostModifier; +import org.bukkit.block.data.BlockData; + +public class ModeOverworld extends IrisEngineMode implements EngineMode { + public ModeOverworld(Engine engine) + { + super(engine); + var terrain = new IrisTerrainNormalActuator(getEngine()); + var biome = new IrisBiomeActuator(getEngine()); + var decorant = new IrisDecorantActuator(getEngine()); + var cave = new IrisCarveModifier(getEngine()); + var post = new IrisPostModifier(getEngine()); + var deposit = new IrisDepositModifier(getEngine()); + var perfection = new IrisPerfectionModifier(getEngine()); + + registerStage(burst( + (x, z, k, p, m) -> generateMatter(x >> 4, z >> 4, m), + (x, z, k, p, m) -> terrain.actuate(x, z, k, m), + (x, z, k, p, m) -> biome.actuate(x, z, p, m) + )); + registerStage((x, z, k, p, m) -> cave.modify(x >> 4, z >> 4, k, m)); + registerStage(burst( + (x, z, k, p, m) -> decorant.actuate(x, z, k, m), + (x, z, k, p, m) -> post.modify(x, z, k, m), + (x, z, k, p, m) -> deposit.modify(x, z, k, m), + (x, z, K, p, m) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m) + )); + registerStage((x, z, k, p, m) -> perfection.modify(x, z, k, m)); + } +} diff --git a/src/main/java/com/volmit/iris/engine/mode/ModeSuperFlat.java b/src/main/java/com/volmit/iris/engine/mode/ModeSuperFlat.java new file mode 100644 index 000000000..89e3b4d64 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/mode/ModeSuperFlat.java @@ -0,0 +1,39 @@ +/* + * 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.mode; + +import com.volmit.iris.engine.actuator.IrisBiomeActuator; +import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.EngineMode; +import com.volmit.iris.engine.framework.IrisEngineMode; + +public class ModeSuperFlat extends IrisEngineMode implements EngineMode { + public ModeSuperFlat(Engine engine) + { + super(engine); + var terrain = new IrisTerrainNormalActuator(getEngine()); + var biome = new IrisBiomeActuator(getEngine()); + + registerStage(burst( + (x, z, k, p, m) -> terrain.actuate(x, z, k, m), + (x, z, k, p, m) -> biome.actuate(x, z, p, m) + )); + } +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisDimension.java b/src/main/java/com/volmit/iris/engine/object/IrisDimension.java index a92911455..5b303fb17 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisDimension.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisDimension.java @@ -171,6 +171,9 @@ public class IrisDimension extends IrisRegistrant { @MaxNumber(360) @Desc("You can rotate the input coordinates by an angle. This can make terrain appear more natural (less sharp corners and lines). This literally rotates the entire dimension by an angle. Hint: Try 12 degrees or something not on a 90 or 45 degree angle.") private double dimensionAngleDeg = 0; + @Required + @Desc("Define the mode of this dimension (required!)") + private IrisDimensionMode mode = new IrisDimensionMode(); @MinNumber(0) @MaxNumber(8192) @Desc("Coordinate fracturing applies noise to the input coordinates. This creates the 'iris swirls' and wavy features. The distance pushes these waves further into places they shouldnt be. This is a block value multiplier.") diff --git a/src/main/java/com/volmit/iris/engine/object/IrisDimensionMode.java b/src/main/java/com/volmit/iris/engine/object/IrisDimensionMode.java new file mode 100644 index 000000000..805b0d142 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/IrisDimensionMode.java @@ -0,0 +1,38 @@ +/* + * 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; + +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.Snippet; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +@Snippet("dimension-mode") +@Accessors(chain = true) +@NoArgsConstructor +@AllArgsConstructor +@Desc("Represents a dimensional mode") +@Data +public class IrisDimensionMode { + @Desc("The dimension type") + private IrisDimensionModeType type = IrisDimensionModeType.OVERWORLD; + +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisDimensionModeType.java b/src/main/java/com/volmit/iris/engine/object/IrisDimensionModeType.java new file mode 100644 index 000000000..789ae615a --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/IrisDimensionModeType.java @@ -0,0 +1,56 @@ +/* + * 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; + +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.EngineMode; +import com.volmit.iris.engine.mode.ModeEnclosure; +import com.volmit.iris.engine.mode.ModeIslands; +import com.volmit.iris.engine.mode.ModeOverworld; +import com.volmit.iris.engine.mode.ModeSuperFlat; +import com.volmit.iris.engine.object.annotations.Desc; + +import java.util.function.Function; + +@Desc("The type of dimension this is") +public enum IrisDimensionModeType { + @Desc("Typical dimensions. Has a fluid height, and all features of a biome based world") + OVERWORLD(ModeOverworld::new), + + @Desc("Ultra fast, but very limited in features. Only supports terrain & biomes. No decorations, mobs, objects, or anything of the sort!") + SUPERFLAT(ModeSuperFlat::new), + + @Desc("Like the nether, a ceiling & floor carved out") + ENCLOSURE(ModeEnclosure::new), + + @Desc("Floating islands of terrain") + ISLANDS(ModeIslands::new), + ; + private final Function factory; + + IrisDimensionModeType(Function factory) + { + this.factory = factory; + } + + public EngineMode create(Engine e) + { + return factory.apply(e); + } +}