mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 15:09:18 +00:00
potential optimization for the noise cache
This commit is contained in:
@@ -234,7 +234,7 @@ public class IrisToolbelt {
|
||||
}
|
||||
|
||||
public static void retainMantleDataForSlice(String className) {
|
||||
toolbeltConfiguration.put("retain.mantle." + className, true);
|
||||
toolbeltConfiguration.put("retain.mantle." + className, Boolean.TRUE);
|
||||
}
|
||||
|
||||
public static boolean isRetainingMantleDataForSlice(String className) {
|
||||
|
||||
@@ -2,22 +2,36 @@ package com.volmit.iris.util.cache;
|
||||
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.VarHandle;
|
||||
|
||||
public class ChunkCache2D<T> {
|
||||
private static final boolean FAST = Boolean.getBoolean("iris.cache.fast");
|
||||
private static final boolean DYNAMIC = Boolean.getBoolean("iris.cache.dynamic");
|
||||
private static final VarHandle AA = MethodHandles.arrayElementVarHandle(Entry[].class);
|
||||
|
||||
private final Entry<T>[] cache;
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public ChunkCache2D() {
|
||||
this.cache = new Entry[256];
|
||||
if (DYNAMIC) return;
|
||||
for (int i = 0; i < cache.length; i++) {
|
||||
cache[i] = FAST ? new FastEntry<>() : new Entry<>();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public T get(int x, int z, Function2<Integer, Integer, T> resolver) {
|
||||
int key = ((z & 15) * 16) + (x & 15);
|
||||
return cache[key].compute(x, z, resolver);
|
||||
var entry = cache[key];
|
||||
if (entry == null) {
|
||||
entry = FAST ? new FastEntry<>() : new Entry<>();
|
||||
if (!AA.compareAndSet(cache, key, null, entry)) {
|
||||
entry = (Entry<T>) AA.getVolatile(cache, key);
|
||||
}
|
||||
}
|
||||
return entry.compute(x, z, resolver);
|
||||
}
|
||||
|
||||
private static class Entry<T> {
|
||||
|
||||
@@ -25,4 +25,8 @@ public class WorldCache2D<T> {
|
||||
public long getSize() {
|
||||
return chunks.size() * 256L;
|
||||
}
|
||||
|
||||
public long getMaxSize() {
|
||||
return chunks.capacity() * 256L;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user