mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 01:04:29 +00:00
Move effect latches into the pack runtime
- Keep one effect interval latch per effect in the pack runtime - Pass the pack runtime to effect checks on players and spawned entities - Resolve the deposit pack runtime once per chunk instead of once per clump
This commit is contained in:
1 parent
66b4ab8bd2
commit
99a6e5ddb6
7 files changed
+38
-25
No files matched your search
+5
-3
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.BiomeEnvironment;
|
||||
@@ -223,17 +224,18 @@ public final class ModdedEngineEffects extends EngineAssignedComponent implement
|
||||
}
|
||||
|
||||
private void applyEffects(NativeWorld level, NativeProtocolPlayer player, Iterable<IrisEffect> effects) {
|
||||
PackRuntime runtime = PackRuntime.of(getEngine());
|
||||
for (IrisEffect effect : effects) {
|
||||
try {
|
||||
applyEffect(level, player, effect);
|
||||
applyEffect(level, player, effect, runtime);
|
||||
} catch (Throwable error) {
|
||||
IrisLogging.reportError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyEffect(NativeWorld level, NativeProtocolPlayer player, IrisEffect effect) {
|
||||
if (!effect.shouldApplyNow()) {
|
||||
private void applyEffect(NativeWorld level, NativeProtocolPlayer player, IrisEffect effect, PackRuntime runtime) {
|
||||
if (!effect.shouldApplyNow(runtime)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.generation.decoration.IrisSurface;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
@@ -127,7 +128,7 @@ public final class ModdedEntitySpawner {
|
||||
|
||||
entity.configureAnimal(irisEntity);
|
||||
|
||||
applySpawnEffect(irisEntity.getSpawnEffect(), entity, level);
|
||||
applySpawnEffect(irisEntity.getSpawnEffect(), entity, level, PackRuntime.of(engine));
|
||||
ModdedEntityCommandRunner.run(irisEntity.getRawCommands(), level.world(), blockX, blockY, blockZ);
|
||||
if (riseEffectActive && entity.living()) {
|
||||
startRiseEffect(engine, level, entity);
|
||||
@@ -200,8 +201,9 @@ public final class ModdedEntitySpawner {
|
||||
return level.chunksSafe(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
private static void applySpawnEffect(IrisEffect effect, NativeSpawnedEntity entity, NativeEntityRuntime level) {
|
||||
if (effect == null || !effect.shouldApplyNow()) {
|
||||
private static void applySpawnEffect(IrisEffect effect, NativeSpawnedEntity entity, NativeEntityRuntime level,
|
||||
PackRuntime runtime) {
|
||||
if (effect == null || !effect.shouldApplyNow(runtime)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,11 @@ import art.arcane.iris.generation.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingEntry;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.world.entity.IrisEffect;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import art.arcane.volmlib.util.scheduling.ChronoLatch;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -73,6 +75,8 @@ public final class PackRuntime {
|
||||
ore -> new SeedTable<>(ORE_CHANCE_SEED_CAPACITY, seed -> ore.createChance(seed, this)));
|
||||
private final RuntimeTable<IrisObjectPlacement, SeedTable<CNG>> surfaceWarps = new RuntimeTable<>(
|
||||
placement -> new SeedTable<>(SURFACE_WARP_SEED_CAPACITY, seed -> placement.createSurfaceWarp(seed, this)));
|
||||
private final RuntimeTable<IrisEffect, ChronoLatch> effectLatches =
|
||||
new RuntimeTable<>(effect -> new ChronoLatch(effect.getInterval()));
|
||||
private final RuntimeTable<IrisDecorator, DecoratorRuntime> decorators =
|
||||
new RuntimeTable<>(decorator -> new DecoratorRuntime(decorator, this));
|
||||
private final RuntimeTable<IrisDepositGenerator, DepositRuntime> deposits =
|
||||
@@ -183,6 +187,11 @@ public final class PackRuntime {
|
||||
return surfaceWarps.get(placement).get(seed);
|
||||
}
|
||||
|
||||
/** Every player and entity of this owner shares one interval latch per effect. */
|
||||
public ChronoLatch effectLatch(IrisEffect effect) {
|
||||
return effectLatches.get(effect);
|
||||
}
|
||||
|
||||
public DecoratorRuntime decorator(IrisDecorator decorator) {
|
||||
return decorators.get(decorator);
|
||||
}
|
||||
|
||||
@@ -101,10 +101,11 @@ public class IrisDepositModifier extends EngineAssignedModifier<NativeBlockState
|
||||
try {
|
||||
List<DepositPlan> plans = new ArrayList<>(generators.size());
|
||||
AboveTerrainHosts aboveTerrainHosts = new AboveTerrainHosts(terrain, context);
|
||||
PackRuntime runtime = PackRuntime.of(getEngine(), getData());
|
||||
int attempts = 0;
|
||||
for (int i = 0; i < generators.size(); i++) {
|
||||
try {
|
||||
DepositPlan plan = plan(generators.get(i), rng.nextParallelRNG(seed * (i + 1L)), context);
|
||||
DepositPlan plan = plan(generators.get(i), rng.nextParallelRNG(seed * (i + 1L)), context, runtime);
|
||||
if (plan.attempts() == 0 || footprintsMissTerrain(plan, highestSurface)
|
||||
|| plan.generator().getPlacementScope() == IrisDepositPlacementScope.ABOVE_TERRAIN
|
||||
&& !aboveTerrainHosts.present(plan.generator().getSurfaceClearance())) {
|
||||
@@ -210,7 +211,7 @@ public class IrisDepositModifier extends EngineAssignedModifier<NativeBlockState
|
||||
}
|
||||
|
||||
public void generate(IrisDepositGenerator k, MantleChunk chunk, Hunk<NativeBlockState> data, RNG rng, int cx, int cz, boolean safe, HeightMap he, ChunkContext context) {
|
||||
DepositPlan plan = plan(k, rng, context);
|
||||
DepositPlan plan = plan(k, rng, context, PackRuntime.of(getEngine(), getData()));
|
||||
if (plan.attempts() == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -232,13 +233,13 @@ public class IrisDepositModifier extends EngineAssignedModifier<NativeBlockState
|
||||
return lowest > (long) highestSurface - Math.max(0, generator.getSurfaceClearance());
|
||||
}
|
||||
|
||||
private DepositPlan plan(IrisDepositGenerator generator, RNG rng, ChunkContext context) {
|
||||
private DepositPlan plan(IrisDepositGenerator generator, RNG rng, ChunkContext context, PackRuntime runtime) {
|
||||
if (generator.getSpawnChance() < rng.d()) {
|
||||
return new DepositPlan(generator, rng.getSeed(), false, 0);
|
||||
return new DepositPlan(generator, runtime, rng.getSeed(), false, 0);
|
||||
}
|
||||
boolean ore = generator.isOre(getData());
|
||||
int attempts = rng.i(generator.getMinPerChunk(), generator.getMaxPerChunk() + 1);
|
||||
return new DepositPlan(generator, rng.getSeed(), ore,
|
||||
return new DepositPlan(generator, runtime, rng.getSeed(), ore,
|
||||
attempts == 0 || surfaceBiomeMayMatch(generator, context) ? attempts : 0);
|
||||
}
|
||||
|
||||
@@ -307,7 +308,7 @@ public class IrisDepositModifier extends EngineAssignedModifier<NativeBlockState
|
||||
if (footprint != null && footprint.empty() && !scalable) {
|
||||
return null;
|
||||
}
|
||||
IrisObject clump = footprint == null ? k.getClump(PackRuntime.of(getEngine(), getData()), clumpRng) : null;
|
||||
IrisObject clump = footprint == null ? k.getClump(plan.runtime(), clumpRng) : null;
|
||||
|
||||
int dim = footprint == null ? clump.getW() : footprint.width();
|
||||
int min = dim / 2;
|
||||
@@ -369,7 +370,7 @@ public class IrisDepositModifier extends EngineAssignedModifier<NativeBlockState
|
||||
|
||||
double sizeMultiplier = depositBiome.getOreDepositSizeMultiplier();
|
||||
if (sizeMultiplier != 1D) {
|
||||
IrisObject scaledClump = k.getClump(PackRuntime.of(getEngine(), getData()), clumpRng, sizeMultiplier);
|
||||
IrisObject scaledClump = k.getClump(plan.runtime(), clumpRng, sizeMultiplier);
|
||||
int scaledDimension = scaledClump.getW();
|
||||
x = clampDepositCenter(x, scaledDimension, 16);
|
||||
if (clippedHeight) {
|
||||
@@ -701,7 +702,7 @@ public class IrisDepositModifier extends EngineAssignedModifier<NativeBlockState
|
||||
}
|
||||
}
|
||||
|
||||
private record DepositPlan(IrisDepositGenerator generator, long seed, boolean ore, int attempts) {
|
||||
private record DepositPlan(IrisDepositGenerator generator, PackRuntime runtime, long seed, boolean ore, int attempts) {
|
||||
}
|
||||
|
||||
private static final class HostStates {
|
||||
|
||||
@@ -31,7 +31,7 @@ import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.scheduling.ChronoLatch;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.platform.registry.RegistryUtil;
|
||||
import art.arcane.iris.world.task.J;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -66,7 +66,6 @@ public class IrisEffect {
|
||||
private static final Set<String> UNKNOWN_SOUND_CATEGORIES = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private final transient AtomicCache<PotionEffectType> pt = new AtomicCache<>();
|
||||
private final transient AtomicCache<ChronoLatch> latch = new AtomicCache<>();
|
||||
private final transient AtomicCache<Particle> particleEffectResolved = new AtomicCache<>();
|
||||
private final transient AtomicCache<Sound> soundResolved = new AtomicCache<>();
|
||||
@RegistryListPotionEffect
|
||||
@@ -176,12 +175,12 @@ public class IrisEffect {
|
||||
private IrisCommandRegistry commandRegistry = null;
|
||||
|
||||
|
||||
public boolean canTick() {
|
||||
return latch.aquire(() -> new ChronoLatch(interval)).flip();
|
||||
public boolean canTick(PackRuntime runtime) {
|
||||
return runtime.effectLatch(this).flip();
|
||||
}
|
||||
|
||||
public boolean shouldApplyNow() {
|
||||
return canTick() && RNG.r.nextInt(chance) == 0;
|
||||
public boolean shouldApplyNow(PackRuntime runtime) {
|
||||
return canTick(runtime) && RNG.r.nextInt(chance) == 0;
|
||||
}
|
||||
|
||||
public String getParticleEffectKey() {
|
||||
@@ -272,7 +271,7 @@ public class IrisEffect {
|
||||
}
|
||||
|
||||
public void apply(Player p, Engine g) {
|
||||
if (!shouldApplyNow()) {
|
||||
if (!shouldApplyNow(PackRuntime.of(g))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -349,8 +348,8 @@ public class IrisEffect {
|
||||
}
|
||||
}
|
||||
|
||||
public void apply(Entity p) {
|
||||
if (!shouldApplyNow()) {
|
||||
public void apply(Entity p, PackRuntime runtime) {
|
||||
if (!shouldApplyNow(runtime)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.world.entity;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.nativelib.entity.NativeEntityOptions;
|
||||
import art.arcane.volmlib.nativelib.entity.NativeEntityType;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
@@ -409,7 +410,7 @@ public class IrisEntity extends IrisRegistrant implements NativeEntityOptions {
|
||||
}
|
||||
|
||||
if (spawnEffect != null) {
|
||||
spawnEffect.apply(e);
|
||||
spawnEffect.apply(e, PackRuntime.of(gen));
|
||||
}
|
||||
|
||||
if (rawCommands.isNotEmpty()) {
|
||||
|
||||
@@ -196,7 +196,6 @@ public class PackRuntimeStateGateTest {
|
||||
);
|
||||
|
||||
private static final List<Entry> PENDING_MIGRATION = List.of(
|
||||
pending("art.arcane.iris.world.entity.IrisEffect", "latch", Kind.RUNTIME),
|
||||
pending("art.arcane.iris.generation.bake.ChunkBakeCache", "recent", Kind.THREAD),
|
||||
pending("art.arcane.iris.generation.hydrology.engine.HydrologyRuntime", "last", Kind.THREAD),
|
||||
pending("art.arcane.iris.generation.mantle.IrisCaveCarver3D", "scratchCache", Kind.THREAD),
|
||||
|
||||
Reference in new issue
Block a user