IrisData no longer invalidates module caches by hand

Drop StructureGraphCatalog.invalidate and IrisObjectScale.invalidate: the caches follow the pack's resource
snapshot and the module world. The scale cache test builds its engine's world state.
This commit is contained in:
piexel committed 2026-10-09 20:45:00 +02:00
1 parent 49b82f7c16
commit 7a3f5961cc
2 files changed
+39 -86

No files matched your search

@@ -37,7 +37,6 @@ import art.arcane.iris.core.modules.PackModuleSet;
import art.arcane.iris.core.pack.PackDirectoryResolver;
import art.arcane.iris.engine.data.cache.AtomicCache;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.structure.StructureGraphCatalog;
import art.arcane.iris.core.structure.authoring.StructureRecoveryResult;
import art.arcane.iris.core.structure.authoring.StructureTransactionWriter;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
@@ -45,7 +44,6 @@ import art.arcane.iris.engine.object.material.IrisBlockData;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.entity.IrisEntity;
import art.arcane.iris.engine.object.noise.expression.IrisExpression;
import art.arcane.iris.engine.object.prefab.IrisObjectScale;
import art.arcane.iris.engine.object.terrain.IrisGenerator;
import art.arcane.iris.engine.object.image.IrisImage;
import art.arcane.iris.engine.object.image.IrisImageMap;
@@ -496,8 +494,6 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
}
public synchronized void hotloaded() {
StructureGraphCatalog.invalidate(this);
IrisObjectScale.invalidate(this);
closed = false;
dataFolder.mkdirs();
recoverStructureTransactions();
@@ -578,8 +574,6 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
/** Forgets everything read so far: the loaders' caches and the module resources, which a new snapshot reads again. */
public void dump() {
StructureGraphCatalog.invalidate(this);
IrisObjectScale.invalidate(this);
for (ResourceLoader<?> i : loaders.values()) {
i.clearCache();
}
@@ -588,7 +582,6 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
/** Reads objects and module resources (structures, jigsaw pools and pieces among them) again after a tool rewrote their files. */
public synchronized void invalidateStructureResources() {
StructureGraphCatalog.invalidate(this);
invalidateLoader(objectLoader);
reloadModuleResources();
}
@@ -4,9 +4,10 @@ import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.prefab.IrisObjectPlacementScaleInterpolator;
import art.arcane.iris.engine.object.prefab.IrisObjectScale;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.volmlib.util.math.RNG;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -20,13 +21,13 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.LockSupport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class IrisObjectScaleCacheTest {
private static final IrisObjectScale.ScaleRequest REQUEST = new IrisObjectScale.ScaleRequest(
@@ -37,55 +38,56 @@ public class IrisObjectScaleCacheTest {
IrisObjectPlacementScaleInterpolator.NONE
);
private Engine engine;
@Before
public void setUp() {
IrisObjectScale.invalidate(null);
engine = mock(Engine.class);
when(engine.getData()).thenReturn(mock(IrisData.class));
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
}
@After
public void tearDown() {
IrisObjectScale.invalidate(null);
private int cacheEntryCount() {
return IrisObjectScale.cacheOf(engine).size();
}
private long cacheEstimatedBytes() {
return IrisObjectScale.cacheOf(engine).estimatedBytes();
}
@Test
public void mutatedOriginCreatesStableReplacementAndCanBeReleased() {
public void mutatedOriginCreatesStableReplacement() {
IrisObject origin = new IrisObject(2, 2, 2);
IrisObjectScale scale = new IrisObjectScale().setSize(2D);
IrisObject first = scale.get(new RNG(1L), origin);
IrisObject first = scale.get(new RNG(1L), origin, engine);
IrisObjectScale.ScaleCache keyCache = new IrisObjectScale.ScaleCache(10L);
IrisObjectScale.CacheKey originalKey = keyCache.key(origin, REQUEST, 0);
int originalHash = originalKey.hashCode();
origin.setW(3);
IrisObject second = scale.get(new RNG(1L), origin);
IrisObject second = scale.get(new RNG(1L), origin, engine);
assertEquals(originalHash, originalKey.hashCode());
assertNotEquals(originalKey, keyCache.key(origin, REQUEST, 0));
assertNotSame(first, second);
assertNotEquals(first.getW(), second.getW());
assertEquals(2, IrisObjectScale.cacheEntryCount());
IrisObjectScale.invalidate(null);
assertEquals(0, IrisObjectScale.cacheEntryCount());
assertEquals(0L, IrisObjectScale.cacheEstimatedBytes());
assertFalse(IrisObjectScale.isOriginCached(origin));
assertEquals(2, cacheEntryCount());
}
@Test
public void voxelMutationReplacesCachedVariants() {
IrisObject origin = new IrisObject(2, 2, 2);
IrisObjectScale scale = new IrisObjectScale().setSize(2D);
IrisObject empty = scale.get(new RNG(1L), origin);
IrisObject empty = scale.get(new RNG(1L), origin, engine);
origin.setUnsigned(0, 0, 0, mock(PlatformBlockState.class));
IrisObject populated = scale.get(new RNG(1L), origin);
IrisObject populated = scale.get(new RNG(1L), origin, engine);
assertEquals(0, empty.getBlocks().size());
assertTrue(populated.getBlocks().size() > 0);
assertNotSame(empty, populated);
assertEquals(2, IrisObjectScale.cacheEntryCount());
assertEquals(2, cacheEntryCount());
}
@Test
@@ -97,18 +99,18 @@ public class IrisObjectScaleCacheTest {
.setMaximumScale(2D);
SequenceRng rng = new SequenceRng();
IrisObject first = scale.get(rng, origin);
IrisObject second = scale.get(rng, origin);
IrisObject third = scale.get(rng, origin);
IrisObject fourth = scale.get(rng, origin);
IrisObject repeated = scale.get(rng, origin);
IrisObject first = scale.get(rng, origin, engine);
IrisObject second = scale.get(rng, origin, engine);
IrisObject third = scale.get(rng, origin, engine);
IrisObject fourth = scale.get(rng, origin, engine);
IrisObject repeated = scale.get(rng, origin, engine);
assertSame(first, repeated);
assertNotEquals(first.getW(), second.getW());
assertNotEquals(second.getW(), third.getW());
assertNotEquals(third.getW(), fourth.getW());
assertEquals(4, IrisObjectScale.cacheEntryCount());
assertTrue(IrisObjectScale.cacheEstimatedBytes() > 0L);
assertEquals(4, cacheEntryCount());
assertTrue(cacheEstimatedBytes() > 0L);
}
@Test
@@ -116,12 +118,12 @@ public class IrisObjectScaleCacheTest {
OverweightScaleObject origin = new OverweightScaleObject();
IrisObjectScale scale = new IrisObjectScale().setSize(2D);
IrisObject result = scale.get(new RNG(1L), origin);
IrisObject result = scale.get(new RNG(1L), origin, engine);
assertEquals(1_000, result.getW());
assertEquals(1, origin.scaleCalls.get());
assertEquals(0, IrisObjectScale.cacheEntryCount());
assertEquals(0L, IrisObjectScale.cacheEstimatedBytes());
assertEquals(0, cacheEntryCount());
assertEquals(0L, cacheEstimatedBytes());
}
@Test
@@ -133,12 +135,12 @@ public class IrisObjectScaleCacheTest {
AtomicReference<Thread> secondThread = new AtomicReference<>();
try {
Future<IrisObject> first = executor.submit(() -> scale.get(new RNG(1L), origin));
Future<IrisObject> first = executor.submit(() -> scale.get(new RNG(1L), origin, engine));
assertTrue(origin.firstScaleEntered.await(5L, TimeUnit.SECONDS));
Future<IrisObject> second = executor.submit(() -> {
secondThread.set(Thread.currentThread());
secondInvoked.countDown();
return scale.get(new RNG(1L), origin);
return scale.get(new RNG(1L), origin, engine);
});
assertTrue(secondInvoked.await(5L, TimeUnit.SECONDS));
@@ -171,15 +173,15 @@ public class IrisObjectScaleCacheTest {
put(cache, firstKey, new IrisObject(1, 1, 1), 4L);
put(cache, secondKey, new IrisObject(1, 1, 1), 4L);
assertTrue(cache.lookup(firstKey).variant() != null);
assertTrue(cache.lookup(firstKey) != null);
put(cache, thirdKey, new IrisObject(1, 1, 1), 4L);
assertEquals(2, cache.size());
assertEquals(8L, cache.estimatedBytes());
assertTrue(cache.estimatedBytes() <= cache.maximumEstimatedBytes());
assertTrue(cache.lookup(firstKey).variant() != null);
assertNull(cache.lookup(secondKey).variant());
assertTrue(cache.lookup(thirdKey).variant() != null);
assertTrue(cache.lookup(firstKey) != null);
assertNull(cache.lookup(secondKey));
assertTrue(cache.lookup(thirdKey) != null);
}
@Test
@@ -188,55 +190,14 @@ public class IrisObjectScaleCacheTest {
IrisObject origin = new IrisObject(1, 1, 1);
IrisObjectScale.CacheKey key = key(origin);
IrisObject variant = new IrisObject(1, 1, 1);
IrisObjectScale.CacheLookup lookup = cache.lookup(key);
IrisObject result = cache.putIfCurrent(key, variant, 11L, lookup.generation());
IrisObject result = cache.putIfAbsent(key, variant, 11L);
assertSame(variant, result);
assertEquals(0, cache.size());
assertEquals(0L, cache.estimatedBytes());
}
@Test
public void invalidationReleasesOnlyTheRequestedRuntime() {
IrisObjectScale.ScaleCache cache = new IrisObjectScale.ScaleCache(20L);
IrisData firstOwner = mock(IrisData.class);
IrisData secondOwner = mock(IrisData.class);
IrisObject firstOrigin = new IrisObject(1, 1, 1);
IrisObject secondOrigin = new IrisObject(1, 1, 1);
firstOrigin.setLoader(firstOwner);
secondOrigin.setLoader(secondOwner);
IrisObjectScale.CacheKey firstKey = key(firstOrigin);
IrisObjectScale.CacheKey secondKey = key(secondOrigin);
put(cache, firstKey, new IrisObject(1, 1, 1), 5L);
put(cache, secondKey, new IrisObject(1, 1, 1), 5L);
cache.invalidate(firstOwner);
assertNull(cache.lookup(firstKey).variant());
assertTrue(cache.lookup(secondKey).variant() != null);
assertEquals(1, cache.size());
assertEquals(5L, cache.estimatedBytes());
}
@Test
public void invalidationRejectsAnInFlightStaleInsertion() {
IrisObjectScale.ScaleCache cache = new IrisObjectScale.ScaleCache(10L);
IrisData owner = mock(IrisData.class);
IrisObject origin = new IrisObject(1, 1, 1);
origin.setLoader(owner);
IrisObjectScale.CacheKey key = key(origin);
IrisObjectScale.CacheLookup lookup = cache.lookup(key);
cache.invalidate(owner);
cache.putIfCurrent(key, new IrisObject(1, 1, 1), 5L, lookup.generation());
assertEquals(0, cache.size());
assertEquals(0L, cache.estimatedBytes());
assertNull(cache.lookup(key).variant());
}
@Test
public void collectedOriginReleasesScaledValueWithOwnerReference() {
IrisObjectScale.ScaleCache cache = new IrisObjectScale.ScaleCache(20L);
@@ -261,8 +222,7 @@ public class IrisObjectScaleCacheTest {
private static void put(IrisObjectScale.ScaleCache cache, IrisObjectScale.CacheKey key,
IrisObject variant, long estimatedBytes) {
IrisObjectScale.CacheLookup lookup = cache.lookup(key);
cache.putIfCurrent(key, variant, estimatedBytes, lookup.generation());
cache.putIfAbsent(key, variant, estimatedBytes);
}
private static final class BlockingScaleObject extends IrisObject {