mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Merge wave1/a1
This commit is contained in:
commit
9c69f1ea88
33 files changed
+1101
-80
No files matched your search
@@ -37,7 +37,6 @@ import art.arcane.iris.core.modules.PackModuleSet;
|
||||
import art.arcane.iris.core.pack.PackDirectoryResolver;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.structure.StructureGraphCatalog;
|
||||
import art.arcane.iris.core.structure.authoring.StructureRecoveryResult;
|
||||
import art.arcane.iris.core.structure.authoring.StructureTransactionWriter;
|
||||
@@ -592,17 +591,22 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
StructureGraphCatalog.invalidate(this);
|
||||
invalidateLoader(objectLoader);
|
||||
reloadModuleResources();
|
||||
for (Engine engine : getEngines()) {
|
||||
IrisStructureLocator.invalidate(engine);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new snapshot of the pack's resources, so the files of every module resource kind are listed and read
|
||||
* again, after a tool added, rewrote or deleted some. Iris's own loaders keep their caches.
|
||||
* again, after a tool added, rewrote or deleted some. Iris's own loaders keep their caches. The engines running
|
||||
* with this pack restart their modules' worlds with the new snapshot, so no module keeps state built from the old
|
||||
* files.
|
||||
*/
|
||||
public void reloadModuleResources() {
|
||||
packResources = new IrisPackResources(this);
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
for (Engine engine : getEngines()) {
|
||||
engine.packResourcesReloaded();
|
||||
}
|
||||
}
|
||||
|
||||
/** The folders below the pack root that hold its resources: Iris's loaders' and its modules' resource kinds'. */
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.volmit.host.MantleRegistration;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -47,6 +48,7 @@ final class IrisGenerationContext implements GenerationContext {
|
||||
private final IrisTerrainSampler terrain;
|
||||
private final ChunkModuleSettings settings;
|
||||
private final IrisModuleMantle mantle;
|
||||
private PackWorld world;
|
||||
|
||||
IrisGenerationContext(Engine engine, int originX, int originZ, BlockStateHunk blocks, IrisModuleMantle.Chunks mantleChunks,
|
||||
Collection<MantleRegistration<?>> mantleLayers) {
|
||||
@@ -104,4 +106,13 @@ final class IrisGenerationContext implements GenerationContext {
|
||||
public PackResources resources() {
|
||||
return engine.getData().getPackResources();
|
||||
}
|
||||
|
||||
/** The world this invocation first asked for; it keeps it if the world restarts meanwhile. */
|
||||
@Override
|
||||
public PackWorld world() {
|
||||
if (world == null) {
|
||||
world = engine.getGeneration().world();
|
||||
}
|
||||
return world;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import com.volmit.host.MantleRegistration;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -44,6 +45,7 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
|
||||
private final IrisTerrainSampler terrain;
|
||||
private final ChunkModuleSettings settings;
|
||||
private final IrisModuleMantle mantle;
|
||||
private PackWorld world;
|
||||
|
||||
IrisMantleGenerationContext(Engine engine, int chunkX, int chunkZ, int reachBlocks, IrisModuleMantle.Chunks chunks,
|
||||
Collection<MantleRegistration<?>> layers) {
|
||||
@@ -92,4 +94,13 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
|
||||
public PackResources resources() {
|
||||
return engine.getData().getPackResources();
|
||||
}
|
||||
|
||||
/** The world this invocation first asked for; it keeps it if the world restarts meanwhile. */
|
||||
@Override
|
||||
public PackWorld world() {
|
||||
if (world == null) {
|
||||
world = engine.getGeneration().world();
|
||||
}
|
||||
return world;
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@ public final class IrisPackResources implements PackResources {
|
||||
private final Supplier<List<ResourceKind<?>>> moduleKindList;
|
||||
private volatile Map<Class<?>, Kind<?>> moduleKinds;
|
||||
private volatile List<String> moduleFolders;
|
||||
private boolean announcedToModules;
|
||||
|
||||
public IrisPackResources(IrisData data) {
|
||||
this(data, () -> data.getModules().pack().catalog().resourceKinds().stream()
|
||||
@@ -97,6 +98,18 @@ public final class IrisPackResources implements PackResources {
|
||||
return snapshotId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs {@code announce}, which tells the pack's modules that this snapshot loaded, unless it ran successfully for
|
||||
* this snapshot before: modules hear of each snapshot once, however many worlds start with it.
|
||||
*/
|
||||
synchronized void loadOnce(Runnable announce) {
|
||||
if (announcedToModules) {
|
||||
return;
|
||||
}
|
||||
announce.run();
|
||||
announcedToModules = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRegistry blocks() {
|
||||
return blocks;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 com.volmit.config.PackSettings;
|
||||
import com.volmit.host.WorldStates;
|
||||
import com.volmit.world.PackWorld;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* One Iris world as modules see it: an engine runtime generating with one snapshot of its pack's resources, and the
|
||||
* state modules keep for it. {@link ModuleWorlds} makes one when the runtime is built and a new one whenever the
|
||||
* pack's resources reload under it. Iris's built-in modules reach the engine through {@link #of(PackWorld)}, as built-in
|
||||
* reaches do through {@link IrisPackSettings#of}.
|
||||
*/
|
||||
public final class IrisPackWorld implements PackWorld {
|
||||
private final Engine engine;
|
||||
private final IrisPackResources resources;
|
||||
private final WorldStates states = new WorldStates();
|
||||
|
||||
IrisPackWorld(Engine engine) {
|
||||
this.engine = engine;
|
||||
this.resources = engine.getData().getPackResources();
|
||||
}
|
||||
|
||||
/** Iris's own view of {@code world}, which Iris hands to every stage, service and lifecycle hook. */
|
||||
public static IrisPackWorld of(PackWorld world) {
|
||||
if (!(world instanceof IrisPackWorld irisWorld)) {
|
||||
throw new IllegalArgumentException("Built-in modules work in worlds Iris generates, not " + world);
|
||||
}
|
||||
return irisWorld;
|
||||
}
|
||||
|
||||
/** The engine generating this world. */
|
||||
public Engine engine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed() {
|
||||
return engine.getSeedManager().getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisPackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackSettings settings() {
|
||||
return new IrisPackSettings(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
|
||||
return states.state(type, () -> create.apply(this));
|
||||
}
|
||||
|
||||
/** Whether the pack's resources were reloaded since this world was made, so it generates with an old snapshot. */
|
||||
boolean isStale() {
|
||||
return engine.getData().getPackResources() != resources;
|
||||
}
|
||||
|
||||
/** Closes the state modules kept, such as workers that hold engine resources. */
|
||||
void closeStates() {
|
||||
states.close();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.object.ObjectTransformer;
|
||||
@@ -26,6 +27,7 @@ import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.BlockView;
|
||||
import com.volmit.world.TerrainSample;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
/** The read-only IrisApi inputs of one Iris object placement. */
|
||||
@@ -36,9 +38,14 @@ final class IrisPlacementInputs implements PlacementContext {
|
||||
private final FeatureSettings settings;
|
||||
private final BlockView blocks;
|
||||
private final PackResources resources;
|
||||
private final Engine engine;
|
||||
private PackWorld world;
|
||||
|
||||
IrisPlacementInputs(long worldSeed, TerrainSampler terrain, FeatureSettings settings, BlockView blocks, PackResources resources) {
|
||||
/** @param engine the engine whose world the placement generates in, or null for a placement without one */
|
||||
IrisPlacementInputs(long worldSeed, TerrainSampler terrain, FeatureSettings settings, BlockView blocks, PackResources resources,
|
||||
Engine engine) {
|
||||
this.resources = resources;
|
||||
this.engine = engine;
|
||||
this.worldSeed = worldSeed;
|
||||
this.terrain = terrain;
|
||||
this.settings = settings;
|
||||
@@ -98,4 +105,16 @@ final class IrisPlacementInputs implements PlacementContext {
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
/** The world this placement first asked for; it keeps it if the world restarts meanwhile. */
|
||||
@Override
|
||||
public PackWorld world() {
|
||||
if (engine == null) {
|
||||
throw new IllegalStateException("This placement runs without an Iris engine, so it is not part of a world");
|
||||
}
|
||||
if (world == null) {
|
||||
world = engine.getGeneration().world();
|
||||
}
|
||||
return world;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public final class ModuleObjectPlacement {
|
||||
geometry, new BlockPosition(x, requestedY, z));
|
||||
IrisPlacementInputs inputs = new IrisPlacementInputs(worldSeed, terrain(engine, ids, area),
|
||||
new PlacementModuleSettings(worldSettings(engine, ids), config.getModuleSettings(), source),
|
||||
new PlacerBlockView(placer, area, states), data.getPackResources());
|
||||
new PlacerBlockView(placer, area, states), data.getPackResources(), engine);
|
||||
long seed = ModuleSeeds.placement(worldSeed, objectKey, x, requestedY, z);
|
||||
PlacementOutcome outcome = placement.runBound(() -> new PlacementRunner(graph)
|
||||
.place(request, edit, inputs, seed, config.getModuleSettings().placement(source)));
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.service.LocateResult;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import com.volmit.world.PackWorld;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* What Iris core asks the pack's modules through their services ({@link com.volmit.service.Service}) instead of reading
|
||||
* their features itself. Each method combines the providers the way their service says. Asking a pack whose modules
|
||||
* fail to load throws its {@link PackModulesException}.
|
||||
*/
|
||||
public final class ModuleServices {
|
||||
private ModuleServices() {
|
||||
}
|
||||
|
||||
/** The objects every module would place in the chunk at {@code chunkX}, {@code chunkZ}, guessed without generating it. */
|
||||
public static Set<String> objectsAt(Engine engine, int chunkX, int chunkZ) {
|
||||
PackWorld world = engine.getGeneration().world();
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (ObjectsAt provider : catalog(engine.getData()).services(ObjectsAt.class)) {
|
||||
keys.addAll(provider.objectsAt(world, chunkX, chunkZ));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/** Every structure key the pack's modules know, placed or not. */
|
||||
public static Set<String> structureKeys(IrisData data) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (StructureLocator provider : catalog(data).services(StructureLocator.class)) {
|
||||
keys.addAll(provider.structures(data.getPackResources()));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/** The keys of the structures the world's modules place and can locate. */
|
||||
public static Set<String> locatableStructures(Engine engine) {
|
||||
PackWorld world = engine.getGeneration().world();
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (StructureLocator provider : catalog(engine.getData()).services(StructureLocator.class)) {
|
||||
keys.addAll(provider.locatable(world));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/** Whether a module of the world can locate structure {@code key}, matched without regard to case. */
|
||||
public static boolean canLocateStructure(Engine engine, String key) {
|
||||
return structureLocatorOf(engine, key).isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the start of structure {@code key} nearest to {@code fromX}, {@code fromZ} with the first module that
|
||||
* can locate it, in the world's own coordinates; not found when none can.
|
||||
*/
|
||||
public static StructureSearch locateStructure(Engine engine, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
PackWorld world = engine.getGeneration().world();
|
||||
LocateResult result = structureLocatorOf(engine, key)
|
||||
.map(provider -> provider.locate(world, key, fromX, fromZ, maxRadiusChunks))
|
||||
.orElse(LocateResult.NOT_FOUND);
|
||||
return StructureSearch.of(result, engine);
|
||||
}
|
||||
|
||||
/** How a structure search ended. A found start is at {@code x}, {@code y}, {@code z}: world coordinates, Y the world's own. */
|
||||
public record StructureSearch(Outcome outcome, int x, int y, int z) {
|
||||
public enum Outcome { FOUND, NOT_FOUND, SEARCH_LIMIT_REACHED }
|
||||
|
||||
private static final StructureSearch NOT_FOUND = new StructureSearch(Outcome.NOT_FOUND, 0, 0, 0);
|
||||
private static final StructureSearch SEARCH_LIMIT_REACHED = new StructureSearch(Outcome.SEARCH_LIMIT_REACHED, 0, 0, 0);
|
||||
|
||||
public boolean found() {
|
||||
return outcome == Outcome.FOUND;
|
||||
}
|
||||
|
||||
/** {@code result} with its height above the dimension's bottom turned into the world's Y. */
|
||||
static StructureSearch of(LocateResult result, Engine engine) {
|
||||
return switch (result) {
|
||||
case LocateResult.Found found -> new StructureSearch(Outcome.FOUND, found.position().x(),
|
||||
found.position().y() + engine.getMinHeight(), found.position().z());
|
||||
case LocateResult.NotFound ignored -> NOT_FOUND;
|
||||
case LocateResult.SearchLimitReached ignored -> SEARCH_LIMIT_REACHED;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** The first provider, in the catalog's order, whose locatable structures hold {@code key}. */
|
||||
private static Optional<StructureLocator> structureLocatorOf(Engine engine, String key) {
|
||||
if (key == null || key.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
PackWorld world = engine.getGeneration().world();
|
||||
String wanted = normalized(key);
|
||||
for (StructureLocator provider : catalog(engine.getData()).services(StructureLocator.class)) {
|
||||
if (provider.locatable(world).stream().map(ModuleServices::normalized).anyMatch(wanted::equals)) {
|
||||
return Optional.of(provider);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static String normalized(String key) {
|
||||
return key.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private static FeatureCatalog catalog(IrisData data) {
|
||||
return data.getModules().pack().catalog();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* 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 com.volmit.host.LifecycleRunner;
|
||||
|
||||
/**
|
||||
* The worlds modules see for one engine runtime, and their lifecycle ({@link com.volmit.ModuleLifecycle}). The runtime
|
||||
* starts its world once it is published, and closes it when it retires: on a hotload, which builds a new runtime with a
|
||||
* new world, and when the engine closes. When the pack's resources reload while the runtime runs, such as after a tool
|
||||
* rewrote structure files, the world restarts in place: modules stop the old world, load the new snapshot and start a
|
||||
* new world with empty state.
|
||||
* <p>
|
||||
* An invocation keeps the world it first asked for. Iris does not wait for running invocations on an in-place restart,
|
||||
* so it closes the old world's state only at the next restart or when the runtime closes, and an invocation that began
|
||||
* before the restart can finish with it.
|
||||
* When the pack's modules fail to load, worlds run without hooks: the failure is reported where the modules load, and
|
||||
* generation reports it again.
|
||||
*/
|
||||
public final class ModuleWorlds {
|
||||
private enum Phase { NOT_STARTED, STARTED, CLOSED }
|
||||
|
||||
private final Engine engine;
|
||||
private volatile IrisPackWorld current;
|
||||
private IrisPackWorld retired;
|
||||
private LifecycleRunner startedWith;
|
||||
private Phase phase = Phase.NOT_STARTED;
|
||||
|
||||
public ModuleWorlds(Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/** The world the runtime generates now, made the first time anyone asks. */
|
||||
public IrisPackWorld current() {
|
||||
IrisPackWorld world = current;
|
||||
if (world != null) {
|
||||
return world;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (current == null) {
|
||||
current = new IrisPackWorld(engine);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
/** Starts the world: tells modules about the pack snapshot if no world started with it yet, then starts the world. */
|
||||
public synchronized void start() {
|
||||
if (phase != Phase.NOT_STARTED) {
|
||||
throw new IllegalStateException("The modules of this Iris runtime were started already");
|
||||
}
|
||||
if (current().isStale()) {
|
||||
replaceUnstartedWorld();
|
||||
}
|
||||
startCurrentWorld();
|
||||
phase = Phase.STARTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* The pack's resources were reloaded under the running runtime: stops the world and starts a new one with the new
|
||||
* snapshot. A runtime that has not started yet only swaps its world, which then starts with the new snapshot.
|
||||
*/
|
||||
public synchronized void restart() {
|
||||
switch (phase) {
|
||||
case NOT_STARTED -> replaceUnstartedWorld();
|
||||
case STARTED -> restartStartedWorld();
|
||||
case CLOSED -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Stops the world, if it started, and closes the state of the current and the previously retired world. */
|
||||
public synchronized void close() {
|
||||
if (phase == Phase.CLOSED) {
|
||||
return;
|
||||
}
|
||||
phase = Phase.CLOSED;
|
||||
RuntimeException failure = attempt(this::stopCurrentWorld, null);
|
||||
failure = attempt(this::closeRetiredWorld, failure);
|
||||
failure = attempt(this::closeCurrentWorld, failure);
|
||||
throwIfFailed(failure);
|
||||
}
|
||||
|
||||
/** Stops the world and starts a new one even when stopping fails, so the runtime never keeps generating unstarted. */
|
||||
private void restartStartedWorld() {
|
||||
RuntimeException failure = attempt(this::stopCurrentWorld, null);
|
||||
failure = attempt(this::closeRetiredWorld, failure);
|
||||
retired = current;
|
||||
current = null;
|
||||
failure = attempt(this::startCurrentWorld, failure);
|
||||
throwIfFailed(failure);
|
||||
}
|
||||
|
||||
/** Drops the world nothing started yet, if one was made, so the next one is made with the current snapshot. */
|
||||
private void replaceUnstartedWorld() {
|
||||
IrisPackWorld unstarted = current;
|
||||
current = null;
|
||||
if (unstarted != null) {
|
||||
unstarted.closeStates();
|
||||
}
|
||||
}
|
||||
|
||||
private void closeCurrentWorld() {
|
||||
if (current != null) {
|
||||
current.closeStates();
|
||||
}
|
||||
}
|
||||
|
||||
private void startCurrentWorld() {
|
||||
LifecycleRunner lifecycles = lifecyclesOfPack();
|
||||
if (lifecycles == null) {
|
||||
return;
|
||||
}
|
||||
IrisPackWorld world = current();
|
||||
world.resources().loadOnce(() -> lifecycles.packLoaded(world.resources(), new PackDeclaredSettings(engine.getData())));
|
||||
lifecycles.worldStarted(world);
|
||||
startedWith = lifecycles;
|
||||
}
|
||||
|
||||
private void stopCurrentWorld() {
|
||||
LifecycleRunner lifecycles = startedWith;
|
||||
startedWith = null;
|
||||
if (lifecycles != null) {
|
||||
lifecycles.worldStopped(current());
|
||||
}
|
||||
}
|
||||
|
||||
private void closeRetiredWorld() {
|
||||
if (retired == null) {
|
||||
return;
|
||||
}
|
||||
IrisPackWorld closing = retired;
|
||||
retired = null;
|
||||
closing.closeStates();
|
||||
}
|
||||
|
||||
/** Runs {@code step}, adding what it throws to {@code failure}, the first failure of a sequence that must not stop. */
|
||||
private static RuntimeException attempt(Runnable step, RuntimeException failure) {
|
||||
try {
|
||||
step.run();
|
||||
return failure;
|
||||
} catch (RuntimeException stepFailure) {
|
||||
if (failure == null) {
|
||||
return stepFailure;
|
||||
}
|
||||
failure.addSuppressed(stepFailure);
|
||||
return failure;
|
||||
}
|
||||
}
|
||||
|
||||
private static void throwIfFailed(RuntimeException failure) {
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
|
||||
/** The hooks of the modules the engine's pack loads, or null when they fail to load. */
|
||||
private LifecycleRunner lifecyclesOfPack() {
|
||||
try {
|
||||
return new LifecycleRunner(engine.getData().getModules().pack().catalog());
|
||||
} catch (PackModulesException failure) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.structure;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
@@ -89,7 +89,7 @@ public final class StructureIndexService {
|
||||
}
|
||||
}
|
||||
|
||||
List<String> iris = new ArrayList<>(StructureResources.structureKeys(data));
|
||||
List<String> iris = new ArrayList<>(ModuleServices.structureKeys(data));
|
||||
iris.removeIf(LEGACY_INDEX_KEY::equals);
|
||||
|
||||
Collections.sort(vanilla);
|
||||
|
||||
@@ -121,6 +121,7 @@ final class EngineRuntimeBuilder {
|
||||
engine.getClosing().set(false);
|
||||
engine.backgroundTasks.openBackgroundTaskAdmission();
|
||||
try {
|
||||
next.generation().startModules();
|
||||
next.worldManager().start();
|
||||
} catch (Throwable e) {
|
||||
engine.getClosing().set(true);
|
||||
@@ -139,7 +140,7 @@ final class EngineRuntimeBuilder {
|
||||
if (engine.runtime == next) {
|
||||
engine.runtime = null;
|
||||
}
|
||||
throw new IllegalStateException("Failed to start the Iris world manager.", e);
|
||||
throw new IllegalStateException("Failed to start the Iris world's modules or its world manager.", e);
|
||||
}
|
||||
scheduleRuntimeTasks(next);
|
||||
IrisLogging.debug("Engine Setup Complete " + next.cacheId());
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine;
|
||||
|
||||
import art.arcane.iris.engine.EngineBackgroundTasks.BackgroundTaskDrain;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.engine.EngineRuntimeBuilder.RuntimeAssembly;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineEffects;
|
||||
@@ -47,7 +48,6 @@ import art.arcane.iris.core.nms.container.BlockPos;
|
||||
import art.arcane.iris.core.nms.container.Pair;
|
||||
import art.arcane.iris.core.structure.StructureIndexService;
|
||||
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||
import art.arcane.iris.engine.mantle.components.ObjectModule;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.iris.util.common.plugin.VolmitSender;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
@@ -387,7 +387,7 @@ public class IrisEngine implements Engine {
|
||||
|
||||
@Override
|
||||
public Set<String> getObjectsAt(int x, int z) {
|
||||
return ObjectModule.placing(this).guess(x, z);
|
||||
return ModuleServices.objectsAt(this, x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -509,6 +509,15 @@ public class IrisEngine implements Engine {
|
||||
return current == null ? publishedTarget : current.target();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packResourcesReloaded() {
|
||||
EngineRuntime current = runtime;
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
current.generation().restartModules();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EngineGeneration getGeneration() {
|
||||
RuntimeAssembly assembly = runtimeAssembly.get();
|
||||
|
||||
@@ -91,6 +91,13 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
|
||||
EngineGeneration getGeneration();
|
||||
|
||||
/**
|
||||
* The pack's resources were read again while this engine runs, such as after a tool rewrote some of its files:
|
||||
* modules restart their world with the new snapshot (see {@link EngineGeneration#restartModules()}). Does nothing
|
||||
* before the engine has a runtime, which starts with the new snapshot anyway.
|
||||
*/
|
||||
void packResourcesReloaded();
|
||||
|
||||
EnginePlatformHooks getPlatformHooks();
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.volmlib.util.math.RollingSequence;
|
||||
import art.arcane.iris.util.common.parallel.MultiBurst;
|
||||
|
||||
public interface EngineComponent {
|
||||
public interface EngineComponent extends AutoCloseable {
|
||||
Engine getEngine();
|
||||
|
||||
RollingSequence getMetrics();
|
||||
@@ -37,6 +37,7 @@ public interface EngineComponent {
|
||||
return getEngine().burst();
|
||||
}
|
||||
|
||||
@Override
|
||||
default void close() {
|
||||
try {
|
||||
EngineComponentCleanup cleanup = IrisServices.getOrNull(EngineComponentCleanup.class);
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.core.modules.ModuleChunkGeneration;
|
||||
import art.arcane.iris.core.modules.ModuleWorlds;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
@@ -27,15 +29,14 @@ 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.
|
||||
* built-in stages included. It also owns the world modules see for this engine runtime ({@link ModuleWorlds}), whose
|
||||
* state store keeps what stages and services hold per world, 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;
|
||||
@@ -43,18 +44,35 @@ public final class EngineGeneration {
|
||||
private static final AtomicLong lastMaintenanceBypassLog = new AtomicLong(0L);
|
||||
|
||||
private final Engine engine;
|
||||
private final Map<Class<?>, Object> states = new ConcurrentHashMap<>();
|
||||
private final ModuleWorlds modules;
|
||||
|
||||
public EngineGeneration(Engine engine) {
|
||||
this.engine = engine;
|
||||
this.modules = new ModuleWorlds(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.
|
||||
* The one {@code type} instance of the world this runtime generates, created by {@code create} the first time a
|
||||
* stage asks; the same store as {@link IrisPackWorld#state}. See {@link com.volmit.world.PackWorld#state} for
|
||||
* what {@code create} may do.
|
||||
*/
|
||||
public <T> T state(Class<T> type, Function<Engine, T> create) {
|
||||
return type.cast(states.computeIfAbsent(type, ignored -> create.apply(engine)));
|
||||
return modules.current().state(type, ignored -> create.apply(engine));
|
||||
}
|
||||
|
||||
/** The world modules see now: stage contexts, services and lifecycle hooks get it. */
|
||||
public IrisPackWorld world() {
|
||||
return modules.current();
|
||||
}
|
||||
|
||||
/** Starts the modules' world once the runtime is published; a module whose hook fails stops the runtime from starting. */
|
||||
public void startModules() {
|
||||
modules.start();
|
||||
}
|
||||
|
||||
/** Restarts the modules' world with the pack's reloaded resources; see {@link ModuleWorlds#restart()}. */
|
||||
public void restartModules() {
|
||||
modules.restart();
|
||||
}
|
||||
|
||||
@BlockCoordinates
|
||||
@@ -80,14 +98,9 @@ public final class EngineGeneration {
|
||||
return bypass;
|
||||
}
|
||||
|
||||
/** Closes the state stages kept, such as actuators that hold engine resources. */
|
||||
/** Stops the modules' world and 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();
|
||||
modules.close();
|
||||
}
|
||||
|
||||
public static boolean shouldDisableContextCacheForMaintenance(boolean maintenanceActive, boolean pregeneratorTargetsWorld) {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.nms.container.BlockPos;
|
||||
import art.arcane.iris.core.nms.container.Pair;
|
||||
@@ -58,10 +57,6 @@ public interface Locator<T> {
|
||||
return new HintedLocator<>(exact, (engine) -> HintedLocator.biomePlan(engine, loadKey));
|
||||
}
|
||||
|
||||
static Locator<art.arcane.iris.engine.object.structure.IrisStructure> structure(String key) {
|
||||
return (e, c) -> IrisStructureLocator.startsInChunk(e, key, c.getX(), c.getZ());
|
||||
}
|
||||
|
||||
static Locator<BlockPos> poi(String type) {
|
||||
return (e, c) -> {
|
||||
Set<Pair<String, BlockPos>> pos = e.getPOIsAt(c.getX(), c.getZ());
|
||||
|
||||
@@ -563,10 +563,6 @@ public final class EngineBukkitOps {
|
||||
find(engine, Locator.poi(type), p, teleport, "POI " + type);
|
||||
}
|
||||
|
||||
public static void gotoStructure(Engine engine, String key, Player player, boolean teleport) {
|
||||
find(engine, Locator.structure(key), player, teleport, "Structure " + key);
|
||||
}
|
||||
|
||||
private static void find(Engine engine, Locator<?> locator, Player player, boolean teleport, String message) {
|
||||
find(engine, locator, player, 120_000, location -> {
|
||||
if (location == null) {
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.util.common.director.specialhandlers;
|
||||
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
|
||||
@@ -57,7 +58,7 @@ public class StructureHandler implements DirectorParameterHandler<String> {
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> locatableKeys = IrisStructureLocator.locatableEditableKeys(activeEngine);
|
||||
Set<String> locatableKeys = ModuleServices.locatableStructures(activeEngine);
|
||||
for (String key : locatableKeys) {
|
||||
String normalizedKey = normalizeKey(key);
|
||||
if (!normalizedKey.isEmpty()
|
||||
@@ -121,7 +122,7 @@ public class StructureHandler implements DirectorParameterHandler<String> {
|
||||
&& IrisStructureLocator.hasLocatableNativePlacement(engine, key);
|
||||
boolean locatableEditableReplacement = !nativePlacement
|
||||
&& decision.status() == NativeStructureGenerationStatus.REPLACED_BY_IRIS
|
||||
&& IrisStructureLocator.hasLocatableEditablePlacement(engine, key);
|
||||
&& ModuleServices.canLocateStructure(engine, key);
|
||||
return isEligibleRegisteredKey(
|
||||
decision, nativePlacement, locatableNativePlacement, locatableEditableReplacement,
|
||||
reachableKeys.contains(normalizedKey), nativeGenerationEnabled);
|
||||
|
||||
Reference in new issue
Block a user