This commit is contained in:
Zoe Gidiere
2025-12-10 18:52:00 -07:00
parent dd2f0365b0
commit f8f6b0b4bc
2 changed files with 13 additions and 11 deletions

View File

@@ -1,6 +1,11 @@
package com.dfsek.terra.addons.biome.extrusion.extrusions;
import com.dfsek.seismic.type.sampler.Sampler;
import java.util.Collection;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import com.dfsek.terra.addons.biome.extrusion.api.Extrusion;
import com.dfsek.terra.addons.biome.extrusion.api.ReplaceableBiome;
import com.dfsek.terra.addons.biome.query.api.BiomeQueries;
@@ -9,11 +14,6 @@ import com.dfsek.terra.api.util.collection.TriStateIntCache;
import com.dfsek.terra.api.util.range.Range;
import com.dfsek.terra.api.world.biome.Biome;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicLongArray;
import java.util.function.IntPredicate;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* Sets biomes at locations based on a sampler.
@@ -44,7 +44,7 @@ public class ReplaceExtrusion implements Extrusion {
long state = cache.get(id);
boolean passes;
if (state == TriStateIntCache.STATE_UNSET) {
if(state == TriStateIntCache.STATE_UNSET) {
// Only run the test if unset in cache
passes = hasTag.test(original);
cache.set(id, passes);
@@ -53,8 +53,8 @@ public class ReplaceExtrusion implements Extrusion {
passes = (state == TriStateIntCache.STATE_TRUE);
}
if (passes) {
if (range.isInRange(y)) {
if(passes) {
if(range.isInRange(y)) {
return biomes.get(sampler, x, y, z, seed).get(original);
}
}

View File

@@ -2,10 +2,11 @@ package com.dfsek.terra.api.util.collection;
import java.util.concurrent.atomic.AtomicLongArray;
public class TriStateIntCache {
public static final long STATE_UNSET = 0L;
public static final long STATE_FALSE = 1L;
public static final long STATE_TRUE = 2L;
public static final long STATE_TRUE = 2L;
private static final long BIT_MASK = 3L;
private final AtomicLongArray data;
@@ -16,6 +17,7 @@ public class TriStateIntCache {
/**
* Checks the cache state without any allocation.
*
* @return STATE_UNSET (0), STATE_FALSE (1), or STATE_TRUE (2)
*/
public long get(int key) {
@@ -39,13 +41,13 @@ public class TriStateIntCache {
// Race condition check:
long existingState = (currentWord >>> bitShift) & BIT_MASK;
if (existingState != STATE_UNSET) {
if(existingState != STATE_UNSET) {
return; // Already set, abort our update
}
// Create new word with our bit set
newWord = (currentWord & ~(BIT_MASK << bitShift)) | (targetState << bitShift);
} while (!data.compareAndSet(arrayIndex, currentWord, newWord));
} while(!data.compareAndSet(arrayIndex, currentWord, newWord));
}
}