mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-28 15:00:11 +00:00
Memoize object block states
- Cache vanilla withProperty variants per state - Cache rotated states per rotation and quantized spin - Hoist the stilt dirt state and rotate only target-layer stilt blocks
This commit is contained in:
1 parent
ec07f55fd8
commit
2f8d3b1d1a
6 files changed
+115
-7
No files matched your search
@@ -80,6 +80,7 @@ public final class BukkitBlockState implements NativeBlockState {
|
||||
private volatile Boolean deepSlate;
|
||||
private volatile Boolean vineBlock;
|
||||
private volatile Boolean tileEntity;
|
||||
private volatile ConcurrentHashMap<String, ConcurrentHashMap<String, NativeBlockState>> propertyVariants;
|
||||
|
||||
private BukkitBlockState(BlockData data, String key) {
|
||||
this.data = data;
|
||||
@@ -428,7 +429,18 @@ public final class BukkitBlockState implements NativeBlockState {
|
||||
BlockData resolved = Bukkit.createBlockData(merged);
|
||||
return of(IrisCustomData.of(resolved, custom.getCustom()));
|
||||
}
|
||||
return of(Bukkit.createBlockData(BlockStateKey.withProperty(key, name, value)));
|
||||
ConcurrentHashMap<String, ConcurrentHashMap<String, NativeBlockState>> variants = propertyVariants;
|
||||
if (variants == null) {
|
||||
variants = new ConcurrentHashMap<>(4);
|
||||
propertyVariants = variants;
|
||||
}
|
||||
ConcurrentHashMap<String, NativeBlockState> values = variants.computeIfAbsent(name, (String ignored) -> new ConcurrentHashMap<>(4));
|
||||
NativeBlockState variant = values.get(value);
|
||||
if (variant == null) {
|
||||
variant = of(Bukkit.createBlockData(BlockStateKey.withProperty(key, name, value)));
|
||||
values.putIfAbsent(value, variant);
|
||||
}
|
||||
return variant;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -86,6 +86,7 @@ public class IrisObject extends IrisRegistrant {
|
||||
NativeBlockState stone,
|
||||
NativeBlockState vair,
|
||||
NativeBlockState vairDebug,
|
||||
NativeBlockState dirt,
|
||||
NativeBlockState[] snowLayers) {
|
||||
}
|
||||
|
||||
@@ -102,6 +103,7 @@ public class IrisObject extends IrisRegistrant {
|
||||
B.getState("STONE"),
|
||||
B.getState("VOID_AIR"),
|
||||
B.getState("COBWEB"),
|
||||
B.getState("minecraft:dirt"),
|
||||
new NativeBlockState[]{B.getState("minecraft:snow[layers=1]"), B.getState("minecraft:snow[layers=2]"), B.getState("minecraft:snow[layers=3]"), B.getState("minecraft:snow[layers=4]"), B.getState("minecraft:snow[layers=5]"), B.getState("minecraft:snow[layers=6]"), B.getState("minecraft:snow[layers=7]"), B.getState("minecraft:snow[layers=8]")});
|
||||
bound = resolved;
|
||||
return resolved;
|
||||
@@ -123,6 +125,10 @@ public class IrisObject extends IrisRegistrant {
|
||||
return bound().vairDebug();
|
||||
}
|
||||
|
||||
static NativeBlockState dirt() {
|
||||
return bound().dirt();
|
||||
}
|
||||
|
||||
static NativeBlockState snowLayer(int layerIndex) {
|
||||
return bound().snowLayers()[layerIndex];
|
||||
}
|
||||
|
||||
@@ -733,7 +733,7 @@ final class IrisObjectPlacementRunner {
|
||||
} else {
|
||||
String mat = IrisObjectShaping.materialKey(d);
|
||||
if (mat.equals("minecraft:grass_block") || mat.equals("minecraft:mycelium") || mat.equals("minecraft:podzol") || mat.equals("minecraft:dirt_path")) {
|
||||
d = B.getState("minecraft:dirt");
|
||||
d = IrisObject.States.dirt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -745,11 +745,10 @@ final class IrisObjectPlacementRunner {
|
||||
if (translating) {
|
||||
i.add(translateOffset);
|
||||
}
|
||||
d = config.getRotation().rotate(d, spinx, spiny, spinz);
|
||||
|
||||
int targetLayer = ceilingHang ? topLayer : lowest;
|
||||
if (i.getBlockY() != targetLayer)
|
||||
continue;
|
||||
d = config.getRotation().rotate(d, spinx, spiny, spinz);
|
||||
|
||||
if (hasEdits) {
|
||||
for (IrisObjectReplace j : config.getEdit()) {
|
||||
|
||||
@@ -50,6 +50,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Snippet("object-rotator")
|
||||
@Accessors(chain = true)
|
||||
@@ -59,6 +60,8 @@ import java.util.Set;
|
||||
@Data
|
||||
public class IrisObjectRotation {
|
||||
private static volatile StateRotator PLATFORM_ROTATOR = null;
|
||||
private static final Object ROTATED_AWAY = new Object();
|
||||
private static final int SPIN_STEPS = 5;
|
||||
|
||||
public interface StateRotator {
|
||||
NativeBlockState rotate(IrisObjectRotation rotation, NativeBlockState state, int spinx, int spiny, int spinz);
|
||||
@@ -91,6 +94,8 @@ public class IrisObjectRotation {
|
||||
@Description("The z axis rotation")
|
||||
private IrisAxisRotationClamp zAxis = new IrisAxisRotationClamp();
|
||||
|
||||
private final transient ConcurrentHashMap<NativeBlockState, Object[]> stateRotations = new ConcurrentHashMap<>();
|
||||
|
||||
public static IrisObjectRotation xFlip180() {
|
||||
IrisObjectRotation rt = new IrisObjectRotation();
|
||||
IrisAxisRotationClamp rtx = new IrisAxisRotationClamp();
|
||||
@@ -316,9 +321,19 @@ public class IrisObjectRotation {
|
||||
return state;
|
||||
}
|
||||
|
||||
BlockData raw = original.clone();
|
||||
BlockData rotated = rotate(raw, spinx, spiny, spinz);
|
||||
return rotated == null ? null : BukkitBlockState.of(rotated);
|
||||
Object[] rotations = stateRotations.computeIfAbsent(state, (NativeBlockState ignored) -> new Object[SPIN_STEPS * SPIN_STEPS * SPIN_STEPS]);
|
||||
int index = (spinStep(spinx) * SPIN_STEPS + spinStep(spiny)) * SPIN_STEPS + spinStep(spinz);
|
||||
Object memo = rotations[index];
|
||||
if (memo == null) {
|
||||
BlockData rotated = rotate(original.clone(), spinx, spiny, spinz);
|
||||
memo = rotated == null ? ROTATED_AWAY : BukkitBlockState.of(rotated);
|
||||
rotations[index] = memo;
|
||||
}
|
||||
return memo == ROTATED_AWAY ? null : (NativeBlockState) memo;
|
||||
}
|
||||
|
||||
private static int spinStep(int spin) {
|
||||
return (int) Math.ceil(Math.abs((spin % 360D) / 90D));
|
||||
}
|
||||
|
||||
private static boolean canRotateBlockData(BlockData data) {
|
||||
|
||||
Reference in new issue
Block a user