mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Replace world modes with one generation path through the module pipelines
EngineGeneration replaces the engine mode: it generates the mantle around a chunk, then runs the pack's chunk graph, Iris's built-in stages included, and keeps the per-runtime state built-in stages need. IrisChunk carries the biome hunk and multicore flag, IrisMantleChunk gives built-in mantle stages Iris's mantle writer, and the module mantle component now runs as the first pass, where carving ran. Built-in modules are loaded with Iris's pack object model as host types.
This commit is contained in:
1 parent
fb348d26c8
commit
0f63a3c59a
34 files changed
+546
-569
No files matched your search
@@ -19,17 +19,18 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Iris's own view of the chunk whose module stages are running: the engine, Iris's block hunk and the
|
||||
* chunk's sampled context. Iris's built-in chunk stages read them through {@link #current()}, bound on the
|
||||
* generating thread while the chunk graph runs, and work on Iris's block states directly; pack modules
|
||||
* cannot see this class.
|
||||
* Iris's own view of the chunk whose module stages are running: the engine, Iris's block and biome hunks and
|
||||
* the chunk's sampled context. Iris's built-in chunk stages read them through {@link #current()}, bound on the
|
||||
* generating thread while the chunk graph runs, and work on Iris's types directly; pack modules cannot see
|
||||
* this class.
|
||||
*/
|
||||
public final class IrisChunk {
|
||||
private static final ScopedValue<IrisChunk> CURRENT = ScopedValue.newInstance();
|
||||
@@ -38,13 +39,18 @@ public final class IrisChunk {
|
||||
private final int originX;
|
||||
private final int originZ;
|
||||
private final Hunk<PlatformBlockState> blocks;
|
||||
private final Hunk<PlatformBiome> biomes;
|
||||
private final boolean multicore;
|
||||
private final ChunkContext context;
|
||||
|
||||
IrisChunk(Engine engine, int originX, int originZ, Hunk<PlatformBlockState> blocks, ChunkContext context) {
|
||||
IrisChunk(Engine engine, int originX, int originZ, Hunk<PlatformBlockState> blocks, Hunk<PlatformBiome> biomes,
|
||||
boolean multicore, ChunkContext context) {
|
||||
this.engine = engine;
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.blocks = blocks;
|
||||
this.biomes = biomes;
|
||||
this.multicore = multicore;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@@ -79,8 +85,28 @@ public final class IrisChunk {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** The chunk's biomes, indexed like {@link #blocks()}. */
|
||||
public Hunk<PlatformBiome> biomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
/** Whether stages may spread their work over threads. */
|
||||
public boolean multicore() {
|
||||
return multicore;
|
||||
}
|
||||
|
||||
/** What the engine sampled for this chunk, such as its biomes and heights. */
|
||||
public ChunkContext context() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/** The {@code type} state of this engine runtime, such as an actuator; see {@link art.arcane.iris.engine.framework.EngineGeneration#state}. */
|
||||
public <T> T state(Class<T> type, Function<Engine, T> create) {
|
||||
return engine.getGeneration().state(type, create);
|
||||
}
|
||||
|
||||
/** Whether stages backed by the mantle skip this chunk, as maintenance regeneration on Folia requires. */
|
||||
public boolean bypassesMantleStages() {
|
||||
return engine.getGeneration().bypassesMantleStages();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Iris's own view of the chunk whose mantle stages are running: the engine, the mantle writer prepared around
|
||||
* the chunk and the generating chunk's sampled context. Iris's built-in mantle stages read them through
|
||||
* {@link #current()}, bound on the thread running the mantle graph, and write Iris's own mantle data; pack
|
||||
* modules cannot see this class.
|
||||
*/
|
||||
public final class IrisMantleChunk {
|
||||
private static final ScopedValue<IrisMantleChunk> CURRENT = ScopedValue.newInstance();
|
||||
|
||||
private final Engine engine;
|
||||
private final MantleWriter writer;
|
||||
private final int chunkX;
|
||||
private final int chunkZ;
|
||||
private final ChunkContext context;
|
||||
|
||||
IrisMantleChunk(Engine engine, MantleWriter writer, int chunkX, int chunkZ, ChunkContext context) {
|
||||
this.engine = engine;
|
||||
this.writer = writer;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/** The mantle chunk whose stages run on this thread. */
|
||||
public static IrisMantleChunk current() {
|
||||
if (!CURRENT.isBound()) {
|
||||
throw new IllegalStateException("No Iris mantle chunk is generating on this thread");
|
||||
}
|
||||
return CURRENT.get();
|
||||
}
|
||||
|
||||
void runBound(Runnable generation) {
|
||||
ScopedValue.where(CURRENT, this).run(generation);
|
||||
}
|
||||
|
||||
public Engine engine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
/** Iris's mantle around the chunk, as far as the mantle pipeline reaches. */
|
||||
public MantleWriter writer() {
|
||||
return writer;
|
||||
}
|
||||
|
||||
public int chunkX() {
|
||||
return chunkX;
|
||||
}
|
||||
|
||||
public int chunkZ() {
|
||||
return chunkZ;
|
||||
}
|
||||
|
||||
/** What the engine sampled for the chunk whose generation asked for this mantle, not necessarily this chunk. */
|
||||
public ChunkContext context() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/** The {@code type} state of this engine runtime; see {@link art.arcane.iris.engine.framework.EngineGeneration#state}. */
|
||||
public <T> T state(Class<T> type, Function<Engine, T> create) {
|
||||
return engine.getGeneration().state(type, create);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,16 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.actuator.BiomeModule;
|
||||
import art.arcane.iris.engine.actuator.DecorantModule;
|
||||
import art.arcane.iris.engine.actuator.TerrainModule;
|
||||
import art.arcane.iris.engine.modifier.CarveModule;
|
||||
import art.arcane.iris.engine.modifier.CustomModule;
|
||||
import art.arcane.iris.engine.modifier.DepositModule;
|
||||
import art.arcane.iris.engine.modifier.FloatingModule;
|
||||
import art.arcane.iris.engine.modifier.MatterModule;
|
||||
import art.arcane.iris.engine.modifier.PerfectionModule;
|
||||
import art.arcane.iris.engine.modifier.PostModule;
|
||||
import art.arcane.iris.engine.object.placement.PlacementModules;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -50,9 +59,14 @@ public final class IrisModuleHost {
|
||||
return Holder.HOST;
|
||||
}
|
||||
|
||||
/** The modules every pack loads before its own: Iris's built-in features. */
|
||||
/** The modules every pack loads before its own: Iris's built-in features, placement and the chunk generation every world runs. */
|
||||
public static List<IrisModule> builtInModules() {
|
||||
return Stream.concat(PlacementModules.all().stream(), Stream.of(new PerfectionModule())).toList();
|
||||
return Stream.concat(PlacementModules.all().stream(), generationModules().stream()).toList();
|
||||
}
|
||||
|
||||
private static List<IrisModule> generationModules() {
|
||||
return List.of(new BiomeModule(), new TerrainModule(), new CarveModule(), new PostModule(), new FloatingModule(),
|
||||
new DepositModule(), new MatterModule(), new DecorantModule(), new PerfectionModule(), new CustomModule());
|
||||
}
|
||||
|
||||
/** Whether {@code type} is one of Iris's own classes that built-in settings may hold. */
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
@@ -30,7 +31,8 @@ import com.volmit.host.ResolvedGraph;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Runs the pack's resolved chunk graph on a chunk. A stage is active where any column of the chunk has its
|
||||
* Runs the pack's resolved chunk graph on a chunk, Iris's built-in stages included: this is how every chunk
|
||||
* generates. A stage is active where any column of the chunk has its
|
||||
* settings at the dimension, the column's region or its biome (see {@link ChunkModuleSettings}). A failing
|
||||
* stage fails the chunk.
|
||||
* <p>
|
||||
@@ -43,13 +45,14 @@ public final class ModuleChunkGeneration {
|
||||
private ModuleChunkGeneration() {
|
||||
}
|
||||
|
||||
/** {@code x} and {@code z} are the chunk's first block, as engine stages receive them. */
|
||||
public static void generate(Engine engine, int x, int z, Hunk<PlatformBlockState> blocks, ChunkContext context) {
|
||||
generate(engine.getData().getModules().pack(), engine, x, z, blocks, context, B::getState);
|
||||
/** {@code x} and {@code z} are the chunk's first block. */
|
||||
public static void generate(Engine engine, int x, int z, Hunk<PlatformBlockState> blocks, Hunk<PlatformBiome> biomes,
|
||||
boolean multicore, ChunkContext context) {
|
||||
generate(engine.getData().getModules().pack(), engine, x, z, blocks, biomes, multicore, context, B::getState);
|
||||
}
|
||||
|
||||
static void generate(LoadedPack pack, Engine engine, int x, int z, Hunk<PlatformBlockState> blocks, ChunkContext context,
|
||||
Function<String, PlatformBlockState> platformStates) {
|
||||
static void generate(LoadedPack pack, Engine engine, int x, int z, Hunk<PlatformBlockState> blocks, Hunk<PlatformBiome> biomes,
|
||||
boolean multicore, ChunkContext context, Function<String, PlatformBlockState> platformStates) {
|
||||
ResolvedGraph chunk = pack.chunk();
|
||||
if (chunk.stages().isEmpty()) {
|
||||
return;
|
||||
@@ -60,7 +63,7 @@ public final class ModuleChunkGeneration {
|
||||
try (PinnedMantleChunk mantle = new PinnedMantleChunk(engine, chunkX, chunkZ)) {
|
||||
IrisGenerationContext inputs = new IrisGenerationContext(engine, x, z, new BlockStateHunk(blocks, platformStates), mantle,
|
||||
pack.catalog().mantle());
|
||||
new IrisChunk(engine, x, z, blocks, context).runBound(() -> new ChunkRunner(chunk).generate(inputs, seed));
|
||||
new IrisChunk(engine, x, z, blocks, biomes, multicore, context).runBound(() -> new ChunkRunner(chunk).generate(inputs, seed));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,15 +29,16 @@ import com.volmit.host.MantleRunner;
|
||||
import com.volmit.host.ResolvedGraph;
|
||||
|
||||
/**
|
||||
* Runs the pack's mantle pipeline as one of Iris's mantle components: once for every chunk the mantle prepares
|
||||
* around a generating chunk, as far as the pipeline's declared reach. It is the last pass, so its stages see what
|
||||
* Iris's own components wrote, and it is disabled while the pack has no mantle stages.
|
||||
* Runs the pack's mantle pipeline, Iris's built-in mantle stages included, as one of Iris's mantle components:
|
||||
* once for every chunk the mantle prepares around a generating chunk, as far as the pipeline's declared reach.
|
||||
* It is the first pass, where carving has always run, so Iris's object, floating object and structure passes
|
||||
* see the caves and whatever else mantle stages wrote. It is disabled while the pack has no mantle stages.
|
||||
*/
|
||||
public final class ModuleMantleComponent extends IrisMantleComponent {
|
||||
/** Marks a mantle chunk whose module stages have run. */
|
||||
public static final MantleFlag FLAG = MantleFlag.of(MantleFlag.MIN_ORDINAL);
|
||||
/** After every Iris component, whatever priority they use. */
|
||||
private static final int PRIORITY = Integer.MAX_VALUE;
|
||||
/** The first pass: the carving stage it runs had priority 0 as a component of its own. */
|
||||
private static final int PRIORITY = 0;
|
||||
|
||||
/** Whether the pack has mantle stages; asked on every chunk, so kept until the next hotload. */
|
||||
private volatile Boolean hasStages;
|
||||
@@ -65,7 +66,8 @@ public final class ModuleMantleComponent extends IrisMantleComponent {
|
||||
@Override
|
||||
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
|
||||
Engine engine = getEngineMantle().getEngine();
|
||||
generate(engine.getData().getModules().pack(), engine, x, z, getRadius(), writer::acquireChunk);
|
||||
IrisMantleChunk chunk = new IrisMantleChunk(engine, writer, x, z, context);
|
||||
chunk.runBound(() -> generate(engine.getData().getModules().pack(), engine, x, z, getRadius(), writer::acquireChunk));
|
||||
}
|
||||
|
||||
/** Runs the mantle stages of chunk {@code x}, {@code z}, with the mantle chunks within {@code reachBlocks} of it. */
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.engine;
|
||||
|
||||
import art.arcane.iris.engine.framework.EngineEffects;
|
||||
import art.arcane.iris.engine.framework.EngineMode;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.framework.EngineTarget;
|
||||
import art.arcane.iris.engine.framework.EngineWorldManager;
|
||||
|
||||
@@ -35,7 +35,7 @@ record EngineRuntime(
|
||||
IrisComplex complex,
|
||||
UpperDimensionContext upperContext,
|
||||
EngineEffects effects,
|
||||
EngineMode mode,
|
||||
EngineGeneration generation,
|
||||
EngineWorldManager worldManager,
|
||||
CompletableFuture<Long> hash32,
|
||||
BiomeMaxes biomeMaxes
|
||||
@@ -52,7 +52,7 @@ record EngineRuntime(
|
||||
nextComplex,
|
||||
nextUpperContext,
|
||||
effects,
|
||||
mode,
|
||||
generation,
|
||||
worldManager,
|
||||
hash32,
|
||||
nextBiomeMaxes);
|
||||
|
||||
@@ -25,7 +25,7 @@ import art.arcane.iris.engine.EngineRuntime.BiomeMaxes;
|
||||
import art.arcane.iris.engine.IrisEngine.LifecycleState;
|
||||
import art.arcane.iris.engine.framework.EngineEffects;
|
||||
import art.arcane.iris.engine.framework.EngineEffectsProvider;
|
||||
import art.arcane.iris.engine.framework.EngineMode;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.framework.EngineTarget;
|
||||
import art.arcane.iris.engine.framework.EngineWorldManager;
|
||||
import art.arcane.iris.engine.framework.EngineWorldManagerProvider;
|
||||
@@ -33,8 +33,6 @@ import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.terrain.IrisBiomePaletteLayer;
|
||||
import art.arcane.iris.engine.object.decoration.IrisDecorator;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimensionMode;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimensionModeType;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
@@ -86,8 +84,7 @@ final class EngineRuntimeBuilder {
|
||||
engine.getMantle().hotload();
|
||||
IrisLogging.debug("[IrisEngine timing] mantle.hotload=" + (M.ms() - started) + "ms");
|
||||
started = M.ms();
|
||||
assembly.mode = createMode();
|
||||
IrisLogging.debug("[IrisEngine timing] setupMode=" + (M.ms() - started) + "ms");
|
||||
assembly.generation = new EngineGeneration(engine);
|
||||
started = M.ms();
|
||||
assembly.worldManager = IrisServices.get(EngineWorldManagerProvider.class).create(engine);
|
||||
if (assembly.worldManager == null) {
|
||||
@@ -201,39 +198,6 @@ final class EngineRuntimeBuilder {
|
||||
return null;
|
||||
}
|
||||
|
||||
private EngineMode createMode() {
|
||||
Throwable configuredFailure = null;
|
||||
try {
|
||||
IrisDimensionMode configuredMode = engine.getDimension().getMode();
|
||||
if (configuredMode == null) {
|
||||
configuredMode = new IrisDimensionMode();
|
||||
engine.getDimension().setMode(configuredMode);
|
||||
}
|
||||
EngineMode configured = configuredMode.create(engine);
|
||||
if (configured == null) {
|
||||
throw new IllegalStateException("Dimension mode factory returned null");
|
||||
}
|
||||
return configured;
|
||||
} catch (Throwable e) {
|
||||
configuredFailure = e;
|
||||
IrisLogging.reportError(e);
|
||||
if (engine.getModeFallbackLogged().compareAndSet(false, true)) {
|
||||
IrisLogging.warn("Failed to initialize configured dimension mode for " + engine.getDimension().getLoadKey() + ", falling back to OVERWORLD mode.");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
EngineMode fallback = IrisDimensionModeType.OVERWORLD.create(engine);
|
||||
if (fallback == null) {
|
||||
throw new IllegalStateException("OVERWORLD mode factory returned null");
|
||||
}
|
||||
return fallback;
|
||||
} catch (Throwable fallbackFailure) {
|
||||
fallbackFailure.addSuppressed(configuredFailure);
|
||||
throw new IllegalStateException("Both configured and fallback Iris engine modes failed.", fallbackFailure);
|
||||
}
|
||||
}
|
||||
|
||||
BiomeMaxes computeBiomeMaxes() {
|
||||
double objectDensity = 0D;
|
||||
double layerDensity = 0D;
|
||||
@@ -297,7 +261,7 @@ final class EngineRuntimeBuilder {
|
||||
IrisComplex complex;
|
||||
UpperDimensionContext upperContext;
|
||||
EngineEffects effects;
|
||||
EngineMode mode;
|
||||
EngineGeneration generation;
|
||||
EngineWorldManager worldManager;
|
||||
CompletableFuture<Long> hash32;
|
||||
|
||||
@@ -307,7 +271,7 @@ final class EngineRuntimeBuilder {
|
||||
}
|
||||
|
||||
EngineRuntime freeze(BiomeMaxes biomeMaxes) {
|
||||
if (complex == null || effects == null || mode == null || worldManager == null || hash32 == null) {
|
||||
if (complex == null || effects == null || generation == null || worldManager == null || hash32 == null) {
|
||||
throw new IllegalStateException("Cannot publish an incomplete Iris engine runtime.");
|
||||
}
|
||||
return new EngineRuntime(
|
||||
@@ -316,7 +280,7 @@ final class EngineRuntimeBuilder {
|
||||
complex,
|
||||
upperContext,
|
||||
effects,
|
||||
mode,
|
||||
generation,
|
||||
worldManager,
|
||||
hash32,
|
||||
biomeMaxes);
|
||||
|
||||
@@ -218,8 +218,8 @@ final class EngineShutdownSequence {
|
||||
}
|
||||
});
|
||||
failure = runCleanup(failure, () -> {
|
||||
if (assembly.mode != null) {
|
||||
assembly.mode.close();
|
||||
if (assembly.generation != null) {
|
||||
assembly.generation.close();
|
||||
}
|
||||
});
|
||||
failure = runCleanup(failure, () -> {
|
||||
@@ -241,7 +241,7 @@ final class EngineShutdownSequence {
|
||||
}
|
||||
failure = runCleanup(failure, engineRuntime.worldManager()::close);
|
||||
failure = runCleanup(failure, engineRuntime.effects()::close);
|
||||
failure = runCleanup(failure, engineRuntime.mode()::close);
|
||||
failure = runCleanup(failure, engineRuntime.generation()::close);
|
||||
failure = runCleanup(failure, engineRuntime.complex()::close);
|
||||
failure = runCleanup(failure, () -> engineRuntime.hash32().cancel(true));
|
||||
return failure;
|
||||
|
||||
@@ -23,7 +23,7 @@ import art.arcane.iris.engine.EngineRuntimeBuilder.RuntimeAssembly;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineEffects;
|
||||
import art.arcane.iris.engine.framework.EngineMetrics;
|
||||
import art.arcane.iris.engine.framework.EngineMode;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.framework.EnginePlatformHooks;
|
||||
import art.arcane.iris.engine.framework.NativeStructureVolume;
|
||||
import art.arcane.iris.engine.framework.NativeStructureVolumeMemo;
|
||||
@@ -148,7 +148,6 @@ public class IrisEngine implements Engine {
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
volatile LifecycleState lifecycleState;
|
||||
private final AtomicBoolean modeFallbackLogged;
|
||||
private final AtomicBoolean prefetchSaveStarted;
|
||||
|
||||
/**
|
||||
@@ -201,7 +200,6 @@ public class IrisEngine implements Engine {
|
||||
mantle = new IrisEngineMantle(this);
|
||||
IrisLogging.debug("[IrisEngine timing] new IrisEngineMantle=" + (M.ms() - _t0) + "ms");
|
||||
cleaning = new AtomicBoolean(false);
|
||||
modeFallbackLogged = new AtomicBoolean(false);
|
||||
prefetchSaveStarted = new AtomicBoolean(false);
|
||||
sealInitialGenerationSession();
|
||||
|
||||
@@ -511,13 +509,13 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EngineMode getMode() {
|
||||
public EngineGeneration getGeneration() {
|
||||
RuntimeAssembly assembly = runtimeAssembly.get();
|
||||
if (assembly != null && assembly.mode != null) {
|
||||
return assembly.mode;
|
||||
if (assembly != null && assembly.generation != null) {
|
||||
return assembly.generation;
|
||||
}
|
||||
EngineRuntime current = runtimeBuilder.requireRuntime("access the engine mode");
|
||||
return current.mode();
|
||||
EngineRuntime current = runtimeBuilder.requireRuntime("access the engine generation");
|
||||
return current.generation();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -635,8 +633,7 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EngineMode activeMode = getMode();
|
||||
activeMode.generate(x, z, blocks, vbiomes, multicore, lease.sessionId());
|
||||
getGeneration().generate(x, z, blocks, vbiomes, multicore, lease.sessionId());
|
||||
}
|
||||
|
||||
boolean skipRealFlag = platformHooks.shouldBypassMantleStages(this);
|
||||
|
||||
@@ -27,7 +27,6 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||
import art.arcane.iris.engine.mantle.MantleComponent;
|
||||
import art.arcane.iris.engine.mantle.MantlePass;
|
||||
import art.arcane.iris.engine.mantle.components.MantleCarvingComponent;
|
||||
import art.arcane.iris.engine.mantle.components.MantleFloatingObjectComponent;
|
||||
import art.arcane.iris.engine.mantle.components.MantleObjectComponent;
|
||||
import art.arcane.iris.engine.mantle.components.IrisStructureComponent;
|
||||
@@ -46,7 +45,6 @@ import art.arcane.volmlib.util.mantle.runtime.MantleDataAdapter;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleHooks;
|
||||
import art.arcane.volmlib.util.mantle.runtime.TectonicPlate;
|
||||
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
|
||||
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import art.arcane.iris.util.common.format.C;
|
||||
import art.arcane.volmlib.util.matter.IrisMatter;
|
||||
@@ -86,7 +84,6 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
this.engine = engine;
|
||||
this.mantle = createMantle(engine);
|
||||
components = new KMap<>();
|
||||
registerComponent(new MantleCarvingComponent(this));
|
||||
object = new MantleObjectComponent(this);
|
||||
registerComponent(object);
|
||||
registerComponent(new MantleFloatingObjectComponent(this));
|
||||
@@ -173,9 +170,6 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
return disabledFlags.aquire(() -> {
|
||||
KList<MantleFlag> disabled = new KList<>();
|
||||
disabled.addAll(getDimension().getDisabledComponents());
|
||||
if (!getDimension().isCarvingEnabled()) {
|
||||
disabled.addIfMissing(ReservedFlag.CARVED);
|
||||
}
|
||||
return Set.copyOf(disabled);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
return null;
|
||||
}
|
||||
|
||||
EngineMode getMode();
|
||||
EngineGeneration getGeneration();
|
||||
|
||||
EnginePlatformHooks getPlatformHooks();
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.modules.ModuleChunkGeneration;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.documentation.BlockCoordinates;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* How every Iris world generates a chunk: the mantle around it first, then the pack's chunk pipeline, Iris's
|
||||
* built-in stages included. It also keeps the state built-in stages hold per engine runtime, such as an
|
||||
* actuator's caches, so a hotload, which builds a new runtime, starts them fresh.
|
||||
*/
|
||||
public final class EngineGeneration {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final long MAINTENANCE_LOG_INTERVAL_MILLIS = 5000L;
|
||||
private static final AtomicLong lastMaintenanceBypassLog = new AtomicLong(0L);
|
||||
|
||||
private final Engine engine;
|
||||
private final Map<Class<?>, Object> states = new ConcurrentHashMap<>();
|
||||
|
||||
public EngineGeneration(Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* The one {@code type} instance of this runtime, created by {@code create} the first time a stage asks.
|
||||
* {@code create} must not ask for other state.
|
||||
*/
|
||||
public <T> T state(Class<T> type, Function<Engine, T> create) {
|
||||
return type.cast(states.computeIfAbsent(type, ignored -> create.apply(engine)));
|
||||
}
|
||||
|
||||
@BlockCoordinates
|
||||
public void generate(int x, int z, Hunk<PlatformBlockState> blocks, Hunk<PlatformBiome> biomes, boolean multicore, long generationSessionId) {
|
||||
boolean cacheContext = !engine.getPlatformHooks().shouldDisableChunkContextCache(engine);
|
||||
ChunkContext.PrefillPlan prefillPlan = cacheContext ? ChunkContext.PrefillPlan.NO_CAVE : ChunkContext.PrefillPlan.NONE;
|
||||
ChunkContext context = new ChunkContext(x, z, engine.getComplex(), generationSessionId, cacheContext, prefillPlan, engine.getMetrics());
|
||||
try (IrisContext.Scope chunkScope = IrisContext.open(engine, generationSessionId, context)) {
|
||||
generateMantle(x, z, multicore, context);
|
||||
ModuleChunkGeneration.generate(engine, x, z, blocks, biomes, multicore, context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether stages backed by the mantle skip this chunk: on Folia, maintenance regeneration runs without the
|
||||
* mantle to stay region-safe.
|
||||
*/
|
||||
public boolean bypassesMantleStages() {
|
||||
boolean bypass = engine.getPlatformHooks().shouldBypassMantleStages(engine);
|
||||
if (bypass) {
|
||||
logMaintenanceBypass();
|
||||
}
|
||||
return bypass;
|
||||
}
|
||||
|
||||
/** Closes the state stages kept, such as actuators that hold engine resources. */
|
||||
public void close() {
|
||||
states.values().forEach(state -> {
|
||||
if (state instanceof EngineComponent component) {
|
||||
component.close();
|
||||
}
|
||||
});
|
||||
states.clear();
|
||||
}
|
||||
|
||||
public static boolean shouldDisableContextCacheForMaintenance(boolean maintenanceActive, boolean pregeneratorTargetsWorld) {
|
||||
return maintenanceActive && !pregeneratorTargetsWorld;
|
||||
}
|
||||
|
||||
private void generateMantle(int x, int z, boolean multicore, ChunkContext context) {
|
||||
if (bypassesMantleStages()) {
|
||||
return;
|
||||
}
|
||||
engine.getMantle().generateMatter(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT, multicore || engine.isStudio(), context);
|
||||
}
|
||||
|
||||
private static void logMaintenanceBypass() {
|
||||
long now = System.currentTimeMillis();
|
||||
long last = lastMaintenanceBypassLog.get();
|
||||
if (now - last >= MAINTENANCE_LOG_INTERVAL_MILLIS && lastMaintenanceBypassLog.compareAndSet(last, now)) {
|
||||
IrisLogging.info("Maintenance regen bypass: skipping mantle-backed stages for Folia safety.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||
import art.arcane.iris.core.modules.ModuleChunkGeneration;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
import art.arcane.volmlib.util.documentation.BlockCoordinates;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.iris.util.common.parallel.BurstExecutor;
|
||||
import art.arcane.iris.util.common.parallel.MultiBurst;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
|
||||
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, ctx) -> {
|
||||
BurstExecutor e = burst().burst(stages.length);
|
||||
e.setMulticore(multicore);
|
||||
// BurstExecutor.complete() logs-and-swallows stage failures; without re-propagation
|
||||
// a multicore run would commit a half-written chunk that the inline (production)
|
||||
// path correctly aborts.
|
||||
java.util.concurrent.atomic.AtomicReference<Throwable> failure = new java.util.concurrent.atomic.AtomicReference<>();
|
||||
|
||||
for (EngineStage i : stages) {
|
||||
e.queue(() -> {
|
||||
if (failure.get() != null) {
|
||||
return;
|
||||
}
|
||||
try (IrisContext.Scope stageScope = IrisContext.open(getEngine(), ctx.getGenerationSessionId(), ctx)) {
|
||||
i.generate(x, z, blocks, biomes, multicore, ctx);
|
||||
} catch (Throwable t) {
|
||||
failure.compareAndSet(null, t);
|
||||
// Rethrow so the inline (multicore=false) path still aborts out of
|
||||
// queue() on the first failure, exactly as before.
|
||||
if (t instanceof Error error) {
|
||||
throw error;
|
||||
}
|
||||
if (t instanceof RuntimeException runtimeException) {
|
||||
throw runtimeException;
|
||||
}
|
||||
throw new IllegalStateException(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
e.complete();
|
||||
|
||||
Throwable t = failure.get();
|
||||
if (t != null) {
|
||||
if (t instanceof Error error) {
|
||||
throw error;
|
||||
}
|
||||
if (t instanceof RuntimeException runtimeException) {
|
||||
throw runtimeException;
|
||||
}
|
||||
throw new IllegalStateException("Burst stage failure during chunk generation", t);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
default IrisComplex getComplex() {
|
||||
return getEngine().getComplex();
|
||||
}
|
||||
|
||||
default EngineMantle getMantle() {
|
||||
return getEngine().getMantle();
|
||||
}
|
||||
|
||||
default void generateMatter(int x, int z, boolean multicore, ChunkContext context) {
|
||||
getMantle().generateMatter(x, z, multicore, context);
|
||||
}
|
||||
|
||||
@BlockCoordinates
|
||||
default void generate(int x, int z, Hunk<PlatformBlockState> blocks, Hunk<PlatformBiome> biomes, boolean multicore, long generationSessionId) {
|
||||
boolean cacheContext = !getEngine().getPlatformHooks().shouldDisableChunkContextCache(getEngine());
|
||||
ChunkContext.PrefillPlan prefillPlan = cacheContext ? ChunkContext.PrefillPlan.NO_CAVE : ChunkContext.PrefillPlan.NONE;
|
||||
ChunkContext ctx = new ChunkContext(x, z, getComplex(), generationSessionId, cacheContext, prefillPlan, getEngine().getMetrics());
|
||||
|
||||
EngineStage[] stages = getStages().toArray(new EngineStage[0]);
|
||||
try (IrisContext.Scope chunkScope = IrisContext.open(getEngine(), generationSessionId, ctx)) {
|
||||
for (EngineStage i : stages) {
|
||||
i.generate(x, z, blocks, biomes, multicore, ctx);
|
||||
}
|
||||
ModuleChunkGeneration.generate(getEngine(), x, z, blocks, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean shouldDisableContextCacheForMaintenance(boolean maintenanceActive, boolean pregeneratorTargetsWorld) {
|
||||
return maintenanceActive && !pregeneratorTargetsWorld;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.volmlib.util.documentation.BlockCoordinates;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
|
||||
public interface EngineStage {
|
||||
@BlockCoordinates
|
||||
void generate(int x, int z, Hunk<PlatformBlockState> blocks, Hunk<PlatformBiome> biomes, boolean multicore, ChunkContext context);
|
||||
|
||||
default void close() {
|
||||
if (this instanceof EngineComponent c) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
|
||||
public abstract class IrisEngineMode implements EngineMode {
|
||||
private final Engine engine;
|
||||
private final KList<EngineStage> 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<EngineStage> getStages() {
|
||||
return stages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStage(EngineStage stage) {
|
||||
stages.add(stage);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
|
||||
public interface Staged {
|
||||
KList<EngineStage> getStages();
|
||||
|
||||
void registerStage(EngineStage stage);
|
||||
|
||||
default void dump() {
|
||||
getStages().forEach(EngineStage::close);
|
||||
getStages().clear();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user