mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-08-29 13:30:50 +00:00
dwa
This commit is contained in:
+8
-4
@@ -57,6 +57,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
private volatile KMap<String, Holder<Biome>> customBiomes;
|
||||
private volatile Map<Biome, Holder<Biome>> vanillaSpawnBiomes;
|
||||
private volatile IrisDimension cacheDimension;
|
||||
private volatile int cacheRuntimeId;
|
||||
|
||||
public CustomBiomeSource(long seed, Engine engine, World world) {
|
||||
this.engine = engine;
|
||||
@@ -67,6 +68,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
this.customBiomes = fillCustomBiomes(this.biomeCustomRegistry, engine, this.fallbackBiome);
|
||||
this.vanillaSpawnBiomes = fillVanillaSpawnBiomes(this.biomeCustomRegistry, this.biomeRegistry, engine);
|
||||
this.cacheDimension = engine.getDimension();
|
||||
this.cacheRuntimeId = engine.getCacheID();
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getAllBiomes(Registry<Biome> customRegistry, Registry<Biome> registry, Engine engine) {
|
||||
@@ -246,11 +248,11 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease("bukkit_spawn_biome");
|
||||
if (lease == null) {
|
||||
throw new IllegalStateException("Iris spawn biome lookup was rejected during an engine transition");
|
||||
return null;
|
||||
}
|
||||
try (lease; IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
if (!isRuntimeAvailable()) {
|
||||
throw new IllegalStateException("Iris spawn biome lookup has no active engine runtime");
|
||||
return null;
|
||||
}
|
||||
ensureCachesCurrent();
|
||||
return vanillaSpawnBiomes.get(biome.value());
|
||||
@@ -434,11 +436,12 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
|
||||
private void ensureCachesCurrent() {
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
if (cacheDimension == dimension) {
|
||||
int runtimeId = engine.getCacheID();
|
||||
if (cacheDimension == dimension && cacheRuntimeId == runtimeId) {
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (cacheDimension == dimension) {
|
||||
if (cacheDimension == dimension && cacheRuntimeId == runtimeId) {
|
||||
return;
|
||||
}
|
||||
KMap<String, Holder<Biome>> refreshedCustomBiomes = fillCustomBiomes(
|
||||
@@ -451,6 +454,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
customBiomes = refreshedCustomBiomes;
|
||||
vanillaSpawnBiomes = refreshedSpawnBiomes;
|
||||
cacheDimension = dimension;
|
||||
cacheRuntimeId = runtimeId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -57,6 +57,7 @@ final class ImportedFeatureStage {
|
||||
private final Engine engine;
|
||||
private volatile FeatureTable featureTable;
|
||||
private volatile IrisDimension inertDimension;
|
||||
private volatile int settledRuntimeId;
|
||||
|
||||
ImportedFeatureStage(Engine engine) {
|
||||
this.engine = engine;
|
||||
@@ -86,18 +87,23 @@ final class ImportedFeatureStage {
|
||||
*/
|
||||
void prepare(WorldGenLevel level) {
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
if (settled(dimension)) {
|
||||
int runtimeId = engine.getCacheID();
|
||||
if (settled(dimension, runtimeId)) {
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (settled(dimension)) {
|
||||
if (settled(dimension, runtimeId)) {
|
||||
return;
|
||||
}
|
||||
build(level, dimension);
|
||||
settledRuntimeId = runtimeId;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean settled(IrisDimension dimension) {
|
||||
private boolean settled(IrisDimension dimension, int runtimeId) {
|
||||
if (settledRuntimeId != runtimeId) {
|
||||
return false;
|
||||
}
|
||||
FeatureTable current = featureTable;
|
||||
if (current != null && current.dimension() == dimension) {
|
||||
return true;
|
||||
|
||||
+18
-4
@@ -128,6 +128,8 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
private final int runtimeHeight;
|
||||
private final int runtimeSeaLevel;
|
||||
private final ConcurrentHashMap<SpawnTableKey, WeightedList<MobSpawnSettings.SpawnerData>> mergedSpawnTables = new ConcurrentHashMap<>();
|
||||
private volatile IrisDimension spawnTableDimension;
|
||||
private volatile int spawnTableRuntimeId;
|
||||
private final ImportedFeatureStage importedFeatures;
|
||||
private final AtomicReference<StudioStructureState> retainedStudioStructureState = new AtomicReference<>();
|
||||
private volatile ReachableStructureCache reachableStructureCache;
|
||||
@@ -310,18 +312,19 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
|
||||
private Set<String> reachableStructureKeys(ServerLevel level) {
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
int runtimeId = engine.getCacheID();
|
||||
ReachableStructureCache cached = reachableStructureCache;
|
||||
if (cached != null && cached.dimension() == dimension) {
|
||||
if (cached != null && cached.dimension() == dimension && cached.runtimeId() == runtimeId) {
|
||||
return cached.keys();
|
||||
}
|
||||
synchronized (this) {
|
||||
cached = reachableStructureCache;
|
||||
if (cached != null && cached.dimension() == dimension) {
|
||||
if (cached != null && cached.dimension() == dimension && cached.runtimeId() == runtimeId) {
|
||||
return cached.keys();
|
||||
}
|
||||
Set<String> reachable = Set.copyOf(
|
||||
VanillaStructureBiomes.reachableStructureKeys(level, customBiomeSource));
|
||||
reachableStructureCache = new ReachableStructureCache(dimension, reachable);
|
||||
reachableStructureCache = new ReachableStructureCache(dimension, runtimeId, reachable);
|
||||
return reachable;
|
||||
}
|
||||
}
|
||||
@@ -738,6 +741,17 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
return explicitSpawns;
|
||||
}
|
||||
|
||||
IrisDimension spawnDimension = engine.getDimension();
|
||||
int spawnRuntimeId = engine.getCacheID();
|
||||
if (spawnTableDimension != spawnDimension || spawnTableRuntimeId != spawnRuntimeId) {
|
||||
synchronized (mergedSpawnTables) {
|
||||
if (spawnTableDimension != spawnDimension || spawnTableRuntimeId != spawnRuntimeId) {
|
||||
mergedSpawnTables.clear();
|
||||
spawnTableDimension = spawnDimension;
|
||||
spawnTableRuntimeId = spawnRuntimeId;
|
||||
}
|
||||
}
|
||||
}
|
||||
SpawnTableKey key = new SpawnTableKey(holder.value(), enumcreaturetype);
|
||||
return mergedSpawnTables.computeIfAbsent(key, ignored -> mergeSpawnTables(vanillaSpawns, explicitSpawns));
|
||||
}
|
||||
@@ -1160,7 +1174,7 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
private record SpawnTableKey(Biome biome, MobCategory category) {
|
||||
}
|
||||
|
||||
private record ReachableStructureCache(IrisDimension dimension, Set<String> keys) {
|
||||
private record ReachableStructureCache(IrisDimension dimension, int runtimeId, Set<String> keys) {
|
||||
}
|
||||
|
||||
private record StructureStepCache(Registry<Structure> registry, List<List<Structure>> structures) {
|
||||
|
||||
+3
-2
@@ -26,8 +26,9 @@ public class CustomBiomeSourceStructureContractTest {
|
||||
|
||||
assertTrue(source.contains("tryAcquireGenerationLease(\"bukkit_possible_biomes\")"));
|
||||
assertTrue(source.contains("tryAcquireGenerationLease(\"bukkit_spawn_biome\")"));
|
||||
assertTrue(source.contains("Iris spawn biome lookup was rejected during an engine transition"));
|
||||
assertTrue(source.contains("Iris spawn biome lookup has no active engine runtime"));
|
||||
assertFalse(source.contains("Iris spawn biome lookup was rejected during an engine transition"));
|
||||
assertFalse(source.contains("Iris spawn biome lookup has no active engine runtime"));
|
||||
assertTrue(source.contains("vanillaSpawnBiomes.get(biome.value())"));
|
||||
assertTrue(source.contains("tryAcquireGenerationLease(\"bukkit_structure_biome\")"));
|
||||
assertTrue(source.contains("tryAcquireGenerationLease(\"bukkit_biomes_within\")"));
|
||||
assertTrue(source.contains("tryAcquireGenerationLease(\"bukkit_visible_biome\")"));
|
||||
|
||||
Reference in New Issue
Block a user