mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 19:51:49 +00:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3b595a712 | ||
|
|
ecc4413d19 | ||
|
|
c7a2af98a5 | ||
|
|
94648946d9 | ||
|
|
ba9694083b | ||
|
|
02f6379808 | ||
|
|
f7084b244f | ||
|
|
1bc7843a52 | ||
|
|
b0b6e54d2d |
No files matched your search
-2
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.nativegen;
|
||||
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.structure.nativegen.GenerationWritePolicy;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeGenerationWriteGuard;
|
||||
@@ -87,7 +86,6 @@ public final class NativeGenerationWriteGuardTest {
|
||||
GenerationHistory history = mock(GenerationHistory.class);
|
||||
GenerationActivation active = mock(GenerationActivation.class);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.history()).thenReturn(history);
|
||||
when(history.activeActivation()).thenReturn(active);
|
||||
when(active.activationId()).thenReturn(4L);
|
||||
|
||||
+1
-3
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.platform.bukkit.nms.v26_2_R1;
|
||||
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.platform.bukkit.nms.BukkitGeneratorContext;
|
||||
import org.bukkit.World;
|
||||
import art.arcane.volmlib.nativelib.v26_2_R1.terrain.NativeChunkGenerator;
|
||||
@@ -119,14 +118,13 @@ public class IrisChunkGeneratorSpawnAdmissionTest {
|
||||
NativeBiomeSourceImpl source = mock(NativeBiomeSourceImpl.class);
|
||||
when(engine.getGenerationSessions()).thenReturn(sessions);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.biomes()).thenReturn(saved);
|
||||
when(saved.nativeSpawnSelection(0, 64, 0, "")).thenAnswer(invocation -> {
|
||||
assertAdmitted();
|
||||
savedReads.incrementAndGet();
|
||||
return new NativeBiomeSpawnSelection(NativeBiomeSpawnSelection.Mode.RETAINED, "minecraft:plains");
|
||||
});
|
||||
when(engine.openGenerationScope(0, 0)).thenAnswer(invocation -> {
|
||||
when(engine.openGenerationHistoryCoordinateScope(0, 0)).thenAnswer(invocation -> {
|
||||
assertAdmitted();
|
||||
routes.incrementAndGet();
|
||||
return null;
|
||||
|
||||
+1
-5
@@ -1,7 +1,5 @@
|
||||
package art.arcane.iris.structure.nativegen;
|
||||
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.structure.nativegen.IrisStructureVolumePolicy;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructureVolumeSource;
|
||||
@@ -167,7 +165,6 @@ public class NativeStructureVolumeIndexTest {
|
||||
public void absentOrMismatchedRuntimeOwnershipKeepsCoordinateRouting() throws Exception {
|
||||
ScopedEngine detached = scopedEngine(true, 1);
|
||||
when(detached.engine().getGenerationHistoryRuntimeRouter()).thenReturn(Optional.empty());
|
||||
when(detached.engine().getGenerationSource()).thenReturn(GenerationSource.singlePack());
|
||||
for (ScopedEngine scoped : List.of(scopedEngine(false, 1), scopedEngine(true, 0),
|
||||
scopedEngine(true, 2), detached)) {
|
||||
NativeStructureVolumeIndex index = NativeStructureVolumeIndex.forTesting(new CountingResolver(0, 0));
|
||||
@@ -475,7 +472,6 @@ public class NativeStructureVolumeIndexTest {
|
||||
GenerationHistoryRuntimeRouter router = mock(GenerationHistoryRuntimeRouter.class);
|
||||
when(engine.hasGenerationRuntimeScope()).thenReturn(scoped);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(engine.getCacheID()).thenReturn(1);
|
||||
if (ownerRuntimeId != 0) {
|
||||
IrisEngine.GenerationRuntimeBinding binding = mock(IrisEngine.GenerationRuntimeBinding.class);
|
||||
@@ -484,7 +480,7 @@ public class NativeStructureVolumeIndexTest {
|
||||
new GenerationHistoryRuntimeRouter.RuntimeOwnership(1L, binding)));
|
||||
}
|
||||
AtomicInteger scopes = new AtomicInteger();
|
||||
when(engine.openGenerationScope(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
when(engine.openGenerationHistoryCoordinateScope(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
scopes.incrementAndGet();
|
||||
return null;
|
||||
});
|
||||
|
||||
-2
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.nativegen.v26_3_R1;
|
||||
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.structure.nativegen.GenerationWritePolicy;
|
||||
|
||||
import art.arcane.volmlib.nativelib.v26_3_R1.terrain.NativeGenerationWriteGuard;
|
||||
@@ -87,7 +86,6 @@ public final class NativeGenerationWriteGuardTest {
|
||||
GenerationHistory history = mock(GenerationHistory.class);
|
||||
GenerationActivation active = mock(GenerationActivation.class);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.history()).thenReturn(history);
|
||||
when(history.activeActivation()).thenReturn(active);
|
||||
when(active.activationId()).thenReturn(4L);
|
||||
|
||||
+1
-3
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.platform.bukkit.nms.v26_3_R1;
|
||||
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.platform.bukkit.nms.BukkitGeneratorContext;
|
||||
import org.bukkit.World;
|
||||
import art.arcane.volmlib.nativelib.v26_3_R1.terrain.NativeChunkGenerator;
|
||||
@@ -123,14 +122,13 @@ public class IrisChunkGeneratorSpawnAdmissionTest {
|
||||
setField(generator, "runtimeLevel", level);
|
||||
when(engine.getGenerationSessions()).thenReturn(sessions);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.biomes()).thenReturn(saved);
|
||||
when(saved.nativeSpawnSelection(0, 64, 0, "")).thenAnswer(invocation -> {
|
||||
assertAdmitted();
|
||||
savedReads.incrementAndGet();
|
||||
return new NativeBiomeSpawnSelection(NativeBiomeSpawnSelection.Mode.RETAINED, "minecraft:plains");
|
||||
});
|
||||
when(engine.openGenerationScope(0, 0)).thenAnswer(invocation -> {
|
||||
when(engine.openGenerationHistoryCoordinateScope(0, 0)).thenAnswer(invocation -> {
|
||||
assertAdmitted();
|
||||
routes.incrementAndGet();
|
||||
return null;
|
||||
|
||||
+262
@@ -0,0 +1,262 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.volmlib.nativelib.common.block.GroundSurvival;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedBlockState;
|
||||
import art.arcane.volmlib.nativelib.block.SurvivalAnswer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Both platforms ask the server's own canSurvive rule where a plant may stand, against the real block tags. */
|
||||
public final class HeadlessGroundSurvivalTest {
|
||||
private static final Logger NATIVE_LOG = Logger.getLogger("VolmLib-Native");
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
HeadlessNativeBootstrap.initialize();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void grassStandsOnSoilButNotOnStone() {
|
||||
assertPlacement(true, Blocks.SHORT_GRASS, Blocks.GRASS_BLOCK);
|
||||
assertPlacement(true, Blocks.SHORT_GRASS, Blocks.PODZOL);
|
||||
assertPlacement(false, Blocks.SHORT_GRASS, Blocks.STONE);
|
||||
assertPlacement(false, Blocks.POPPY, Blocks.STONE);
|
||||
assertPlacement(false, Blocks.FERN, Blocks.OAK_LEAVES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cactusNeedsSandOrCactus() {
|
||||
for (Block ground : new Block[]{Blocks.CACTUS, Blocks.SAND, Blocks.RED_SAND}) {
|
||||
assertPlacement(true, Blocks.CACTUS, ground);
|
||||
}
|
||||
assertPlacement(false, Blocks.CACTUS, Blocks.STONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sugarCaneNeedsItsSubstrate() {
|
||||
for (Block ground : new Block[]{Blocks.SUGAR_CANE, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT,
|
||||
Blocks.PODZOL, Blocks.MYCELIUM, Blocks.ROOTED_DIRT, Blocks.MOSS_BLOCK, Blocks.PALE_MOSS_BLOCK,
|
||||
Blocks.MUD, Blocks.MUDDY_MANGROVE_ROOTS, Blocks.SAND, Blocks.RED_SAND, Blocks.SUSPICIOUS_SAND}) {
|
||||
assertPlacement(true, Blocks.SUGAR_CANE, ground);
|
||||
}
|
||||
for (Block ground : new Block[]{Blocks.STONE, Blocks.GRAVEL, Blocks.CLAY, Blocks.DIRT_PATH,
|
||||
Blocks.FARMLAND, Blocks.AIR, Blocks.WATER}) {
|
||||
assertPlacement(false, Blocks.SUGAR_CANE, ground);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void netherGroundCoverAcceptsNyliumAndSoulSoilButRejectsBarrenBlocks() {
|
||||
for (Block plant : new Block[]{Blocks.CRIMSON_ROOTS, Blocks.WARPED_ROOTS, Blocks.NETHER_SPROUTS}) {
|
||||
for (Block ground : new Block[]{Blocks.CRIMSON_NYLIUM, Blocks.WARPED_NYLIUM, Blocks.SOUL_SOIL}) {
|
||||
assertPlacement(true, plant, ground);
|
||||
}
|
||||
for (Block ground : new Block[]{Blocks.NETHERRACK, Blocks.STONE, Blocks.GRAVEL, Blocks.AIR}) {
|
||||
assertPlacement(false, plant, ground);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blocksThatRestOnNoGroundStillFit() {
|
||||
assertPlacement(true, Blocks.WALL_TORCH, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.VINE, Blocks.SAND);
|
||||
assertPlacement(true, Blocks.COCOA, Blocks.STONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deadBushStaysOffGrassAsPacksExpect() {
|
||||
assertPlacement(true, Blocks.DEAD_BUSH, Blocks.SAND);
|
||||
assertPlacement(false, Blocks.DEAD_BUSH, Blocks.GRASS_BLOCK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingStandsOnAir() {
|
||||
assertPlacement(false, Blocks.VINE, Blocks.AIR);
|
||||
assertPlacement(false, Blocks.SHORT_GRASS, Blocks.CAVE_AIR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plantsThatReadMoreOfTheLevelAreAnsweredByTheirOwnRule() {
|
||||
List<LogRecord> warnings = warningsDuring(() -> {
|
||||
assertPlacement(true, Blocks.BAMBOO, Blocks.GRASS_BLOCK);
|
||||
assertPlacement(false, Blocks.BAMBOO, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.KELP, Blocks.STONE);
|
||||
assertPlacement(false, Blocks.KELP, Blocks.MAGMA_BLOCK);
|
||||
assertPlacement(true, Blocks.SEAGRASS, Blocks.SAND);
|
||||
assertPlacement(false, Blocks.SEAGRASS, Blocks.MAGMA_BLOCK);
|
||||
assertPlacement(true, Blocks.LILY_PAD, Blocks.WATER);
|
||||
assertPlacement(false, Blocks.LILY_PAD, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.SWEET_BERRY_BUSH, Blocks.GRASS_BLOCK);
|
||||
assertPlacement(false, Blocks.SWEET_BERRY_BUSH, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.BROWN_MUSHROOM, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.RED_MUSHROOM, Blocks.MYCELIUM);
|
||||
assertPlacement(false, Blocks.BROWN_MUSHROOM, Blocks.GLASS);
|
||||
assertPlacement(true, Blocks.CRIMSON_FUNGUS, Blocks.CRIMSON_NYLIUM);
|
||||
assertPlacement(false, Blocks.WARPED_FUNGUS, Blocks.NETHERRACK);
|
||||
assertPlacement(true, Blocks.WHEAT, Blocks.FARMLAND);
|
||||
assertPlacement(false, Blocks.CARROTS, Blocks.DIRT);
|
||||
});
|
||||
assertEquals(messages(warnings), 0, warnings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyVanillaBlockIsAnsweredWithoutFailingOpen() {
|
||||
GroundSurvival survival = new GroundSurvival();
|
||||
List<LogRecord> warnings = warningsDuring(() -> {
|
||||
for (Block plant : BuiltInRegistries.BLOCK) {
|
||||
if (needsARunningPaperServer(plant)) {
|
||||
continue;
|
||||
}
|
||||
for (Block ground : new Block[]{Blocks.GRASS_BLOCK, Blocks.STONE, Blocks.WATER}) {
|
||||
survival.canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState());
|
||||
}
|
||||
}
|
||||
});
|
||||
assertEquals(messages(warnings), 0, warnings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRuleThatThrowsIsLeftUnansweredAndWarnsOncePerBlock() {
|
||||
BlockState firstState = throwingStateOf(Blocks.SHORT_GRASS);
|
||||
BlockState secondState = throwingStateOf(Blocks.SHORT_GRASS);
|
||||
GroundSurvival survival = new GroundSurvival();
|
||||
List<LogRecord> warnings = warningsDuring(() -> {
|
||||
for (BlockState plant : new BlockState[]{firstState, secondState}) {
|
||||
for (Block ground : new Block[]{Blocks.STONE, Blocks.SAND, Blocks.GRASS_BLOCK}) {
|
||||
assertEquals(SurvivalAnswer.UNANSWERED, survival.canSurviveOn(plant, ground.defaultBlockState()));
|
||||
}
|
||||
}
|
||||
});
|
||||
assertEquals(messages(warnings), 1, warnings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRuleThatThrowsFallsBackToThePlacementTable() {
|
||||
ModdedBlockState grass = ModdedBlockState.deferred(throwingStateOf(Blocks.SHORT_GRASS), Map.of(), "iris:test");
|
||||
warningsDuring(() -> {
|
||||
assertTrue(grass.canPlaceOnto(wrap(Blocks.GRASS_BLOCK)));
|
||||
assertFalse(grass.canPlaceOnto(wrap(Blocks.STONE)));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRuleThatOnlyAnswersForSomeGroundsDoesNotPassAsAWallBlock() {
|
||||
BlockState plant = mock(BlockState.class);
|
||||
when(plant.getBlock()).thenReturn(Blocks.SHORT_GRASS);
|
||||
when(plant.canSurvive(any(), any())).thenAnswer(asked -> {
|
||||
LevelReader level = asked.getArgument(0);
|
||||
BlockPos plantPos = asked.getArgument(1);
|
||||
if (level.getBlockState(plantPos.below()).is(Blocks.STONE)) {
|
||||
return false;
|
||||
}
|
||||
throw new IllegalStateException("custom rule failed");
|
||||
});
|
||||
GroundSurvival survival = new GroundSurvival();
|
||||
warningsDuring(() -> assertEquals(SurvivalAnswer.UNANSWERED,
|
||||
survival.canSurviveOn(plant, Blocks.STONE.defaultBlockState())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatorThreadsAskingAtOnceGetTheSameAnswers() {
|
||||
Block[] plants = {Blocks.SHORT_GRASS, Blocks.CACTUS, Blocks.SUGAR_CANE, Blocks.VINE, Blocks.BROWN_MUSHROOM};
|
||||
Block[] grounds = {Blocks.GRASS_BLOCK, Blocks.SAND, Blocks.STONE, Blocks.WATER};
|
||||
GroundSurvival alone = new GroundSurvival();
|
||||
GroundSurvival shared = new GroundSurvival();
|
||||
List<Integer> threads = Arrays.asList(new Integer[16]);
|
||||
threads.parallelStream().forEach(ignored -> {
|
||||
for (Block plant : plants) {
|
||||
for (Block ground : grounds) {
|
||||
assertEquals(plant + " on " + ground,
|
||||
alone.canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()),
|
||||
shared.canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Paper's chorus plant reads Paper's global configuration, which only a running server loads.
|
||||
private static boolean needsARunningPaperServer(Block plant) {
|
||||
return plant == Blocks.CHORUS_PLANT;
|
||||
}
|
||||
|
||||
private static BlockState throwingStateOf(Block block) {
|
||||
BlockState state = mock(BlockState.class);
|
||||
when(state.getBlock()).thenReturn(block);
|
||||
when(state.isSingletonState()).thenReturn(true);
|
||||
when(state.canSurvive(any(), any())).thenThrow(new IllegalStateException("custom rule failed"));
|
||||
return state;
|
||||
}
|
||||
|
||||
private static void assertPlacement(boolean expected, Block plant, Block ground) {
|
||||
String pair = plant + " on " + ground;
|
||||
assertEquals("modded " + pair, expected, moddedPlacement(plant, ground));
|
||||
assertEquals("bukkit native " + pair, expected ? SurvivalAnswer.SURVIVES : SurvivalAnswer.FAILS,
|
||||
new GroundSurvival().canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()));
|
||||
}
|
||||
|
||||
private static boolean moddedPlacement(Block plant, Block ground) {
|
||||
return wrap(plant).canPlaceOnto(wrap(ground));
|
||||
}
|
||||
|
||||
private static ModdedBlockState wrap(Block block) {
|
||||
return ModdedBlockState.deferred(block.defaultBlockState(), Map.of(), "iris:test");
|
||||
}
|
||||
|
||||
private static List<LogRecord> warningsDuring(Runnable checks) {
|
||||
List<LogRecord> warnings = new CopyOnWriteArrayList<>();
|
||||
Handler capture = new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
|
||||
warnings.add(record);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
};
|
||||
NATIVE_LOG.addHandler(capture);
|
||||
try {
|
||||
checks.run();
|
||||
} finally {
|
||||
NATIVE_LOG.removeHandler(capture);
|
||||
}
|
||||
return warnings;
|
||||
}
|
||||
|
||||
private static String messages(List<LogRecord> warnings) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
for (LogRecord warning : warnings) {
|
||||
text.append(warning.getMessage()).append(" (").append(warning.getThrown()).append(")\n");
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
}
|
||||
+1
-5
@@ -1,7 +1,5 @@
|
||||
package art.arcane.iris.structure.nativegen;
|
||||
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.structure.nativegen.IrisStructureVolumePolicy;
|
||||
|
||||
import art.arcane.volmlib.nativelib.v26_3_R1.terrain.NativeStructureVolumeSource;
|
||||
@@ -167,7 +165,6 @@ public class NativeStructureVolumeIndexTest {
|
||||
public void absentOrMismatchedRuntimeOwnershipKeepsCoordinateRouting() throws Exception {
|
||||
ScopedEngine detached = scopedEngine(true, 1);
|
||||
when(detached.engine().getGenerationHistoryRuntimeRouter()).thenReturn(Optional.empty());
|
||||
when(detached.engine().getGenerationSource()).thenReturn(GenerationSource.singlePack());
|
||||
for (ScopedEngine scoped : List.of(scopedEngine(false, 1), scopedEngine(true, 0),
|
||||
scopedEngine(true, 2), detached)) {
|
||||
NativeStructureVolumeIndex index = NativeStructureVolumeIndex.forTesting(new CountingResolver(0, 0));
|
||||
@@ -475,7 +472,6 @@ public class NativeStructureVolumeIndexTest {
|
||||
GenerationHistoryRuntimeRouter router = mock(GenerationHistoryRuntimeRouter.class);
|
||||
when(engine.hasGenerationRuntimeScope()).thenReturn(scoped);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(engine.getCacheID()).thenReturn(1);
|
||||
if (ownerRuntimeId != 0) {
|
||||
IrisEngine.GenerationRuntimeBinding binding = mock(IrisEngine.GenerationRuntimeBinding.class);
|
||||
@@ -484,7 +480,7 @@ public class NativeStructureVolumeIndexTest {
|
||||
new GenerationHistoryRuntimeRouter.RuntimeOwnership(1L, binding)));
|
||||
}
|
||||
AtomicInteger scopes = new AtomicInteger();
|
||||
when(engine.openGenerationScope(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
when(engine.openGenerationHistoryCoordinateScope(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
scopes.incrementAndGet();
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -58,6 +58,7 @@ import art.arcane.iris.platform.agent.AttachSignal;
|
||||
import art.arcane.iris.platform.bootstrap.Bindings;
|
||||
import art.arcane.iris.platform.bootstrap.ServerProperties;
|
||||
import art.arcane.iris.platform.bootstrap.SlimJar;
|
||||
import art.arcane.iris.platform.bukkit.BlockRulesSVC;
|
||||
import art.arcane.iris.platform.bukkit.BoardSVC;
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||
import art.arcane.iris.platform.bukkit.api.IrisApiEventSVC;
|
||||
@@ -681,6 +682,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
new GlobalCacheSVC(),
|
||||
new LogFilterSVC(),
|
||||
new ExternalDataSVC(),
|
||||
new BlockRulesSVC(),
|
||||
new EditSVC(),
|
||||
new ObjectSVC(),
|
||||
new ObjectStudioSaveService(),
|
||||
|
||||
@@ -24,6 +24,7 @@ import art.arcane.iris.pack.datapack.ServerConfigurator;
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.world.runtime.ChunkClearer;
|
||||
import art.arcane.iris.generation.validation.GoldenHashScanner;
|
||||
import art.arcane.iris.world.runtime.InPlaceChunkRegenerator;
|
||||
import art.arcane.iris.generation.runtime.IrisEngineSVC;
|
||||
import art.arcane.iris.pack.IrisPackBenchmarking;
|
||||
import art.arcane.iris.world.IrisToolbelt;
|
||||
@@ -304,6 +305,51 @@ public class CommandDeveloper implements DirectorExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Regen ---
|
||||
|
||||
@Director(name = "regen", aliases = {"rg"}, description = "Delete and regenerate nearby chunks in place using Iris generation", descriptionKey = "iris.director.commanddeveloper.director.delete_regenerate_nearby_chunks_place_using_iris_generation", origin = DirectorOrigin.PLAYER)
|
||||
public void regen(
|
||||
@Param(name = "radius", description = "The radius of nearby chunks", descriptionKey = "iris.director.commanddeveloper.param.radius_nearby_chunks", defaultValue = "5")
|
||||
int radius
|
||||
) {
|
||||
if (radius < 0) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_DEVELOPER_RADIUS_MUST_BE_0_GREATER_2));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = player();
|
||||
VolmitSender commandSender = sender();
|
||||
World world = player.getWorld();
|
||||
if (!IrisToolbelt.isIrisWorld(world)) {
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_DEVELOPER_YOU_MUST_BE_IRIS_WORLD_USE_REGEN));
|
||||
return;
|
||||
}
|
||||
|
||||
Engine engine = IrisToolbelt.access(world).getEngine();
|
||||
if (engine == null) {
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_DEVELOPER_ENGINE_ACCESS_THIS_WORLD_IS_NULL_GENERATE_NEARBY_CHUNKS_FIRST));
|
||||
return;
|
||||
}
|
||||
|
||||
int chunks = (radius * 2 + 1) * (radius * 2 + 1);
|
||||
|
||||
// The player position must be read on the thread owning the player; the regenerator hops per chunk itself.
|
||||
if (!J.runEntity(player, () -> {
|
||||
int centerX = player.getLocation().getBlockX() >> 4;
|
||||
int centerZ = player.getLocation().getBlockZ() >> 4;
|
||||
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_DEVELOPER_REGEN_STARTED_CHUNK_S_AROUND_DELETING_REGENERATING_PLACE, MessageArgument.untrusted("chunks", chunks), MessageArgument.untrusted("centerX", centerX), MessageArgument.untrusted("centerZ", centerZ)));
|
||||
Iris.info("Regen run start: world=" + world.getName()
|
||||
+ " center=" + centerX + "," + centerZ
|
||||
+ " radius=" + radius
|
||||
+ " chunks=" + chunks);
|
||||
|
||||
new InPlaceChunkRegenerator(world, engine, commandSender, centerX, centerZ, radius).start();
|
||||
})) {
|
||||
Iris.warn("Could not schedule regen on the thread owning " + player.getName() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
@Director(name = "goldenhash", aliases = {"gold"}, description = "Generate chunks into buffers (no world writes) and hash blocks+biomes; captures a golden file or verifies against an existing one. Deletes the world's entire mantle - use on disposable test worlds.", descriptionKey = "iris.director.commanddeveloper.director.generate_chunks_into_buffers_no_world_writes_hash_blocks_biomes_captures_golden", origin = DirectorOrigin.BOTH)
|
||||
public void goldenhash(
|
||||
@Param(description = "The world to scan", descriptionKey = "iris.director.commanddeveloper.param.world_scan", contextual = true, contextualOverride = true)
|
||||
|
||||
@@ -34,7 +34,6 @@ import art.arcane.iris.structure.BulkStructureImporter;
|
||||
import art.arcane.iris.structure.FeatureImporter;
|
||||
import art.arcane.iris.structure.StructureImporter;
|
||||
import art.arcane.iris.world.IrisToolbelt;
|
||||
import art.arcane.iris.world.runtime.InPlaceChunkRegenerator;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.world.loot.InventorySlotType;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
@@ -221,49 +220,6 @@ public class CommandStudio implements DirectorExecutor {
|
||||
LanguageAudience.run(audience, () -> sendHotloadResult(commandSender, failure)));
|
||||
}
|
||||
|
||||
@Director(name = "regen", aliases = {"rg"}, description = "Delete and regenerate nearby chunks in place using Iris generation", descriptionKey = "iris.director.commanddeveloper.director.delete_regenerate_nearby_chunks_place_using_iris_generation", origin = DirectorOrigin.PLAYER)
|
||||
public void regen(
|
||||
@Param(name = "radius", description = "The radius of nearby chunks", descriptionKey = "iris.director.commanddeveloper.param.radius_nearby_chunks", defaultValue = "5")
|
||||
int radius
|
||||
) {
|
||||
if (radius < 0) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_DEVELOPER_RADIUS_MUST_BE_0_GREATER_2));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = player();
|
||||
VolmitSender commandSender = sender();
|
||||
World world = player.getWorld();
|
||||
if (!IrisToolbelt.isIrisWorld(world)) {
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_DEVELOPER_YOU_MUST_BE_IRIS_WORLD_USE_REGEN));
|
||||
return;
|
||||
}
|
||||
|
||||
Engine engine = IrisToolbelt.access(world).getEngine();
|
||||
if (engine == null) {
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_DEVELOPER_ENGINE_ACCESS_THIS_WORLD_IS_NULL_GENERATE_NEARBY_CHUNKS_FIRST));
|
||||
return;
|
||||
}
|
||||
|
||||
int chunks = (radius * 2 + 1) * (radius * 2 + 1);
|
||||
|
||||
// The player position must be read on the thread owning the player; the regenerator hops per chunk itself.
|
||||
if (!J.runEntity(player, () -> {
|
||||
int centerX = player.getLocation().getBlockX() >> 4;
|
||||
int centerZ = player.getLocation().getBlockZ() >> 4;
|
||||
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_DEVELOPER_REGEN_STARTED_CHUNK_S_AROUND_DELETING_REGENERATING_PLACE, MessageArgument.untrusted("chunks", chunks), MessageArgument.untrusted("centerX", centerX), MessageArgument.untrusted("centerZ", centerZ)));
|
||||
Iris.info("Regen run start: world=" + world.getName()
|
||||
+ " center=" + centerX + "," + centerZ
|
||||
+ " radius=" + radius
|
||||
+ " chunks=" + chunks);
|
||||
|
||||
new InPlaceChunkRegenerator(world, engine, commandSender, centerX, centerZ, radius).start();
|
||||
})) {
|
||||
Iris.warn("Could not schedule regen on the thread owning " + player.getName() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
@Director(description = "Toggle your Studio debug scoreboard", descriptionKey = "iris.director.commandstudio.director.toggle_your_studio_debug_scoreboard", aliases = {"board", "sidebar", "sb"}, origin = DirectorOrigin.PLAYER)
|
||||
public void scoreboard() {
|
||||
Player target = player();
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import art.arcane.iris.platform.bukkit.nms.INMS;
|
||||
import art.arcane.iris.platform.bukkit.plugin.IrisService;
|
||||
import io.papermc.paper.event.server.ServerResourcesReloadedEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
/** Lets the server's placement rules apply again after a resource reload, which may have changed the block tags they read. */
|
||||
public class BlockRulesSVC implements IrisService {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResourcesReloaded(ServerResourcesReloadedEvent event) {
|
||||
if (INMS.isBound()) {
|
||||
INMS.get().forgetBlockRules();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export default {
|
||||
await context.step('regeneration removes target furniture and preserves neighbor ownership', async () => {
|
||||
const ready = await context.command('/iriscenative neighbor', /CE_NEIGHBOR_READY|CE_FAILED/, 30000)
|
||||
context.expect(ready.includes('CE_NEIGHBOR_READY chunk=2,0 furniture=3 target=1'), ready)
|
||||
const regenerated = await context.command('/iris studio regen radius=0', /Regen complete:|Regen failed:/, 90000)
|
||||
const regenerated = await context.command('/iris developer regen radius=0', /Regen complete:|Regen failed:/, 90000)
|
||||
context.expect(regenerated.includes('Regen complete:'), regenerated)
|
||||
const response = await context.command('/iriscenative loaded', /CE_LOADED|CE_FAILED/, 30000)
|
||||
context.expect(response.includes('CE_LOADED removed=1 untouched=1 replacement=1 wall=1 target=1'), response)
|
||||
|
||||
-4
@@ -1,7 +1,5 @@
|
||||
package art.arcane.iris.world;
|
||||
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.Iris;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
@@ -49,7 +47,6 @@ public class BukkitWorldReconcilerRuntimeTest {
|
||||
fixture.backend().validateLoadedRuntime(fixture.world(), fixture.key(), "overworld", 1337L));
|
||||
when(fixture.generator().getStartupReady()).thenReturn(CompletableFuture.completedFuture(null));
|
||||
when(fixture.engine().getGenerationHistoryRuntimeRouter()).thenReturn(Optional.empty());
|
||||
when(fixture.engine().getGenerationSource()).thenReturn(GenerationSource.singlePack());
|
||||
assertEquals(BukkitWorldReconciler.LoadedRuntimeStatus.UNAVAILABLE,
|
||||
fixture.backend().validateLoadedRuntime(fixture.world(), fixture.key(), "overworld", 1337L));
|
||||
}
|
||||
@@ -155,7 +152,6 @@ public class BukkitWorldReconcilerRuntimeTest {
|
||||
when(generator.getGenerationHistory()).thenReturn(history);
|
||||
when(generator.getDimensionKey()).thenReturn("overworld");
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.history()).thenReturn(history);
|
||||
when(history.paths()).thenReturn(GenerationHistoryPaths.forDimension(root));
|
||||
when(history.activeEpoch()).thenReturn(epoch);
|
||||
|
||||
@@ -104,7 +104,7 @@ repositories {
|
||||
name = 'FabricMC'
|
||||
url = uri('https://maven.fabricmc.net/')
|
||||
}
|
||||
maven { url = uri('https://repo.codemc.org/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.io/repository/maven-public/') }
|
||||
maven { url = uri('https://jitpack.io') }
|
||||
maven { url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/') }
|
||||
}
|
||||
@@ -331,7 +331,6 @@ tasks.named('shadowJar', ShadowJar).configure {
|
||||
if ((int) irisModTarget.java == 21) {
|
||||
exclude(java21RuntimeExclusions)
|
||||
}
|
||||
exclude('META-INF/maven/**')
|
||||
exclude('META-INF/proguard/**')
|
||||
exclude('META-INF/*.SF')
|
||||
exclude('META-INF/*.DSA')
|
||||
@@ -415,6 +414,7 @@ tasks.named('assemble').configure {
|
||||
}
|
||||
|
||||
pluginPackaging {
|
||||
nativeBoundaryChecks = true
|
||||
artifacts {
|
||||
create('distribution') {
|
||||
taskName = irisModTarget.fabricRemap ? 'remapJar' : 'shadowJar'
|
||||
|
||||
@@ -121,7 +121,7 @@ repositories {
|
||||
maven fg.forgeMaven
|
||||
maven fg.minecraftLibsMaven
|
||||
mavenCentral()
|
||||
maven { url = uri('https://repo.codemc.org/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.io/repository/maven-public/') }
|
||||
maven { url = uri('https://jitpack.io') }
|
||||
maven { url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/') }
|
||||
}
|
||||
@@ -320,7 +320,6 @@ tasks.named('shadowJar', ShadowJar).configure {
|
||||
if ((int) irisModTarget.java == 21) {
|
||||
exclude(java21RuntimeExclusions)
|
||||
}
|
||||
exclude('META-INF/maven/**')
|
||||
exclude('META-INF/proguard/**')
|
||||
exclude('META-INF/*.SF')
|
||||
exclude('META-INF/*.DSA')
|
||||
@@ -377,6 +376,7 @@ tasks.named('assemble').configure {
|
||||
}
|
||||
|
||||
pluginPackaging {
|
||||
nativeBoundaryChecks = true
|
||||
artifacts {
|
||||
create('distribution') {
|
||||
taskName = 'shadowJar'
|
||||
|
||||
+15
-23
@@ -82,9 +82,6 @@ import art.arcane.iris.structure.nativegen.NativeFeatureGenerationPolicy;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureStartPlan;
|
||||
import art.arcane.iris.world.history.GenerationEpoch;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.generation.runtime.GenerationRoute;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.GenerationRegistryContract;
|
||||
import art.arcane.iris.world.history.GenerationRegistryContractFactory;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
@@ -905,7 +902,7 @@ public final class IrisModdedChunkGenerator implements NativeGeneratorOwner, Nat
|
||||
importedFeatures.evictRuntime(runtimeIdentity);
|
||||
}
|
||||
|
||||
private GenerationRoute openHistoryRoute(
|
||||
private GenerationHistoryRuntimeRouter.RuntimeRoute openHistoryRoute(
|
||||
Engine current,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
@@ -914,16 +911,16 @@ public final class IrisModdedChunkGenerator implements NativeGeneratorOwner, Nat
|
||||
if (allowsGenerationHistoryBypass(current)) {
|
||||
return null;
|
||||
}
|
||||
GenerationSource source = requireVersionedSource(current, operation);
|
||||
GenerationHistoryRuntimeRouter router = requireHistoryRouter(current, operation);
|
||||
try {
|
||||
return source.openRoute(chunkX, chunkZ);
|
||||
return router.openRoute(chunkX, chunkZ);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Iris " + operation + " could not route chunk "
|
||||
+ chunkX + "," + chunkZ + " through generation history.", failure);
|
||||
}
|
||||
}
|
||||
|
||||
private GenerationScope openHistoryCoordinateScope(
|
||||
private GenerationHistoryRuntimeRouter.CoordinateScope openHistoryCoordinateScope(
|
||||
Engine current,
|
||||
int blockX,
|
||||
int blockZ,
|
||||
@@ -932,27 +929,15 @@ public final class IrisModdedChunkGenerator implements NativeGeneratorOwner, Nat
|
||||
if (allowsGenerationHistoryBypass(current)) {
|
||||
return null;
|
||||
}
|
||||
GenerationSource source = requireVersionedSource(current, operation);
|
||||
GenerationHistoryRuntimeRouter router = requireHistoryRouter(current, operation);
|
||||
try {
|
||||
return source.openGenerationScope(blockX, blockZ);
|
||||
return router.openCoordinateScope(blockX, blockZ);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Iris " + operation + " could not route block "
|
||||
+ blockX + "," + blockZ + " through generation history.", failure);
|
||||
}
|
||||
}
|
||||
|
||||
private GenerationSource requireVersionedSource(Engine current, String operation) {
|
||||
if (!(current instanceof IrisEngine irisEngine)) {
|
||||
throw new IllegalStateException("Iris " + operation + " requires an IrisEngine runtime.");
|
||||
}
|
||||
GenerationSource source = irisEngine.getGenerationSource();
|
||||
if (!source.keepsPackVersions()) {
|
||||
throw new IllegalStateException("Iris " + operation
|
||||
+ " requires an attached generation-history runtime router.");
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
private GenerationHistoryRuntimeRouter requireHistoryRouter(Engine current, String operation) {
|
||||
if (!(current instanceof IrisEngine irisEngine)) {
|
||||
throw new IllegalStateException("Iris " + operation + " requires an IrisEngine runtime.");
|
||||
@@ -981,6 +966,12 @@ public final class IrisModdedChunkGenerator implements NativeGeneratorOwner, Nat
|
||||
+ "generation-history routing.");
|
||||
}
|
||||
|
||||
private static GenerationHistoryRuntimeRouter.RuntimeRoute.RuntimeScope openHistoryRuntimeScope(
|
||||
GenerationHistoryRuntimeRouter.RuntimeRoute route
|
||||
) {
|
||||
return route == null ? null : route.openRuntimeScope();
|
||||
}
|
||||
|
||||
GenerationSessionLease requireGenerationLease(Engine current, String operation) {
|
||||
try {
|
||||
return current.acquireGenerationLease(operation);
|
||||
@@ -1159,12 +1150,13 @@ public final class IrisModdedChunkGenerator implements NativeGeneratorOwner, Nat
|
||||
|
||||
@Override
|
||||
public byte[] terrainReceipt(NativeGenerationRoute nativeRoute) throws IOException {
|
||||
return nativeRoute == null ? null : ((GenerationRoute) nativeRoute).naturalTerrainReceipt();
|
||||
GenerationHistoryRuntimeRouter.RuntimeRoute route = (GenerationHistoryRuntimeRouter.RuntimeRoute) nativeRoute;
|
||||
return ModdedNativeTerrainReceipts.encode(route);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long structureActivation(NativeGenerationRoute route) {
|
||||
return ((GenerationRoute) route).activationId();
|
||||
return ((GenerationHistoryRuntimeRouter.RuntimeRoute) route).activation().activationId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+13
-16
@@ -37,8 +37,7 @@ import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionException;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionLease;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisBiomeCustom;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
@@ -272,7 +271,7 @@ final class ModdedBiomePolicy<H, S> implements NativeModdedBiomePolicy<H, S> {
|
||||
if (engine == null) {
|
||||
return access.serializedNoise(quartX, quartY, quartZ, sampler);
|
||||
}
|
||||
GenerationScope historyScope = openHistoryCoordinateScope(
|
||||
GenerationHistoryRuntimeRouter.CoordinateScope historyScope = openHistoryCoordinateScope(
|
||||
engine, quartX << 2, quartZ << 2, "modded_structure_biome");
|
||||
try (historyScope) {
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease(engine, "modded_structure_biome");
|
||||
@@ -335,7 +334,7 @@ final class ModdedBiomePolicy<H, S> implements NativeModdedBiomePolicy<H, S> {
|
||||
}
|
||||
|
||||
private H locateVisibleBiome(Engine engine, int quartX, int quartY, int quartZ, S sampler) {
|
||||
try (GenerationScope ignored = openHistoryCoordinateScope(
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored = openHistoryCoordinateScope(
|
||||
engine, quartX << 2, quartZ << 2, "modded_locate_visible_biome")) {
|
||||
return resolveVisibleBiome(engine, quartX, quartY, quartZ, sampler, null);
|
||||
}
|
||||
@@ -427,7 +426,7 @@ final class ModdedBiomePolicy<H, S> implements NativeModdedBiomePolicy<H, S> {
|
||||
if (engine == null) {
|
||||
return access.serializedNoise(quartX, quartY, quartZ, sampler);
|
||||
}
|
||||
GenerationScope historyScope = openHistoryCoordinateScope(
|
||||
GenerationHistoryRuntimeRouter.CoordinateScope historyScope = openHistoryCoordinateScope(
|
||||
engine, quartX << 2, quartZ << 2, "modded_visible_biome");
|
||||
try (historyScope) {
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease(engine, "modded_visible_biome");
|
||||
@@ -483,7 +482,7 @@ final class ModdedBiomePolicy<H, S> implements NativeModdedBiomePolicy<H, S> {
|
||||
if (engine == null) {
|
||||
return null;
|
||||
}
|
||||
GenerationScope historyScope = openHistoryCoordinateScope(
|
||||
GenerationHistoryRuntimeRouter.CoordinateScope historyScope = openHistoryCoordinateScope(
|
||||
engine, blockX, blockZ, "modded_surface_spawn_biome");
|
||||
try (historyScope) {
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease(engine, "modded_surface_spawn_biome");
|
||||
@@ -572,7 +571,7 @@ final class ModdedBiomePolicy<H, S> implements NativeModdedBiomePolicy<H, S> {
|
||||
}
|
||||
boolean surfaceQuery;
|
||||
try (lease) {
|
||||
try (GenerationScope historyScope = openHistoryCoordinateScope(
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope = openHistoryCoordinateScope(
|
||||
engine, x, z, "modded_biomes_within");
|
||||
IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
if (!isReady(engine)) {
|
||||
@@ -593,7 +592,7 @@ final class ModdedBiomePolicy<H, S> implements NativeModdedBiomePolicy<H, S> {
|
||||
Set<H> biomes = new HashSet<>(columns);
|
||||
for (int quartZ = minQuartZ; quartZ <= maxQuartZ; quartZ++) {
|
||||
for (int quartX = minQuartX; quartX <= maxQuartX; quartX++) {
|
||||
try (GenerationScope historyScope = openHistoryCoordinateScope(
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope = openHistoryCoordinateScope(
|
||||
engine, quartX << 2, quartZ << 2, "modded_biomes_within");
|
||||
IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
biomes.add(getSurfaceStructureBiome(engine, quartX, quartZ, sampler));
|
||||
@@ -856,7 +855,7 @@ final class ModdedBiomePolicy<H, S> implements NativeModdedBiomePolicy<H, S> {
|
||||
throw new IllegalStateException("Iris structure biome source is not bound to its generator");
|
||||
}
|
||||
Engine engine = current.awaitEngine().get();
|
||||
GenerationScope historyScope = openHistoryCoordinateScope(
|
||||
GenerationHistoryRuntimeRouter.CoordinateScope historyScope = openHistoryCoordinateScope(
|
||||
engine, quartX << 2, quartZ << 2, "modded_structure_state_biome");
|
||||
try (historyScope) {
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease(engine, "modded_structure_state_biome");
|
||||
@@ -958,7 +957,7 @@ final class ModdedBiomePolicy<H, S> implements NativeModdedBiomePolicy<H, S> {
|
||||
return current == null ? null : current.currentEngine().get();
|
||||
}
|
||||
|
||||
private GenerationScope openHistoryCoordinateScope(
|
||||
private GenerationHistoryRuntimeRouter.CoordinateScope openHistoryCoordinateScope(
|
||||
Engine engine,
|
||||
int blockX,
|
||||
int blockZ,
|
||||
@@ -971,13 +970,11 @@ final class ModdedBiomePolicy<H, S> implements NativeModdedBiomePolicy<H, S> {
|
||||
if (!(engine instanceof IrisEngine irisEngine)) {
|
||||
throw new IllegalStateException("Iris " + operation + " requires an IrisEngine runtime.");
|
||||
}
|
||||
GenerationSource source = irisEngine.getGenerationSource();
|
||||
if (!source.keepsPackVersions()) {
|
||||
throw new IllegalStateException("Iris " + operation
|
||||
+ " requires an attached generation-history runtime router.");
|
||||
}
|
||||
GenerationHistoryRuntimeRouter router = irisEngine.getGenerationHistoryRuntimeRouter().orElseThrow(() ->
|
||||
new IllegalStateException("Iris " + operation
|
||||
+ " requires an attached generation-history runtime router."));
|
||||
try {
|
||||
return source.openGenerationScope(blockX, blockZ);
|
||||
return router.openCoordinateScope(blockX, blockZ);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Iris " + operation + " could not route block "
|
||||
+ blockX + "," + blockZ + " through generation history.", failure);
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.NativeTerrainReceipt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ModdedNativeTerrainReceipts {
|
||||
private ModdedNativeTerrainReceipts() {
|
||||
}
|
||||
|
||||
public static byte[] encode(GenerationHistoryRuntimeRouter.RuntimeRoute route) throws IOException {
|
||||
return route == null || route.naturalTerrain().isEmpty() ? null
|
||||
: NativeTerrainReceipt.encode(route.naturalTerrain().orElseThrow(),
|
||||
route.activation().activationId(), route.epoch().epochId());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -73,6 +73,7 @@ final class ModdedCommandHelp {
|
||||
Entry.command("catalog", "[namespace|refresh]", ModdedCatalogMessages.HELP_CATALOG),
|
||||
Entry.group("ingest", ModdedCatalogMessages.HELP_INGEST),
|
||||
Entry.command("metrics", "", ModdedHelpMessages.COMMAND_METRICS_PRINT_GENERATION_METRICS_FOR_YOUR_CURRENT_IRIS_DIMENSION, "measure"),
|
||||
Entry.command("regen", "[radius]", ModdedHelpMessages.COMMAND_REGEN_DELETE_AND_REGENERATE_NEARBY_CHUNKS_IN_PLACE, "rg"),
|
||||
Entry.group("pregen", ModdedHelpMessages.GROUP_PREGEN_PREGENERATE_AN_IRIS_DIMENSION, "pregenerate"),
|
||||
Entry.command("wand", "", ModdedHelpMessages.COMMAND_WAND_GET_AN_IRIS_OBJECT_WAND),
|
||||
Entry.command("dust", "", ModdedHelpMessages.COMMAND_DUST_GET_DUST_THAT_REVEALS_OBJECT_PLACEMENTS, "d"),
|
||||
@@ -150,7 +151,6 @@ final class ModdedCommandHelp {
|
||||
Entry.command("tpstudio", "", ModdedHelpMessages.COMMAND_TPSTUDIO_TELEPORT_INTO_THE_OPEN_STUDIO_DIMENSION, "stp"),
|
||||
Entry.command("status", "", ModdedHelpMessages.COMMAND_STATUS_SHOW_THE_OPEN_STUDIO_DIMENSION_AND_ITS_PACK),
|
||||
Entry.command("hotload", "", ModdedHelpMessages.COMMAND_HOTLOAD_REFRESH_THE_OPEN_STUDIO, "refresh"),
|
||||
Entry.command("regen", "[radius]", ModdedHelpMessages.COMMAND_REGEN_DELETE_AND_REGENERATE_NEARBY_CHUNKS_IN_PLACE, "rg"),
|
||||
Entry.command("noise", "[generator] [seed]", ModdedHelpMessages.COMMAND_NOISE_OPEN_THE_NOISE_EXPLORER_GUI_ON_THE_SERVER_DISPLAY, "nmap"),
|
||||
Entry.command("map", "", ModdedHelpMessages.COMMAND_MAP_OPEN_THE_VISION_MAP_GUI_ON_THE_SERVER_DISPLAY, "render"),
|
||||
Entry.command("vscode", "[pack]", ModdedHelpMessages.COMMAND_VSCODE_REGENERATE_THE_CODE_WORKSPACE_FOR_A_PACK_AND_OPEN_IT_IN_YOUR, "vsc"),
|
||||
|
||||
+10
@@ -120,6 +120,9 @@ final class ModdedCommandTree {
|
||||
root.then(metricsTree("metrics"));
|
||||
root.then(metricsTree("measure"));
|
||||
|
||||
root.then(regenTree("regen"));
|
||||
root.then(regenTree("rg"));
|
||||
|
||||
root.then(pregenTree("pregen"));
|
||||
root.then(pregenTree("pregenerate"));
|
||||
|
||||
@@ -219,6 +222,13 @@ final class ModdedCommandTree {
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> IrisModdedCommands.metrics(context.getSource())));
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<NativeCommandSource> regenTree(String name) {
|
||||
return NativeCommandRegistration.literal(name).requires(GATE)
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> IrisModdedCommands.regen(context.getSource(), 0)))
|
||||
.then(NativeCommandRegistration.argument("radius", IntegerArgumentType.integer(0, 64))
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> IrisModdedCommands.regen(context.getSource(), IntegerArgumentType.getInteger(context, "radius")))));
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<NativeCommandSource> gotoTree(String name) {
|
||||
return NativeCommandRegistration.literal(name).requires(GATE)
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> ModdedCommandHelp.send(context.getSource(), name)))
|
||||
|
||||
-9
@@ -159,8 +159,6 @@ public final class ModdedStudioCommands {
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> hotload(context.getSource()))));
|
||||
root.then(NativeCommandRegistration.literal("refresh")
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> hotload(context.getSource()))));
|
||||
root.then(regenTree("regen"));
|
||||
root.then(regenTree("rg"));
|
||||
root.then(workspaceTree("vscode", true));
|
||||
root.then(workspaceTree("vsc", true));
|
||||
root.then(workspaceTree("update", false));
|
||||
@@ -212,13 +210,6 @@ public final class ModdedStudioCommands {
|
||||
STUDIOS.clear();
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<NativeCommandSource> regenTree(String name) {
|
||||
return NativeCommandRegistration.literal(name)
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> IrisModdedCommands.regen(context.getSource(), 0)))
|
||||
.then(NativeCommandRegistration.argument("radius", IntegerArgumentType.integer(0, 64))
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> IrisModdedCommands.regen(context.getSource(), IntegerArgumentType.getInteger(context, "radius")))));
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<NativeCommandSource> openTree(String name) {
|
||||
return NativeCommandRegistration.literal(name)
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> openHelp(context.getSource())))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.DimensionStackLayout;
|
||||
@@ -207,7 +206,6 @@ public class ModdedBiomePolicyTest {
|
||||
when(router.openCoordinateScope(anyInt(), anyInt())).thenReturn(scope);
|
||||
IrisEngine engine = mock(IrisEngine.class);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
|
||||
-17
@@ -206,23 +206,6 @@ public class IrisModdedCommandParityTest {
|
||||
assertNotNull("pack cp", child(child(iris, "pk"), "cp").getCommand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regenLivesUnderStudio() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
CommandDispatcher<CommandSourceStack> dispatcher = new CommandDispatcher<>();
|
||||
|
||||
IrisModdedCommands.register(new NativeCommandRegistration(dispatcher));
|
||||
|
||||
CommandNode<CommandSourceStack> iris = child(dispatcher.getRoot(), "iris");
|
||||
assertNotNull("std regen", child(child(iris, "std"), "regen").getCommand());
|
||||
assertNotNull("studio rg radius", child(child(child(iris, "studio"), "rg"), "radius").getCommand());
|
||||
assertNull("top-level regen", iris.getChild("regen"));
|
||||
assertNull("top-level rg", iris.getChild("rg"));
|
||||
assertTrue(ModdedCommandHelp.consoleLines("studio").stream().anyMatch((String line) ->
|
||||
line.startsWith("/iris studio regen [radius] (rg) - ")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consoleHelpListsEveryEntryWithInlineUsageAndDescription() {
|
||||
List<String> root = ModdedCommandHelp.consoleLines("");
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.nativegen;
|
||||
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.structure.nativegen.IrisStructurePolicy;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructureReferenceRepair;
|
||||
@@ -440,7 +439,7 @@ public class NativeStructureReferenceRepairTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationScope openGenerationScope(
|
||||
public GenerationHistoryRuntimeRouter.CoordinateScope openGenerationHistoryCoordinateScope(
|
||||
int blockX,
|
||||
int blockZ
|
||||
) {
|
||||
|
||||
@@ -105,7 +105,7 @@ repositories {
|
||||
name = 'NeoForged'
|
||||
url = uri('https://maven.neoforged.net/releases/')
|
||||
}
|
||||
maven { url = uri('https://repo.codemc.org/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.io/repository/maven-public/') }
|
||||
maven { url = uri('https://jitpack.io') }
|
||||
maven { url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/') }
|
||||
}
|
||||
@@ -304,7 +304,6 @@ tasks.named('shadowJar', ShadowJar).configure {
|
||||
if ((int) irisModTarget.java == 21) {
|
||||
exclude(java21RuntimeExclusions)
|
||||
}
|
||||
exclude('META-INF/maven/**')
|
||||
exclude('META-INF/proguard/**')
|
||||
exclude('META-INF/*.SF')
|
||||
exclude('META-INF/*.DSA')
|
||||
@@ -361,6 +360,7 @@ tasks.named('assemble').configure {
|
||||
}
|
||||
|
||||
pluginPackaging {
|
||||
nativeBoundaryChecks = true
|
||||
artifacts {
|
||||
create('distribution') {
|
||||
taskName = 'shadowJar'
|
||||
|
||||
+7
-8
@@ -1,5 +1,4 @@
|
||||
import art.arcane.volmit.packaging.PackedJar
|
||||
import art.arcane.volmit.packaging.PackagingMode
|
||||
import art.arcane.volmit.packaging.NativeDevelopmentTargets
|
||||
import io.papermc.paperweight.userdev.PaperweightUser
|
||||
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension
|
||||
@@ -654,7 +653,7 @@ allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri('https://repo.papermc.io/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.org/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.io/repository/maven-public/') }
|
||||
|
||||
maven {
|
||||
url = uri('https://jitpack.io')
|
||||
@@ -759,11 +758,6 @@ pluginPackaging {
|
||||
packedJarAccessors = ['art/arcane/iris/platform/bukkit/plugin/VolmitPlugin#getJarFile']
|
||||
packedPayloadOnlyPrefixes = ['iris-language-guides/', 'META-INF/iris/generation-kernels/abi-', 'iris/icons/views/', 'iris/datapack/']
|
||||
packedMaximumBootstrapClasses = 90
|
||||
stripDirectories = true
|
||||
stripLocalVariables = true
|
||||
releaseCompression = providers.gradleProperty('compactRelease')
|
||||
.map { String value -> value.toBoolean() }
|
||||
.getOrElse(!PackagingMode.resolve(providers).development())
|
||||
prunePrefixes = ['art/arcane/volmlib/']
|
||||
keepPrefixes = ['art/arcane/volmlib/util/matter/slices/', 'art/arcane/volmlib/nativelib/']
|
||||
shrinkRules = [file('packaging/shrink.pro'), nativeRuntimeRules.get().asFile]
|
||||
@@ -1010,7 +1004,12 @@ tasks.withType(PackedJar).configureEach {
|
||||
dependsOn(tasks.named('verifyBukkitArtifact'), nativeRuntime)
|
||||
nativeArtifacts.set(providers.provider { embeddedNatives() })
|
||||
doLast { PackedJar task ->
|
||||
NativeRuntimeArtifacts.verifyPacked(task.outputJar.get().asFile, nativeRuntimeModules, embeddedNatives())
|
||||
File artifact = task.outputJar.get().asFile
|
||||
Map<String, byte[]> outer = NativeRuntimeArtifacts.entries(artifact)
|
||||
Map<String, byte[]> runtime = outer.containsKey('META-INF/volmit/runtime.properties')
|
||||
? PackedJar.readRuntime(artifact.toPath()) : outer
|
||||
NativeRuntimeArtifacts.verifyPacked(runtime, outer.get(NativeRuntimeArtifacts.MANIFEST), nativeRuntimeModules,
|
||||
embeddedNatives())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ dependencies {
|
||||
implementation(gradleApi())
|
||||
implementation('org.ow2.asm:asm:9.10.1')
|
||||
implementation('org.apache.commons:commons-compress:1.28.0')
|
||||
implementation('org.tukaani:xz:1.10')
|
||||
implementation('io.papermc.paperweight:paperweight-userdev:2.0.0-beta.21')
|
||||
testImplementation('junit:junit:4.13.2')
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import org.gradle.api.GradleException;
|
||||
import org.tukaani.xz.XZInputStream;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
@@ -28,7 +27,6 @@ import java.util.zip.ZipInputStream;
|
||||
public final class NativeRuntimeArtifacts {
|
||||
public static final String MANIFEST = "META-INF/iris/native-runtime.properties";
|
||||
public static final String RESOURCES = "META-INF/iris/native/";
|
||||
private static final String PAYLOAD = "META-INF/volmit/runtime.jar.xz";
|
||||
private static final String GROUP = "com.github.VolmitSoftware.VolmLib";
|
||||
private static final String NATIVE = "art/arcane/volmlib/nativelib/";
|
||||
|
||||
@@ -99,35 +97,20 @@ public final class NativeRuntimeArtifacts {
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyPacked(File artifact, List<String> modules, Map<String, File> natives) throws IOException {
|
||||
/** Checks the native providers inside {@code runtime}, the entries the plugin runs from, against the resolved build. */
|
||||
public static void verifyPacked(Map<String, byte[]> runtime, byte[] outerManifest, List<String> modules,
|
||||
Map<String, File> natives) throws IOException {
|
||||
requireModules(natives, modules);
|
||||
Map<String, byte[]> contents;
|
||||
try (JarFile jar = new JarFile(artifact)) {
|
||||
JarEntry payload = jar.getJarEntry(PAYLOAD);
|
||||
if (payload == null) {
|
||||
contents = read(Files.newInputStream(artifact.toPath()));
|
||||
} else {
|
||||
try (InputStream input = new XZInputStream(jar.getInputStream(payload))) {
|
||||
contents = read(new ByteArrayInputStream(input.readAllBytes()));
|
||||
}
|
||||
JarEntry outer = jar.getJarEntry(MANIFEST);
|
||||
byte[] embedded = contents.get(MANIFEST);
|
||||
if (outer != null && embedded != null) {
|
||||
try (InputStream input = jar.getInputStream(outer)) {
|
||||
if (!Arrays.equals(input.readAllBytes(), embedded)) {
|
||||
throw new GradleException("Packed native runtime manifests differ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
byte[] manifest = contents.get(MANIFEST);
|
||||
byte[] manifest = runtime.get(MANIFEST);
|
||||
if (manifest == null) {
|
||||
throw new GradleException("Missing native runtime dependency manifest");
|
||||
}
|
||||
if (outerManifest != null && !Arrays.equals(outerManifest, manifest)) {
|
||||
throw new GradleException("Packed native runtime manifests differ");
|
||||
}
|
||||
verifyManifest(manifest, natives);
|
||||
for (String module : natives.keySet()) {
|
||||
byte[] provider = contents.get(RESOURCES + module + ".jar");
|
||||
byte[] provider = runtime.get(RESOURCES + module + ".jar");
|
||||
if (provider == null) {
|
||||
throw new GradleException("Missing embedded native provider: " + module);
|
||||
}
|
||||
@@ -137,6 +120,18 @@ public final class NativeRuntimeArtifacts {
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, byte[]> entries(File artifact) throws IOException {
|
||||
Map<String, byte[]> contents = new TreeMap<>();
|
||||
try (ZipInputStream archive = new ZipInputStream(Files.newInputStream(artifact.toPath()))) {
|
||||
for (ZipEntry entry = archive.getNextEntry(); entry != null; entry = archive.getNextEntry()) {
|
||||
if (!entry.isDirectory()) {
|
||||
contents.put(entry.getName(), archive.readAllBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
private static void verifyManifest(byte[] bytes, Map<String, File> natives) throws IOException {
|
||||
Properties manifest = new Properties();
|
||||
manifest.load(new ByteArrayInputStream(bytes));
|
||||
@@ -163,18 +158,6 @@ public final class NativeRuntimeArtifacts {
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, byte[]> read(InputStream source) throws IOException {
|
||||
Map<String, byte[]> contents = new TreeMap<>();
|
||||
try (ZipInputStream archive = new ZipInputStream(source)) {
|
||||
for (ZipEntry entry = archive.getNextEntry(); entry != null; entry = archive.getNextEntry()) {
|
||||
if (!entry.isDirectory()) {
|
||||
contents.put(entry.getName(), archive.readAllBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
private static boolean implementation(String name) {
|
||||
if (!name.startsWith(NATIVE)) {
|
||||
return false;
|
||||
|
||||
@@ -4,13 +4,11 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.tukaani.xz.LZMA2Options;
|
||||
import org.tukaani.xz.XZOutputStream;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
@@ -22,6 +20,7 @@ import java.util.TreeMap;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
@@ -89,15 +88,35 @@ public class NativeRuntimeArtifactsTest {
|
||||
public void verifiesTheEmbeddedProviderBytesInsideThePackedRuntime() throws Exception {
|
||||
Map<String, File> natives = natives();
|
||||
Map<String, byte[]> runtime = runtime(natives, natives);
|
||||
NativeRuntimeArtifacts.verifyPacked(packed(runtime), MODULES, natives);
|
||||
NativeRuntimeArtifacts.verifyPacked(jar("ordinary.jar", runtime), MODULES, natives);
|
||||
byte[] manifest = runtime.get(NativeRuntimeArtifacts.MANIFEST);
|
||||
NativeRuntimeArtifacts.verifyPacked(runtime, manifest, MODULES, natives);
|
||||
NativeRuntimeArtifacts.verifyPacked(runtime, null, MODULES, natives);
|
||||
Map<String, File> rebuilt = new TreeMap<>(natives);
|
||||
rebuilt.put("native-v26_2_R1", provider("rebuilt.jar", "art/arcane/volmlib/util/collection/KMap"));
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(packed(runtime(natives, rebuilt)),
|
||||
MODULES, natives));
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(runtime(natives, rebuilt),
|
||||
manifest, MODULES, natives));
|
||||
Map<String, byte[]> missing = new TreeMap<>(runtime);
|
||||
missing.remove(NativeRuntimeArtifacts.RESOURCES + "native-v26_2_R1.jar");
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(packed(missing), MODULES, natives));
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(missing, manifest, MODULES, natives));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsAnOuterManifestThatDiffersFromTheRuntimeOne() throws Exception {
|
||||
Map<String, File> natives = natives();
|
||||
Map<String, byte[]> runtime = runtime(natives, natives);
|
||||
byte[] outer = (new String(runtime.get(NativeRuntimeArtifacts.MANIFEST), StandardCharsets.UTF_8) + "extra=1\n")
|
||||
.getBytes(StandardCharsets.UTF_8);
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(runtime, outer, MODULES, natives));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readsEveryFileEntryOfAnOrdinaryJar() throws Exception {
|
||||
Map<String, byte[]> runtime = runtime(natives(), natives());
|
||||
Map<String, byte[]> read = NativeRuntimeArtifacts.entries(jar("ordinary.jar", runtime));
|
||||
assertEquals(runtime.keySet(), read.keySet());
|
||||
for (Map.Entry<String, byte[]> entry : runtime.entrySet()) {
|
||||
assertArrayEquals(entry.getValue(), read.get(entry.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, File> natives() throws IOException {
|
||||
@@ -137,17 +156,6 @@ public class NativeRuntimeArtifactsTest {
|
||||
return contents;
|
||||
}
|
||||
|
||||
private File packed(Map<String, byte[]> runtime) throws IOException {
|
||||
ByteArrayOutputStream compressed = new ByteArrayOutputStream();
|
||||
try (XZOutputStream xz = new XZOutputStream(compressed, new LZMA2Options(1))) {
|
||||
xz.write(Files.readAllBytes(jar("payload.jar", runtime).toPath()));
|
||||
}
|
||||
Map<String, byte[]> outer = new TreeMap<>();
|
||||
outer.put(NativeRuntimeArtifacts.MANIFEST, runtime.get(NativeRuntimeArtifacts.MANIFEST));
|
||||
outer.put("META-INF/volmit/runtime.jar.xz", compressed.toByteArray());
|
||||
return jar("packed.jar", outer);
|
||||
}
|
||||
|
||||
private File jar(String name, Map<String, byte[]> contents) throws IOException {
|
||||
Path file = temporary.newFolder().toPath().resolve(name);
|
||||
try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(file))) {
|
||||
|
||||
@@ -400,7 +400,7 @@ public class IrisSettings {
|
||||
@Data
|
||||
public static class IrisSettingsStudio {
|
||||
public boolean openVSCode = true;
|
||||
public boolean keepPackVersions = false;
|
||||
public boolean blendChanges = true;
|
||||
public boolean disableTimeAndWeather = true;
|
||||
public boolean entitySpawning = true;
|
||||
public boolean autoStartDefaultStudio = false;
|
||||
|
||||
@@ -18,27 +18,37 @@
|
||||
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.runtime.SeedTable;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
|
||||
/**
|
||||
* What one engine derives from an {@link IrisBiomePaletteLayer}: the block selection and depth generators of the
|
||||
* seeds that sample it.
|
||||
* seeds that sample it. A column walk asks for one layer seed per depth, so the layer table holds the layer's whole
|
||||
* thickness for a few parent seeds instead of rebuilding a generator on every depth step.
|
||||
*/
|
||||
public final class PaletteLayerRuntime {
|
||||
private static final int LAYER_SEED_CAPACITY = 32;
|
||||
private static final int LAYER_RECENT_SLOTS = 32;
|
||||
private static final int MAX_LAYER_RECENT_SLOTS = 4096;
|
||||
private static final int PARENT_SEEDS_PER_LAYER = 4;
|
||||
private static final int HEIGHT_SEED_CAPACITY = 32;
|
||||
|
||||
private final PackRuntime runtime;
|
||||
private final SeedTable<CNG> layerGenerators;
|
||||
private final SeedTable<CNG> heightGenerators;
|
||||
private final boolean shareGenerator;
|
||||
|
||||
public PaletteLayerRuntime(IrisBiomePaletteLayer layer, PackRuntime runtime) {
|
||||
this.runtime = runtime;
|
||||
this.layerGenerators = new SeedTable<>(LAYER_SEED_CAPACITY, LAYER_RECENT_SLOTS,
|
||||
seed -> layer.createLayerGenerator(seed, runtime));
|
||||
IrisGeneratorStyle style = layer.getStyle();
|
||||
// A seeded style rolls from its own seed and the world seed, never the caller's, so every depth builds the same noise.
|
||||
this.shareGenerator = style != null
|
||||
&& (style.isSeeded() || style.canShareExpressionGenerator(runtime.data()));
|
||||
int depthSeeds = Math.max(1, Math.max(layer.getMinHeight(), layer.getMaxHeight()));
|
||||
this.layerGenerators = new SeedTable<>(Math.max(LAYER_SEED_CAPACITY, depthSeeds * PARENT_SEEDS_PER_LAYER),
|
||||
recentSlots(depthSeeds), seed -> layer.createLayerGenerator(seed, runtime));
|
||||
this.heightGenerators = new SeedTable<>(HEIGHT_SEED_CAPACITY, IrisBiomePaletteLayer::createHeightGenerator);
|
||||
}
|
||||
|
||||
@@ -48,10 +58,16 @@ public final class PaletteLayerRuntime {
|
||||
}
|
||||
|
||||
public CNG layerGenerator(long seed) {
|
||||
return layerGenerators.get(seed);
|
||||
return layerGenerators.get(shareGenerator ? 0L : seed);
|
||||
}
|
||||
|
||||
public CNG heightGenerator(long seed) {
|
||||
return heightGenerators.get(seed);
|
||||
}
|
||||
|
||||
/** Consecutive depth seeds land in distinct slots when the slot count covers the thickness. */
|
||||
private static int recentSlots(int depthSeeds) {
|
||||
int covering = Integer.highestOneBit(Math.min(depthSeeds, MAX_LAYER_RECENT_SLOTS) - 1) << 1;
|
||||
return Math.clamp(covering, LAYER_RECENT_SLOTS, MAX_LAYER_RECENT_SLOTS);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.context.IrisContext;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.runtime.BiomeEnvironment;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.SavedBiomeRuntime;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionException;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionLease;
|
||||
@@ -19,6 +20,7 @@ import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.world.history.GenerationSemanticIndex;
|
||||
import art.arcane.iris.world.history.GenerationSemanticQueries;
|
||||
import art.arcane.iris.world.history.GenerationFindCatalog;
|
||||
import art.arcane.iris.world.history.GenerationHistory;
|
||||
import art.arcane.iris.world.history.ChunkGenerationSemantics;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeWorld;
|
||||
@@ -166,8 +168,8 @@ public final class BiomeLocator implements Locator<IrisBiome> {
|
||||
|
||||
@Override
|
||||
public SearchCandidate nearestRecordedCandidate(Engine engine, Position2 origin, int maximumRadius) {
|
||||
GenerationSource source = GenerationLocatorPolicy.source(engine);
|
||||
if (!source.keepsPackVersions()) {
|
||||
GenerationHistory history = GenerationLocatorPolicy.history(engine).orElse(null);
|
||||
if (history == null) {
|
||||
return null;
|
||||
}
|
||||
Set<Position2> rejected = new HashSet<>();
|
||||
@@ -176,7 +178,7 @@ public final class BiomeLocator implements Locator<IrisBiome> {
|
||||
new ChunkGenerationSemantics.BlockPosition((origin.getX() << 4) + 8, originWorldY,
|
||||
(origin.getZ() << 4) + 8), maximumRadius);
|
||||
while (!engine.isClosing() && !Thread.currentThread().isInterrupted() && System.nanoTime() < searchDeadline) {
|
||||
GenerationSemanticIndex.Match match = source.recordedChunks().findNearest(query,
|
||||
GenerationSemanticIndex.Match match = history.findRecorded(query,
|
||||
record -> !rejected.contains(new Position2(record.chunkX(), record.chunkZ()))).orElse(null);
|
||||
if (match == null) {
|
||||
return null;
|
||||
@@ -234,7 +236,7 @@ public final class BiomeLocator implements Locator<IrisBiome> {
|
||||
|
||||
public SubterrainPosition position(Engine engine, Position2 chunk) {
|
||||
if (authoredTarget != null || cavernTargets.containsKey(chunk) || surfaceTargets.contains(chunk) || authored
|
||||
|| GenerationLocatorPolicy.generatesWithActivePack(engine, chunk)) {
|
||||
|| activePredictionWithoutHistory(engine, chunk)) {
|
||||
return position(engine, chunk, Optional.empty());
|
||||
}
|
||||
try {
|
||||
@@ -324,8 +326,26 @@ public final class BiomeLocator implements Locator<IrisBiome> {
|
||||
return GenerationSemanticQueries.drySubterrainLanding(engine, candidate, running).orElse(null);
|
||||
}
|
||||
|
||||
private static boolean activePredictionWithoutHistory(Engine engine, Position2 chunk) {
|
||||
if (!(engine instanceof IrisEngine irisEngine)) {
|
||||
return true;
|
||||
}
|
||||
GenerationHistoryRuntimeRouter router = irisEngine.getGenerationHistoryRuntimeRouter().orElse(null);
|
||||
if (router == null) {
|
||||
return true;
|
||||
}
|
||||
GenerationHistory history = router.history();
|
||||
return history.isActiveUnowned(chunk.getX(), chunk.getZ()) && history.semantics(chunk.getX(), chunk.getZ()).isEmpty();
|
||||
}
|
||||
|
||||
public CompletableFuture<Optional<SavedBiomeRuntime.ReadSession>> prepareRead(Engine engine, Position2 chunk) {
|
||||
return GenerationLocatorPolicy.source(engine).savedBiomes().readChunk(chunk.getX(), chunk.getZ());
|
||||
if (engine instanceof IrisEngine irisEngine) {
|
||||
GenerationHistoryRuntimeRouter router = irisEngine.getGenerationHistoryRuntimeRouter().orElse(null);
|
||||
if (router != null) {
|
||||
return router.biomes().readChunkAsync(chunk.getX(), chunk.getZ()).thenApply(Optional::of);
|
||||
}
|
||||
}
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
}
|
||||
|
||||
public SubterrainPosition landing(Engine engine, NativeWorld world, SubterrainPosition target,
|
||||
|
||||
@@ -5,8 +5,8 @@ import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.world.history.ChunkGenerationSemantics;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.GenerationHistory;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.GenerationSemanticIndex;
|
||||
import art.arcane.volmlib.util.math.Position2;
|
||||
|
||||
@@ -66,7 +66,11 @@ final class HistoryAwareLocator<T> implements Locator<T> {
|
||||
|
||||
@Override
|
||||
public SearchCandidate nearestRecordedCandidate(Engine engine, Position2 origin, int maxChunkRadius) {
|
||||
GenerationSemanticIndex.Match match = GenerationLocatorPolicy.source(engine).recordedChunks().findNearest(
|
||||
GenerationHistory history = GenerationLocatorPolicy.history(engine).orElse(null);
|
||||
if (history == null) {
|
||||
return null;
|
||||
}
|
||||
GenerationSemanticIndex.Match match = history.findRecorded(
|
||||
GenerationSemanticIndex.Query.acrossActivations(
|
||||
kind,
|
||||
key,
|
||||
@@ -76,8 +80,7 @@ final class HistoryAwareLocator<T> implements Locator<T> {
|
||||
blockCenter(origin.getZ())
|
||||
),
|
||||
maxChunkRadius
|
||||
),
|
||||
recorded -> true
|
||||
)
|
||||
).orElse(null);
|
||||
if (match == null) {
|
||||
return null;
|
||||
@@ -133,27 +136,40 @@ final class GenerationLocatorPolicy {
|
||||
private GenerationLocatorPolicy() {
|
||||
}
|
||||
|
||||
static GenerationSource source(Engine engine) {
|
||||
return engine instanceof IrisEngine irisEngine ? irisEngine.getGenerationSource() : GenerationSource.singlePack();
|
||||
static Optional<GenerationHistory> history(Engine engine) {
|
||||
if (!(engine instanceof IrisEngine irisEngine)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return irisEngine.getGenerationHistoryRuntimeRouter()
|
||||
.map(GenerationHistoryRuntimeRouter::history);
|
||||
}
|
||||
|
||||
static Optional<ChunkGenerationSemantics> recorded(Engine engine, Position2 chunk) {
|
||||
return source(engine).recordedChunks().semantics(chunk.getX(), chunk.getZ());
|
||||
GenerationHistory history = history(engine).orElse(null);
|
||||
if (history == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return history.semantics(chunk.getX(), chunk.getZ())
|
||||
.filter(ChunkGenerationSemantics::sealed);
|
||||
}
|
||||
|
||||
static boolean allowsActivePrediction(Engine engine, Position2 chunk) {
|
||||
if (!engine.getComplex().allowsNewGenerationChunk(chunk.getX(), chunk.getZ())) {
|
||||
return false;
|
||||
}
|
||||
return generatesWithActivePack(engine, chunk);
|
||||
}
|
||||
|
||||
static boolean generatesWithActivePack(Engine engine, Position2 chunk) {
|
||||
return !source(engine).recordedChunks().ownedByEarlierPack(chunk.getX(), chunk.getZ()) && recorded(engine, chunk).isEmpty();
|
||||
GenerationHistory history = history(engine).orElse(null);
|
||||
if (history == null) {
|
||||
return true;
|
||||
}
|
||||
return history.isActiveUnowned(chunk.getX(), chunk.getZ())
|
||||
&& recorded(engine, chunk).isEmpty();
|
||||
}
|
||||
|
||||
static boolean allowsHistoricalFallback(Engine engine, Position2 chunk) {
|
||||
return source(engine).recordedChunks().ownedByEarlierPack(chunk.getX(), chunk.getZ()) && recorded(engine, chunk).isEmpty();
|
||||
GenerationHistory history = history(engine).orElse(null);
|
||||
return history != null
|
||||
&& history.isHistoricallyOwned(chunk.getX(), chunk.getZ())
|
||||
&& recorded(engine, chunk).isEmpty();
|
||||
}
|
||||
|
||||
static boolean allowsProceduralPrediction(Engine engine, Position2 chunk) {
|
||||
@@ -168,7 +184,8 @@ final class GenerationLocatorPolicy {
|
||||
if (radius < 0) {
|
||||
throw new IllegalArgumentException("Historical fallback radius cannot be negative.");
|
||||
}
|
||||
return source(engine).recordedChunks().hasUnrecordedEarlierPackChunkInSquare(center.getX(), center.getZ(), radius);
|
||||
GenerationHistory history = history(engine).orElse(null);
|
||||
return history != null && history.hasHistoricalFallbackInSquare(center.getX(), center.getZ(), radius);
|
||||
}
|
||||
|
||||
static boolean evaluateScoped(
|
||||
@@ -182,7 +199,8 @@ final class GenerationLocatorPolicy {
|
||||
}
|
||||
int blockX = Math.multiplyExact(chunk.getX(), 16);
|
||||
int blockZ = Math.multiplyExact(chunk.getZ(), 16);
|
||||
try (GenerationScope ignored = irisEngine.openGenerationScope(blockX, blockZ)) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
irisEngine.openGenerationHistoryCoordinateScope(blockX, blockZ)) {
|
||||
return requiredQuery.getAsBoolean();
|
||||
} catch (IOException exception) {
|
||||
throw new IllegalStateException("Unable to scope an Iris locator query at chunk "
|
||||
@@ -201,7 +219,8 @@ final class GenerationLocatorPolicy {
|
||||
}
|
||||
int blockX = Math.multiplyExact(chunk.getX(), 16);
|
||||
int blockZ = Math.multiplyExact(chunk.getZ(), 16);
|
||||
try (GenerationScope ignored = irisEngine.openGenerationScope(blockX, blockZ)) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
irisEngine.openGenerationHistoryCoordinateScope(blockX, blockZ)) {
|
||||
return requiredQuery.get();
|
||||
} catch (IOException exception) {
|
||||
throw new IllegalStateException("Unable to scope an Iris locator query at chunk "
|
||||
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.generation.noise;
|
||||
import art.arcane.iris.generation.image.IrisImageMap;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.loading.ResourceLoader;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.world.history.GenerationKernelRegistry;
|
||||
@@ -42,7 +43,9 @@ import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Snippet("style")
|
||||
@@ -99,6 +102,46 @@ public class IrisGeneratorStyle {
|
||||
return createNoCache(rng, runtime, 1, 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this style can share an expression generator across caller seeds within a pack runtime.
|
||||
*/
|
||||
public boolean canShareExpressionGenerator(IrisData data) {
|
||||
return expression != null && canShareExpressionGenerator(data, new HashSet<>());
|
||||
}
|
||||
|
||||
private boolean canShareExpressionGenerator(IrisData data, Set<String> activeExpressions) {
|
||||
if (getClass() != IrisGeneratorStyle.class || expression == null || data == null
|
||||
|| fracture != null || cellularFrequency != 0D || cacheSize != 0
|
||||
|| !activeExpressions.add(expression)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
ResourceLoader<IrisExpression> loader = data.getExpressionLoader();
|
||||
IrisExpression source = loader == null ? null : loader.load(expression);
|
||||
if (source == null || source.getClass() != IrisExpression.class
|
||||
|| source.getVariables() == null || source.getFunctions() == null) {
|
||||
return false;
|
||||
}
|
||||
for (IrisExpressionLoad variable : source.getVariables()) {
|
||||
if (variable.getEngineValue() != null || variable.getEngineStreamValue() != null
|
||||
|| (variable.getStyleValue() != null
|
||||
&& !variable.getStyleValue().canShareExpressionGenerator(data, activeExpressions))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (IrisExpressionFunction function : source.getFunctions()) {
|
||||
if (function.getEngineStreamValue() != null || function.getStyleValue() == null
|
||||
|| !function.getStyleValue().canShareExpressionGenerator(data, activeExpressions)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
activeExpressions.remove(expression);
|
||||
}
|
||||
}
|
||||
|
||||
public CNG createScaledGenerator(RNG rng, PackRuntime runtime, double scaleFactor) {
|
||||
return createNoCache(rng, runtime).bake().scale(scaleFactor).bake();
|
||||
}
|
||||
|
||||
@@ -258,9 +258,11 @@ final class EngineHotloader {
|
||||
throw new IllegalStateException("Studio engine changed while its generation cutover was draining.");
|
||||
}
|
||||
engine.prepareRuntimeHotload();
|
||||
int transitionWidth = IrisSettings.get().getGenerator().getGenerationTransitionWidthBlocks();
|
||||
history.stageUpdateReplacingStalePending(update.source(), update.fingerprint(),
|
||||
update.dimensionContract(), update.registryContract(), transitionWidth);
|
||||
IrisSettings settings = IrisSettings.get();
|
||||
int transitionWidth = settings.getStudio().isBlendChanges()
|
||||
? settings.getGenerator().getGenerationTransitionWidthBlocks() : 0;
|
||||
history.stageUpdate(update.source(), update.fingerprint(), update.dimensionContract(),
|
||||
update.registryContract(), transitionWidth);
|
||||
}
|
||||
long stagedAt = System.nanoTime();
|
||||
cutover.promotePending();
|
||||
|
||||
@@ -27,6 +27,7 @@ import art.arcane.iris.generation.mantle.ObjectContinuationPersistence;
|
||||
import art.arcane.iris.generation.stage.IrisDimensionStackActuator;
|
||||
import art.arcane.iris.generation.stage.IrisTransitionGeometryActuator;
|
||||
import art.arcane.iris.world.history.FloatingBiomeOverlay;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.SavedTerrainChunk;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBiome;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -234,9 +235,17 @@ public interface EngineMode extends Staged {
|
||||
if (!(getEngine() instanceof IrisEngine irisEngine)) {
|
||||
return List.of();
|
||||
}
|
||||
GenerationHistoryRuntimeRouter router = irisEngine.getGenerationHistoryRuntimeRouter().orElse(null);
|
||||
if (router == null) {
|
||||
return List.of();
|
||||
}
|
||||
List<GenerationHistoryRuntimeRouter.ObjectContinuation> fragments = router.objectContinuations(
|
||||
getComplex().getTransitionGenerationPlan(), x >> 4, z >> 4);
|
||||
if (fragments.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
try {
|
||||
List<Matter> continuations = irisEngine.getGenerationSource().transitions().objectContinuations(
|
||||
getComplex().getTransitionGenerationPlan(), x >> 4, z >> 4);
|
||||
List<Matter> continuations = router.decodeObjectContinuations(fragments);
|
||||
for (Matter continuation : continuations) {
|
||||
if (continuation.getHeight() != getEngine().getHeight()) {
|
||||
throw new IOException("Object continuation height does not match the world");
|
||||
@@ -255,8 +264,8 @@ public interface EngineMode extends Staged {
|
||||
if (!(getEngine() instanceof IrisEngine irisEngine)) {
|
||||
return;
|
||||
}
|
||||
GenerationSource source = irisEngine.getGenerationSource();
|
||||
if (!source.keepsPackVersions()) {
|
||||
GenerationHistoryRuntimeRouter router = irisEngine.getGenerationHistoryRuntimeRouter().orElse(null);
|
||||
if (router == null) {
|
||||
return;
|
||||
}
|
||||
FloatingBiomeOverlay floating = context.getFloatingBiomes();
|
||||
@@ -274,7 +283,8 @@ public interface EngineMode extends Staged {
|
||||
try {
|
||||
SavedTerrainChunk terrain = IrisTransitionGeometryActuator.capture(
|
||||
x, z, blocks, biomes, getEngine().getMinHeight(), context, true);
|
||||
source.transitions().recordNaturalTerrain(terrain, floating);
|
||||
router.recordNaturalTerrain(terrain);
|
||||
router.recordFloatingBiomes(x >> 4, z >> 4, floating);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Unable to capture natural terrain at " + (x >> 4) + "," + (z >> 4), failure);
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeGenerationRoute;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A native chunk generation pass routed to the activation that owns the chunk.
|
||||
*/
|
||||
public interface GenerationRoute extends NativeGenerationRoute {
|
||||
long activationId();
|
||||
|
||||
/**
|
||||
* @return the receipt for the natural terrain this pass captured, or null when it captured none
|
||||
*/
|
||||
byte[] naturalTerrainReceipt() throws IOException;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeGenerationScope;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Binds the calling thread to the pack that owns one column until closed.
|
||||
*/
|
||||
public interface GenerationScope extends NativeGenerationScope {
|
||||
/**
|
||||
* Records what the scoped chunk generated, when its pack keeps a record.
|
||||
*
|
||||
* @return true when this call recorded the chunk
|
||||
*/
|
||||
boolean claimGeneratedSemantics() throws IOException;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.world.history.GenerationBoundary;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Answers which pack generated, or will generate, a chunk. A single-pack world always answers the current pack. A
|
||||
* versioned world keeps every earlier pack version and routes each chunk to the one that owns it.
|
||||
*/
|
||||
public interface GenerationSource {
|
||||
static GenerationSource singlePack() {
|
||||
return SinglePackGenerationSource.INSTANCE;
|
||||
}
|
||||
|
||||
/** True when chunks may belong to an earlier pack version than the one loaded now. */
|
||||
boolean keepsPackVersions();
|
||||
|
||||
GenerationScope openGenerationScope(int blockX, int blockZ) throws IOException;
|
||||
|
||||
/** Like {@link #openGenerationScope(int, int)}, but may borrow the runtime the thread is already bound to. */
|
||||
GenerationScope openReadScope(int blockX, int blockZ) throws IOException;
|
||||
|
||||
/** @return null when every chunk generates with the current pack and needs no route */
|
||||
GenerationRoute openRoute(int chunkX, int chunkZ) throws IOException;
|
||||
|
||||
/** The activation and runtime the calling thread generates for, while it holds a route. */
|
||||
Optional<RouteOwnership> currentRouteOwnership();
|
||||
|
||||
boolean predatesActivePack(long activationId);
|
||||
|
||||
/** Lets the current pack regenerate these chunks, whichever pack generated them before. */
|
||||
void releaseForRegeneration(List<GenerationBoundary.ChunkCoordinate> chunks) throws IOException;
|
||||
|
||||
void sync() throws IOException;
|
||||
|
||||
SavedBiomes savedBiomes();
|
||||
|
||||
RecordedChunks recordedChunks();
|
||||
|
||||
PackTransitions transitions();
|
||||
|
||||
record RouteOwnership(long activationId, IrisEngine.GenerationRuntimeBinding binding) {
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,8 @@ import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.image.IrisImageMapApplication;
|
||||
import art.arcane.iris.generation.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.generation.mantle.ObjectContinuationBundle;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.generation.terrain.InferredType;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisBiomeGeneratorLink;
|
||||
@@ -1722,7 +1724,7 @@ public class IrisComplex implements DataProvider {
|
||||
|
||||
public boolean isHistoricalChunk(int chunkX, int chunkZ) {
|
||||
return transitionGenerationPlan != null
|
||||
&& transitionGenerationPlan.isHistoricalChunk(chunkX, chunkZ);
|
||||
&& transitionGenerationPlan.boundary().isHistoricalChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
public boolean allowsMantleWrite(int blockX, int blockZ) {
|
||||
@@ -1732,7 +1734,7 @@ public class IrisComplex implements DataProvider {
|
||||
|
||||
public boolean allowsMantleChunkWrite(int chunkX, int chunkZ) {
|
||||
return transitionGenerationPlan == null
|
||||
|| !transitionGenerationPlan.isHistoricalChunk(chunkX, chunkZ);
|
||||
|| !transitionGenerationPlan.boundary().isHistoricalChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
public boolean allowsNewDiscreteContentAt(int blockX, int blockZ) {
|
||||
@@ -1765,8 +1767,10 @@ public class IrisComplex implements DataProvider {
|
||||
if (!transitionGenerationPlan.allowsNewFootprint(minimumX, minimumZ, maximumX, maximumZ)) {
|
||||
return false;
|
||||
}
|
||||
return !(terrainEngine instanceof IrisEngine irisEngine) || irisEngine.getGenerationSource()
|
||||
.transitions().allowsObjectFootprint(transitionGenerationPlan, minimumX, minimumZ, maximumX, maximumZ);
|
||||
GenerationHistoryRuntimeRouter router = terrainEngine instanceof IrisEngine irisEngine
|
||||
? irisEngine.getGenerationHistoryRuntimeRouter().orElse(null) : null;
|
||||
return router == null || router.allowsObjectFootprint(transitionGenerationPlan,
|
||||
new ObjectContinuationBundle.Bounds(minimumX, minimumZ, maximumX, maximumZ));
|
||||
}
|
||||
|
||||
public Optional<String> historicalPhysicalBiomeKeyAt(int blockX, int blockY, int blockZ) {
|
||||
|
||||
@@ -30,7 +30,6 @@ import art.arcane.iris.structure.nativegen.NativeStructureOwnershipStore;
|
||||
import art.arcane.iris.world.history.GenerationBoundarySignatureSampler;
|
||||
import art.arcane.iris.world.history.GenerationHistory;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.world.history.ChunkGenerationSemantics;
|
||||
import art.arcane.iris.world.history.GenerationKernelRegistry;
|
||||
import art.arcane.iris.world.history.TransitionGenerationPlan;
|
||||
@@ -177,8 +176,9 @@ public class IrisEngine implements Engine {
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
volatile GenerationHistoryRuntimeRouter generationHistoryRuntimeRouter;
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private volatile GenerationSource generationSource = GenerationSource.singlePack();
|
||||
private volatile boolean generationHistoryRoutingRequired;
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private volatile SubterrainGate subterrainGate;
|
||||
@@ -499,7 +499,8 @@ public class IrisEngine implements Engine {
|
||||
@Override
|
||||
public void generateMatter(int x, int z, boolean multicore, ChunkContext context) {
|
||||
awaitGenerationCacheWarm();
|
||||
try (GenerationScope historyScope = openGenerationScope(x << 4, z << 4);
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope =
|
||||
openGenerationHistoryCoordinateScope(x << 4, z << 4);
|
||||
GenerationSessionLease lease = acquireGenerationLease("matter_generate");
|
||||
IrisContext.Scope ignored = IrisContext.open(this, lease.sessionId(), context)) {
|
||||
IrisComplex activeComplex = getComplex();
|
||||
@@ -524,12 +525,12 @@ public class IrisEngine implements Engine {
|
||||
if (!usesSavedBiomeEnvironment()) {
|
||||
return Engine.super.draw(x, z);
|
||||
}
|
||||
return getGenerationSource().savedBiomes().readSurface(x, z, saved -> {
|
||||
return generationHistoryRuntimeRouter.biomes().readSurfaceBiome(x, z, saved -> {
|
||||
if (saved.isPresent()) {
|
||||
return drawBiomeEnvironment(x, z, saved.get());
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "draw a pregeneration preview")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "draw a pregeneration preview")) {
|
||||
return Engine.super.draw(x, z);
|
||||
}
|
||||
});
|
||||
@@ -553,8 +554,8 @@ public class IrisEngine implements Engine {
|
||||
return CompletableFuture.completedFuture(getBiomeEnvironment(x, y, z));
|
||||
}
|
||||
int worldY = y + getWorld().minHeight();
|
||||
return getGenerationSource().savedBiomes().readChunk(Math.floorDiv(x, 16), Math.floorDiv(z, 16))
|
||||
.thenApply(read -> read.flatMap(session -> session.resolve(x, worldY, z, false))
|
||||
return generationHistoryRuntimeRouter.biomes().readChunkAsync(Math.floorDiv(x, 16), Math.floorDiv(z, 16))
|
||||
.thenApply(session -> session.resolve(x, worldY, z, false)
|
||||
.orElseGet(() -> resolveUnsavedBiomeEnvironment(x, y, z)));
|
||||
} catch (RuntimeException | Error failure) {
|
||||
return CompletableFuture.failedFuture(failure);
|
||||
@@ -567,8 +568,8 @@ public class IrisEngine implements Engine {
|
||||
if (saved.isPresent()) {
|
||||
return saved.get();
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a mantle biome environment")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a mantle biome environment")) {
|
||||
return Engine.super.getBiomeOrMantleEnvironment(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -579,8 +580,8 @@ public class IrisEngine implements Engine {
|
||||
if (saved.isPresent()) {
|
||||
return saved.get();
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a surface biome environment")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a surface biome environment")) {
|
||||
return Engine.super.getSurfaceBiomeEnvironment(x, z);
|
||||
}
|
||||
}
|
||||
@@ -594,8 +595,8 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
|
||||
private BiomeEnvironment resolveUnsavedBiomeEnvironment(int x, int y, int z) {
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a biome environment")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a biome environment")) {
|
||||
return Engine.super.getBiomeEnvironment(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -604,11 +605,11 @@ public class IrisEngine implements Engine {
|
||||
if (!usesSavedBiomeEnvironment()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return getGenerationSource().savedBiomes().at(x, y + getWorld().minHeight(), z, surface);
|
||||
return generationHistoryRuntimeRouter.biomes().resolve(x, y + getWorld().minHeight(), z, surface);
|
||||
}
|
||||
|
||||
private boolean usesSavedBiomeEnvironment() {
|
||||
if (hasGenerationRuntimeScope() || !getGenerationSource().keepsPackVersions()) {
|
||||
if (hasGenerationRuntimeScope() || generationHistoryRuntimeRouter == null) {
|
||||
return false;
|
||||
}
|
||||
IrisContext context = IrisContext.get();
|
||||
@@ -619,9 +620,10 @@ public class IrisEngine implements Engine {
|
||||
@Override
|
||||
public SubterrainCell getSubterrainCell(int x, int y, int z) {
|
||||
EngineThreadState.Frame frame = threadState.current();
|
||||
if ((frame == null || frame.binding == null) && getGenerationSource().keepsPackVersions()) {
|
||||
Optional<SubterrainCell> saved = generationSource
|
||||
.savedBiomes().subterrainCellAt(x, y + targetIn(frame).getWorld().minHeight(), z);
|
||||
GenerationHistoryRuntimeRouter router = generationHistoryRuntimeRouter;
|
||||
if ((frame == null || frame.binding == null) && router != null) {
|
||||
Optional<SubterrainCell> saved = router.biomes()
|
||||
.subterrainCell(x, y + targetIn(frame).getWorld().minHeight(), z);
|
||||
if (saved.isPresent()) {
|
||||
return saved.get();
|
||||
}
|
||||
@@ -643,7 +645,7 @@ public class IrisEngine implements Engine {
|
||||
@ChunkCoordinates
|
||||
public SubterrainChunkCells subterrainChunkCells(int chunkX, int chunkZ) {
|
||||
EngineThreadState.Frame frame = threadState.current();
|
||||
if ((frame == null || frame.binding == null) && getGenerationSource().keepsPackVersions()) {
|
||||
if ((frame == null || frame.binding == null) && generationHistoryRuntimeRouter != null) {
|
||||
return SubterrainChunkCells.delegated(this);
|
||||
}
|
||||
SubterrainPlanner planner = subterrainPlannerIn(frame);
|
||||
@@ -671,7 +673,7 @@ public class IrisEngine implements Engine {
|
||||
@ChunkCoordinates
|
||||
@Override
|
||||
public boolean subterrainAbsentInChunk(int chunkX, int chunkZ) {
|
||||
if (!hasGenerationRuntimeScope() && getGenerationSource().keepsPackVersions()) {
|
||||
if (!hasGenerationRuntimeScope() && generationHistoryRuntimeRouter != null) {
|
||||
return false;
|
||||
}
|
||||
return Engine.super.subterrainAbsentInChunk(chunkX, chunkZ);
|
||||
@@ -696,8 +698,8 @@ public class IrisEngine implements Engine {
|
||||
if (saved.isPresent()) {
|
||||
return saved.get().biome();
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a biome")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a biome")) {
|
||||
return Engine.super.getBiome(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -709,8 +711,8 @@ public class IrisEngine implements Engine {
|
||||
if (saved.isPresent()) {
|
||||
return saved.get().biome();
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a biome or mantle biome")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a biome or mantle biome")) {
|
||||
return Engine.super.getBiomeOrMantle(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -725,8 +727,8 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
return;
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a biome or mantle biome column")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a biome or mantle biome column")) {
|
||||
Engine.super.getBiomeOrMantleColumn(x, z, step, biomes, regions);
|
||||
}
|
||||
}
|
||||
@@ -738,8 +740,8 @@ public class IrisEngine implements Engine {
|
||||
if (saved.isPresent()) {
|
||||
return saved.get().region();
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a region")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a region")) {
|
||||
return Engine.super.getRegion(x, z);
|
||||
}
|
||||
}
|
||||
@@ -751,8 +753,8 @@ public class IrisEngine implements Engine {
|
||||
if (saved.isPresent()) {
|
||||
return saved.get().region();
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a vertical region")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a vertical region")) {
|
||||
return Engine.super.getRegion(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -764,8 +766,8 @@ public class IrisEngine implements Engine {
|
||||
if (saved.isPresent()) {
|
||||
return saved.get().biome();
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a cave or mantle biome")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a cave or mantle biome")) {
|
||||
return Engine.super.getCaveOrMantleBiome(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -774,7 +776,7 @@ public class IrisEngine implements Engine {
|
||||
@Override
|
||||
public IrisBiome getCaveBiome(int x, int z) {
|
||||
if (usesSavedBiomeEnvironment()) {
|
||||
Optional<BiomeEnvironment> saved = getGenerationSource().savedBiomes().caveBaseAt(x, z);
|
||||
Optional<BiomeEnvironment> saved = generationHistoryRuntimeRouter.biomes().resolveCaveBase(x, z);
|
||||
if (saved.isPresent()) {
|
||||
return saved.get().biome();
|
||||
}
|
||||
@@ -782,8 +784,8 @@ public class IrisEngine implements Engine {
|
||||
if (usesScopedNaturalTerrain()) {
|
||||
return Engine.super.getCaveBiome(x, z);
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a cave biome")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a cave biome")) {
|
||||
return Engine.super.getCaveBiome(x, z);
|
||||
}
|
||||
}
|
||||
@@ -809,8 +811,8 @@ public class IrisEngine implements Engine {
|
||||
if (usesScopedNaturalTerrain()) {
|
||||
return Engine.super.getCaveBiome(x, y, z, state);
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a vertical cave biome")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a vertical cave biome")) {
|
||||
return Engine.super.getCaveBiome(x, y, z, state);
|
||||
}
|
||||
}
|
||||
@@ -825,8 +827,8 @@ public class IrisEngine implements Engine {
|
||||
if (usesScopedNaturalTerrain()) {
|
||||
return Engine.super.getSurfaceBiome(x, z);
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve a surface biome")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve a surface biome")) {
|
||||
return Engine.super.getSurfaceBiome(x, z);
|
||||
}
|
||||
}
|
||||
@@ -834,8 +836,8 @@ public class IrisEngine implements Engine {
|
||||
@BlockCoordinates
|
||||
@Override
|
||||
public double getSlope(int x, int z) {
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve terrain slope")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve terrain slope")) {
|
||||
return Engine.super.getSlope(x, z);
|
||||
}
|
||||
}
|
||||
@@ -849,8 +851,8 @@ public class IrisEngine implements Engine {
|
||||
@BlockCoordinates
|
||||
@Override
|
||||
public int getHeight(int x, int z, boolean ignoreFluid) {
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x, z, "resolve terrain height")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x, z, "resolve terrain height")) {
|
||||
return Engine.super.getHeight(x, z, ignoreFluid);
|
||||
}
|
||||
}
|
||||
@@ -858,12 +860,12 @@ public class IrisEngine implements Engine {
|
||||
@ChunkCoordinates
|
||||
@Override
|
||||
public Set<String> getObjectsAt(int x, int z) {
|
||||
Optional<ChunkGenerationSemantics> recorded = getGenerationSource().recordedChunks().semantics(x, z);
|
||||
Optional<ChunkGenerationSemantics> recorded = recordedChunkSemantics(x, z);
|
||||
if (recorded.isPresent()) {
|
||||
return recorded.get().objectKeys();
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(x << 4, z << 4, "resolve chunk objects")) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(x << 4, z << 4, "resolve chunk objects")) {
|
||||
return getMantle().getObjectComponent().guess(x, z);
|
||||
}
|
||||
}
|
||||
@@ -871,12 +873,12 @@ public class IrisEngine implements Engine {
|
||||
@ChunkCoordinates
|
||||
@Override
|
||||
public Set<ChunkGenerationSemantics.PointOfInterest> getPOIsAt(int chunkX, int chunkZ) {
|
||||
Optional<ChunkGenerationSemantics> recorded = getGenerationSource().recordedChunks().semantics(chunkX, chunkZ);
|
||||
Optional<ChunkGenerationSemantics> recorded = recordedChunkSemantics(chunkX, chunkZ);
|
||||
if (recorded.isPresent()) {
|
||||
return new HashSet<>(recorded.get().pointsOfInterest());
|
||||
}
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(
|
||||
chunkX << 4, chunkZ << 4, "resolve chunk points of interest")) {
|
||||
Set<ChunkGenerationSemantics.PointOfInterest> pois = new HashSet<>();
|
||||
getMantle().getMantle().iterateChunk(
|
||||
@@ -890,6 +892,12 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<ChunkGenerationSemantics> recordedChunkSemantics(int chunkX, int chunkZ) {
|
||||
GenerationHistoryRuntimeRouter router = getGenerationHistoryRuntimeRouter().orElse(null);
|
||||
return router == null ? Optional.empty()
|
||||
: router.history().semantics(chunkX, chunkZ).filter(ChunkGenerationSemantics::sealed);
|
||||
}
|
||||
|
||||
private void warmupChunk(int x, int z) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
@@ -965,8 +973,8 @@ public class IrisEngine implements Engine {
|
||||
int queryMaximumX = Math.min(maximumX, chunkMinimumX + 15);
|
||||
int queryMinimumZ = Math.max(minimumZ, chunkMinimumZ);
|
||||
int queryMaximumZ = Math.min(maximumZ, chunkMinimumZ + 15);
|
||||
try (GenerationScope ignored =
|
||||
openReadScope(
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openGenerationHistoryReadScope(
|
||||
chunkMinimumX,
|
||||
chunkMinimumZ,
|
||||
"resolve native structure volumes")) {
|
||||
@@ -1062,25 +1070,46 @@ public class IrisEngine implements Engine {
|
||||
return Optional.ofNullable(generationHistoryRuntimeRouter);
|
||||
}
|
||||
|
||||
public GenerationHistoryRuntimeRouter.CoordinateScope openGenerationHistoryCoordinateScope(
|
||||
int blockX,
|
||||
int blockZ
|
||||
) throws IOException {
|
||||
GenerationHistoryRuntimeRouter router = generationHistoryRuntimeRouter;
|
||||
if (router != null) {
|
||||
return router.openCoordinateScope(blockX, blockZ);
|
||||
}
|
||||
if (!generationHistoryRoutingRequired) {
|
||||
return null;
|
||||
}
|
||||
router = generationHistoryRuntimeRouter;
|
||||
if (router == null) {
|
||||
throw new IllegalStateException("Iris generation-history runtime router is detached.");
|
||||
}
|
||||
return router.openCoordinateScope(blockX, blockZ);
|
||||
}
|
||||
|
||||
public boolean hasGenerationRuntimeScope() {
|
||||
return threadState.binding() != null;
|
||||
}
|
||||
|
||||
public boolean hasGenerationHistoryRouting() {
|
||||
return generationHistoryRuntimeRouter != null || generationHistoryRoutingRequired;
|
||||
}
|
||||
|
||||
private boolean usesScopedNaturalTerrain() {
|
||||
return hasGenerationRuntimeScope() && getComplex().isNaturalTerrainContext();
|
||||
}
|
||||
|
||||
public GenerationScope openGenerationScope(int blockX, int blockZ) throws IOException {
|
||||
return getGenerationSource().openGenerationScope(blockX, blockZ);
|
||||
}
|
||||
|
||||
private GenerationScope openReadScope(
|
||||
private GenerationHistoryRuntimeRouter.CoordinateScope openGenerationHistoryReadScope(
|
||||
int blockX,
|
||||
int blockZ,
|
||||
String operation
|
||||
) {
|
||||
try {
|
||||
return getGenerationSource().openReadScope(blockX, blockZ);
|
||||
GenerationHistoryRuntimeRouter router = generationHistoryRuntimeRouter;
|
||||
return router == null
|
||||
? openGenerationHistoryCoordinateScope(blockX, blockZ)
|
||||
: router.openReadScope(blockX, blockZ);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Unable to " + operation + " through Iris generation history at "
|
||||
+ blockX + "," + blockZ + ".", failure);
|
||||
@@ -1100,7 +1129,7 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
shutdownSequence.retainGenerationHistory(required.history());
|
||||
generationHistoryRuntimeRouter = required;
|
||||
generationSource = new VersionedGenerationSource(required);
|
||||
generationHistoryRoutingRequired = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1108,18 +1137,11 @@ public class IrisEngine implements Engine {
|
||||
public void detachGenerationHistoryRuntimeRouter(GenerationHistoryRuntimeRouter router) {
|
||||
synchronized (generationHistoryRuntimeRouterLock) {
|
||||
if (generationHistoryRuntimeRouter == router) {
|
||||
releaseGenerationHistoryRuntimeRouterLocked();
|
||||
generationHistoryRuntimeRouter = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseGenerationHistoryRuntimeRouterLocked() {
|
||||
generationHistoryRuntimeRouter = null;
|
||||
if (generationSource instanceof VersionedGenerationSource versioned) {
|
||||
versioned.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void closeAttachedGenerationHistoryRuntimeRouter() {
|
||||
GenerationHistoryRuntimeRouter attached;
|
||||
synchronized (generationHistoryRuntimeRouterLock) {
|
||||
@@ -1131,7 +1153,7 @@ public class IrisEngine implements Engine {
|
||||
attached.close();
|
||||
synchronized (generationHistoryRuntimeRouterLock) {
|
||||
if (generationHistoryRuntimeRouter == attached) {
|
||||
releaseGenerationHistoryRuntimeRouterLocked();
|
||||
generationHistoryRuntimeRouter = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1617,7 +1639,8 @@ public class IrisEngine implements Engine {
|
||||
if (platformHooks.shouldRefuseGeneration(this)) {
|
||||
refuseMaintenanceGeneration(x >> 4, z >> 4);
|
||||
}
|
||||
try (GenerationScope historyScope = openGenerationScope(x, z);
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope =
|
||||
openGenerationHistoryCoordinateScope(x, z);
|
||||
GenerationSessionLease lease = acquireGenerationLease("chunk_generate");
|
||||
IrisContext.Scope generationScope = IrisContext.open(this, lease.sessionId(), null)) {
|
||||
getEngineData().getStatistics().generatedChunk();
|
||||
@@ -1706,8 +1729,12 @@ public class IrisEngine implements Engine {
|
||||
|
||||
@Override
|
||||
public void syncGenerationHistory() {
|
||||
GenerationHistoryRuntimeRouter router = getGenerationHistoryRuntimeRouter().orElse(null);
|
||||
if (router == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
getGenerationSource().sync();
|
||||
router.history().sync();
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Unable to force Iris generation history to stable storage for "
|
||||
+ getWorld().name() + ".", failure);
|
||||
|
||||
@@ -113,7 +113,7 @@ final class MarkerSpawnScanner {
|
||||
|
||||
private Map<IrisPosition, MarkerSpawnData> collectMarkerSpawnData(int chunkX, int chunkZ) {
|
||||
if (manager.getEngine() instanceof IrisEngine engine) {
|
||||
engine.getGenerationSource().savedBiomes().prepareChunk(chunkX, chunkZ);
|
||||
engine.getGenerationHistoryRuntimeRouter().ifPresent(router -> router.biomes().prepareChunk(chunkX, chunkZ));
|
||||
}
|
||||
Map<IrisPosition, MarkerSpawnData> markerData = new KMap<>();
|
||||
manager.getMantle().iterateChunk(chunkX, chunkZ, MatterMarker.class, (x, y, z, t) -> {
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.world.history.FloatingBiomeOverlay;
|
||||
import art.arcane.iris.world.history.SavedTerrainChunk;
|
||||
import art.arcane.iris.world.history.TransitionGenerationPlan;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Answers what generation reads and writes at the border between pack versions.
|
||||
*/
|
||||
public interface PackTransitions {
|
||||
/** Object fragments that earlier packs placed across the transition band into this chunk. */
|
||||
List<Matter> objectContinuations(TransitionGenerationPlan plan, int chunkX, int chunkZ) throws IOException;
|
||||
|
||||
boolean allowsObjectFootprint(TransitionGenerationPlan plan, int minimumX, int minimumZ, int maximumX, int maximumZ);
|
||||
|
||||
void recordNaturalTerrain(SavedTerrainChunk terrain, FloatingBiomeOverlay floatingBiomes);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.world.history.ChunkGenerationSemantics;
|
||||
import art.arcane.iris.world.history.GenerationSemanticIndex;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Answers what earlier generation recorded about each chunk, for locate and recorded lookups.
|
||||
*/
|
||||
public interface RecordedChunks {
|
||||
boolean ownedByEarlierPack(int chunkX, int chunkZ);
|
||||
|
||||
boolean hasUnrecordedEarlierPackChunkInSquare(int centerChunkX, int centerChunkZ, int radius);
|
||||
|
||||
Optional<ChunkGenerationSemantics> semantics(int chunkX, int chunkZ);
|
||||
|
||||
Optional<GenerationSemanticIndex.Match> findNearest(
|
||||
GenerationSemanticIndex.Query query,
|
||||
Predicate<ChunkGenerationSemantics> eligibility
|
||||
);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
import art.arcane.iris.world.history.SavedBiomeRuntime;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Answers which biomes an earlier pack version saved for the chunks it generated.
|
||||
*/
|
||||
public interface SavedBiomes {
|
||||
Optional<BiomeEnvironment> at(int blockX, int worldY, int blockZ, boolean surface);
|
||||
|
||||
Optional<BiomeEnvironment> caveBaseAt(int blockX, int blockZ);
|
||||
|
||||
Optional<SubterrainCell> subterrainCellAt(int blockX, int worldY, int blockZ);
|
||||
|
||||
<T> T readSurface(int blockX, int blockZ, Function<Optional<BiomeEnvironment>, T> reader)
|
||||
throws InterruptedException;
|
||||
|
||||
CompletableFuture<Optional<SavedBiomeRuntime.ReadSession>> readChunk(int chunkX, int chunkZ);
|
||||
|
||||
void prepareChunk(int chunkX, int chunkZ);
|
||||
|
||||
boolean mayHaveBlockDropRules(String material);
|
||||
}
|
||||
-174
@@ -1,174 +0,0 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
import art.arcane.iris.world.history.ChunkGenerationSemantics;
|
||||
import art.arcane.iris.world.history.FloatingBiomeOverlay;
|
||||
import art.arcane.iris.world.history.GenerationBoundary;
|
||||
import art.arcane.iris.world.history.GenerationSemanticIndex;
|
||||
import art.arcane.iris.world.history.SavedBiomeRuntime;
|
||||
import art.arcane.iris.world.history.SavedTerrainChunk;
|
||||
import art.arcane.iris.world.history.TransitionGenerationPlan;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Every chunk belongs to the pack loaded now, so nothing is routed, recorded or stored.
|
||||
*/
|
||||
final class SinglePackGenerationSource implements GenerationSource {
|
||||
static final SinglePackGenerationSource INSTANCE = new SinglePackGenerationSource();
|
||||
private static final GenerationScope UNROUTED = new UnroutedScope();
|
||||
private static final SavedBiomes NO_SAVED_BIOMES = new NoSavedBiomes();
|
||||
private static final RecordedChunks NO_RECORDED_CHUNKS = new NoRecordedChunks();
|
||||
private static final PackTransitions NO_TRANSITIONS = new NoTransitions();
|
||||
|
||||
private SinglePackGenerationSource() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keepsPackVersions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationScope openGenerationScope(int blockX, int blockZ) {
|
||||
return UNROUTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationScope openReadScope(int blockX, int blockZ) {
|
||||
return UNROUTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationRoute openRoute(int chunkX, int chunkZ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RouteOwnership> currentRouteOwnership() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean predatesActivePack(long activationId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseForRegeneration(List<GenerationBoundary.ChunkCoordinate> chunks) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedBiomes savedBiomes() {
|
||||
return NO_SAVED_BIOMES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecordedChunks recordedChunks() {
|
||||
return NO_RECORDED_CHUNKS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackTransitions transitions() {
|
||||
return NO_TRANSITIONS;
|
||||
}
|
||||
|
||||
private static final class UnroutedScope implements GenerationScope {
|
||||
@Override
|
||||
public boolean claimGeneratedSemantics() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class NoSavedBiomes implements SavedBiomes {
|
||||
@Override
|
||||
public Optional<BiomeEnvironment> at(int blockX, int worldY, int blockZ, boolean surface) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BiomeEnvironment> caveBaseAt(int blockX, int blockZ) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SubterrainCell> subterrainCellAt(int blockX, int worldY, int blockZ) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T readSurface(int blockX, int blockZ, Function<Optional<BiomeEnvironment>, T> reader) {
|
||||
return reader.apply(Optional.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Optional<SavedBiomeRuntime.ReadSession>> readChunk(int chunkX, int chunkZ) {
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareChunk(int chunkX, int chunkZ) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayHaveBlockDropRules(String material) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class NoRecordedChunks implements RecordedChunks {
|
||||
@Override
|
||||
public boolean ownedByEarlierPack(int chunkX, int chunkZ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUnrecordedEarlierPackChunkInSquare(int centerChunkX, int centerChunkZ, int radius) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ChunkGenerationSemantics> semantics(int chunkX, int chunkZ) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GenerationSemanticIndex.Match> findNearest(
|
||||
GenerationSemanticIndex.Query query,
|
||||
Predicate<ChunkGenerationSemantics> eligibility
|
||||
) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class NoTransitions implements PackTransitions {
|
||||
@Override
|
||||
public List<Matter> objectContinuations(TransitionGenerationPlan plan, int chunkX, int chunkZ) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsObjectFootprint(
|
||||
TransitionGenerationPlan plan, int minimumX, int minimumZ, int maximumX, int maximumZ
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordNaturalTerrain(SavedTerrainChunk terrain, FloatingBiomeOverlay floatingBiomes) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,7 +308,7 @@ final class WorldBlockDropRouter {
|
||||
return true;
|
||||
}
|
||||
if (manager.getEngine() instanceof IrisEngine engine) {
|
||||
return engine.getGenerationSource().savedBiomes().mayHaveBlockDropRules(material);
|
||||
return engine.getGenerationHistoryRuntimeRouter().map(router -> router.biomes().mayHaveBlockDropRules(material)).orElse(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1421,7 +1421,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
&& context != null && context.getChunkContext() != null
|
||||
&& context.getChunkContext().getComplex() == complex;
|
||||
boolean natural = generating && context.getChunkContext().isNaturalTerrain();
|
||||
boolean unrouted = !bound && worker && !irisEngine.getGenerationSource().keepsPackVersions();
|
||||
boolean unrouted = !bound && worker && !irisEngine.hasGenerationHistoryRouting();
|
||||
boolean scoped = natural || generating && contentChunk || unrouted;
|
||||
this.subterrainFirst = unrouted;
|
||||
this.chunkLimited = !natural && !unrouted;
|
||||
|
||||
@@ -300,14 +300,6 @@ public class IrisPostModifier extends EngineAssignedModifier<NativeBlockState> {
|
||||
setPostBlock(x, h + 1, z, result, originX, originZ, currentData);
|
||||
}
|
||||
}
|
||||
|
||||
if (B.isFoliage(b) || IrisProceduralBlocks.materialKey(b).equals("minecraft:dead_bush")) {
|
||||
NativeBlockState onto = getPostBlock(x, h, z, originX, originZ, currentData);
|
||||
|
||||
if (!B.canPlaceOnto(b, onto) && !B.isDecorant(b)) {
|
||||
setPostBlock(x, h + 1, z, AIR.get(), originX, originZ, currentData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAir(int x, int y, int z, int originX, int originZ, Hunk<NativeBlockState> currentData) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import art.arcane.iris.integration.ExternalDataSVC;
|
||||
import art.arcane.iris.generation.cache.Cache;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
|
||||
import art.arcane.iris.platform.bukkit.nms.INMS;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.generation.block.IrisCustomData;
|
||||
@@ -83,6 +84,7 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
||||
|
||||
@EventHandler
|
||||
public void onReload(CraftEngineReloadEvent event) {
|
||||
forgetServerBlockRules();
|
||||
if (!updateContent()) {
|
||||
return;
|
||||
}
|
||||
@@ -92,6 +94,13 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
||||
}
|
||||
}
|
||||
|
||||
// Custom blocks carry their own placement rules, so answers about them can change with a reload.
|
||||
private static void forgetServerBlockRules() {
|
||||
if (INMS.isBound()) {
|
||||
INMS.get().forgetBlockRules();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<BlockProperty> getBlockProperties(@NotNull Identifier blockId) throws MissingResourceException {
|
||||
ImmutableBlockState blockState = findBlockState(blockId);
|
||||
|
||||
@@ -143,7 +143,7 @@ public class DataFixerV1217 extends DataFixerV1213 {
|
||||
attributes.put("minecraft:gameplay/bed_rule", new JSONObject()
|
||||
.put("can_set_spawn", "never")
|
||||
.put("can_sleep", "never")
|
||||
.put("destroy_on_use", true));
|
||||
.put("explodes", true));
|
||||
}
|
||||
|
||||
attributes.put("minecraft:gameplay/respawn_anchor_works", json.remove("respawn_anchor_works"));
|
||||
|
||||
@@ -49,6 +49,16 @@ public final class DataFixerV263 extends DataFixerV1217 {
|
||||
return fixed;
|
||||
}
|
||||
|
||||
/** 26.3 renamed the bed rule's explodes flag to destroy_on_use; the old key is ignored there. */
|
||||
@Override
|
||||
public void fixDimension(Dimension dimension, JSONObject json) {
|
||||
super.fixDimension(dimension, json);
|
||||
JSONObject bedRule = json.getJSONObject("attributes").optJSONObject("minecraft:gameplay/bed_rule");
|
||||
if (bedRule != null && bedRule.has("explodes")) {
|
||||
bedRule.put("destroy_on_use", bedRule.remove("explodes"));
|
||||
}
|
||||
}
|
||||
|
||||
private static void color(JSONObject object, String key) {
|
||||
if (object.opt(key) instanceof Number value) {
|
||||
object.put(key, String.format(Locale.ROOT, "#%06x", value.intValue() & 0xFFFFFF));
|
||||
|
||||
@@ -25,6 +25,7 @@ import art.arcane.iris.integration.ExternalDataSVC;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.volmlib.nativelib.terrain.BlockStateKey;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.nativelib.block.SurvivalAnswer;
|
||||
import art.arcane.iris.generation.block.IrisCustomData;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
@@ -429,7 +430,18 @@ public final class BukkitBlockState implements NativeBlockState {
|
||||
|
||||
@Override
|
||||
public boolean canPlaceOnto(NativeBlockState onto) {
|
||||
return BukkitBlockResolution.canPlaceOnto(data.getMaterial(), ((BlockData) onto.nativeHandle()).getMaterial());
|
||||
BlockData plant = realBlockOf(data);
|
||||
BlockData ground = realBlockOf((BlockData) onto.nativeHandle());
|
||||
SurvivalAnswer serverRule = INMS.isBound() ? INMS.get().canSurviveOn(plant, ground) : SurvivalAnswer.UNANSWERED;
|
||||
return switch (serverRule) {
|
||||
case SURVIVES -> true;
|
||||
case FAILS -> false;
|
||||
case UNANSWERED -> BukkitBlockResolution.canPlaceOnto(plant.getMaterial(), ground.getMaterial());
|
||||
};
|
||||
}
|
||||
|
||||
private static BlockData realBlockOf(BlockData data) {
|
||||
return data instanceof IrisCustomData custom ? custom.getBase() : data;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,7 @@ import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionException;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionLease;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisBiomeCustom;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
@@ -310,7 +310,7 @@ public final class BukkitBiomePolicy<H, V> implements NativeBiomeSourcePolicy<H>
|
||||
public H getNoiseBiome(int x, int y, int z) {
|
||||
int blockX = x << 2;
|
||||
int blockZ = z << 2;
|
||||
try (GenerationScope historyScope =
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope =
|
||||
openHistoryCoordinateScope(blockX, blockZ, "bukkit_structure_biome");
|
||||
GenerationSessionLease lease = requireGenerationLease(
|
||||
"bukkit_structure_biome",
|
||||
@@ -436,7 +436,7 @@ public final class BukkitBiomePolicy<H, V> implements NativeBiomeSourcePolicy<H>
|
||||
}
|
||||
|
||||
private H locateVisibleBiomeHolder(int quartX, int quartY, int quartZ) {
|
||||
try (GenerationScope ignored = openHistoryCoordinateScope(
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored = openHistoryCoordinateScope(
|
||||
quartX << 2, quartZ << 2, "bukkit_locate_visible_biome")) {
|
||||
return resolveVisibleBiomeHolder(quartX, quartY, quartZ, null);
|
||||
}
|
||||
@@ -501,7 +501,7 @@ public final class BukkitBiomePolicy<H, V> implements NativeBiomeSourcePolicy<H>
|
||||
private H getSurfaceStructureBiomeHolder(int x, int z) {
|
||||
int blockX = x << 2;
|
||||
int blockZ = z << 2;
|
||||
try (GenerationScope historyScope =
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope =
|
||||
openHistoryCoordinateScope(blockX, blockZ, "bukkit_surface_structure_biome")) {
|
||||
RuntimeColumnKey columnKey = new RuntimeColumnKey(
|
||||
engine.getCacheID(), packColumnKey(x, z));
|
||||
@@ -563,7 +563,7 @@ public final class BukkitBiomePolicy<H, V> implements NativeBiomeSourcePolicy<H>
|
||||
private H getNaturalSurfaceStructureBiomeHolder(int x, int z) {
|
||||
int blockX = x << 2;
|
||||
int blockZ = z << 2;
|
||||
try (GenerationScope historyScope =
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope =
|
||||
openHistoryCoordinateScope(blockX, blockZ, "bukkit_natural_structure_biome")) {
|
||||
RuntimeColumnKey columnKey = new RuntimeColumnKey(
|
||||
engine.getCacheID(), packColumnKey(x, z));
|
||||
@@ -633,7 +633,7 @@ public final class BukkitBiomePolicy<H, V> implements NativeBiomeSourcePolicy<H>
|
||||
}
|
||||
|
||||
public H getVisibleNoiseBiome(int x, int y, int z) {
|
||||
try (GenerationScope historyScope = openHistoryCoordinateScope(
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope = openHistoryCoordinateScope(
|
||||
x << 2, z << 2, "bukkit_visible_biome");
|
||||
GenerationSessionLease lease = requireGenerationLease(
|
||||
"bukkit_visible_biome",
|
||||
@@ -749,7 +749,7 @@ public final class BukkitBiomePolicy<H, V> implements NativeBiomeSourcePolicy<H>
|
||||
return !engine.isClosed() && engine.getComplex() != null;
|
||||
}
|
||||
|
||||
private GenerationScope openHistoryCoordinateScope(
|
||||
private GenerationHistoryRuntimeRouter.CoordinateScope openHistoryCoordinateScope(
|
||||
int blockX,
|
||||
int blockZ,
|
||||
String operation
|
||||
@@ -758,7 +758,7 @@ public final class BukkitBiomePolicy<H, V> implements NativeBiomeSourcePolicy<H>
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return irisEngine.openGenerationScope(blockX, blockZ);
|
||||
return irisEngine.openGenerationHistoryCoordinateScope(blockX, blockZ);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Iris " + operation
|
||||
+ " could not route generation history at "
|
||||
|
||||
+18
-10
@@ -4,10 +4,11 @@ import art.arcane.iris.generation.context.IrisContext;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionException;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionLease;
|
||||
import art.arcane.iris.generation.runtime.GenerationRoute;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.platform.generation.BukkitChunkGenerator;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.NativeTerrainReceipt;
|
||||
import art.arcane.iris.world.history.SavedTerrainChunk;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeGenerationLease;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeTerrainPipelinePolicy;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -15,7 +16,7 @@ import org.bukkit.NamespacedKey;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BukkitGenerationPolicy
|
||||
implements NativeTerrainPipelinePolicy<GenerationRoute> {
|
||||
implements NativeTerrainPipelinePolicy<GenerationHistoryRuntimeRouter.RuntimeRoute> {
|
||||
private static final NamespacedKey NATURAL_TERRAIN = new NamespacedKey("iris", "natural_terrain");
|
||||
|
||||
private final Engine engine;
|
||||
@@ -43,16 +44,19 @@ public class BukkitGenerationPolicy
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationRoute openRoute(int chunkX, int chunkZ, String operation) {
|
||||
public GenerationHistoryRuntimeRouter.RuntimeRoute openRoute(int chunkX, int chunkZ, String operation) {
|
||||
if (!(engine instanceof IrisEngine irisEngine)) {
|
||||
return null;
|
||||
}
|
||||
GenerationSource source = irisEngine.getGenerationSource();
|
||||
if (!source.keepsPackVersions() && generator != null && generator.getGenerationHistory() != null) {
|
||||
throw new IllegalStateException("Iris " + operation + " has no generation-history runtime router.");
|
||||
GenerationHistoryRuntimeRouter router = irisEngine.getGenerationHistoryRuntimeRouter().orElse(null);
|
||||
if (router == null) {
|
||||
if (generator != null && generator.getGenerationHistory() != null) {
|
||||
throw new IllegalStateException("Iris " + operation + " has no generation-history runtime router.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return source.openRoute(chunkX, chunkZ);
|
||||
return router.openRoute(chunkX, chunkZ);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Iris " + operation
|
||||
+ " could not route generation history for chunk " + chunkX + "," + chunkZ + ".", failure);
|
||||
@@ -90,7 +94,11 @@ public class BukkitGenerationPolicy
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] naturalTerrainReceipt(GenerationRoute route) throws IOException {
|
||||
return route.naturalTerrainReceipt();
|
||||
public byte[] naturalTerrainReceipt(GenerationHistoryRuntimeRouter.RuntimeRoute route) throws IOException {
|
||||
if (route.naturalTerrain().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
SavedTerrainChunk terrain = route.naturalTerrain().orElseThrow();
|
||||
return NativeTerrainReceipt.encode(terrain, route.activation().activationId(), route.epoch().epochId());
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import art.arcane.iris.structure.nativegen.IrisStructureVolumePolicy;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureStartPlan;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureVolumeIndex;
|
||||
import art.arcane.iris.generation.runtime.GenerationRoute;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.NativeBiomeSpawnSelection;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBukkitGeneratorContext;
|
||||
@@ -31,7 +31,7 @@ import java.util.function.IntConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class BukkitGeneratorContext extends BukkitGenerationPolicy implements NativeBukkitGeneratorContext<
|
||||
Engine, IrisDimension, NativeStructureStartPlan, NativeStructureOwnershipRecord, GenerationRoute> {
|
||||
Engine, IrisDimension, NativeStructureStartPlan, NativeStructureOwnershipRecord, GenerationHistoryRuntimeRouter.RuntimeRoute> {
|
||||
private static final NamespacedKey STRUCTURE_ACTIVATION = new NamespacedKey("iris", "structure_activation");
|
||||
private final Options options;
|
||||
private final BukkitChunkGenerator generator;
|
||||
@@ -118,7 +118,7 @@ public final class BukkitGeneratorContext extends BukkitGenerationPolicy impleme
|
||||
public NativeGenerationScope openCoordinateScope(int blockX, int blockZ, String operation) {
|
||||
if (!(current() instanceof IrisEngine irisEngine)) { return null; }
|
||||
try {
|
||||
return irisEngine.openGenerationScope(blockX, blockZ);
|
||||
return irisEngine.openGenerationHistoryCoordinateScope(blockX, blockZ);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Iris " + operation + " could not route generation history at "
|
||||
+ blockX + "," + blockZ + ".", failure);
|
||||
@@ -139,7 +139,7 @@ public final class BukkitGeneratorContext extends BukkitGenerationPolicy impleme
|
||||
public NamespacedKey structureActivationKey() { return STRUCTURE_ACTIVATION; }
|
||||
|
||||
@Override
|
||||
public long activationId(GenerationRoute route) { return route.activationId(); }
|
||||
public long activationId(GenerationHistoryRuntimeRouter.RuntimeRoute route) { return route.activation().activationId(); }
|
||||
|
||||
@Override
|
||||
public void failed(String operation, Throwable failure) { IrisLogging.reportError(operation, failure); }
|
||||
|
||||
+4
-4
@@ -7,7 +7,7 @@ import art.arcane.iris.generation.runtime.GenerationSessionLease;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.platform.generation.BukkitChunkGenerator;
|
||||
import art.arcane.iris.studio.generation.JigsawStudioGenerator;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.TerrainNativeBlockKeys;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockColumn;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeTerrainColumnPolicy;
|
||||
@@ -51,12 +51,12 @@ public final class BukkitTerrainColumnPolicy implements NativeTerrainColumnPolic
|
||||
return TerrainNativeBlockKeys.placementKey(stateKey);
|
||||
}
|
||||
|
||||
private GenerationScope openHistory(Query query) {
|
||||
private GenerationHistoryRuntimeRouter.CoordinateScope openHistory(Query query) {
|
||||
if (!(engine instanceof IrisEngine irisEngine)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return irisEngine.openGenerationScope(query.blockX(), query.blockZ());
|
||||
return irisEngine.openGenerationHistoryCoordinateScope(query.blockX(), query.blockZ());
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Iris " + query.operation() + " could not route generation history at "
|
||||
+ query.blockX() + "," + query.blockZ() + ".", failure);
|
||||
@@ -65,7 +65,7 @@ public final class BukkitTerrainColumnPolicy implements NativeTerrainColumnPolic
|
||||
|
||||
private final class Session implements ColumnSession {
|
||||
private final Query query;
|
||||
private final GenerationScope history;
|
||||
private final GenerationHistoryRuntimeRouter.CoordinateScope history;
|
||||
private final GenerationSessionLease lease;
|
||||
private final IrisContext.Scope context;
|
||||
|
||||
|
||||
@@ -41,8 +41,6 @@ import art.arcane.iris.studio.jigsaw.JigsawStudioSession;
|
||||
import art.arcane.iris.studio.StudioSVC;
|
||||
import art.arcane.iris.world.IrisToolbelt;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.runtime.IrisWorldManager;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
@@ -1096,23 +1094,11 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
|
||||
withExclusiveControl(() -> {
|
||||
if (!studioUpdatesPaused && !closing) {
|
||||
hotloadEngine();
|
||||
getEngine().hotload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void hotloadEngine() {
|
||||
Engine activeEngine = getEngine();
|
||||
long started = M.ms();
|
||||
activeEngine.hotload();
|
||||
IrisLogging.info("Hotloaded " + packKeyOf(activeEngine) + " in " + (M.ms() - started) + "ms");
|
||||
}
|
||||
|
||||
private static String packKeyOf(Engine activeEngine) {
|
||||
IrisDimension dimension = activeEngine.getDimension();
|
||||
return dimension == null ? "unknown pack" : dimension.getLoadKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> hotloadAsync() {
|
||||
if (!canHotloadStudio()) {
|
||||
@@ -1122,7 +1108,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
if (!canHotloadStudio()) {
|
||||
throw new IllegalStateException("Studio is not ready for hotload.");
|
||||
}
|
||||
hotloadEngine();
|
||||
getEngine().hotload();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1147,7 +1133,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
if (!initialEntryPending && !studioUpdatesPaused && shouldRunStudioHotload(isStudio(), closing, jigsawStudioActive)) {
|
||||
IrisLogging.debug("Studio update admission: world=%s wait=%dms",
|
||||
getTarget().getWorld().name(), TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - queuedAt));
|
||||
hotloadEngine();
|
||||
getEngine().hotload();
|
||||
}
|
||||
}, pending));
|
||||
}
|
||||
@@ -1371,13 +1357,16 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
} else {
|
||||
SectionBuffer blocks = new SectionBuffer(d.getMaxHeight() - d.getMinHeight());
|
||||
Hunk<NativeBiome> biomes = new ColumnBiomeHunk(d.getMaxHeight() - d.getMinHeight(), () -> BukkitBiome.of(Biome.PLAINS));
|
||||
try (GenerationScope historyScope = openGenerationScope(engine, x << 4, z << 4);
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope =
|
||||
openGenerationHistoryCoordinateScope(engine, x << 4, z << 4);
|
||||
GenerationSessionLease lease = engine.acquireGenerationLease("bukkit_terrain_stage");
|
||||
IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
engine.generate(x << 4, z << 4, blocks, biomes,
|
||||
initialEntryPending || studioEntryBootstrapActive.get() || engine.shouldGenerateMulticore());
|
||||
ChunkDataOutput.apply(d, blocks);
|
||||
historyScope.claimGeneratedSemantics();
|
||||
if (historyScope != null) {
|
||||
historyScope.claimGeneratedSemantics();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1401,22 +1390,21 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
}
|
||||
}
|
||||
|
||||
private GenerationScope openGenerationScope(Engine currentEngine, int blockX, int blockZ) throws IOException {
|
||||
return requireGenerationSource(currentEngine).openGenerationScope(blockX, blockZ);
|
||||
}
|
||||
|
||||
private GenerationSource requireGenerationSource(Engine currentEngine) {
|
||||
private @Nullable GenerationHistoryRuntimeRouter.CoordinateScope openGenerationHistoryCoordinateScope(
|
||||
Engine currentEngine,
|
||||
int blockX,
|
||||
int blockZ
|
||||
) throws IOException {
|
||||
if (generationHistory == null) {
|
||||
return null;
|
||||
}
|
||||
if (!(currentEngine instanceof IrisEngine irisEngine)) {
|
||||
if (generationHistory != null) {
|
||||
throw new IllegalStateException("Persistent Iris generation requires an IrisEngine runtime.");
|
||||
}
|
||||
return GenerationSource.singlePack();
|
||||
throw new IllegalStateException("Persistent Iris generation requires an IrisEngine runtime.");
|
||||
}
|
||||
GenerationSource source = irisEngine.getGenerationSource();
|
||||
if (generationHistory != null && !source.keepsPackVersions()) {
|
||||
throw new IllegalStateException("Persistent Iris generation has no generation-history runtime router.");
|
||||
}
|
||||
return source;
|
||||
GenerationHistoryRuntimeRouter router = irisEngine.getGenerationHistoryRuntimeRouter()
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"Persistent Iris generation has no generation-history runtime router."));
|
||||
return router.openCoordinateScope(blockX, blockZ);
|
||||
}
|
||||
|
||||
private boolean isExpectedTeardown(Engine currentEngine, Throwable throwable) {
|
||||
@@ -1466,7 +1454,8 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
default -> false;
|
||||
};
|
||||
|
||||
try (GenerationScope historyScope = openGenerationScope(currentEngine, x, z);
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope historyScope =
|
||||
openGenerationHistoryCoordinateScope(currentEngine, x, z);
|
||||
GenerationSessionLease lease = currentEngine.acquireGenerationLease("bukkit_base_height");
|
||||
IrisContext.Scope ignored = IrisContext.open(currentEngine, lease.sessionId(), null)) {
|
||||
return currentEngine.getMinHeight() + currentEngine.getHeight(x, z, ignoreFluid) + 1;
|
||||
|
||||
@@ -5,6 +5,7 @@ import art.arcane.iris.generation.runtime.DimensionStackLayout;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.structure.object.IrisStaticObjectLayer;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockPositionPredicate;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -21,7 +22,8 @@ public final class GenerationWritePolicy {
|
||||
if (activation <= 0 || !(engine instanceof IrisEngine irisEngine)) {
|
||||
return false;
|
||||
}
|
||||
return irisEngine.getGenerationSource().predatesActivePack(activation);
|
||||
GenerationHistoryRuntimeRouter router = irisEngine.getGenerationHistoryRuntimeRouter().orElse(null);
|
||||
return router != null && activation < router.history().activeActivation().activationId();
|
||||
}
|
||||
|
||||
public static StructureSeaSurface seaSurface(Engine engine) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import art.arcane.volmlib.nativelib.terrain.structure.StructureFingerprint;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureInjectionPolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureReferencePolicy;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -75,12 +75,12 @@ public record IrisStructurePolicy(Engine engine)
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationScope openOriginScope(int chunkX, int chunkZ) {
|
||||
public GenerationHistoryRuntimeRouter.CoordinateScope openOriginScope(int chunkX, int chunkZ) {
|
||||
if (!(engine instanceof IrisEngine irisEngine)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return irisEngine.openGenerationScope(chunkX << 4, chunkZ << 4);
|
||||
return irisEngine.openGenerationHistoryCoordinateScope(chunkX << 4, chunkZ << 4);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Unable to resolve native structure references for origin "
|
||||
+ chunkX + "," + chunkZ + " through generation history.", failure);
|
||||
|
||||
+6
-4
@@ -4,7 +4,7 @@ import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.GenerationClosedException;
|
||||
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.generation.mantle.EngineMantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
@@ -19,6 +19,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -418,11 +419,12 @@ public final class NativeStructureOwnershipStore {
|
||||
if (!(active instanceof IrisEngine irisEngine)) {
|
||||
return new RuntimeMantleOwner(0L, runtimeId, null, mantle);
|
||||
}
|
||||
GenerationSource source = irisEngine.getGenerationSource();
|
||||
if (!source.keepsPackVersions()) {
|
||||
Optional<GenerationHistoryRuntimeRouter> attached = irisEngine.getGenerationHistoryRuntimeRouter();
|
||||
if (attached.isEmpty()) {
|
||||
return new RuntimeMantleOwner(0L, runtimeId, null, mantle);
|
||||
}
|
||||
GenerationSource.RouteOwnership routed = source.currentRouteOwnership()
|
||||
GenerationHistoryRuntimeRouter.RuntimeOwnership routed = attached.get()
|
||||
.currentRuntimeOwnership()
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"Native structure ownership requires an active generation-history runtime route."));
|
||||
if (routed.binding().runtimeId() != runtimeId) {
|
||||
|
||||
+14
-6
@@ -7,8 +7,7 @@ import art.arcane.volmlib.nativelib.terrain.structure.NativeStructureVolume;
|
||||
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
|
||||
@@ -169,7 +168,11 @@ public final class NativeStructureVolumeIndex {
|
||||
if (!(engine instanceof IrisEngine irisEngine) || !irisEngine.hasGenerationRuntimeScope()) {
|
||||
return null;
|
||||
}
|
||||
GenerationSource.RouteOwnership ownership = irisEngine.getGenerationSource().currentRouteOwnership().orElse(null);
|
||||
GenerationHistoryRuntimeRouter router = irisEngine.getGenerationHistoryRuntimeRouter().orElse(null);
|
||||
if (router == null) {
|
||||
return null;
|
||||
}
|
||||
GenerationHistoryRuntimeRouter.RuntimeOwnership ownership = router.currentRuntimeOwnership().orElse(null);
|
||||
int runtimeId = runtimeId(engine);
|
||||
return ownership != null && ownership.binding().runtimeId() == runtimeId ? runtimeId : null;
|
||||
}
|
||||
@@ -188,7 +191,8 @@ public final class NativeStructureVolumeIndex {
|
||||
}
|
||||
|
||||
KList<NativeStructureVolume> originVolumes(Engine engine, int chunkX, int chunkZ) {
|
||||
try (GenerationScope ignored = openGenerationScope(engine, chunkX, chunkZ)) {
|
||||
try (GenerationHistoryRuntimeRouter.CoordinateScope ignored =
|
||||
openHistoryCoordinateScope(engine, chunkX, chunkZ)) {
|
||||
int runtimeId = runtimeId(engine);
|
||||
return cached(
|
||||
originCache,
|
||||
@@ -254,12 +258,16 @@ public final class NativeStructureVolumeIndex {
|
||||
return ((long) chunkX << 32) ^ (chunkZ & 0xffffffffL);
|
||||
}
|
||||
|
||||
private static GenerationScope openGenerationScope(Engine engine, int chunkX, int chunkZ) {
|
||||
private static GenerationHistoryRuntimeRouter.CoordinateScope openHistoryCoordinateScope(
|
||||
Engine engine,
|
||||
int chunkX,
|
||||
int chunkZ
|
||||
) {
|
||||
if (!(engine instanceof IrisEngine irisEngine)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return irisEngine.openGenerationScope(chunkX << 4, chunkZ << 4);
|
||||
return irisEngine.openGenerationHistoryCoordinateScope(chunkX << 4, chunkZ << 4);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Unable to route native structure origin "
|
||||
+ chunkX + "," + chunkZ + " through generation history.", failure);
|
||||
|
||||
@@ -12,7 +12,7 @@ import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.hunk.Hunk;
|
||||
@@ -108,10 +108,11 @@ public final class IrisStaticObjectLayer {
|
||||
if (complex.getTransitionGenerationPlan() == null) {
|
||||
return this;
|
||||
}
|
||||
GenerationSource source = engine instanceof IrisEngine irisEngine ? irisEngine.getGenerationSource() : null;
|
||||
boolean cacheable = source == null || source.keepsPackVersions();
|
||||
GenerationHistoryRuntimeRouter router = engine instanceof IrisEngine irisEngine
|
||||
? irisEngine.getGenerationHistoryRuntimeRouter().orElse(null) : null;
|
||||
boolean cacheable = !(engine instanceof IrisEngine) || router != null;
|
||||
TransitionLayer cached = transitionLayer;
|
||||
if (cacheable && cached != null && cached.complex() == complex && cached.source() == source) {
|
||||
if (cacheable && cached != null && cached.complex() == complex && cached.router() == router) {
|
||||
return cached.layer();
|
||||
}
|
||||
List<Placement> accepted = new ArrayList<>(placements.size());
|
||||
@@ -124,7 +125,7 @@ public final class IrisStaticObjectLayer {
|
||||
}
|
||||
IrisStaticObjectLayer filtered = accepted.size() == placements.size() ? this : merge(accepted);
|
||||
if (cacheable) {
|
||||
transitionLayer = new TransitionLayer(complex, source, filtered);
|
||||
transitionLayer = new TransitionLayer(complex, router, filtered);
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
@@ -248,7 +249,7 @@ public final class IrisStaticObjectLayer {
|
||||
private record Placement(ObjectContinuationBundle.PlacementKey key, Map<Long, Chunk> chunks, Footprint footprint) {
|
||||
}
|
||||
|
||||
private record TransitionLayer(IrisComplex complex, GenerationSource source, IrisStaticObjectLayer layer) {
|
||||
private record TransitionLayer(IrisComplex complex, GenerationHistoryRuntimeRouter router, IrisStaticObjectLayer layer) {
|
||||
}
|
||||
|
||||
private static final class Compilation implements IObjectPlacer {
|
||||
|
||||
@@ -139,10 +139,6 @@ public class IrisCreator {
|
||||
);
|
||||
}
|
||||
|
||||
private boolean usesSinglePackStudio() {
|
||||
return studio && !IrisSettings.get().getStudio().isKeepPackVersions();
|
||||
}
|
||||
|
||||
public static int removeTransientStudioWorldsFromBukkitYml() throws IOException {
|
||||
return BukkitWorldConfiguration.removeMatching(
|
||||
BUKKIT_YML,
|
||||
@@ -271,9 +267,7 @@ public class IrisCreator {
|
||||
long packPreparationStart = System.nanoTime();
|
||||
GenerationHistory publishedHistory = null;
|
||||
IrisDimension installedDimension;
|
||||
if (usesSinglePackStudio()) {
|
||||
installedDimension = resolvedDimension;
|
||||
} else if (benchmark && !studio) {
|
||||
if (benchmark && !studio) {
|
||||
installedDimension = studioService.installIntoTransientWorld(sender, resolvedDimension, dimensionRoot);
|
||||
} else {
|
||||
StudioSVC.GenerationPublication publication = studioService.installIntoWorld(
|
||||
|
||||
@@ -138,9 +138,6 @@ public class IrisWorldCreator {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (studio && generationHistory == null) {
|
||||
return null;
|
||||
}
|
||||
Path root = Objects.requireNonNull(dimensionRoot, "Dimension root").toPath().toAbsolutePath().normalize();
|
||||
try {
|
||||
if (generationHistory == null) {
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package art.arcane.iris.world.history;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
final class AttachedRouter {
|
||||
private volatile GenerationHistoryRuntimeRouter router;
|
||||
|
||||
AttachedRouter(GenerationHistoryRuntimeRouter router) {
|
||||
this.router = Objects.requireNonNull(router, "generation-history runtime router");
|
||||
}
|
||||
|
||||
void detach() {
|
||||
router = null;
|
||||
}
|
||||
|
||||
GenerationHistoryRuntimeRouter attachedOrNull() {
|
||||
return router;
|
||||
}
|
||||
|
||||
GenerationHistoryRuntimeRouter require() {
|
||||
GenerationHistoryRuntimeRouter attached = router;
|
||||
if (attached == null) {
|
||||
throw new IllegalStateException("Iris generation-history runtime router is detached.");
|
||||
}
|
||||
return attached;
|
||||
}
|
||||
}
|
||||
@@ -144,17 +144,6 @@ public final class ChunkGenerationOwnership {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean reclaim(int chunkX, int chunkZ, long activation) throws IOException {
|
||||
requireActivation(activation);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
RegionGenerationOwnership region = regionForAssignment(chunkX, chunkZ);
|
||||
return region.reclaim(chunkX, chunkZ, activation);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public int assignAll(WorldChunkInventory inventory, long activation) throws IOException {
|
||||
requireActivation(activation);
|
||||
lock.writeLock().lock();
|
||||
|
||||
@@ -82,17 +82,6 @@ public final class GenerationBoundary {
|
||||
int minimumZ,
|
||||
int maximumX,
|
||||
int maximumZ
|
||||
) {
|
||||
return intersectsHistoricalBlocks(minimumX, minimumZ, maximumX, maximumZ, (chunkX, chunkZ) -> true);
|
||||
}
|
||||
|
||||
/** Like {@link #intersectsHistoricalBlocks(int, int, int, int)}, counting only historical chunks the filter keeps. */
|
||||
public boolean intersectsHistoricalBlocks(
|
||||
int minimumX,
|
||||
int minimumZ,
|
||||
int maximumX,
|
||||
int maximumZ,
|
||||
ChunkFilter counted
|
||||
) {
|
||||
if (minimumX > maximumX || minimumZ > maximumZ) {
|
||||
throw new IllegalArgumentException("Generation footprint bounds are inverted");
|
||||
@@ -110,7 +99,7 @@ public final class GenerationBoundary {
|
||||
if (candidateCount <= historicalChunkCount) {
|
||||
for (long chunkX = minimumChunkX; chunkX <= maximumChunkX; chunkX++) {
|
||||
for (long chunkZ = minimumChunkZ; chunkZ <= maximumChunkZ; chunkZ++) {
|
||||
if (isHistoricalChunk((int) chunkX, (int) chunkZ) && counted.test((int) chunkX, (int) chunkZ)) {
|
||||
if (isHistoricalChunk((int) chunkX, (int) chunkZ)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -122,8 +111,7 @@ public final class GenerationBoundary {
|
||||
historicalChunks.forEach((chunkX, chunkZ) -> {
|
||||
if (!found[0]
|
||||
&& chunkX >= minimumChunkX && chunkX <= maximumChunkX
|
||||
&& chunkZ >= minimumChunkZ && chunkZ <= maximumChunkZ
|
||||
&& counted.test(chunkX, chunkZ)) {
|
||||
&& chunkZ >= minimumChunkZ && chunkZ <= maximumChunkZ) {
|
||||
found[0] = true;
|
||||
}
|
||||
});
|
||||
@@ -410,11 +398,6 @@ public final class GenerationBoundary {
|
||||
void accept(int chunkX, int chunkZ) throws IOException;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ChunkFilter {
|
||||
boolean test(int chunkX, int chunkZ);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BlockColumnConsumer {
|
||||
void accept(int blockX, int blockZ) throws IOException;
|
||||
|
||||
@@ -122,22 +122,6 @@ public final class GenerationBoundaryStore {
|
||||
return publishCatalog(activationId, builder);
|
||||
}
|
||||
|
||||
synchronized void discardSnapshot(long activationId) throws IOException {
|
||||
Path target = snapshotPath(activationId);
|
||||
if (!Files.exists(directory, LinkOption.NOFOLLOW_LINKS)) {
|
||||
return;
|
||||
}
|
||||
validateStorageAncestors();
|
||||
try (GenerationPublicationLock ignored = GenerationPublicationLock.acquire(
|
||||
directory,
|
||||
".activation-" + activationId + SNAPSHOT_FILE_SUFFIX + ".lock"
|
||||
)) {
|
||||
if (Files.deleteIfExists(target)) {
|
||||
forceDirectory(directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GenerationBoundary load(long activationId) throws IOException {
|
||||
requireActivation(activationId);
|
||||
validateStorageAncestors();
|
||||
|
||||
@@ -51,7 +51,6 @@ public final class GenerationHistory {
|
||||
private final Map<Long, GenerationBoundary> boundaryCache;
|
||||
private final Map<Long, TerrainBoundarySignatureStore.Snapshot> terrainSignatureCache;
|
||||
private final Map<Long, TransitionGenerationPlan> transitionPlanCache;
|
||||
private final Long2ObjectOpenHashMap<ReclaimedChunks> reclaimedChunksByActivation = new Long2ObjectOpenHashMap<>();
|
||||
private final ArrayBlockingQueue<PendingSemanticClaim> pendingSemanticClaims =
|
||||
new ArrayBlockingQueue<>(MAXIMUM_PENDING_SEMANTIC_CLAIMS);
|
||||
private final AtomicBoolean semanticWriter = new AtomicBoolean();
|
||||
@@ -344,31 +343,6 @@ public final class GenerationHistory {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stages an update like {@link #stageUpdate(Path, String, GenerationEpoch.DimensionContract,
|
||||
* GenerationRegistryContract, int)}, but first discards a pending activation for a different pack that never
|
||||
* published its transition. A failed Studio hotload leaves such an activation behind, and the newer pack supersedes
|
||||
* it.
|
||||
*/
|
||||
public synchronized GenerationActivation stageUpdateReplacingStalePending(
|
||||
Path packSource,
|
||||
String packFingerprint,
|
||||
GenerationEpoch.DimensionContract dimensionContract,
|
||||
GenerationRegistryContract registryContract,
|
||||
int transitionWidthBlocks
|
||||
) throws IOException {
|
||||
return stageUpdate(
|
||||
packSource,
|
||||
packFingerprint,
|
||||
GenerationPackFingerprint.CURRENT_VERSION,
|
||||
dimensionContract,
|
||||
registryContract,
|
||||
transitionWidthBlocks,
|
||||
kernels.current(),
|
||||
StalePendingUpdate.REPLACE
|
||||
);
|
||||
}
|
||||
|
||||
synchronized GenerationActivation stageUpdate(
|
||||
Path packSource,
|
||||
String packFingerprint,
|
||||
@@ -384,8 +358,7 @@ public final class GenerationHistory {
|
||||
dimensionContract,
|
||||
registryContract,
|
||||
transitionWidthBlocks,
|
||||
version,
|
||||
StalePendingUpdate.REJECT
|
||||
version
|
||||
);
|
||||
}
|
||||
|
||||
@@ -396,8 +369,7 @@ public final class GenerationHistory {
|
||||
GenerationEpoch.DimensionContract dimensionContract,
|
||||
GenerationRegistryContract registryContract,
|
||||
int transitionWidthBlocks,
|
||||
GenerationKernelRegistry.Version version,
|
||||
StalePendingUpdate stalePending
|
||||
GenerationKernelRegistry.Version version
|
||||
) throws IOException {
|
||||
GenerationEpoch candidate = epoch(
|
||||
packFingerprint,
|
||||
@@ -421,20 +393,17 @@ public final class GenerationHistory {
|
||||
}
|
||||
|
||||
Optional<GenerationActivation> pending = store.pendingActivation();
|
||||
if (pending.isPresent() && !pending.get().epochId().equals(candidate.epochId())) {
|
||||
if (stalePending == StalePendingUpdate.REJECT) {
|
||||
if (pending.isPresent()) {
|
||||
GenerationActivation activation = pending.get();
|
||||
if (!activation.epochId().equals(candidate.epochId())) {
|
||||
throw new IllegalStateException("A different generation activation is already pending.");
|
||||
}
|
||||
discardStalePending(pending.get());
|
||||
pending = Optional.empty();
|
||||
}
|
||||
if (pending.isPresent()) {
|
||||
packs.requireExactPack(
|
||||
candidate.epochId(),
|
||||
candidate.packFingerprint(),
|
||||
candidate.packFingerprintVersion()
|
||||
);
|
||||
return pending.get();
|
||||
return activation;
|
||||
}
|
||||
|
||||
if (store.activeEpoch().equals(candidate)) {
|
||||
@@ -466,29 +435,6 @@ public final class GenerationHistory {
|
||||
return store.preparePendingActivation(candidate, transitionWidthBlocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Snapshots go before the manifest entry: a snapshot left without its activation would block the next activation
|
||||
* that reuses the ID, while an activation left without snapshots simply publishes them again.
|
||||
*/
|
||||
private void discardStalePending(GenerationActivation stale) throws IOException {
|
||||
if (stale.transition().isComplete()) {
|
||||
throw new IllegalStateException("A different generation activation is already pending.");
|
||||
}
|
||||
long activationId = stale.activationId();
|
||||
boundaries.discardSnapshot(activationId);
|
||||
terrainSignatures.discardSnapshot(activationId);
|
||||
boundaryCache.remove(activationId);
|
||||
terrainSignatureCache.remove(activationId);
|
||||
transitionPlanCache.remove(activationId);
|
||||
reclaimedChunksByActivation.remove(activationId);
|
||||
store.discardPendingActivation(activationId);
|
||||
}
|
||||
|
||||
private enum StalePendingUpdate {
|
||||
REJECT,
|
||||
REPLACE
|
||||
}
|
||||
|
||||
GenerationActivation promotePending(
|
||||
Collection<TerrainBoundarySignature> signatures
|
||||
) throws IOException {
|
||||
@@ -658,8 +604,7 @@ public final class GenerationHistory {
|
||||
active.dimensionContract(),
|
||||
active.registryContract(),
|
||||
transitionWidthBlocks,
|
||||
kernels.current(),
|
||||
StalePendingUpdate.REJECT
|
||||
kernels.current()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1048,83 +993,12 @@ public final class GenerationHistory {
|
||||
transition.terrainSignatureIdentity()
|
||||
),
|
||||
boundary,
|
||||
terrainSnapshot,
|
||||
reclaimedChunks(activationId, boundary)
|
||||
terrainSnapshot
|
||||
);
|
||||
transitionPlanCache.put(activationId, plan);
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hands the given chunks to the active activation so they regenerate like new chunks. Ownership, the boundary's
|
||||
* reclaimed set, recorded semantics and saved biomes change together, so a later promotion still finds every
|
||||
* record owned by the activation that claimed it. Records go first: a crash in between leaves chunks with an owner
|
||||
* and no record, which generation recovers from, instead of records that contradict their owner.
|
||||
*
|
||||
* @return how many chunks changed owner
|
||||
*/
|
||||
public synchronized int releaseForRegeneration(List<GenerationBoundary.ChunkCoordinate> chunks) throws IOException {
|
||||
GenerationActivation active = store.activeActivation();
|
||||
if (active.isInitial()) {
|
||||
return 0;
|
||||
}
|
||||
long activationId = active.activationId();
|
||||
GenerationBoundary boundary = boundary(activationId);
|
||||
List<GenerationBoundary.ChunkCoordinate> released = chunksTheActivePackMayOwn(chunks, boundary, activationId);
|
||||
semantics.forgetEarlierClaims(released, activationId);
|
||||
savedBiomes.forgetEarlierClaims(released, activationId);
|
||||
return reclaimBoundaryChunks(released, boundary, activationId);
|
||||
}
|
||||
|
||||
private List<GenerationBoundary.ChunkCoordinate> chunksTheActivePackMayOwn(
|
||||
List<GenerationBoundary.ChunkCoordinate> chunks, GenerationBoundary boundary, long activationId
|
||||
) {
|
||||
List<GenerationBoundary.ChunkCoordinate> released = new ArrayList<>(chunks.size());
|
||||
for (GenerationBoundary.ChunkCoordinate chunk : chunks) {
|
||||
if (boundary.isHistoricalChunk(chunk.chunkX(), chunk.chunkZ())
|
||||
|| resolveActivation(chunk.chunkX(), chunk.chunkZ()).activationId() == activationId) {
|
||||
released.add(chunk);
|
||||
}
|
||||
}
|
||||
return released;
|
||||
}
|
||||
|
||||
private int reclaimBoundaryChunks(
|
||||
List<GenerationBoundary.ChunkCoordinate> chunks, GenerationBoundary boundary, long activationId
|
||||
) throws IOException {
|
||||
ReclaimedChunks reclaimed = reclaimedChunks(activationId, boundary);
|
||||
int moved = 0;
|
||||
for (GenerationBoundary.ChunkCoordinate chunk : chunks) {
|
||||
if (!boundary.isHistoricalChunk(chunk.chunkX(), chunk.chunkZ())
|
||||
|| reclaimed.contains(chunk.chunkX(), chunk.chunkZ())) {
|
||||
continue;
|
||||
}
|
||||
ownership.reclaim(chunk.chunkX(), chunk.chunkZ(), activationId);
|
||||
reclaimed.add(chunk.chunkX(), chunk.chunkZ());
|
||||
moved++;
|
||||
}
|
||||
if (moved > 0) {
|
||||
ownership.persist();
|
||||
}
|
||||
return moved;
|
||||
}
|
||||
|
||||
/** Every plan of one activation shares this set, so a plan rebuilt after cache eviction still sees later reclaims. */
|
||||
private ReclaimedChunks reclaimedChunks(long activationId, GenerationBoundary boundary) throws IOException {
|
||||
ReclaimedChunks existing = reclaimedChunksByActivation.get(activationId);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
ReclaimedChunks loaded = new ReclaimedChunks();
|
||||
ownership.forEachAssignment((chunkX, chunkZ, owner) -> {
|
||||
if (owner == activationId && boundary.isHistoricalChunk(chunkX, chunkZ)) {
|
||||
loaded.add(chunkX, chunkZ);
|
||||
}
|
||||
});
|
||||
reclaimedChunksByActivation.put(activationId, loaded);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public synchronized int explicitChunkCount() {
|
||||
return ownership.explicitChunkCount();
|
||||
}
|
||||
|
||||
+2
-29
@@ -11,8 +11,6 @@ import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.runtime.IrisEngineMantle;
|
||||
import art.arcane.iris.generation.runtime.EngineTarget;
|
||||
import art.arcane.iris.generation.runtime.GenerationClosedException;
|
||||
import art.arcane.iris.generation.runtime.GenerationRoute;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.generation.runtime.GenerationTransitionGate;
|
||||
import art.arcane.iris.generation.mantle.ObjectContinuationBundle;
|
||||
import art.arcane.iris.world.storage.matter.IrisMatterContext;
|
||||
@@ -140,19 +138,6 @@ public final class GenerationHistoryRuntimeRouter implements AutoCloseable {
|
||||
public record ObjectContinuation(long activationId, ObjectContinuationBundle.Fragment fragment) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Hands chunks to the active pack, so they generate like new chunks. Regen uses it to rebuild chunks from before the
|
||||
* last hotload with the current pack, objects and caves included.
|
||||
*/
|
||||
public int releaseForRegeneration(List<GenerationBoundary.ChunkCoordinate> chunks) throws IOException {
|
||||
try (GenerationTransitionGate.Participation ignored = engine.getGenerationSessions().transitionGate().enter()) {
|
||||
int released = history.releaseForRegeneration(chunks);
|
||||
biomes.invalidateQueries(chunks);
|
||||
objectContinuations.clear();
|
||||
return released;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean allowsObjectFootprint(TransitionGenerationPlan plan, ObjectContinuationBundle.Bounds bounds) {
|
||||
return objectContinuations.allowsFootprint(plan, bounds.minimumX(), bounds.minimumZ(), bounds.maximumX(), bounds.maximumZ());
|
||||
}
|
||||
@@ -1467,7 +1452,7 @@ public final class GenerationHistoryRuntimeRouter implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class RuntimeRoute implements GenerationRoute {
|
||||
public static final class RuntimeRoute implements NativeGenerationRoute {
|
||||
private final GenerationHistoryRuntimeRouter router;
|
||||
private final GenerationHistory.GenerationStage stage;
|
||||
private final RuntimeLease lease;
|
||||
@@ -1513,18 +1498,6 @@ public final class GenerationHistoryRuntimeRouter implements AutoCloseable {
|
||||
return stage.activation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long activationId() {
|
||||
return stage.activation().activationId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] naturalTerrainReceipt() throws IOException {
|
||||
SavedTerrainChunk terrain = naturalTerrain;
|
||||
return terrain == null ? null
|
||||
: NativeTerrainReceipt.encode(terrain, activationId(), stage.epoch().epochId());
|
||||
}
|
||||
|
||||
public GenerationEpoch epoch() {
|
||||
return stage.epoch();
|
||||
}
|
||||
@@ -1790,7 +1763,7 @@ public final class GenerationHistoryRuntimeRouter implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CoordinateScope implements GenerationScope {
|
||||
public static final class CoordinateScope implements NativeGenerationScope {
|
||||
private final int blockX;
|
||||
private final int blockZ;
|
||||
private final RuntimeRoute route;
|
||||
|
||||
@@ -183,13 +183,6 @@ public final class GenerationHistoryStore {
|
||||
return updated.pendingActivation().orElseThrow();
|
||||
}
|
||||
|
||||
public synchronized void discardPendingActivation(long expectedActivationId) throws IOException {
|
||||
requireUsable();
|
||||
GenerationManifest updated = manifest.discardPending(expectedActivationId);
|
||||
writeUpdatedManifest(updated);
|
||||
manifest = updated;
|
||||
}
|
||||
|
||||
public synchronized GenerationActivation completePendingTransition(
|
||||
long expectedActivationId,
|
||||
String boundaryIdentity,
|
||||
|
||||
@@ -155,32 +155,6 @@ public final class GenerationManifest {
|
||||
));
|
||||
}
|
||||
|
||||
GenerationManifest discardPending(long expectedActivationId) {
|
||||
GenerationActivation pending = pendingActivation()
|
||||
.orElseThrow(() -> new IllegalStateException("No generation activation is pending."));
|
||||
if (pending.activationId() != expectedActivationId) {
|
||||
throw new IllegalStateException("Pending activation changed before it was discarded.");
|
||||
}
|
||||
if (pending.transition().isComplete()) {
|
||||
throw new IllegalStateException("A pending activation that published its transition cannot be discarded.");
|
||||
}
|
||||
TreeMap<Long, GenerationActivation> nextActivations = new TreeMap<>(activations);
|
||||
nextActivations.remove(pending.activationId());
|
||||
TreeMap<String, GenerationEpoch> nextEpochs = new TreeMap<>(epochs);
|
||||
boolean epochStillReferenced = nextActivations.values().stream()
|
||||
.anyMatch(activation -> activation.epochId().equals(pending.epochId()));
|
||||
if (!epochStillReferenced) {
|
||||
nextEpochs.remove(pending.epochId());
|
||||
}
|
||||
return new GenerationManifest(new State(
|
||||
schemaVersion,
|
||||
nextEpochs,
|
||||
nextActivations,
|
||||
activeActivationId,
|
||||
null
|
||||
));
|
||||
}
|
||||
|
||||
GenerationManifest completePendingTransition(
|
||||
long expectedActivationId,
|
||||
String boundaryIdentity,
|
||||
|
||||
@@ -31,7 +31,6 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
@@ -342,7 +341,19 @@ public final class GenerationSemanticIndex {
|
||||
int regionZ = regionZ(regionKey);
|
||||
RegionShard previous = loadRegionLocked(regionKey, regionX, regionZ);
|
||||
RegionShard replacement = previous.retainingStoredClaims(stored, selected);
|
||||
removed += replaceRegionLocked(regionKey, previous, replacement);
|
||||
int count = previous.recordCount() - replacement.recordCount();
|
||||
if (count == 0) {
|
||||
continue;
|
||||
}
|
||||
byte[] encoded = replacement.encode();
|
||||
String hash = sha256(encoded);
|
||||
publisher.publish(directory, regionX, regionZ, encoded);
|
||||
pointerPublisher.publish(directory, regionX, regionZ, hash);
|
||||
String previousHash = shardHashes.put(regionKey, hash);
|
||||
regionRecordCounts.put(regionKey, replacement.recordCount());
|
||||
cacheRegion(regionKey, replacement);
|
||||
removed += count;
|
||||
deleteUnreferencedShard(regionX, regionZ, previousHash, hash);
|
||||
}
|
||||
return removed;
|
||||
} finally {
|
||||
@@ -351,61 +362,6 @@ public final class GenerationSemanticIndex {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the records of the given chunks that an activation other than the one now owning them claimed, so those
|
||||
* chunks can be generated and recorded again by their owner.
|
||||
*
|
||||
* @return how many records were dropped
|
||||
*/
|
||||
public int forgetEarlierClaims(Collection<GenerationBoundary.ChunkCoordinate> chunks, long owningActivationId)
|
||||
throws IOException {
|
||||
Map<Long, LongOpenHashSet> chunksByRegion = new LinkedHashMap<>();
|
||||
for (GenerationBoundary.ChunkCoordinate chunk : chunks) {
|
||||
chunksByRegion.computeIfAbsent(packRegion(chunk.chunkX() >> 5, chunk.chunkZ() >> 5),
|
||||
ignored -> new LongOpenHashSet()).add(ChunkGenerationOwnership.packChunk(chunk.chunkX(), chunk.chunkZ()));
|
||||
}
|
||||
if (chunksByRegion.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
lock.writeLock().lock();
|
||||
publicationLock.lock();
|
||||
try {
|
||||
compactJournals();
|
||||
int removed = 0;
|
||||
for (Map.Entry<Long, LongOpenHashSet> region : chunksByRegion.entrySet()) {
|
||||
long regionKey = region.getKey();
|
||||
RegionShard previous = loadRegionLocked(regionKey, regionX(regionKey), regionZ(regionKey));
|
||||
RegionShard replacement = previous.withoutEarlierClaims(region.getValue(), owningActivationId);
|
||||
removed += replaceRegionLocked(regionKey, previous, replacement);
|
||||
}
|
||||
if (removed > 0) {
|
||||
riverRevision.incrementAndGet();
|
||||
}
|
||||
return removed;
|
||||
} finally {
|
||||
publicationLock.unlock();
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private int replaceRegionLocked(long regionKey, RegionShard previous, RegionShard replacement) throws IOException {
|
||||
int count = previous.recordCount() - replacement.recordCount();
|
||||
if (count == 0) {
|
||||
return 0;
|
||||
}
|
||||
int regionX = regionX(regionKey);
|
||||
int regionZ = regionZ(regionKey);
|
||||
byte[] encoded = replacement.encode();
|
||||
String hash = sha256(encoded);
|
||||
publisher.publish(directory, regionX, regionZ, encoded);
|
||||
pointerPublisher.publish(directory, regionX, regionZ, hash);
|
||||
String previousHash = shardHashes.put(regionKey, hash);
|
||||
regionRecordCounts.put(regionKey, replacement.recordCount());
|
||||
cacheRegion(regionKey, replacement);
|
||||
deleteUnreferencedShard(regionX, regionZ, previousHash, hash);
|
||||
return count;
|
||||
}
|
||||
|
||||
public void compactJournals() throws IOException {
|
||||
lock.writeLock().lock();
|
||||
publicationLock.lock();
|
||||
@@ -2640,23 +2596,6 @@ public final class GenerationSemanticIndex {
|
||||
return replacement;
|
||||
}
|
||||
|
||||
private RegionShard withoutEarlierClaims(LongOpenHashSet chunks, long owningActivationId) {
|
||||
RegionShard replacement = new RegionShard(regionX, regionZ);
|
||||
for (int index = 0; index < records.length; index++) {
|
||||
ChunkGenerationSemantics record = records[index];
|
||||
if (record == null) {
|
||||
continue;
|
||||
}
|
||||
boolean forgotten = record.activationId() != owningActivationId
|
||||
&& chunks.contains(ChunkGenerationOwnership.packChunk(record.chunkX(), record.chunkZ()));
|
||||
if (!forgotten) {
|
||||
replacement.records[index] = record;
|
||||
replacement.recordCount++;
|
||||
}
|
||||
}
|
||||
return replacement;
|
||||
}
|
||||
|
||||
private RegionShard withRecord(ChunkGenerationSemantics semantics) {
|
||||
if ((semantics.chunkX() >> 5) != regionX || (semantics.chunkZ() >> 5) != regionZ) {
|
||||
throw new IllegalArgumentException("Chunk does not belong to generation semantic shard");
|
||||
|
||||
@@ -35,7 +35,7 @@ final class HistoricalObjectContinuations {
|
||||
}
|
||||
|
||||
List<ObjectContinuation> at(TransitionGenerationPlan plan, int chunkX, int chunkZ) {
|
||||
if (plan == null || plan.isHistoricalChunk(chunkX, chunkZ)) {
|
||||
if (plan == null || plan.boundary().isHistoricalChunk(chunkX, chunkZ)) {
|
||||
return List.of();
|
||||
}
|
||||
RegionKey key = new RegionKey(plan.activationId(), chunkX >> 5, chunkZ >> 5);
|
||||
@@ -74,7 +74,7 @@ final class HistoricalObjectContinuations {
|
||||
for (Map.Entry<Long, ObjectContinuationBundle> entry : stored.entrySet()) {
|
||||
int chunkX = ChunkGenerationOwnership.chunkX(entry.getKey());
|
||||
int chunkZ = ChunkGenerationOwnership.chunkZ(entry.getKey());
|
||||
if (plan.isHistoricalChunk(chunkX, chunkZ)) {
|
||||
if (plan.boundary().isHistoricalChunk(chunkX, chunkZ)) {
|
||||
continue;
|
||||
}
|
||||
for (ObjectContinuationBundle.Fragment fragment : entry.getValue().fragments()) {
|
||||
@@ -99,7 +99,7 @@ final class HistoricalObjectContinuations {
|
||||
private boolean intersectsSavedPlacement(TransitionGenerationPlan plan, long activationId,
|
||||
ObjectContinuationBundle.Fragment fragment) {
|
||||
for (ObjectContinuationBundle.ChunkPosition chunk : fragment.touchedChunks()) {
|
||||
if (plan.isHistoricalChunk(chunk.x(), chunk.z())
|
||||
if (plan.boundary().isHistoricalChunk(chunk.x(), chunk.z())
|
||||
&& history.resolveActivation(chunk.x(), chunk.z()).activationId() == activationId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package art.arcane.iris.world.history;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Historical chunks that regen rebuilt with their activation's own pack. They generate like chunks the transition never
|
||||
* froze. Ownership records each one, so the set is rebuilt after a restart.
|
||||
*/
|
||||
final class ReclaimedChunks {
|
||||
private final Set<Long> chunks = ConcurrentHashMap.newKeySet();
|
||||
|
||||
boolean contains(int chunkX, int chunkZ) {
|
||||
return !chunks.isEmpty() && chunks.contains(ChunkGenerationOwnership.packChunk(chunkX, chunkZ));
|
||||
}
|
||||
|
||||
boolean add(int chunkX, int chunkZ) {
|
||||
return chunks.add(ChunkGenerationOwnership.packChunk(chunkX, chunkZ));
|
||||
}
|
||||
}
|
||||
@@ -203,20 +203,6 @@ final class RegionGenerationOwnership {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Moves an owned chunk to a newer activation; regen uses it when it rebuilds the chunk with that activation's pack. */
|
||||
synchronized boolean reclaim(int chunkX, int chunkZ, long activation) {
|
||||
requireActivation(activation);
|
||||
int index = chunkIndex(chunkX, chunkZ);
|
||||
long existing = activations[index];
|
||||
if (existing == 0L || existing >= activation) {
|
||||
throw new IllegalStateException("Chunk " + chunkX + "," + chunkZ + " belongs to activation " + existing
|
||||
+ " and cannot be reclaimed by activation " + activation);
|
||||
}
|
||||
activations[index] = activation;
|
||||
dirty = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
synchronized int discardUnstoredClaims(WorldChunkInventory stored, Set<Long> activationIds) {
|
||||
int removed = 0;
|
||||
for (int localZ = 0; localZ < CHUNKS_PER_SIDE; localZ++) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -256,18 +255,8 @@ public final class SavedBiomeRuntime implements AutoCloseable {
|
||||
public void capture(SavedBiomeChunk chunk) throws IOException {
|
||||
requireOpen();
|
||||
store.claimAndPersist(chunk);
|
||||
invalidateQuery(chunk.chunkX(), chunk.chunkZ());
|
||||
}
|
||||
|
||||
void invalidateQueries(Collection<GenerationBoundary.ChunkCoordinate> chunks) {
|
||||
for (GenerationBoundary.ChunkCoordinate chunk : chunks) {
|
||||
invalidateQuery(chunk.chunkX(), chunk.chunkZ());
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidateQuery(int chunkX, int chunkZ) {
|
||||
synchronized (queries) {
|
||||
long key = key(chunkX, chunkZ);
|
||||
long key = key(chunk.chunkX(), chunk.chunkZ());
|
||||
PreparedQuery removed = queries.remove(key);
|
||||
if (removed != null) {
|
||||
queryBytes -= removed.estimatedBytes();
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -352,48 +351,6 @@ public final class SavedBiomeStore {
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the saved biomes of the given chunks that an activation other than the one now owning them captured, so
|
||||
* their owner can capture them again.
|
||||
*
|
||||
* @return how many chunks were dropped
|
||||
*/
|
||||
public int forgetEarlierClaims(Collection<GenerationBoundary.ChunkCoordinate> chunks, long owningActivationId)
|
||||
throws IOException {
|
||||
requireSafeAncestors();
|
||||
if (chunks.isEmpty() || !Files.exists(directory, LinkOption.NOFOLLOW_LINKS)) {
|
||||
return 0;
|
||||
}
|
||||
Map<Long, List<GenerationBoundary.ChunkCoordinate>> chunksByRegion = new LinkedHashMap<>();
|
||||
for (GenerationBoundary.ChunkCoordinate chunk : chunks) {
|
||||
chunksByRegion.computeIfAbsent(key(chunk.chunkX() >> 5, chunk.chunkZ() >> 5),
|
||||
ignored -> new ArrayList<>()).add(chunk);
|
||||
}
|
||||
int removed = 0;
|
||||
for (List<GenerationBoundary.ChunkCoordinate> regionChunks : chunksByRegion.values()) {
|
||||
GenerationBoundary.ChunkCoordinate anchor = regionChunks.getFirst();
|
||||
synchronized (regionLock(anchor.chunkX(), anchor.chunkZ())) {
|
||||
requireWritable();
|
||||
RegionIndex region = region(anchor.chunkX(), anchor.chunkZ());
|
||||
boolean[] discarded = new boolean[1024];
|
||||
int count = 0;
|
||||
for (GenerationBoundary.ChunkCoordinate chunk : regionChunks) {
|
||||
int slot = slot(chunk.chunkX(), chunk.chunkZ());
|
||||
if (!discarded[slot] && region.offsets[slot] != 0L
|
||||
&& readRecord(region, slot).activationId() != owningActivationId) {
|
||||
discarded[slot] = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count != 0) {
|
||||
rewriteRegion(region, discarded);
|
||||
removed = Math.addExact(removed, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
int cachedRegionCount() {
|
||||
synchronized (regions) {
|
||||
return regions.size();
|
||||
|
||||
@@ -224,22 +224,6 @@ public final class TerrainBoundarySignatureStore {
|
||||
return load(activationId);
|
||||
}
|
||||
|
||||
synchronized void discardSnapshot(long activationId) throws IOException {
|
||||
Path target = snapshotPath(activationId);
|
||||
if (!Files.exists(directory, LinkOption.NOFOLLOW_LINKS)) {
|
||||
return;
|
||||
}
|
||||
validateStorageAncestors();
|
||||
try (GenerationPublicationLock ignored = GenerationPublicationLock.acquire(
|
||||
directory,
|
||||
".activation-" + activationId + SNAPSHOT_FILE_SUFFIX + ".lock"
|
||||
)) {
|
||||
if (Files.deleteIfExists(target)) {
|
||||
forceDirectory(directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Snapshot load(long activationId) throws IOException {
|
||||
requireActivation(activationId);
|
||||
validateStorageAncestors();
|
||||
|
||||
@@ -10,23 +10,12 @@ public final class TransitionGenerationPlan {
|
||||
private final TransitionBoundarySampler terrainSampler;
|
||||
private final TransitionBandIndex terrainBand;
|
||||
private final TerrainSample newTerrain;
|
||||
private final ReclaimedChunks reclaimedChunks;
|
||||
|
||||
public TransitionGenerationPlan(
|
||||
Specification specification,
|
||||
GenerationBoundary boundary,
|
||||
TerrainBoundarySignatureStore.Snapshot terrainSignatures
|
||||
) {
|
||||
this(specification, boundary, terrainSignatures, new ReclaimedChunks());
|
||||
}
|
||||
|
||||
TransitionGenerationPlan(
|
||||
Specification specification,
|
||||
GenerationBoundary boundary,
|
||||
TerrainBoundarySignatureStore.Snapshot terrainSignatures,
|
||||
ReclaimedChunks reclaimedChunks
|
||||
) {
|
||||
this.reclaimedChunks = Objects.requireNonNull(reclaimedChunks, "Reclaimed chunks");
|
||||
this.specification = Objects.requireNonNull(specification, "Transition specification");
|
||||
this.boundary = Objects.requireNonNull(boundary, "Generation boundary");
|
||||
this.terrainSignatures = Objects.requireNonNull(terrainSignatures, "Terrain signatures");
|
||||
@@ -87,13 +76,8 @@ public final class TransitionGenerationPlan {
|
||||
return terrainSignatures;
|
||||
}
|
||||
|
||||
/** A chunk the boundary froze, unless regen has since rebuilt it with this activation's pack. */
|
||||
public boolean isHistoricalChunk(int chunkX, int chunkZ) {
|
||||
return boundary.isHistoricalChunk(chunkX, chunkZ) && !reclaimedChunks.contains(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
public boolean isHistoricalBlock(int blockX, int blockZ) {
|
||||
return isHistoricalChunk(blockX >> 4, blockZ >> 4);
|
||||
return boundary.isHistoricalBlock(blockX, blockZ);
|
||||
}
|
||||
|
||||
public double distanceToHistoricalChunks(int blockX, int blockZ) {
|
||||
@@ -105,7 +89,7 @@ public final class TransitionGenerationPlan {
|
||||
}
|
||||
|
||||
public boolean allowsNewDiscreteContentAt(int blockX, int blockZ) {
|
||||
return !isHistoricalBlock(blockX, blockZ);
|
||||
return !boundary.isHistoricalBlock(blockX, blockZ);
|
||||
}
|
||||
|
||||
public boolean hasTransitionAtChunk(int chunkX, int chunkZ) {
|
||||
@@ -120,7 +104,7 @@ public final class TransitionGenerationPlan {
|
||||
}
|
||||
|
||||
public TerrainSample terrainSampleAt(int blockX, int blockZ) {
|
||||
if (isHistoricalBlock(blockX, blockZ)) {
|
||||
if (boundary.isHistoricalBlock(blockX, blockZ)) {
|
||||
return TerrainSample.historicalTerrain();
|
||||
}
|
||||
return hasTransitionAtChunk(blockX >> 4, blockZ >> 4) ? terrainSampler.sample(blockX, blockZ) : newTerrain;
|
||||
@@ -145,8 +129,7 @@ public final class TransitionGenerationPlan {
|
||||
if (minimumX > maximumX || minimumZ > maximumZ) {
|
||||
throw new IllegalArgumentException("Generation footprint bounds are inverted");
|
||||
}
|
||||
return !boundary.intersectsHistoricalBlocks(minimumX, minimumZ, maximumX, maximumZ,
|
||||
(chunkX, chunkZ) -> !reclaimedChunks.contains(chunkX, chunkZ));
|
||||
return !boundary.intersectsHistoricalBlocks(minimumX, minimumZ, maximumX, maximumZ);
|
||||
}
|
||||
|
||||
long terrainCatalogProbeCount() {
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
package art.arcane.iris.world.history;
|
||||
|
||||
import art.arcane.iris.generation.runtime.GenerationRoute;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.generation.runtime.PackTransitions;
|
||||
import art.arcane.iris.generation.runtime.RecordedChunks;
|
||||
import art.arcane.iris.generation.runtime.SavedBiomes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Routes each chunk to the generation activation that owns it. Once its router detaches the world can no longer
|
||||
* generate, and the source refuses to route instead of falling back to the current pack.
|
||||
*/
|
||||
public final class VersionedGenerationSource implements GenerationSource {
|
||||
private final AttachedRouter router;
|
||||
private final SavedBiomes savedBiomes;
|
||||
private final RecordedChunks recordedChunks;
|
||||
private final PackTransitions transitions;
|
||||
|
||||
public VersionedGenerationSource(GenerationHistoryRuntimeRouter router) {
|
||||
this.router = new AttachedRouter(router);
|
||||
this.savedBiomes = new VersionedSavedBiomes(this.router);
|
||||
this.recordedChunks = new VersionedRecordedChunks(this.router);
|
||||
this.transitions = new VersionedPackTransitions(this.router);
|
||||
}
|
||||
|
||||
public void detach() {
|
||||
router.detach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keepsPackVersions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationScope openGenerationScope(int blockX, int blockZ) throws IOException {
|
||||
return router.require().openCoordinateScope(blockX, blockZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationScope openReadScope(int blockX, int blockZ) throws IOException {
|
||||
return router.require().openReadScope(blockX, blockZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationRoute openRoute(int chunkX, int chunkZ) throws IOException {
|
||||
return router.require().openRoute(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RouteOwnership> currentRouteOwnership() {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
if (attached == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return attached.currentRuntimeOwnership()
|
||||
.map(ownership -> new RouteOwnership(ownership.activationId(), ownership.binding()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean predatesActivePack(long activationId) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached != null && activationId < attached.history().activeActivation().activationId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseForRegeneration(List<GenerationBoundary.ChunkCoordinate> chunks) throws IOException {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
if (attached != null) {
|
||||
attached.releaseForRegeneration(chunks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync() throws IOException {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
if (attached != null) {
|
||||
attached.history().sync();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedBiomes savedBiomes() {
|
||||
return savedBiomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecordedChunks recordedChunks() {
|
||||
return recordedChunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackTransitions transitions() {
|
||||
return transitions;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package art.arcane.iris.world.history;
|
||||
|
||||
import art.arcane.iris.generation.mantle.ObjectContinuationBundle;
|
||||
import art.arcane.iris.generation.runtime.PackTransitions;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
final class VersionedPackTransitions implements PackTransitions {
|
||||
private final AttachedRouter router;
|
||||
|
||||
VersionedPackTransitions(AttachedRouter router) {
|
||||
this.router = router;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Matter> objectContinuations(TransitionGenerationPlan plan, int chunkX, int chunkZ) throws IOException {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
if (attached == null) {
|
||||
return List.of();
|
||||
}
|
||||
List<GenerationHistoryRuntimeRouter.ObjectContinuation> fragments =
|
||||
attached.objectContinuations(plan, chunkX, chunkZ);
|
||||
return fragments.isEmpty() ? List.of() : attached.decodeObjectContinuations(fragments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsObjectFootprint(
|
||||
TransitionGenerationPlan plan, int minimumX, int minimumZ, int maximumX, int maximumZ
|
||||
) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached == null || attached.allowsObjectFootprint(plan,
|
||||
new ObjectContinuationBundle.Bounds(minimumX, minimumZ, maximumX, maximumZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordNaturalTerrain(SavedTerrainChunk terrain, FloatingBiomeOverlay floatingBiomes) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
if (attached == null) {
|
||||
return;
|
||||
}
|
||||
attached.recordNaturalTerrain(terrain);
|
||||
attached.recordFloatingBiomes(terrain.chunkX(), terrain.chunkZ(), floatingBiomes);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package art.arcane.iris.world.history;
|
||||
|
||||
import art.arcane.iris.generation.runtime.RecordedChunks;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
final class VersionedRecordedChunks implements RecordedChunks {
|
||||
private final AttachedRouter router;
|
||||
|
||||
VersionedRecordedChunks(AttachedRouter router) {
|
||||
this.router = router;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ownedByEarlierPack(int chunkX, int chunkZ) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached != null && attached.history().isHistoricallyOwned(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUnrecordedEarlierPackChunkInSquare(int centerChunkX, int centerChunkZ, int radius) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached != null && attached.history().hasHistoricalFallbackInSquare(centerChunkX, centerChunkZ, radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ChunkGenerationSemantics> semantics(int chunkX, int chunkZ) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
if (attached == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return attached.history().semantics(chunkX, chunkZ).filter(ChunkGenerationSemantics::sealed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GenerationSemanticIndex.Match> findNearest(
|
||||
GenerationSemanticIndex.Query query,
|
||||
Predicate<ChunkGenerationSemantics> eligibility
|
||||
) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached == null ? Optional.empty() : attached.history().findRecorded(query, eligibility);
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package art.arcane.iris.world.history;
|
||||
|
||||
import art.arcane.iris.generation.runtime.BiomeEnvironment;
|
||||
import art.arcane.iris.generation.runtime.SavedBiomes;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
final class VersionedSavedBiomes implements SavedBiomes {
|
||||
private final AttachedRouter router;
|
||||
|
||||
VersionedSavedBiomes(AttachedRouter router) {
|
||||
this.router = router;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BiomeEnvironment> at(int blockX, int worldY, int blockZ, boolean surface) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached == null ? Optional.empty() : attached.biomes().resolve(blockX, worldY, blockZ, surface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BiomeEnvironment> caveBaseAt(int blockX, int blockZ) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached == null ? Optional.empty() : attached.biomes().resolveCaveBase(blockX, blockZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SubterrainCell> subterrainCellAt(int blockX, int worldY, int blockZ) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached == null ? Optional.empty() : attached.biomes().subterrainCell(blockX, worldY, blockZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T readSurface(int blockX, int blockZ, Function<Optional<BiomeEnvironment>, T> reader)
|
||||
throws InterruptedException {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached == null ? reader.apply(Optional.empty())
|
||||
: attached.biomes().readSurfaceBiome(blockX, blockZ, reader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Optional<SavedBiomeRuntime.ReadSession>> readChunk(int chunkX, int chunkZ) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
if (attached == null) {
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
}
|
||||
return attached.biomes().readChunkAsync(chunkX, chunkZ).thenApply(Optional::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareChunk(int chunkX, int chunkZ) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
if (attached != null) {
|
||||
attached.biomes().prepareChunk(chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayHaveBlockDropRules(String material) {
|
||||
GenerationHistoryRuntimeRouter attached = router.attachedOrNull();
|
||||
return attached != null && attached.biomes().mayHaveBlockDropRules(material);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,6 @@ public final class ChunkJobReporter {
|
||||
private final AtomicBoolean failed = new AtomicBoolean(false);
|
||||
private final AtomicInteger applied = new AtomicInteger(0);
|
||||
private final AtomicInteger failures = new AtomicInteger(0);
|
||||
private final AtomicInteger skipped = new AtomicInteger(0);
|
||||
private volatile int total = 0;
|
||||
private volatile long startMs = 0L;
|
||||
|
||||
@@ -90,17 +89,7 @@ public final class ChunkJobReporter {
|
||||
failures.incrementAndGet();
|
||||
}
|
||||
|
||||
updateProgress();
|
||||
}
|
||||
|
||||
/** A chunk the job had nothing to do for. It leaves the total, so the summary only counts chunks the job worked on. */
|
||||
public void countSkipped() {
|
||||
skipped.incrementAndGet();
|
||||
updateProgress();
|
||||
}
|
||||
|
||||
private void updateProgress() {
|
||||
int finished = applied.get() + failures.get() + skipped.get();
|
||||
int finished = applied.get() + failures.get();
|
||||
if (total > 0) {
|
||||
progress.set(Math.min(0.999D, (double) finished / total));
|
||||
}
|
||||
@@ -108,18 +97,10 @@ public final class ChunkJobReporter {
|
||||
|
||||
public void finish(boolean error) {
|
||||
progress.set(1.0D);
|
||||
failed.set(error || (applied.get() == 0 && workedTotal() > 0));
|
||||
failed.set(error || (applied.get() == 0 && total > 0));
|
||||
complete.set(true);
|
||||
}
|
||||
|
||||
public int skipped() {
|
||||
return skipped.get();
|
||||
}
|
||||
|
||||
private int workedTotal() {
|
||||
return total - skipped.get();
|
||||
}
|
||||
|
||||
public int applied() {
|
||||
return applied.get();
|
||||
}
|
||||
@@ -170,7 +151,7 @@ public final class ChunkJobReporter {
|
||||
MessageArgument.trusted("percent", percent),
|
||||
MessageArgument.trusted("stage", stage.get()),
|
||||
MessageArgument.trusted("applied", applied.get()),
|
||||
MessageArgument.trusted("total", total <= 0 ? "?" : workedTotal())
|
||||
MessageArgument.trusted("total", total <= 0 ? "?" : total)
|
||||
));
|
||||
}
|
||||
}, REPORT_INTERVAL_TICKS));
|
||||
@@ -185,14 +166,14 @@ public final class ChunkJobReporter {
|
||||
? IrisLanguage.text(
|
||||
RuntimeProgressMessages.CHUNK_SUMMARY_FAILED,
|
||||
MessageArgument.trusted("applied", applied.get()),
|
||||
MessageArgument.trusted("total", workedTotal()),
|
||||
MessageArgument.trusted("total", total),
|
||||
MessageArgument.trusted("elapsed", Form.duration(elapsed, 1)),
|
||||
MessageArgument.trusted("failures", failures.get())
|
||||
)
|
||||
: IrisLanguage.text(
|
||||
RuntimeProgressMessages.CHUNK_SUMMARY,
|
||||
MessageArgument.trusted("applied", applied.get()),
|
||||
MessageArgument.trusted("total", workedTotal()),
|
||||
MessageArgument.trusted("total", total),
|
||||
MessageArgument.trusted("elapsed", Form.duration(elapsed, 1))
|
||||
);
|
||||
|
||||
|
||||
@@ -25,16 +25,8 @@ import art.arcane.iris.platform.bukkit.nms.INMS;
|
||||
import art.arcane.iris.generation.chunk.TerrainChunk;
|
||||
import art.arcane.iris.generation.chunk.ChunkDataHunkView;
|
||||
import art.arcane.iris.generation.chunk.TerrainChunkBiomeHunkView;
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||
import art.arcane.iris.platform.generation.BukkitChunkGenerator;
|
||||
import art.arcane.iris.platform.generation.BukkitChunkGenerator.GenerationStagePermit;
|
||||
import art.arcane.iris.platform.generation.EngineBukkitOps;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.world.history.GenerationBoundary;
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.generation.runtime.WrongEngineBroException;
|
||||
import art.arcane.iris.world.IrisToolbelt;
|
||||
import art.arcane.iris.generation.mantle.EngineMantle;
|
||||
import art.arcane.iris.generation.mantle.DeferredPlacementRecords;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBiome;
|
||||
@@ -54,12 +46,8 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
@@ -67,8 +55,6 @@ import java.util.function.Consumer;
|
||||
public final class InPlaceChunkRegenerator {
|
||||
private static final int BIOME_STEP = 4;
|
||||
private static final int APPLY_AHEAD = 8;
|
||||
private static final int PROBE_BATCH_CHUNKS = 256;
|
||||
private static final String GENERATION_STAGE = "regen";
|
||||
|
||||
private final World world;
|
||||
private final Engine engine;
|
||||
@@ -96,15 +82,13 @@ public final class InPlaceChunkRegenerator {
|
||||
private void run() {
|
||||
boolean error = false;
|
||||
try {
|
||||
List<int[]> targets = ChunkJobReporter.orderedTargets(centerChunkX, centerChunkZ, radius);
|
||||
releaseForRegeneration(engine, targets);
|
||||
reporter.setStage(IrisLanguage.text(RuntimeProgressMessages.CHUNK_STAGE_RESETTING_MANTLE));
|
||||
resetMantleMargin();
|
||||
|
||||
List<int[]> targets = ChunkJobReporter.orderedTargets(centerChunkX, centerChunkZ, radius);
|
||||
reporter.setTotal(targets.size());
|
||||
reporter.setStage(IrisLanguage.text(RuntimeProgressMessages.CHUNK_STAGE_REGENERATING));
|
||||
regenerate(targets);
|
||||
logSkippedChunks();
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
error = true;
|
||||
@@ -113,33 +97,6 @@ public final class InPlaceChunkRegenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private void logSkippedChunks() {
|
||||
if (reporter.skipped() == 0) {
|
||||
return;
|
||||
}
|
||||
IrisLogging.info("Regen skipped " + reporter.skipped() + " chunks in " + world.getName()
|
||||
+ " that were never generated; they generate fresh when visited.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Chunks generated before the last hotload stay frozen to the old pack, which bars objects, caves and structures there.
|
||||
* Regen always rebuilds with the current pack, so it hands its targets over first.
|
||||
*/
|
||||
static void releaseForRegeneration(Engine engine, List<int[]> targets) throws IOException {
|
||||
if (!(engine instanceof IrisEngine irisEngine)) {
|
||||
return;
|
||||
}
|
||||
GenerationSource source = irisEngine.getGenerationSource();
|
||||
if (!source.keepsPackVersions()) {
|
||||
return;
|
||||
}
|
||||
List<GenerationBoundary.ChunkCoordinate> chunks = new ArrayList<>(targets.size());
|
||||
for (int[] target : targets) {
|
||||
chunks.add(new GenerationBoundary.ChunkCoordinate(target[0], target[1]));
|
||||
}
|
||||
source.releaseForRegeneration(chunks);
|
||||
}
|
||||
|
||||
private void resetMantleMargin() {
|
||||
EngineMantle engineMantle = engine.getMantle();
|
||||
Mantle<Matter> mantle = engineMantle.getMantle();
|
||||
@@ -154,133 +111,59 @@ public final class InPlaceChunkRegenerator {
|
||||
|
||||
private void regenerate(List<int[]> targets) throws InterruptedException {
|
||||
Semaphore inFlight = new Semaphore(APPLY_AHEAD);
|
||||
CountDownLatch allApplied = new CountDownLatch(targets.size());
|
||||
|
||||
for (int from = 0; from < targets.size(); from += PROBE_BATCH_CHUNKS) {
|
||||
List<int[]> batch = targets.subList(from, Math.min(targets.size(), from + PROBE_BATCH_CHUNKS));
|
||||
for (int[] generated : generatedChunksOf(batch)) {
|
||||
inFlight.acquire();
|
||||
MultiBurst.burst.lazy(() -> regenerateChunk(generated[0], generated[1], inFlight::release));
|
||||
}
|
||||
}
|
||||
for (int[] target : targets) {
|
||||
int chunkX = target[0];
|
||||
int chunkZ = target[1];
|
||||
|
||||
inFlight.acquire(APPLY_AHEAD);
|
||||
}
|
||||
inFlight.acquire();
|
||||
MultiBurst.burst.lazy(() -> {
|
||||
// Settle exactly once no matter which path fails: an unguarded throw here
|
||||
// (TerrainChunk.create, runRegion) parked the regen thread on the latch
|
||||
// forever and stranded the player's boss bar. CAS is required — on Folia's
|
||||
// owned-region path runRegion runs the apply inline before returning.
|
||||
AtomicBoolean settled = new AtomicBoolean();
|
||||
Consumer<Boolean> settle = ok -> {
|
||||
if (settled.compareAndSet(false, true)) {
|
||||
reporter.countApplied(ok);
|
||||
inFlight.release();
|
||||
allApplied.countDown();
|
||||
}
|
||||
};
|
||||
try {
|
||||
TerrainChunk buffer = TerrainChunk.create(world);
|
||||
engine.generate(chunkX << 4, chunkZ << 4, new ChunkDataHunkView(buffer.getChunkData()),
|
||||
new TerrainChunkBiomeHunkView(buffer), false);
|
||||
|
||||
/**
|
||||
* Chunks that were never generated are skipped: their mantle is reset, so they generate fresh when first visited.
|
||||
* Regenerating them here would generate each one twice, and loading them on the server thread stalls it.
|
||||
*/
|
||||
private List<int[]> generatedChunksOf(List<int[]> batch) {
|
||||
List<CompletableFuture<Chunk>> loads = new ArrayList<>(batch.size());
|
||||
for (int[] target : batch) {
|
||||
loads.add(loadIfGenerated(target[0], target[1]));
|
||||
}
|
||||
boolean scheduled = J.runRegion(world, chunkX, chunkZ, () -> {
|
||||
boolean ok = false;
|
||||
try {
|
||||
applyToLiveChunk(chunkX, chunkZ, buffer);
|
||||
ok = true;
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
} finally {
|
||||
settle.accept(ok);
|
||||
}
|
||||
});
|
||||
|
||||
List<int[]> generated = new ArrayList<>(batch.size());
|
||||
for (int index = 0; index < batch.size(); index++) {
|
||||
try {
|
||||
if (loads.get(index).join() == null) {
|
||||
reporter.countSkipped();
|
||||
continue;
|
||||
}
|
||||
generated.add(batch.get(index));
|
||||
} catch (CompletionException | CancellationException e) {
|
||||
IrisLogging.reportError(e);
|
||||
reporter.countApplied(false);
|
||||
}
|
||||
}
|
||||
return generated;
|
||||
}
|
||||
|
||||
/** Spigot has no async chunk loading, so its fallback loads in place; that must happen on the server thread. */
|
||||
private CompletableFuture<Chunk> loadIfGenerated(int chunkX, int chunkZ) {
|
||||
if (BukkitPlatform.isPaperServer()) {
|
||||
return BukkitPlatform.chunkAtAsync(world, chunkX, chunkZ, false);
|
||||
}
|
||||
return J.sfut(() -> BukkitPlatform.chunkAtAsync(world, chunkX, chunkZ, false)).thenCompose(load -> load);
|
||||
}
|
||||
|
||||
private void regenerateChunk(int chunkX, int chunkZ, Runnable release) {
|
||||
// Settle exactly once no matter which path fails: an unguarded throw stranded the regen thread and the
|
||||
// player's boss bar. CAS is required because the apply can run inline, before the scheduling call returns.
|
||||
AtomicBoolean settled = new AtomicBoolean();
|
||||
Consumer<Boolean> settle = ok -> {
|
||||
if (settled.compareAndSet(false, true)) {
|
||||
reporter.countApplied(ok);
|
||||
release.run();
|
||||
}
|
||||
};
|
||||
try {
|
||||
TerrainChunk buffer = generate(chunkX, chunkZ);
|
||||
loadIfGenerated(chunkX, chunkZ).whenComplete((chunk, loadFailure) -> {
|
||||
if (loadFailure != null) {
|
||||
IrisLogging.reportError(loadFailure);
|
||||
}
|
||||
if (!scheduledApply(chunk, buffer, settle)) {
|
||||
if (!scheduled) {
|
||||
IrisLogging.warn("Regen could not schedule chunk apply at " + chunkX + "," + chunkZ + " in " + world.getName() + ".");
|
||||
settle.accept(false);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
settle.accept(false);
|
||||
}
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
settle.accept(false);
|
||||
}
|
||||
|
||||
allApplied.await();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false when the apply could not be handed to the thread owning the chunk, so the caller settles the chunk
|
||||
* as failed; true leaves settling to the apply.
|
||||
*/
|
||||
private boolean scheduledApply(Chunk chunk, TerrainChunk buffer, Consumer<Boolean> settle) {
|
||||
if (chunk == null) {
|
||||
IrisLogging.warn("Regen could not load a chunk it found generated in " + world.getName() + ".");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return runOnThreadOwning(chunk, () -> settle.accept(applied(chunk, buffer)));
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Holds a generation stage like any chunk the server generates, so a hotload waits for it instead of rejecting it. */
|
||||
private TerrainChunk generate(int chunkX, int chunkZ) throws WrongEngineBroException {
|
||||
TerrainChunk buffer = TerrainChunk.create(world);
|
||||
try (GenerationStagePermit ignored = acquireGenerationStage()) {
|
||||
engine.generate(chunkX << 4, chunkZ << 4, new ChunkDataHunkView(buffer.getChunkData()),
|
||||
new TerrainChunkBiomeHunkView(buffer), false);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private GenerationStagePermit acquireGenerationStage() {
|
||||
if (IrisToolbelt.access(world) instanceof BukkitChunkGenerator generator) {
|
||||
return generator.acquireGenerationStage(GENERATION_STAGE);
|
||||
}
|
||||
return GenerationStagePermit.noop();
|
||||
}
|
||||
|
||||
private boolean runOnThreadOwning(Chunk chunk, Runnable task) {
|
||||
if (!J.isFolia() && J.isPrimaryThread()) {
|
||||
task.run();
|
||||
return true;
|
||||
}
|
||||
return J.runRegion(world, chunk.getX(), chunk.getZ(), task);
|
||||
}
|
||||
|
||||
private boolean applied(Chunk chunk, TerrainChunk buffer) {
|
||||
try {
|
||||
applyToLiveChunk(chunk, buffer);
|
||||
return true;
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void applyToLiveChunk(Chunk chunk, TerrainChunk buffer) {
|
||||
int chunkX = chunk.getX();
|
||||
int chunkZ = chunk.getZ();
|
||||
private void applyToLiveChunk(int chunkX, int chunkZ, TerrainChunk buffer) {
|
||||
Chunk chunk = world.getChunkAt(chunkX, chunkZ);
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
if (!(entity instanceof Player)) {
|
||||
entity.remove();
|
||||
|
||||
@@ -72,25 +72,18 @@ public class IrisSettingsDefaultsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioPackVersionsAreOptInAndAcceptEnabledHotload() {
|
||||
public void studioBlendingDefaultsOnAndAcceptsDisabledHotload() {
|
||||
IrisSettings defaults = new IrisSettings();
|
||||
assertFalse(defaults.getStudio().isKeepPackVersions());
|
||||
assertFalse(new Gson().fromJson("{\"studio\":{}}", IrisSettings.class).getStudio().isKeepPackVersions());
|
||||
assertTrue(new Gson().toJson(defaults).contains("\"keepPackVersions\":false"));
|
||||
assertTrue(defaults.getStudio().isBlendChanges());
|
||||
assertTrue(new Gson().fromJson("{\"studio\":{}}", IrisSettings.class).getStudio().isBlendChanges());
|
||||
assertTrue(new Gson().toJson(defaults).contains("\"blendChanges\":true"));
|
||||
|
||||
IrisSettings changed = IrisSettings.parseHotloadSnapshot("{\"studio\":{\"keepPackVersions\":true}}");
|
||||
IrisSettings changed = IrisSettings.parseHotloadSnapshot("{\"studio\":{\"blendChanges\":false}}");
|
||||
|
||||
assertTrue(changed.getStudio().isKeepPackVersions());
|
||||
assertFalse(changed.getStudio().isBlendChanges());
|
||||
assertEquals(256, changed.getGenerator().getGenerationTransitionWidthBlocks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settingsSavedBeforePackVersionsBecameOptInStaySinglePack() {
|
||||
IrisSettings saved = IrisSettings.parseHotloadSnapshot("{\"studio\":{\"blendChanges\":true}}");
|
||||
|
||||
assertFalse(saved.getStudio().isKeepPackVersions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hotloadSnapshotIsValidatedBeforeReplacingLiveSettings() {
|
||||
IrisSettings previous = IrisSettings.settings;
|
||||
|
||||
+74
@@ -2,14 +2,20 @@ package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.noise.IrisExpression;
|
||||
import art.arcane.iris.generation.noise.IrisExpressionFunction;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.loading.ResourceLoader;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -17,6 +23,9 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -28,6 +37,71 @@ public final class IrisBiomePaletteLayerGeneratorCacheTest {
|
||||
private static final int SIGNATURE = 7;
|
||||
private static final long LAYER_SIGNATURE = 2L;
|
||||
|
||||
@Test
|
||||
public void coordinateOnlyLayerSharesOneGeneratorWithoutChangingItsSamples() {
|
||||
IrisGeneratorStyle color = new IrisGeneratorStyle().setExpression("color");
|
||||
PackRuntime runtime = runtimeWithExpressions(Map.of(
|
||||
"material", new IrisExpression()
|
||||
.setExpression("if(y >= 25 + 19 * cos((x-y)/43), 0.90, color(abs(sin((x-y)/19 + z/33)), 0, 0))")
|
||||
.setFunctions(new KList<>(new IrisExpressionFunction().setName("color").setArgs(3).setStyleValue(color))),
|
||||
"color", new IrisExpression().setExpression("if(x < 0.03, 0.70, if(x < 0.07, 0.40, 0.10))")));
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle().setExpression("material");
|
||||
IrisBiomePaletteLayer layer = new IrisBiomePaletteLayer().zero().setStyle(style);
|
||||
CNG shared = layer.getLayerGenerator(new RNG(17L), 0, runtime);
|
||||
List<String> blocks = List.of("end_stone", "blackstone", "obsidian", "air");
|
||||
|
||||
for (int depth = 0; depth < 79; depth++) {
|
||||
RNG caller = new RNG(17L + depth * 41L);
|
||||
long originalSeed = caller.getSeed() + depth + LAYER_SIGNATURE;
|
||||
CNG original = style.createNoCache(new RNG(originalSeed), runtime);
|
||||
assertSame(shared, layer.getLayerGenerator(caller, depth, runtime));
|
||||
for (int x = -32; x < 32; x += 3) {
|
||||
double z = 41.5D - x;
|
||||
assertEquals(original.fit(blocks, x, depth, z), shared.fit(blocks, x, depth, z));
|
||||
assertEquals(original.noise(x, depth, z), shared.noise(x, depth, z), 0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedSeededNoiseKeepsDistinctLayerGenerators() {
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle().setExpression("seeded");
|
||||
PackRuntime runtime = runtimeWithExpressions(Map.of(
|
||||
"seeded", new IrisExpression().setExpression("noise(x, z)")
|
||||
.setFunctions(new KList<>(new IrisExpressionFunction()
|
||||
.setName("noise").setStyleValue(NoiseStyle.SIMPLEX.style())))));
|
||||
IrisBiomePaletteLayer layer = new IrisBiomePaletteLayer().zero().setStyle(style);
|
||||
CNG first = layer.getLayerGenerator(new RNG(17L), 0, runtime);
|
||||
CNG second = layer.getLayerGenerator(new RNG(29L), 0, runtime);
|
||||
|
||||
assertNotSame(first, second);
|
||||
assertEquals(style.createNoCache(new RNG(17L + LAYER_SIGNATURE), runtime).noise(-23D, 7D, 11D),
|
||||
first.noise(-23D, 7D, 11D), 0D);
|
||||
assertEquals(style.createNoCache(new RNG(29L + LAYER_SIGNATURE), runtime).noise(-23D, 7D, 11D),
|
||||
second.noise(-23D, 7D, 11D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recursiveAndMissingExpressionReferencesDoNotQualifyForSharing() {
|
||||
IrisGeneratorStyle recursive = new IrisGeneratorStyle().setExpression("recursive");
|
||||
IrisGeneratorStyle missing = new IrisGeneratorStyle().setExpression("missing");
|
||||
PackRuntime runtime = runtimeWithExpressions(Map.of(
|
||||
"recursive", new IrisExpression().setExpression("again(x, z)")
|
||||
.setFunctions(new KList<>(new IrisExpressionFunction()
|
||||
.setName("again").setStyleValue(recursive)))));
|
||||
|
||||
assertFalse(recursive.canShareExpressionGenerator(runtime.data()));
|
||||
assertFalse(missing.canShareExpressionGenerator(runtime.data()));
|
||||
}
|
||||
|
||||
private static PackRuntime runtimeWithExpressions(Map<String, IrisExpression> contents) {
|
||||
IrisData data = MockPackData.create();
|
||||
ResourceLoader<IrisExpression> expressions = mock();
|
||||
when(data.getExpressionLoader()).thenReturn(expressions);
|
||||
when(expressions.load(any(String.class))).thenAnswer(call -> contents.get(call.getArgument(0)));
|
||||
return data.standalonePackRuntime();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void callerSeedsDoNotShareAFirstWinnerGenerator() {
|
||||
GeneratorFixture fixture = new GeneratorFixture();
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public final class PaletteLayerDepthCacheTest {
|
||||
private static final long[] PARENT_SEEDS = {0L, 17L, -9_223_372_036_854_775_807L, 8_675_309L, 1_234_567_890_123L};
|
||||
private static final int[] THICKNESSES = {1, 8, 33, 96, 300};
|
||||
private static final int LAYER_INDEX = 3;
|
||||
private static final int COLUMNS = 256;
|
||||
private static final int BENCH_THICKNESS = 96;
|
||||
private static final int BENCH_CHUNKS = 8;
|
||||
|
||||
@Test
|
||||
public void deepLayerBuildsEachDepthGeneratorOnce() {
|
||||
CountingStyle style = new CountingStyle(NoiseStyle.SIMPLEX);
|
||||
IrisBiomePaletteLayer layer = layer(style, BENCH_THICKNESS);
|
||||
PackRuntime runtime = MockPackData.create().standalonePackRuntime();
|
||||
|
||||
walkChunks(layer, runtime, new RNG(17L), BENCH_THICKNESS, 2);
|
||||
|
||||
assertEquals(BENCH_THICKNESS, style.builds.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seededLayerBuildsOneGeneratorForEveryDepthAndParent() {
|
||||
CountingStyle style = new CountingStyle(NoiseStyle.SIMPLEX);
|
||||
style.setSeed(4_242L);
|
||||
IrisBiomePaletteLayer layer = layer(style, BENCH_THICKNESS);
|
||||
PackRuntime runtime = MockPackData.create().standalonePackRuntime();
|
||||
|
||||
for (long parentSeed : PARENT_SEEDS) {
|
||||
walkChunks(layer, runtime, new RNG(parentSeed), BENCH_THICKNESS, 1);
|
||||
}
|
||||
|
||||
assertEquals(1, style.builds.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cachedDepthGeneratorsMatchFreshBuilds() {
|
||||
assertMatchesFreshBuilds(new IrisGeneratorStyle(NoiseStyle.SIMPLEX));
|
||||
assertMatchesFreshBuilds(new IrisGeneratorStyle(NoiseStyle.CELLULAR).setFracture(
|
||||
new IrisGeneratorStyle(NoiseStyle.PERLIN).zoomed(3D)).zoomed(0.5D));
|
||||
assertMatchesFreshBuilds(new IrisGeneratorStyle(NoiseStyle.SIMPLEX).setSeed(77L));
|
||||
assertMatchesFreshBuilds(new IrisGeneratorStyle(NoiseStyle.PERLIN).setSeed(-3L)
|
||||
.setFracture(new IrisGeneratorStyle(NoiseStyle.SIMPLEX)));
|
||||
}
|
||||
|
||||
/** Prints builds and thread CPU time for a deep-layer chunk walk; compare runs on the same machine. */
|
||||
@Test
|
||||
public void reportDeepLayerWalkCost() {
|
||||
ThreadMXBean threads = ManagementFactory.getThreadMXBean();
|
||||
for (int round = 0; round < 3; round++) {
|
||||
for (boolean fractured : new boolean[]{false, true}) {
|
||||
CountingStyle style = new CountingStyle(fractured ? NoiseStyle.CELLULAR : NoiseStyle.SIMPLEX);
|
||||
if (fractured) {
|
||||
style.setFracture(new IrisGeneratorStyle(NoiseStyle.PERLIN).zoomed(3D));
|
||||
}
|
||||
IrisBiomePaletteLayer layer = layer(style, BENCH_THICKNESS);
|
||||
PackRuntime runtime = MockPackData.create().standalonePackRuntime();
|
||||
long start = threads.getCurrentThreadCpuTime();
|
||||
double sink = walkChunks(layer, runtime, new RNG(17L), BENCH_THICKNESS, BENCH_CHUNKS);
|
||||
long cpu = threads.getCurrentThreadCpuTime() - start;
|
||||
System.out.printf("palette depth walk %s: thickness=%d chunks=%d builds=%d cpu=%.1fms (%.2fms/chunk) sink=%.3f%n",
|
||||
fractured ? "cellular+fracture" : "simplex", BENCH_THICKNESS, BENCH_CHUNKS, style.builds.get(),
|
||||
cpu / 1e6D, cpu / 1e6D / BENCH_CHUNKS, sink);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertMatchesFreshBuilds(IrisGeneratorStyle style) {
|
||||
for (int thickness : THICKNESSES) {
|
||||
IrisBiomePaletteLayer layer = layer(style, thickness);
|
||||
PackRuntime runtime = MockPackData.create().standalonePackRuntime();
|
||||
int blockCount = layer.getBlockData(runtime.data()).size();
|
||||
for (int pass = 0; pass < 2; pass++) {
|
||||
for (long parentSeed : PARENT_SEEDS) {
|
||||
RNG parent = new RNG(parentSeed);
|
||||
for (int depth = 0; depth < thickness; depth++) {
|
||||
int signature = LAYER_INDEX + depth;
|
||||
long seed = parentSeed + signature + thickness + thickness + blockCount;
|
||||
CNG fresh = style.createNoCache(new RNG(seed), runtime);
|
||||
CNG cached = layer.getLayerGenerator(parent, signature, runtime);
|
||||
for (int sample = 0; sample < 6; sample++) {
|
||||
double x = sample * 37.25D - 91D + depth;
|
||||
double z = 13.5D - sample * 19D - depth;
|
||||
assertEquals(fresh.noise(x, depth, z), cached.noise(x, depth, z), 0D);
|
||||
assertEquals(fresh.noise(x, z), cached.noise(x, z), 0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double walkChunks(IrisBiomePaletteLayer layer, PackRuntime runtime, RNG parent, int thickness, int chunks) {
|
||||
double sink = 0D;
|
||||
for (int chunk = 0; chunk < chunks; chunk++) {
|
||||
for (int column = 0; column < COLUMNS; column++) {
|
||||
double x = chunk * 16 + (column & 15);
|
||||
double z = column >> 4;
|
||||
for (int depth = 0; depth < thickness; depth++) {
|
||||
sink += layer.getLayerGenerator(parent, LAYER_INDEX + depth, runtime).noise(x + depth, depth, z - depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sink;
|
||||
}
|
||||
|
||||
private static IrisBiomePaletteLayer layer(IrisGeneratorStyle style, int thickness) {
|
||||
return new IrisBiomePaletteLayer().zero().setStyle(style).setMinHeight(thickness).setMaxHeight(thickness);
|
||||
}
|
||||
|
||||
private static final class CountingStyle extends IrisGeneratorStyle {
|
||||
private final AtomicInteger builds = new AtomicInteger();
|
||||
|
||||
private CountingStyle(NoiseStyle style) {
|
||||
super(style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CNG createNoCache(RNG rng, PackRuntime runtime) {
|
||||
builds.incrementAndGet();
|
||||
return super.createNoCache(rng, runtime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package art.arcane.iris.generation.locator;
|
||||
|
||||
import art.arcane.iris.generation.runtime.GenerationSource;
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
@@ -48,7 +46,6 @@ public class BiomeLocatorTest {
|
||||
GenerationHistory history = mock(GenerationHistory.class);
|
||||
SavedBiomeRuntime saved = mock(SavedBiomeRuntime.class);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.history()).thenReturn(history);
|
||||
when(router.biomes()).thenReturn(saved);
|
||||
when(history.isActiveUnowned(0, 0)).thenReturn(true);
|
||||
@@ -67,9 +64,7 @@ public class BiomeLocatorTest {
|
||||
SavedBiomeRuntime saved = mock(SavedBiomeRuntime.class);
|
||||
BiomeEnvironment environment = mock(BiomeEnvironment.class);
|
||||
when(retained.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(retained.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
GenerationHistory history = historyOwning(0, 0);
|
||||
when(router.history()).thenReturn(history);
|
||||
when(router.history()).thenReturn(mock(GenerationHistory.class));
|
||||
when(router.biomes()).thenReturn(saved);
|
||||
when(environment.biome()).thenReturn(biome("deep"));
|
||||
when(saved.resolve(8, -20, 8, false)).thenReturn(Optional.of(environment));
|
||||
@@ -87,7 +82,6 @@ public class BiomeLocatorTest {
|
||||
GenerationHistoryRuntimeRouter router = mock(GenerationHistoryRuntimeRouter.class);
|
||||
GenerationHistory history = mock(GenerationHistory.class);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.history()).thenReturn(history);
|
||||
Position2 near = new Position2(1, 0);
|
||||
Position2 far = new Position2(4, 0);
|
||||
@@ -137,9 +131,7 @@ public class BiomeLocatorTest {
|
||||
BiomeEnvironment environment = mock(BiomeEnvironment.class);
|
||||
when(environment.biome()).thenReturn(biome("deep"));
|
||||
when(retained.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(retained.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
GenerationHistory history = historyOwning(0, 0);
|
||||
when(router.history()).thenReturn(history);
|
||||
when(router.history()).thenReturn(mock(GenerationHistory.class));
|
||||
when(router.biomes()).thenReturn(saved);
|
||||
when(saved.readChunkAsync(0, 0)).thenReturn(CompletableFuture.completedFuture(read));
|
||||
when(read.resolve(0, -20, 0, false)).thenReturn(Optional.of(environment));
|
||||
@@ -154,10 +146,8 @@ public class BiomeLocatorTest {
|
||||
when(retained.getData().getBiomeLoader().load("deep")).thenReturn(biome("deep"));
|
||||
when(retained.getCaveBiome(8, 8)).thenReturn(biome("other"));
|
||||
when(retained.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.empty());
|
||||
when(retained.getGenerationSource()).thenReturn(GenerationSource.singlePack());
|
||||
BiomeLocator locator = (BiomeLocator) BiomeLocator.forBiome(retained, "deep", 59);
|
||||
when(retained.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(retained.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
assertEquals(new SubterrainPosition(0, -20, 0), locator.position(retained, new Position2(0, 0)));
|
||||
verify(read).resolve(0, -20, 0, false);
|
||||
}
|
||||
@@ -170,7 +160,6 @@ public class BiomeLocatorTest {
|
||||
SavedBiomeRuntime saved = mock(SavedBiomeRuntime.class);
|
||||
BiomeEnvironment environment = mock(BiomeEnvironment.class);
|
||||
when(retained.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(retained.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.history()).thenReturn(mock(GenerationHistory.class));
|
||||
when(router.biomes()).thenReturn(saved);
|
||||
when(environment.biome()).thenReturn(biome("deep"));
|
||||
@@ -208,12 +197,6 @@ public class BiomeLocatorTest {
|
||||
assertEquals(new SubterrainPosition(8, 102, 8), locator.position(engine, new Position2(0, 0)));
|
||||
}
|
||||
|
||||
private static GenerationHistory historyOwning(int chunkX, int chunkZ) {
|
||||
GenerationHistory history = mock(GenerationHistory.class);
|
||||
when(history.isHistoricallyOwned(chunkX, chunkZ)).thenReturn(true);
|
||||
return history;
|
||||
}
|
||||
|
||||
private static Engine catalogEngine() {
|
||||
Engine engine = mock(Engine.class, RETURNS_DEEP_STUBS);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package art.arcane.iris.generation.locator;
|
||||
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.generation.runtime.GenerationScope;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionLease;
|
||||
|
||||
@@ -529,7 +527,6 @@ public class HintedLocatorTest {
|
||||
GenerationHistory history = mock(GenerationHistory.class);
|
||||
GenerationHistoryRuntimeRouter router = mock(GenerationHistoryRuntimeRouter.class);
|
||||
when(routedEngine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(routedEngine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(routedEngine.acquireGenerationLease(any(String.class))).thenReturn(GenerationSessionLease.noop());
|
||||
when(router.history()).thenReturn(history);
|
||||
when(history.hasHistoricalFallbackInSquare(anyInt(), anyInt(), anyInt())).thenReturn(false);
|
||||
@@ -667,7 +664,6 @@ public class HintedLocatorTest {
|
||||
|
||||
when(routedEngine.getComplex()).thenReturn(routedComplex);
|
||||
when(routedEngine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(routedEngine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.history()).thenReturn(history);
|
||||
when(history.semantics(anyInt(), anyInt())).thenAnswer(invocation -> switch (
|
||||
invocation.<Integer>getArgument(0)
|
||||
@@ -684,9 +680,9 @@ public class HintedLocatorTest {
|
||||
invocation.<Integer>getArgument(0) == 3);
|
||||
when(routedComplex.allowsNewGenerationChunk(anyInt(), anyInt())).thenAnswer(invocation ->
|
||||
invocation.<Integer>getArgument(0) == 3);
|
||||
when(routedEngine.openGenerationScope(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
GenerationScope scope =
|
||||
mock(GenerationScope.class);
|
||||
when(routedEngine.openGenerationHistoryCoordinateScope(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
GenerationHistoryRuntimeRouter.CoordinateScope scope =
|
||||
mock(GenerationHistoryRuntimeRouter.CoordinateScope.class);
|
||||
scopeDepth.incrementAndGet();
|
||||
doAnswer(close -> {
|
||||
scopeDepth.decrementAndGet();
|
||||
@@ -726,7 +722,6 @@ public class HintedLocatorTest {
|
||||
|
||||
when(routedEngine.getComplex()).thenReturn(routedComplex);
|
||||
when(routedEngine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(routedEngine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(routedEngine.isClosed()).thenReturn(false);
|
||||
when(routedEngine.acquireGenerationLease(any(String.class))).thenReturn(GenerationSessionLease.noop());
|
||||
when(router.history()).thenReturn(history);
|
||||
@@ -740,9 +735,9 @@ public class HintedLocatorTest {
|
||||
&& Math.abs((long) invocation.<Integer>getArgument(1)) <= invocation.<Integer>getArgument(2));
|
||||
when(history.isActiveUnowned(anyInt(), anyInt())).thenReturn(false);
|
||||
when(routedComplex.allowsNewGenerationChunk(anyInt(), anyInt())).thenReturn(false);
|
||||
when(routedEngine.openGenerationScope(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
GenerationScope scope =
|
||||
mock(GenerationScope.class);
|
||||
when(routedEngine.openGenerationHistoryCoordinateScope(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
GenerationHistoryRuntimeRouter.CoordinateScope scope =
|
||||
mock(GenerationHistoryRuntimeRouter.CoordinateScope.class);
|
||||
scopeDepth.incrementAndGet();
|
||||
doAnswer(close -> {
|
||||
scopeDepth.decrementAndGet();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.platform.bukkit.nms.BukkitGenerationPolicy;
|
||||
import art.arcane.iris.world.IrisWorld;
|
||||
@@ -111,7 +110,6 @@ public class EngineHotloaderRecoveryTest {
|
||||
when(engine.acquireGenerationLease(anyString())).thenAnswer(invocation ->
|
||||
sessions.acquireForEngine(engine, invocation.getArgument(0, String.class)));
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(router.history()).thenReturn(history);
|
||||
when(router.beginStudioCutover(anyLong())).thenReturn(cutover);
|
||||
when(background.drainBackgroundTasks(anyString())).thenReturn(
|
||||
|
||||
-2
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
@@ -47,7 +46,6 @@ public class EngineHotloaderRetirementTest {
|
||||
GenerationHistory history = mock(GenerationHistory.class);
|
||||
when(router.history()).thenReturn(history);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(engine.isStudio()).thenReturn(true);
|
||||
IrisWorld world = mock(IrisWorld.class);
|
||||
when(world.name()).thenReturn("studio");
|
||||
|
||||
-82
@@ -1,82 +0,0 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
import art.arcane.iris.structure.placement.StructureReachability;
|
||||
import art.arcane.iris.world.IrisWorld;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class EngineHotloaderSinglePackStudioTest {
|
||||
private static final String DIMENSION_KEY = "overworld";
|
||||
|
||||
@Test
|
||||
public void studioHotloadWithoutHistoryReloadsTheAuthoringPackInPlace() throws Exception {
|
||||
IrisEngine engine = mock(IrisEngine.class);
|
||||
setField(engine, "lifecycleLock", new Object());
|
||||
EngineRuntimeBuilder runtimeBuilder = mock(EngineRuntimeBuilder.class);
|
||||
setField(engine, "runtimeBuilder", runtimeBuilder);
|
||||
EngineRuntime previousRuntime = mock(EngineRuntime.class);
|
||||
EngineRuntime nextRuntime = mock(EngineRuntime.class);
|
||||
engine.runtime = previousRuntime;
|
||||
engine.lifecycleState = IrisEngine.LifecycleState.RUNNING;
|
||||
when(engine.isStudio()).thenReturn(true);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.empty());
|
||||
File authoring = new File("authoring-pack");
|
||||
IrisData previousData = mock(IrisData.class);
|
||||
when(previousData.getDataFolder()).thenReturn(authoring);
|
||||
when(engine.getData()).thenReturn(previousData);
|
||||
IrisDimension previousDimension = mock(IrisDimension.class);
|
||||
when(previousDimension.getLoadKey()).thenReturn(DIMENSION_KEY);
|
||||
when(engine.getDimension()).thenReturn(previousDimension);
|
||||
IrisWorld world = mock(IrisWorld.class);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
when(engine.getPlatformHooks()).thenReturn(mock(EnginePlatformHooks.class));
|
||||
when(engine.getEngineData()).thenReturn(mock(IrisEngineData.class, RETURNS_DEEP_STUBS));
|
||||
when(engine.getPrefetchSaveStarted()).thenReturn(new AtomicBoolean(true));
|
||||
IrisData replacementData = mock(IrisData.class, RETURNS_DEEP_STUBS);
|
||||
IrisDimension replacementDimension = mock(IrisDimension.class);
|
||||
when(replacementData.getDimensionLoader().load(DIMENSION_KEY)).thenReturn(replacementDimension);
|
||||
when(runtimeBuilder.buildRuntime(any(EngineTarget.class))).thenReturn(nextRuntime);
|
||||
|
||||
try (MockedStatic<IrisData> data = mockStatic(IrisData.class);
|
||||
MockedStatic<StudioGenerationUpdate> updates = mockStatic(StudioGenerationUpdate.class);
|
||||
MockedStatic<IrisStructureLocator> structures = mockStatic(IrisStructureLocator.class);
|
||||
MockedStatic<StructureReachability> reachability = mockStatic(StructureReachability.class)) {
|
||||
data.when(() -> IrisData.openRuntime(authoring)).thenReturn(replacementData);
|
||||
|
||||
new EngineHotloader(engine).hotloadSilently();
|
||||
|
||||
updates.verifyNoInteractions();
|
||||
}
|
||||
|
||||
ArgumentCaptor<EngineTarget> target = ArgumentCaptor.forClass(EngineTarget.class);
|
||||
verify(runtimeBuilder).buildRuntime(target.capture());
|
||||
assertSame(replacementDimension, target.getValue().getDimension());
|
||||
assertSame(replacementData, target.getValue().getData());
|
||||
verify(runtimeBuilder).publishRuntime(nextRuntime, previousRuntime);
|
||||
verify(replacementData).registerEngine(engine);
|
||||
verify(previousData).unregisterEngine(engine);
|
||||
}
|
||||
|
||||
private static void setField(IrisEngine engine, String name, Object value) throws ReflectiveOperationException {
|
||||
Field field = IrisEngine.class.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(engine, value);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -134,7 +134,7 @@ public class EngineModeGenerationWaterTest {
|
||||
private static IrisEngine matterEngine(IrisComplex complex, EngineMantle mantle) throws Exception {
|
||||
IrisEngine engine = mock(IrisEngine.class);
|
||||
doNothing().when(engine).awaitGenerationCacheWarm();
|
||||
doReturn(mock(GenerationScope.class)).when(engine).openGenerationScope(anyInt(), anyInt());
|
||||
doReturn(mock(GenerationHistoryRuntimeRouter.CoordinateScope.class)).when(engine).openGenerationHistoryCoordinateScope(anyInt(), anyInt());
|
||||
doReturn(mock(GenerationSessionLease.class)).when(engine).acquireGenerationLease(anyString());
|
||||
doReturn(complex).when(engine).getComplex();
|
||||
doReturn(mantle).when(engine).getMantle();
|
||||
|
||||
+1
-3
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.FloatingBiomeOverlay;
|
||||
import art.arcane.iris.world.history.TransitionGenerationPlan;
|
||||
@@ -88,7 +87,7 @@ public final class EngineModeTerrainGenerationTest {
|
||||
assertEquals(256, customWrites.get());
|
||||
assertSame(custom, blocks.getRaw(0, 2, 0));
|
||||
assertEquals("itemsadder:rocks/ruby_ore", receipt.get().column(-16, -32).geometry().voxelAt(2).stateKey());
|
||||
verify(fixture.engine, never()).openGenerationScope(anyInt(), anyInt());
|
||||
verify(fixture.engine, never()).openGenerationHistoryCoordinateScope(anyInt(), anyInt());
|
||||
assertEquals(41L, fixture.lastSessionId);
|
||||
assertNull(IrisContext.get());
|
||||
}
|
||||
@@ -201,7 +200,6 @@ public final class EngineModeTerrainGenerationTest {
|
||||
when(engine.getMinHeight()).thenReturn(0);
|
||||
when(engine.getMode()).thenReturn(mode);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.of(router));
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
EnginePlatformHooks hooks = mock(EnginePlatformHooks.class);
|
||||
when(engine.getPlatformHooks()).thenReturn(hooks);
|
||||
when(hooks.shouldDisableChunkContextCache(engine)).thenReturn(true);
|
||||
|
||||
@@ -916,7 +916,6 @@ public class EngineShutdownDrainTest {
|
||||
doReturn(new GenerationRuntime.BiomeMaxes(0D, 0D, 0D)).when(builder).computeBiomeMaxes();
|
||||
setField(engine, "runtimeBuilder", builder);
|
||||
when(engine.getGenerationHistoryRuntimeRouter()).thenReturn(Optional.empty());
|
||||
when(engine.getGenerationSource()).thenReturn(GenerationSource.singlePack());
|
||||
return kernel;
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -6,7 +6,6 @@ import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.world.IrisWorld;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.world.history.VersionedGenerationSource;
|
||||
import art.arcane.iris.world.history.SavedBiomeRuntime;
|
||||
import art.arcane.iris.world.history.SavedBiomeUnavailableException;
|
||||
import org.junit.Test;
|
||||
@@ -126,7 +125,6 @@ public class IrisEngineBiomeEnvironmentAsyncTest {
|
||||
field.setAccessible(true);
|
||||
field.set(engine, router);
|
||||
when(router.biomes()).thenReturn(biomes);
|
||||
when(engine.getGenerationSource()).thenReturn(new VersionedGenerationSource(router));
|
||||
when(engine.getWorld()).thenReturn(IrisWorld.builder().name("test").minHeight(-64).maxHeight(320).build());
|
||||
doCallRealMethod().when(engine).getBiomeEnvironmentAsync(anyInt(), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ public class IrisEngineFailureReportingTest {
|
||||
Field platformHooks = IrisEngine.class.getDeclaredField("platformHooks");
|
||||
platformHooks.setAccessible(true);
|
||||
platformHooks.set(engine, mock(EnginePlatformHooks.class));
|
||||
doThrow(failure).when(engine).openGenerationScope(-352, -144);
|
||||
doThrow(failure).when(engine).openGenerationHistoryCoordinateScope(-352, -144);
|
||||
doCallRealMethod().when(engine).generate(-352, -144, null, null, false);
|
||||
doCallRealMethod().when(engine).fail("Failed to generate -352, -144", failure);
|
||||
doCallRealMethod().when(engine).hasFailed();
|
||||
|
||||
Loaded 100 of 128 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user