From 4b8cfd9fddab61839275d25023c199ffb114f88f Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 2 Aug 2021 17:04:47 -0400 Subject: [PATCH] Aquire engine data in expressions --- .../iris/core/project/loader/IrisData.java | 3 + .../com/volmit/iris/engine/IrisEngine.java | 1 + .../engine/object/IrisEngineStreamType.java | 71 +++++++++++++++++++ .../engine/object/IrisEngineValueType.java | 56 +++++++++++++++ .../engine/object/IrisExpressionLoad.java | 33 ++++++++- 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/volmit/iris/engine/object/IrisEngineStreamType.java create mode 100644 src/main/java/com/volmit/iris/engine/object/IrisEngineValueType.java diff --git a/src/main/java/com/volmit/iris/core/project/loader/IrisData.java b/src/main/java/com/volmit/iris/core/project/loader/IrisData.java index 2fa51d76e..898cf76db 100644 --- a/src/main/java/com/volmit/iris/core/project/loader/IrisData.java +++ b/src/main/java/com/volmit/iris/core/project/loader/IrisData.java @@ -19,6 +19,7 @@ package com.volmit.iris.core.project.loader; import com.volmit.iris.Iris; +import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.*; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.math.RNG; @@ -47,6 +48,7 @@ public class IrisData { private KMap, ResourceLoader> loaders = new KMap<>(); private boolean closed; private final File dataFolder; + private Engine engine; private final int id; public IrisData(File dataFolder) { @@ -54,6 +56,7 @@ public class IrisData { } public IrisData(File dataFolder, boolean oneshot) { + this.engine = null; this.dataFolder = dataFolder; this.id = RNG.r.imax(); closed = false; diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 382ec57fc..115559635 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -101,6 +101,7 @@ public class IrisEngine extends BlockPopulator implements Engine { Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + target.getHeight() + " height)"); metrics = new EngineMetrics(32); this.target = target; + getData().setEngine(this); getEngineData(); this.framework = new IrisEngineFramework(this); worldManager = new IrisWorldManager(this); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEngineStreamType.java b/src/main/java/com/volmit/iris/engine/object/IrisEngineStreamType.java new file mode 100644 index 000000000..51d65191a --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/IrisEngineStreamType.java @@ -0,0 +1,71 @@ +/* + * 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.EngineFramework; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.stream.ProceduralStream; + +import java.util.function.Function; + +@Desc("Represents a stream from the engine") +public enum IrisEngineStreamType +{ + @Desc("Represents the given slope at the x, z coordinates") + SLOPE((f) -> f.getComplex().getSlopeStream()), + + @Desc("Represents the real terrain height ignoring fluid, this includes carving, caves & noise features into this stream.") + TRUE_HEIGHT((f) -> f.getComplex().getTrueHeightStream().forceDouble()), + + @Desc("Represents the real terrain height including fluid, this includes carving, caves & noise features into this stream.") + TRUE_HEIGHT_OR_FLUID((f) -> f.getComplex().getTrueHeightStream().forceDouble().max(f.getComplex().getFluidHeight())), + + @Desc("Represents the base generator height at the given position. This includes only the biome generators / interpolation and noise features but does not include carving, caves.") + HEIGHT((f) -> f.getComplex().getHeightStream()), + + @Desc("Represents the base generator height at the given position. This includes only the biome generators / interpolation and noise features but does not include carving, caves. with Max(height, fluidHeight).") + HEIGHT_OR_FLUID((f) -> f.getComplex().getHeightFluidStream()), + + @Desc("Represents the overlay noise generators summed (dimension setting)") + OVERLAY_NOISE((f) -> f.getComplex().getOverlayStream()), + + @Desc("Represents the overlay noise generators summed (dimension setting)") + HEIGHT_NO_FEATURES((f) -> f.getComplex().getHeightStreamNoFeatures()), + + @Desc("Represents the object chance clip. If a noise feature alters the object chance in this area this number will drop below 1. (100%)") + OBJECT_CHANCE_CLIP((f) -> f.getComplex().getObjectChanceStream()), + + @Desc("Represents the noise style of regions") + REGION_STYLE((f) -> f.getComplex().getRegionStyleStream()), + + @Desc("Represents the identity of regions. Each region has a unique number (very large numbers)") + REGION_IDENTITY((f) -> f.getComplex().getRegionIdentityStream()); + + private Function> getter; + + private IrisEngineStreamType(Function> getter) + { + this.getter = getter; + } + + public ProceduralStream get(EngineFramework engine) + { + return getter.apply(engine); + } +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEngineValueType.java b/src/main/java/com/volmit/iris/engine/object/IrisEngineValueType.java new file mode 100644 index 000000000..17f5f97ce --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/IrisEngineValueType.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.EngineFramework; +import com.volmit.iris.engine.object.annotations.Desc; + +import java.util.function.Function; + +@Desc("Represents a value from the engine") +public enum IrisEngineValueType +{ + @Desc("Represents actual height of the engine") + ENGINE_HEIGHT((f) -> Double.valueOf(f.getEngine().getHeight())), + + @Desc("Represents virtual bottom of the engine in the compound. If this engine is on top of another engine, it's min height would be at the maxHeight of the previous engine + 1") + ENGINE_MIN_HEIGHT((f) -> Double.valueOf(f.getEngine().getMinHeight())), + + @Desc("Represents virtual top of the engine in the compound. If this engine is below another engine, it's max height would be at the minHeight of the next engine - 1") + ENGINE_MAX_HEIGHT((f) -> Double.valueOf(f.getEngine().getMaxHeight())), + + @Desc("Represents the position of the engine in the dimensional compound. The bottom (first) dimension stasts at 0. Each new dimension added stacks on top with n+1 for the id.") + ENGINE_INDEX((f) -> Double.valueOf(f.getEngine().getIndex())), + + @Desc("The fluid height defined in the dimension file") + FLUID_HEIGHT((f) -> Double.valueOf(f.getComplex().getFluidHeight())), + ; + + private Function getter; + + private IrisEngineValueType(Function getter) + { + this.getter = getter; + } + + public Double get(EngineFramework engine) + { + return getter.apply(engine); + } +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisExpressionLoad.java b/src/main/java/com/volmit/iris/engine/object/IrisExpressionLoad.java index d48d1a780..42d953d6c 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisExpressionLoad.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisExpressionLoad.java @@ -19,8 +19,10 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.engine.cache.AtomicCache; import com.volmit.iris.engine.object.annotations.Desc; import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.stream.ProceduralStream; import com.volmit.iris.util.math.RNG; import lombok.AllArgsConstructor; import lombok.Data; @@ -43,10 +45,29 @@ public class IrisExpressionLoad { @Desc("If the style value is not defined, this value will be used") private double staticValue = -1; - @Desc("If defined, this variable will use a generator style as it's result") + @Desc("If defined, this variable will use a generator style as it's value") private IrisGeneratorStyle styleValue = null; + @Desc("If defined, iris will use an internal stream from the engine as it's value") + private IrisEngineStreamType engineStreamValue = null; + + @Desc("If defined, iris will use an internal value from the engine as it's value") + private IrisEngineValueType engineValue = null; + + private transient AtomicCache> streamCache = new AtomicCache<>(); + private transient AtomicCache valueCache = new AtomicCache<>(); + public double getValue(RNG rng, IrisData data, double x, double z) { + if(engineValue != null) + { + return valueCache.aquire(() -> engineValue.get(data.getEngine().getFramework())); + } + + if(engineStreamValue != null) + { + return streamCache.aquire(() -> engineStreamValue.get(data.getEngine().getFramework())).get(x, z); + } + if (styleValue != null) { return styleValue.create(rng, data).noise(x, z); } @@ -55,6 +76,16 @@ public class IrisExpressionLoad { } public double getValue(RNG rng, IrisData data, double x, double y, double z) { + if(engineValue != null) + { + return valueCache.aquire(() -> engineValue.get(data.getEngine().getFramework())); + } + + if(engineStreamValue != null) + { + return streamCache.aquire(() -> engineStreamValue.get(data.getEngine().getFramework())).get(x, z); + } + if (styleValue != null) { return styleValue.create(rng, data).noise(x, y, z); }