mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 10:14:36 +00:00
Stop closed engines from staying in memory
Weak engine refs in pack caches
This commit is contained in:
1 parent
1e04f61957
commit
a8e7abf852
20 files changed
+278
-59
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
package art.arcane.iris.generation.bake;
|
package art.arcane.iris.generation.bake;
|
||||||
|
|
||||||
import art.arcane.iris.generation.cache.ConcurrentClockCache;
|
import art.arcane.iris.generation.cache.ConcurrentClockCache;
|
||||||
|
import art.arcane.iris.generation.cache.ReleasableThreadLocal;
|
||||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -16,7 +17,7 @@ public final class ChunkBakeCache {
|
|||||||
|
|
||||||
private final PlaneSource source;
|
private final PlaneSource source;
|
||||||
private final ConcurrentClockCache<ChunkPlanes> entries;
|
private final ConcurrentClockCache<ChunkPlanes> entries;
|
||||||
private final ThreadLocal<Recent> recent = ThreadLocal.withInitial(Recent::new);
|
private final ReleasableThreadLocal<Recent> recent = new ReleasableThreadLocal<>(Recent::new);
|
||||||
private volatile int generation;
|
private volatile int generation;
|
||||||
|
|
||||||
public ChunkBakeCache(PlaneSource source, int capacityChunks) {
|
public ChunkBakeCache(PlaneSource source, int capacityChunks) {
|
||||||
@@ -37,6 +38,7 @@ public final class ChunkBakeCache {
|
|||||||
generation++;
|
generation++;
|
||||||
entries.forEach(ChunkPlanes::release);
|
entries.forEach(ChunkPlanes::release);
|
||||||
entries.clear();
|
entries.clear();
|
||||||
|
recent.releaseAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long[] census() {
|
public long[] census() {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
|||||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
||||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||||
|
import art.arcane.iris.generation.runtime.EngineRef;
|
||||||
import art.arcane.iris.generation.terrain.InferredType;
|
import art.arcane.iris.generation.terrain.InferredType;
|
||||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||||
import art.arcane.iris.generation.terrain.IrisTerrain3D;
|
import art.arcane.iris.generation.terrain.IrisTerrain3D;
|
||||||
@@ -526,7 +527,7 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
|
|||||||
if (recent != null && recent.key.matches(seed, scale, data, engine)) {
|
if (recent != null && recent.key.matches(seed, scale, data, engine)) {
|
||||||
return recent.generator;
|
return recent.generator;
|
||||||
}
|
}
|
||||||
ChildGeneratorKey key = new ChildGeneratorKey(seed, scale, data, engine);
|
ChildGeneratorKey key = new ChildGeneratorKey(seed, scale, data, EngineRef.of(engine));
|
||||||
CNG generator = childrenGenerators.computeIfAbsent(key,
|
CNG generator = childrenGenerators.computeIfAbsent(key,
|
||||||
ignored -> getChildStyle().createScaledGenerator(new RNG(seed), data, scale));
|
ignored -> getChildStyle().createScaledGenerator(new RNG(seed), data, scale));
|
||||||
recentChildGenerator = new CachedChildGenerator(key, generator);
|
recentChildGenerator = new CachedChildGenerator(key, generator);
|
||||||
@@ -725,15 +726,19 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ChildGeneratorKey(long seed, double scale, IrisData data, Engine engine) {
|
private record ChildGeneratorKey(long seed, double scale, IrisData data, EngineRef engine) {
|
||||||
private boolean matches(long seed, double scale, IrisData data, Engine engine) {
|
private boolean matches(long seed, double scale, IrisData data, Engine engine) {
|
||||||
return this.seed == seed && Double.doubleToLongBits(this.scale) == Double.doubleToLongBits(scale)
|
return this.seed == seed && Double.doubleToLongBits(this.scale) == Double.doubleToLongBits(scale)
|
||||||
&& this.data == data && this.engine == engine;
|
&& this.data == data && this.engine.refersTo(engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
return object instanceof ChildGeneratorKey other && matches(other.seed, other.scale, other.data, other.engine);
|
return object instanceof ChildGeneratorKey other
|
||||||
|
&& seed == other.seed
|
||||||
|
&& Double.doubleToLongBits(scale) == Double.doubleToLongBits(other.scale)
|
||||||
|
&& data == other.data
|
||||||
|
&& engine.equals(other.engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -741,7 +746,7 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
|
|||||||
int hash = Long.hashCode(seed);
|
int hash = Long.hashCode(seed);
|
||||||
hash = 31 * hash + Double.hashCode(scale);
|
hash = 31 * hash + Double.hashCode(scale);
|
||||||
hash = 31 * hash + System.identityHashCode(data);
|
hash = 31 * hash + System.identityHashCode(data);
|
||||||
return 31 * hash + System.identityHashCode(engine);
|
return 31 * hash + engine.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package art.arcane.iris.generation.biome;
|
|||||||
|
|
||||||
import art.arcane.iris.generation.cache.LazyBoundedCache;
|
import art.arcane.iris.generation.cache.LazyBoundedCache;
|
||||||
import art.arcane.iris.generation.runtime.Engine;
|
import art.arcane.iris.generation.runtime.Engine;
|
||||||
|
import art.arcane.iris.generation.runtime.EngineRef;
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
import art.arcane.volmlib.util.collection.KList;
|
import art.arcane.volmlib.util.collection.KList;
|
||||||
import art.arcane.volmlib.util.math.RNG;
|
import art.arcane.volmlib.util.math.RNG;
|
||||||
@@ -39,29 +40,29 @@ final class IrisBiomeLayerHeightCache {
|
|||||||
|
|
||||||
private static final class GeneratorKey {
|
private static final class GeneratorKey {
|
||||||
private final IrisData data;
|
private final IrisData data;
|
||||||
private final Engine engine;
|
private final EngineRef engine;
|
||||||
private final long seed;
|
private final long seed;
|
||||||
|
|
||||||
private GeneratorKey(IrisData data, Engine engine, long seed) {
|
private GeneratorKey(IrisData data, Engine engine, long seed) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.engine = engine;
|
this.engine = EngineRef.of(engine);
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matches(IrisData data, Engine engine, long seed) {
|
private boolean matches(IrisData data, Engine engine, long seed) {
|
||||||
return this.data == data && this.engine == engine && this.seed == seed;
|
return this.data == data && this.engine.refersTo(engine) && this.seed == seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
return this == object || object instanceof GeneratorKey other
|
return this == object || object instanceof GeneratorKey other
|
||||||
&& matches(other.data, other.engine, other.seed);
|
&& data == other.data && engine.equals(other.engine) && seed == other.seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = System.identityHashCode(data);
|
int result = System.identityHashCode(data);
|
||||||
result = 31 * result + System.identityHashCode(engine);
|
result = 31 * result + engine.hashCode();
|
||||||
return 31 * result + Long.hashCode(seed);
|
return 31 * result + Long.hashCode(seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package art.arcane.iris.generation.biome;
|
|||||||
import art.arcane.iris.generation.block.IrisBlockData;
|
import art.arcane.iris.generation.block.IrisBlockData;
|
||||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||||
|
import art.arcane.iris.generation.runtime.EngineRef;
|
||||||
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
||||||
|
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
@@ -198,17 +199,17 @@ public class IrisBiomePaletteLayer {
|
|||||||
|
|
||||||
private static final class LayerGeneratorKey {
|
private static final class LayerGeneratorKey {
|
||||||
private final IrisData data;
|
private final IrisData data;
|
||||||
private final Engine engine;
|
private final EngineRef engine;
|
||||||
private final long seed;
|
private final long seed;
|
||||||
|
|
||||||
private LayerGeneratorKey(IrisData data, Engine engine, long seed) {
|
private LayerGeneratorKey(IrisData data, Engine engine, long seed) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.engine = engine;
|
this.engine = EngineRef.of(engine);
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matches(IrisData data, Engine engine, long seed) {
|
private boolean matches(IrisData data, Engine engine, long seed) {
|
||||||
return this.data == data && this.engine == engine && this.seed == seed;
|
return this.data == data && this.engine.refersTo(engine) && this.seed == seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -219,13 +220,13 @@ public class IrisBiomePaletteLayer {
|
|||||||
if (!(object instanceof LayerGeneratorKey other)) {
|
if (!(object instanceof LayerGeneratorKey other)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return data == other.data && engine == other.engine && seed == other.seed;
|
return data == other.data && engine.equals(other.engine) && seed == other.seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = System.identityHashCode(data);
|
int result = System.identityHashCode(data);
|
||||||
result = 31 * result + System.identityHashCode(engine);
|
result = 31 * result + engine.hashCode();
|
||||||
result = 31 * result + Long.hashCode(seed);
|
result = 31 * result + Long.hashCode(seed);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
package art.arcane.iris.generation.cache;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A per-instance thread local whose owner can drop every thread's value when it closes.
|
||||||
|
* A plain ThreadLocal leaves its values in pooled threads that outlive the owner, and with them
|
||||||
|
* whatever they reference, until each thread happens to clean the stale entry.
|
||||||
|
*/
|
||||||
|
public final class ReleasableThreadLocal<T> {
|
||||||
|
private final Supplier<? extends T> factory;
|
||||||
|
private final Set<Slot<T>> slots = ConcurrentHashMap.newKeySet();
|
||||||
|
private final ThreadLocal<Slot<T>> local = ThreadLocal.withInitial(this::registerSlot);
|
||||||
|
|
||||||
|
public ReleasableThreadLocal(Supplier<? extends T> factory) {
|
||||||
|
this.factory = Objects.requireNonNull(factory, "factory");
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
Slot<T> slot = local.get();
|
||||||
|
T value = slot.value;
|
||||||
|
if (value == null) {
|
||||||
|
value = factory.get();
|
||||||
|
slot.value = value;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void releaseAll() {
|
||||||
|
for (Slot<T> slot : slots) {
|
||||||
|
slot.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Slot<T> registerSlot() {
|
||||||
|
Slot<T> slot = new Slot<>();
|
||||||
|
slots.add(slot);
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class Slot<T> {
|
||||||
|
private T value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,13 +73,11 @@ final class DecoratorCore {
|
|||||||
boolean caveSkipFluid;
|
boolean caveSkipFluid;
|
||||||
boolean underwater;
|
boolean underwater;
|
||||||
int fluidHeight;
|
int fluidHeight;
|
||||||
EngineMantle mantle;
|
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
caveSkipFluid = false;
|
caveSkipFluid = false;
|
||||||
underwater = false;
|
underwater = false;
|
||||||
fluidHeight = 0;
|
fluidHeight = 0;
|
||||||
mantle = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +223,7 @@ final class DecoratorCore {
|
|||||||
|
|
||||||
static void placeStackUp(IrisDecorator decorator, int x, int z, int realX, int realZ,
|
static void placeStackUp(IrisDecorator decorator, int x, int z, int realX, int realZ,
|
||||||
int height, int max, Hunk<NativeBlockState> data,
|
int height, int max, Hunk<NativeBlockState> data,
|
||||||
RNG rng, IrisData irisData, PlaceOpts opts) {
|
RNG rng, IrisData irisData, PlaceOpts opts, EngineMantle mantle) {
|
||||||
if (height < 0 || height >= data.getHeight()) {
|
if (height < 0 || height >= data.getHeight()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -263,7 +261,7 @@ final class DecoratorCore {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!IrisSugarCane.canPlace(block, data, x, y, z, realX, realZ,
|
if (!IrisSugarCane.canPlace(block, data, x, y, z, realX, realZ,
|
||||||
opts.mantle == null ? null : opts.mantle.getEngine())) {
|
mantle == null ? null : mantle.getEngine())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (IrisSpeleothems.isSpike(block)) {
|
if (IrisSpeleothems.isSpike(block)) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import art.arcane.iris.generation.cache.LazyBoundedCache;
|
|||||||
import art.arcane.iris.generation.block.IrisBlockData;
|
import art.arcane.iris.generation.block.IrisBlockData;
|
||||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||||
|
import art.arcane.iris.generation.runtime.EngineRef;
|
||||||
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
||||||
|
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
@@ -152,10 +153,10 @@ public class IrisDecorator {
|
|||||||
long seed = rng.getSeed();
|
long seed = rng.getSeed();
|
||||||
Engine engine = data == null ? null : data.getEngine();
|
Engine engine = data == null ? null : data.getEngine();
|
||||||
Generators recent = recentGenerators;
|
Generators recent = recentGenerators;
|
||||||
if (recent != null && recent.key.seed == seed && recent.key.data == data && recent.key.engine == engine) {
|
if (recent != null && recent.key.seed == seed && recent.key.data == data && recent.key.engine.refersTo(engine)) {
|
||||||
return recent;
|
return recent;
|
||||||
}
|
}
|
||||||
Generators selected = generators.computeIfAbsent(new GeneratorKey(seed, data, engine), Generators::new);
|
Generators selected = generators.computeIfAbsent(new GeneratorKey(seed, data, EngineRef.of(engine)), Generators::new);
|
||||||
recentGenerators = selected;
|
recentGenerators = selected;
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
@@ -374,17 +375,17 @@ public class IrisDecorator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record GeneratorKey(long seed, IrisData data, Engine engine) {
|
private record GeneratorKey(long seed, IrisData data, EngineRef engine) {
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
return other instanceof GeneratorKey key
|
return other instanceof GeneratorKey key
|
||||||
&& seed == key.seed && data == key.data && engine == key.engine;
|
&& seed == key.seed && data == key.data && engine.equals(key.engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return 31 * (31 * Long.hashCode(seed) + System.identityHashCode(data))
|
return 31 * (31 * Long.hashCode(seed) + System.identityHashCode(data))
|
||||||
+ System.identityHashCode(engine);
|
+ engine.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,7 @@ package art.arcane.iris.generation.decoration;
|
|||||||
|
|
||||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||||
|
import art.arcane.iris.generation.runtime.EngineRef;
|
||||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||||
import art.arcane.iris.pack.value.IrisRange;
|
import art.arcane.iris.pack.value.IrisRange;
|
||||||
|
|
||||||
@@ -91,26 +92,26 @@ public class IrisOreGenerator {
|
|||||||
private OreChance chance(RNG rng, IrisData data, Engine engine) {
|
private OreChance chance(RNG rng, IrisData data, Engine engine) {
|
||||||
long seed = rng.getSeed();
|
long seed = rng.getSeed();
|
||||||
CachedChance recent = recentChance;
|
CachedChance recent = recentChance;
|
||||||
if (recent != null && recent.key.seed == seed && recent.key.data == data && recent.key.engine == engine) {
|
if (recent != null && recent.key.seed == seed && recent.key.data == data && recent.key.engine.refersTo(engine)) {
|
||||||
return recent.chance;
|
return recent.chance;
|
||||||
}
|
}
|
||||||
ChanceKey key = new ChanceKey(seed, data, engine);
|
ChanceKey key = new ChanceKey(seed, data, EngineRef.of(engine));
|
||||||
OreChance selected = chanceCache.computeIfAbsent(key, ignored -> OreChance.of(chanceStyle.create(rng, data)));
|
OreChance selected = chanceCache.computeIfAbsent(key, ignored -> OreChance.of(chanceStyle.create(rng, data)));
|
||||||
recentChance = new CachedChance(key, selected);
|
recentChance = new CachedChance(key, selected);
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ChanceKey(long seed, IrisData data, Engine engine) {
|
private record ChanceKey(long seed, IrisData data, EngineRef engine) {
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
return other instanceof ChanceKey key
|
return other instanceof ChanceKey key
|
||||||
&& seed == key.seed && data == key.data && engine == key.engine;
|
&& seed == key.seed && data == key.data && engine.equals(key.engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return 31 * (31 * Long.hashCode(seed) + System.identityHashCode(data))
|
return 31 * (31 * Long.hashCode(seed) + System.identityHashCode(data))
|
||||||
+ System.identityHashCode(engine);
|
+ engine.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator {
|
|||||||
opts.underwater = underwater;
|
opts.underwater = underwater;
|
||||||
opts.fluidHeight = fluidHeight;
|
opts.fluidHeight = fluidHeight;
|
||||||
opts.caveSkipFluid = caveSkipFluid;
|
opts.caveSkipFluid = caveSkipFluid;
|
||||||
opts.mantle = getEngine().getMantle();
|
DecoratorCore.placeStackUp(decorator, x, z, realX, realZ, height, max, data, partRNG, getData(), opts,
|
||||||
DecoratorCore.placeStackUp(decorator, x, z, realX, realZ, height, max, data, partRNG, getData(), opts);
|
getEngine().getMantle());
|
||||||
aquaticSnapshot.restoreIfUnsupported(data, x, z);
|
aquaticSnapshot.restoreIfUnsupported(data, x, z);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package art.arcane.iris.generation.noise;
|
|||||||
|
|
||||||
import art.arcane.iris.generation.image.IrisImageMap;
|
import art.arcane.iris.generation.image.IrisImageMap;
|
||||||
|
|
||||||
|
import art.arcane.iris.generation.runtime.EngineRef;
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
import art.arcane.iris.generation.cache.LazyBoundedCache;
|
import art.arcane.iris.generation.cache.LazyBoundedCache;
|
||||||
import art.arcane.iris.generation.runtime.Engine;
|
import art.arcane.iris.generation.runtime.Engine;
|
||||||
@@ -307,17 +308,17 @@ public class IrisGeneratorStyle {
|
|||||||
|
|
||||||
private static final class GeneratorCacheKey {
|
private static final class GeneratorCacheKey {
|
||||||
private final IrisData data;
|
private final IrisData data;
|
||||||
private final Engine engine;
|
private final EngineRef engine;
|
||||||
private final long seed;
|
private final long seed;
|
||||||
|
|
||||||
private GeneratorCacheKey(IrisData data, Engine engine, long seed) {
|
private GeneratorCacheKey(IrisData data, Engine engine, long seed) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.engine = engine;
|
this.engine = EngineRef.of(engine);
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matches(IrisData data, Engine engine, long seed) {
|
private boolean matches(IrisData data, Engine engine, long seed) {
|
||||||
return this.data == data && this.engine == engine && this.seed == seed;
|
return this.data == data && this.engine.refersTo(engine) && this.seed == seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -328,13 +329,13 @@ public class IrisGeneratorStyle {
|
|||||||
if (!(other instanceof GeneratorCacheKey key)) {
|
if (!(other instanceof GeneratorCacheKey key)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return data == key.data && engine == key.engine && seed == key.seed;
|
return data == key.data && engine.equals(key.engine) && seed == key.seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = System.identityHashCode(data);
|
int result = System.identityHashCode(data);
|
||||||
result = 31 * result + System.identityHashCode(engine);
|
result = 31 * result + engine.hashCode();
|
||||||
return 31 * result + Long.hashCode(seed);
|
return 31 * result + Long.hashCode(seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package art.arcane.iris.generation.noise;
|
package art.arcane.iris.generation.noise;
|
||||||
|
|
||||||
|
import art.arcane.iris.generation.runtime.EngineRef;
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
import art.arcane.iris.generation.cache.LazyBoundedCache;
|
import art.arcane.iris.generation.cache.LazyBoundedCache;
|
||||||
import art.arcane.iris.generation.runtime.Engine;
|
import art.arcane.iris.generation.runtime.Engine;
|
||||||
@@ -313,17 +314,17 @@ public class IrisNoiseGenerator {
|
|||||||
|
|
||||||
private static final class GeneratorKey {
|
private static final class GeneratorKey {
|
||||||
private final IrisData data;
|
private final IrisData data;
|
||||||
private final Engine engine;
|
private final EngineRef engine;
|
||||||
private final long seed;
|
private final long seed;
|
||||||
|
|
||||||
private GeneratorKey(IrisData data, Engine engine, long seed) {
|
private GeneratorKey(IrisData data, Engine engine, long seed) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.engine = engine;
|
this.engine = EngineRef.of(engine);
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matches(IrisData data, Engine engine, long seed) {
|
private boolean matches(IrisData data, Engine engine, long seed) {
|
||||||
return this.data == data && this.engine == engine && this.seed == seed;
|
return this.data == data && this.engine.refersTo(engine) && this.seed == seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -334,13 +335,13 @@ public class IrisNoiseGenerator {
|
|||||||
if (!(object instanceof GeneratorKey other)) {
|
if (!(object instanceof GeneratorKey other)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return data == other.data && engine == other.engine && seed == other.seed;
|
return data == other.data && engine.equals(other.engine) && seed == other.seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = System.identityHashCode(data);
|
int result = System.identityHashCode(data);
|
||||||
result = 31 * result + System.identityHashCode(engine);
|
result = 31 * result + engine.hashCode();
|
||||||
result = 31 * result + Long.hashCode(seed);
|
result = 31 * result + Long.hashCode(seed);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package art.arcane.iris.generation.runtime;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identifies an engine in pack-object cache keys without keeping it alive. Pack objects outlive
|
||||||
|
* worlds and sit in thread-local scratch on pooled threads, so a strong engine there pins a closed world.
|
||||||
|
*/
|
||||||
|
public final class EngineRef {
|
||||||
|
private static final EngineRef NONE = new EngineRef(null);
|
||||||
|
private final WeakReference<Engine> engine;
|
||||||
|
private final int identity;
|
||||||
|
|
||||||
|
EngineRef(Engine engine) {
|
||||||
|
this.engine = new WeakReference<>(engine);
|
||||||
|
this.identity = System.identityHashCode(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EngineRef of(Engine engine) {
|
||||||
|
if (engine == null) {
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
if (engine instanceof IrisEngine irisEngine) {
|
||||||
|
return irisEngine.getCacheRef();
|
||||||
|
}
|
||||||
|
return new EngineRef(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean refersTo(Engine candidate) {
|
||||||
|
if (candidate == null) {
|
||||||
|
return this == NONE;
|
||||||
|
}
|
||||||
|
return this != NONE && engine.refersTo(candidate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
if (this == object) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(object instanceof EngineRef other) || this == NONE || other == NONE || identity != other.identity) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Engine live = engine.get();
|
||||||
|
return live != null && other.engine.refersTo(live);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return identity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ import art.arcane.iris.generation.bake.ChunkPlanes;
|
|||||||
import art.arcane.iris.generation.bake.GeneratorEvaluations;
|
import art.arcane.iris.generation.bake.GeneratorEvaluations;
|
||||||
import art.arcane.iris.generation.bake.PlaneSource;
|
import art.arcane.iris.generation.bake.PlaneSource;
|
||||||
import art.arcane.iris.generation.bake.TerrainProgram;
|
import art.arcane.iris.generation.bake.TerrainProgram;
|
||||||
|
import art.arcane.iris.generation.cache.ReleasableThreadLocal;
|
||||||
import art.arcane.iris.generation.noise.TerrainBatchScratch;
|
import art.arcane.iris.generation.noise.TerrainBatchScratch;
|
||||||
import art.arcane.iris.generation.stream.BakedDoubleStream;
|
import art.arcane.iris.generation.stream.BakedDoubleStream;
|
||||||
import art.arcane.iris.generation.stream.BakedHeightStream;
|
import art.arcane.iris.generation.stream.BakedHeightStream;
|
||||||
@@ -155,9 +156,9 @@ public class IrisComplex implements DataProvider {
|
|||||||
InferredType.SHORE
|
InferredType.SHORE
|
||||||
};
|
};
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private final transient ThreadLocal<GridBoundsCache> gridBoundsCache = ThreadLocal.withInitial(GridBoundsCache::new);
|
private final transient ReleasableThreadLocal<GridBoundsCache> gridBoundsCache = new ReleasableThreadLocal<>(GridBoundsCache::new);
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private final transient ThreadLocal<EffectiveWater.Chunks> effectiveChunks = ThreadLocal.withInitial(EffectiveWater.Chunks::new);
|
private final transient ReleasableThreadLocal<EffectiveWater.Chunks> effectiveChunks = new ReleasableThreadLocal<>(EffectiveWater.Chunks::new);
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private final int biomeBoundsSamplingStep;
|
private final int biomeBoundsSamplingStep;
|
||||||
private transient volatile SharedCornerBounds sharedCornerBounds;
|
private transient volatile SharedCornerBounds sharedCornerBounds;
|
||||||
@@ -2993,6 +2994,8 @@ public class IrisComplex implements DataProvider {
|
|||||||
terrain3D.clear();
|
terrain3D.clear();
|
||||||
}
|
}
|
||||||
bakeCache.clear();
|
bakeCache.clear();
|
||||||
|
gridBoundsCache.releaseAll();
|
||||||
|
effectiveChunks.releaseAll();
|
||||||
if (transitionDisplacement != null) {
|
if (transitionDisplacement != null) {
|
||||||
transitionDisplacement.clear();
|
transitionDisplacement.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,10 @@ import art.arcane.volmlib.util.scheduling.ChronoLatch;
|
|||||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -99,6 +101,10 @@ public class IrisEngine implements Engine {
|
|||||||
private final AtomicDouble perSecond;
|
private final AtomicDouble perSecond;
|
||||||
private final AtomicLong lastGPS;
|
private final AtomicLong lastGPS;
|
||||||
private final EngineTarget target;
|
private final EngineTarget target;
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
@EqualsAndHashCode.Exclude
|
||||||
|
@ToString.Exclude
|
||||||
|
private final EngineRef cacheRef = new EngineRef(this);
|
||||||
private final InitializationMode initializationMode;
|
private final InitializationMode initializationMode;
|
||||||
private final Path initialMantleStorageDirectory;
|
private final Path initialMantleStorageDirectory;
|
||||||
private final GenerationKernelRegistry.Version initialKernelVersion;
|
private final GenerationKernelRegistry.Version initialKernelVersion;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import art.arcane.iris.generation.block.TileData;
|
|||||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||||
|
|
||||||
|
import art.arcane.iris.generation.runtime.EngineRef;
|
||||||
import art.arcane.iris.pack.loading.IrisData;
|
import art.arcane.iris.pack.loading.IrisData;
|
||||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||||
import art.arcane.iris.generation.cache.LazyBoundedCache;
|
import art.arcane.iris.generation.cache.LazyBoundedCache;
|
||||||
@@ -168,17 +169,17 @@ public class IrisMaterialPalette implements StructurePalette {
|
|||||||
|
|
||||||
private static final class LayerGeneratorKey {
|
private static final class LayerGeneratorKey {
|
||||||
private final IrisData data;
|
private final IrisData data;
|
||||||
private final Engine engine;
|
private final EngineRef engine;
|
||||||
private final long seed;
|
private final long seed;
|
||||||
|
|
||||||
private LayerGeneratorKey(IrisData data, Engine engine, long seed) {
|
private LayerGeneratorKey(IrisData data, Engine engine, long seed) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.engine = engine;
|
this.engine = EngineRef.of(engine);
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matches(IrisData data, Engine engine, long seed) {
|
private boolean matches(IrisData data, Engine engine, long seed) {
|
||||||
return this.data == data && this.engine == engine && this.seed == seed;
|
return this.data == data && this.engine.refersTo(engine) && this.seed == seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -189,13 +190,13 @@ public class IrisMaterialPalette implements StructurePalette {
|
|||||||
if (!(object instanceof LayerGeneratorKey other)) {
|
if (!(object instanceof LayerGeneratorKey other)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return data == other.data && engine == other.engine && seed == other.seed;
|
return data == other.data && engine.equals(other.engine) && seed == other.seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = System.identityHashCode(data);
|
int result = System.identityHashCode(data);
|
||||||
result = 31 * result + System.identityHashCode(engine);
|
result = 31 * result + engine.hashCode();
|
||||||
result = 31 * result + Long.hashCode(seed);
|
result = 31 * result + Long.hashCode(seed);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
|||||||
import art.arcane.iris.generation.noise.IrisNoiseGenerator;
|
import art.arcane.iris.generation.noise.IrisNoiseGenerator;
|
||||||
import art.arcane.iris.generation.noise.IrisStyledRange;
|
import art.arcane.iris.generation.noise.IrisStyledRange;
|
||||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||||
|
import art.arcane.iris.generation.runtime.EngineRef;
|
||||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||||
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
||||||
import art.arcane.iris.world.loot.IrisLootTable;
|
import art.arcane.iris.world.loot.IrisLootTable;
|
||||||
@@ -517,12 +518,12 @@ public class IrisObjectPlacement {
|
|||||||
|
|
||||||
private static final class SurfaceWarpCacheKey {
|
private static final class SurfaceWarpCacheKey {
|
||||||
private final IrisData data;
|
private final IrisData data;
|
||||||
private final Engine engine;
|
private final EngineRef engine;
|
||||||
private final long seed;
|
private final long seed;
|
||||||
|
|
||||||
private SurfaceWarpCacheKey(IrisData data, Engine engine, long seed) {
|
private SurfaceWarpCacheKey(IrisData data, Engine engine, long seed) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.engine = engine;
|
this.engine = EngineRef.of(engine);
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,13 +535,13 @@ public class IrisObjectPlacement {
|
|||||||
if (!(other instanceof SurfaceWarpCacheKey key)) {
|
if (!(other instanceof SurfaceWarpCacheKey key)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return data == key.data && engine == key.engine && seed == key.seed;
|
return data == key.data && engine.equals(key.engine) && seed == key.seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = System.identityHashCode(data);
|
int result = System.identityHashCode(data);
|
||||||
result = 31 * result + System.identityHashCode(engine);
|
result = 31 * result + engine.hashCode();
|
||||||
return 31 * result + Long.hashCode(seed);
|
return 31 * result + Long.hashCode(seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package art.arcane.iris.generation.cache;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class ReleasableThreadLocalTest {
|
||||||
|
private static final long THREAD_WAIT_SECONDS = 5L;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void keepsOneValuePerThreadUntilReleased() {
|
||||||
|
ReleasableThreadLocal<Object> local = new ReleasableThreadLocal<>(Object::new);
|
||||||
|
|
||||||
|
Object first = local.get();
|
||||||
|
|
||||||
|
assertSame(first, local.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void releaseAllDropsValuesHeldByOtherLiveThreads() throws Exception {
|
||||||
|
ReleasableThreadLocal<Object> local = new ReleasableThreadLocal<>(Object::new);
|
||||||
|
AtomicReference<Object> beforeRelease = new AtomicReference<>();
|
||||||
|
AtomicReference<Object> afterRelease = new AtomicReference<>();
|
||||||
|
CountDownLatch valueCreated = new CountDownLatch(1);
|
||||||
|
CountDownLatch released = new CountDownLatch(1);
|
||||||
|
Thread pooledWorker = new Thread(() -> {
|
||||||
|
beforeRelease.set(local.get());
|
||||||
|
valueCreated.countDown();
|
||||||
|
awaitQuietly(released);
|
||||||
|
afterRelease.set(local.get());
|
||||||
|
});
|
||||||
|
|
||||||
|
pooledWorker.start();
|
||||||
|
assertTrue(valueCreated.await(THREAD_WAIT_SECONDS, TimeUnit.SECONDS));
|
||||||
|
local.releaseAll();
|
||||||
|
released.countDown();
|
||||||
|
pooledWorker.join(TimeUnit.SECONDS.toMillis(THREAD_WAIT_SECONDS));
|
||||||
|
|
||||||
|
assertNotSame(beforeRelease.get(), afterRelease.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void awaitQuietly(CountDownLatch latch) {
|
||||||
|
try {
|
||||||
|
latch.await(THREAD_WAIT_SECONDS, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException interrupted) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -179,7 +179,7 @@ public class DecoratorCoreTest {
|
|||||||
output.set(0, 2, 0, air);
|
output.set(0, 2, 0, air);
|
||||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||||
|
|
||||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), data, opts);
|
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), data, opts, null);
|
||||||
|
|
||||||
assertSame(support, output.get(0, 1, 0));
|
assertSame(support, output.get(0, 1, 0));
|
||||||
assertSame(decorant, output.get(0, 2, 0));
|
assertSame(decorant, output.get(0, 2, 0));
|
||||||
@@ -202,7 +202,7 @@ public class DecoratorCoreTest {
|
|||||||
output.set(0, 2, 0, occupied);
|
output.set(0, 2, 0, occupied);
|
||||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||||
|
|
||||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), data, opts);
|
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), data, opts, null);
|
||||||
|
|
||||||
assertSame(support, output.get(0, 1, 0));
|
assertSame(support, output.get(0, 1, 0));
|
||||||
assertSame(occupied, output.get(0, 2, 0));
|
assertSame(occupied, output.get(0, 2, 0));
|
||||||
@@ -233,7 +233,7 @@ public class DecoratorCoreTest {
|
|||||||
output.set(0, 4, 0, air);
|
output.set(0, 4, 0, air);
|
||||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||||
|
|
||||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 4, output, new RNG(1L), data, opts);
|
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 4, output, new RNG(1L), data, opts, null);
|
||||||
|
|
||||||
assertSame(decorant, output.get(0, 2, 0));
|
assertSame(decorant, output.get(0, 2, 0));
|
||||||
assertSame(occupied, output.get(0, 3, 0));
|
assertSame(occupied, output.get(0, 3, 0));
|
||||||
@@ -941,7 +941,7 @@ public class DecoratorCoreTest {
|
|||||||
opts.underwater = submerged;
|
opts.underwater = submerged;
|
||||||
opts.fluidHeight = height;
|
opts.fluidHeight = height;
|
||||||
if (upward) {
|
if (upward) {
|
||||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 0, height, output, new RNG(1L), data, opts);
|
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 0, height, output, new RNG(1L), data, opts, null);
|
||||||
} else {
|
} else {
|
||||||
DecoratorCore.placeStackDown(decorator, 0, 0, 0, 0, height, 1, output, new RNG(1L), data, height, opts, null);
|
DecoratorCore.placeStackDown(decorator, 0, 0, 0, 0, height, 1, output, new RNG(1L), data, height, opts, null);
|
||||||
}
|
}
|
||||||
@@ -1057,7 +1057,7 @@ public class DecoratorCoreTest {
|
|||||||
|
|
||||||
private void place() {
|
private void place() {
|
||||||
if (upward) {
|
if (upward) {
|
||||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 0, height, output, new RNG(1L), data, opts);
|
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 0, height, output, new RNG(1L), data, opts, null);
|
||||||
} else {
|
} else {
|
||||||
DecoratorCore.placeStackDown(decorator, 0, 0, 0, 0, height, 1, output, new RNG(1L), data, height, opts, null);
|
DecoratorCore.placeStackDown(decorator, 0, 0, 0, 0, height, 1, output, new RNG(1L), data, height, opts, null);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ public class DecoratorStackSamplingTest {
|
|||||||
int z = coordinate * 3 - 7;
|
int z = coordinate * 3 - 7;
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case 0 -> DecoratorCore.placeStackUp(decorator, 0, 0, coordinate, z, 0, height,
|
case 0 -> DecoratorCore.placeStackUp(decorator, 0, 0, coordinate, z, 0, height,
|
||||||
output, rng, data, opts);
|
output, rng, data, opts, null);
|
||||||
case 1 -> DecoratorCore.placeStackDown(decorator, 0, 0, coordinate, z, height, 0,
|
case 1 -> DecoratorCore.placeStackDown(decorator, 0, 0, coordinate, z, height, 0,
|
||||||
output, rng, data, height, opts, null);
|
output, rng, data, height, opts, null);
|
||||||
case 2 -> assertEquals(height, DecoratorCore.placeFloatingStacked(decorator, 0, 0,
|
case 2 -> assertEquals(height, DecoratorCore.placeFloatingStacked(decorator, 0, 0,
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package art.arcane.iris.generation.runtime;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
public class EngineRefTest {
|
||||||
|
@Test
|
||||||
|
public void refsToTheSameEngineAreEqual() {
|
||||||
|
Engine engine = mock(Engine.class);
|
||||||
|
|
||||||
|
EngineRef first = EngineRef.of(engine);
|
||||||
|
EngineRef second = EngineRef.of(engine);
|
||||||
|
|
||||||
|
assertEquals(first, second);
|
||||||
|
assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
assertTrue(first.refersTo(engine));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void refsToDifferentEnginesDiffer() {
|
||||||
|
Engine engine = mock(Engine.class);
|
||||||
|
Engine otherEngine = mock(Engine.class);
|
||||||
|
|
||||||
|
assertNotEquals(EngineRef.of(engine), EngineRef.of(otherEngine));
|
||||||
|
assertFalse(EngineRef.of(engine).refersTo(otherEngine));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void missingEngineOnlyMatchesMissingEngine() {
|
||||||
|
Engine engine = mock(Engine.class);
|
||||||
|
|
||||||
|
assertEquals(EngineRef.of(null), EngineRef.of(null));
|
||||||
|
assertTrue(EngineRef.of(null).refersTo(null));
|
||||||
|
assertFalse(EngineRef.of(null).refersTo(engine));
|
||||||
|
assertFalse(EngineRef.of(engine).refersTo(null));
|
||||||
|
assertNotEquals(EngineRef.of(null), EngineRef.of(engine));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user