9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-27 11:09:06 +00:00
This commit is contained in:
cyberpwn
2021-09-25 13:52:50 -04:00
parent 57ef3842e9
commit 384a28c517
83 changed files with 323 additions and 670 deletions

View File

@@ -42,12 +42,9 @@ public class KMap<K, V> extends ConcurrentHashMap<K, V> {
put(gMap);
}
public K getKey(V value)
{
for(KeyPair<K,V> i : keypair())
{
if(i.getV().equals(value))
{
public K getKey(V value) {
for (KeyPair<K, V> i : keypair()) {
if (i.getV().equals(value)) {
return i.getK();
}
}

View File

@@ -400,13 +400,11 @@ public class B {
try {
String bd = bdxf.trim();
if(bd.startsWith("minecraft:cauldron[level="))
{
if (bd.startsWith("minecraft:cauldron[level=")) {
bd = bd.replaceAll("\\Q:cauldron[\\E", ":water_cauldron[");
}
if(bd.equals("minecraft:grass_path"))
{
if (bd.equals("minecraft:grass_path")) {
return DIRT_PATH.createBlockData();
}

View File

@@ -20,7 +20,6 @@ package com.volmit.iris.util.data;
import com.volmit.iris.util.function.Function2;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReferenceArray;
public class ChunkCache<T> {
@@ -30,14 +29,12 @@ public class ChunkCache<T> {
cache = new AtomicReferenceArray<>(256);
}
public T compute(int x, int z, Function2<Integer, Integer, T> function)
{
T t = get(x&15, z&15);
public T compute(int x, int z, Function2<Integer, Integer, T> function) {
T t = get(x & 15, z & 15);
if(t == null)
{
if (t == null) {
t = function.apply(x, z);
set(x&15, z&15, t);
set(x & 15, z & 15, t);
}
return t;

View File

@@ -22,25 +22,21 @@ import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.collection.KMap;
public class ComplexCache<T> {
private KMap<Long, ChunkCache<T>> chunks;
private final KMap<Long, ChunkCache<T>> chunks;
public ComplexCache()
{
public ComplexCache() {
chunks = new KMap<>();
}
public boolean has(int x, int z)
{
public boolean has(int x, int z) {
return chunks.containsKey(Cache.key(x, z));
}
public void invalidate(int x, int z)
{
public void invalidate(int x, int z) {
chunks.remove(Cache.key(x, z));
}
public ChunkCache<T> chunk(int x, int z)
{
public ChunkCache<T> chunk(int x, int z) {
return chunks.computeIfAbsent(Cache.key(x, z), (f) -> new ChunkCache<>());
}
}

View File

@@ -24,27 +24,25 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.math.RollingSequence;
public class KCache<K,V> implements MeteredCache {
public class KCache<K, V> implements MeteredCache {
private final long max;
private CacheLoader<K, V> loader;
private LoadingCache<K, V> cache;
private final LoadingCache<K, V> cache;
private final boolean fastDump;
private final RollingSequence msu = new RollingSequence(100);
public KCache(CacheLoader<K, V> loader, long max)
{
public KCache(CacheLoader<K, V> loader, long max) {
this(loader, max, false);
}
public KCache(CacheLoader<K, V> loader, long max, boolean fastDump)
{
public KCache(CacheLoader<K, V> loader, long max, boolean fastDump) {
this.max = max;
this.fastDump = fastDump;
this.loader = loader;
this.cache = create(loader);
}
private LoadingCache<K,V> create(CacheLoader<K,V> loader) {
private LoadingCache<K, V> create(CacheLoader<K, V> loader) {
return Caffeine
.newBuilder()
.maximumSize(max)
@@ -54,23 +52,19 @@ public class KCache<K,V> implements MeteredCache {
}
public void setLoader(CacheLoader<K, V> loader)
{
public void setLoader(CacheLoader<K, V> loader) {
this.loader = loader;
}
public void invalidate(K k)
{
public void invalidate(K k) {
cache.invalidate(k);
}
public void invalidate()
{
public void invalidate() {
cache.invalidateAll();
}
public V get(K k)
{
public V get(K k) {
return cache.get(k);
}

View File

@@ -59,32 +59,26 @@ public class BitStorage {
this(bits, length, (AtomicLongArray) null);
}
private static AtomicLongArray atomic(long[] data)
{
if(data == null)
{
private static AtomicLongArray atomic(long[] data) {
if (data == null) {
return null;
}
AtomicLongArray d = new AtomicLongArray(data.length);
for(int i = 0; i < data.length; i++)
{
for (int i = 0; i < data.length; i++) {
d.set(i, data[i]);
}
return d;
}
private static long[] atomic(AtomicLongArray data)
{
if(data == null)
{
private static long[] atomic(AtomicLongArray data) {
if (data == null) {
return null;
}
long[] d = new long[data.length()];
for(int i = 0; i < data.length(); i++)
{
for (int i = 0; i < data.length(); i++) {
d[i] = data.get(i);
}
@@ -107,8 +101,7 @@ public class BitStorage {
this.divideShift = MAGIC[var3 + 2];
int var4 = (length + this.valuesPerLong - 1) / this.valuesPerLong;
if (data != null) {
if (data.length() != var4)
{
if (data.length() != var4) {
throw new RuntimeException("NO!");
}
this.data = data;
@@ -166,8 +159,7 @@ public class BitStorage {
public void getAll(IntConsumer var0) {
int var1 = 0;
for(int i = 0; i < data.length(); i++)
{
for (int i = 0; i < data.length(); i++) {
long var5 = data.get(i);
for (int var7 = 0; var7 < this.valuesPerLong; var7++) {
var0.accept((int) (var5 & this.mask));

View File

@@ -20,7 +20,6 @@ package com.volmit.iris.util.data.palette;
import com.google.common.collect.Iterators;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicIntegerArray;
@@ -49,16 +48,14 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
public K byId(int var0) {
if (var0 < 0 || var0 >= this.byId.length())
{
if (var0 < 0 || var0 >= this.byId.length()) {
return null;
}
return this.byId.get(var0);
}
private int getValue(int var0) {
if (var0 == -1)
{
if (var0 == -1) {
return -1;
}
return this.values.get(var0);
@@ -79,8 +76,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
}
private int nextId() {
while (nextId < byId.length() && byId.get(nextId) != null)
{
while (nextId < byId.length() && byId.get(nextId) != null) {
nextId++;
}
return nextId;
@@ -95,8 +91,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
this.nextId = 0;
this.size = 0;
for (int var3 = 0; var3 < var1.length(); var3++) {
if (var1.get(var3) != null)
{
if (var1.get(var3) != null) {
addMapping(var1.get(var3), var2.get(var3));
}
}
@@ -126,8 +121,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
private int indexOf(K var0, int var1) {
int var2;
for (var2 = var1; var2 < this.keys.length(); var2++) {
if (this.keys.get(var2) == null)
{
if (this.keys.get(var2) == null) {
return 0;
}
if (this.keys.get(var2).equals(var0))
@@ -158,11 +152,12 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
}
public Iterator<K> iterator() {
return Iterators.filter(new Iterator<K>(){
return Iterators.filter(new Iterator<K>() {
int i = 0;
@Override
public boolean hasNext() {
return i < byId.length()-1;
return i < byId.length() - 1;
}
@Override
@@ -174,15 +169,12 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
public void clear() {
for(int i = 0; i < Math.max(keys.length(), byId.length()); i++)
{
if(i < keys.length() - 1)
{
for (int i = 0; i < Math.max(keys.length(), byId.length()); i++) {
if (i < keys.length() - 1) {
keys.set(i, null);
}
if(i < byId.length() - 1)
{
if (i < byId.length() - 1) {
byId.set(i, null);
}
}

View File

@@ -18,8 +18,6 @@
package com.volmit.iris.util.data.palette;
import com.volmit.iris.util.nbt.tag.ListTag;
import java.util.List;
import java.util.function.Predicate;
@@ -28,11 +26,9 @@ public class GlobalPalette<T> implements Palette<T> {
private final T defaultValue;
public GlobalPalette(T... f)
{
public GlobalPalette(T... f) {
IdMapper<T> mapper = new IdMapper<>();
for(T i : f)
{
for (T i : f) {
mapper.add(i);
}
registry = mapper;

View File

@@ -20,12 +20,8 @@ package com.volmit.iris.util.data.palette;
import com.volmit.iris.Iris;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.nbt.tag.ListTag;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
public class HashMapPalette<T> implements Palette<T> {
private final KMap<T, Integer> values;
@@ -41,16 +37,14 @@ public class HashMapPalette<T> implements Palette<T> {
}
public int idFor(T var0) {
if(var0 == null)
{
if (var0 == null) {
return 0;
}
return this.values.computeIfAbsent(var0, (k) -> {
int newId = id++;
if (newId >= 1 << this.bits)
{
if (newId >= 1 << this.bits) {
Iris.info(newId + " to...");
newId = this.resizeHandler.onResize(this.bits + 1, var0);
Iris.info(newId + "..");

View File

@@ -49,8 +49,7 @@ public class IdMapper<T> implements IdMap<T> {
public void addMapping(T var0, int var1) {
this.tToId.put(var0, Integer.valueOf(var1));
while (this.idToT.size() <= var1)
{
while (this.idToT.size() <= var1) {
this.idToT.add(null);
}
this.idToT.set(var1, var0);
@@ -68,8 +67,7 @@ public class IdMapper<T> implements IdMap<T> {
}
public final T byId(int var0) {
if (var0 >= 0 && var0 < this.idToT.size())
{
if (var0 >= 0 && var0 < this.idToT.size()) {
return this.idToT.get(var0);
}
return null;

View File

@@ -20,7 +20,6 @@ package com.volmit.iris.util.data.palette;
import java.util.List;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.Predicate;
public class LinearPalette<T> implements Palette<T> {
private final AtomicReferenceArray<T> values;
@@ -37,13 +36,11 @@ public class LinearPalette<T> implements Palette<T> {
public int idFor(T var0) {
int var1;
for (var1 = 0; var1 < size; var1++) {
if(values.get(var1) == null && var0 == null)
{
if (values.get(var1) == null && var0 == null) {
return var1;
}
if (values.get(var1) != null && values.get(var1).equals(var0))
{
if (values.get(var1) != null && values.get(var1).equals(var0)) {
return var1;
}
}
@@ -57,8 +54,7 @@ public class LinearPalette<T> implements Palette<T> {
}
public T valueFor(int var0) {
if (var0 >= 0 && var0 < size)
{
if (var0 >= 0 && var0 < size) {
return this.values.get(var0);
}
return null;
@@ -70,8 +66,7 @@ public class LinearPalette<T> implements Palette<T> {
@Override
public void read(List<T> fromList) {
for (int i = 0; i < fromList.size(); i++)
{
for (int i = 0; i < fromList.size(); i++) {
values.set(i, fromList.get(i));
}
@@ -80,8 +75,7 @@ public class LinearPalette<T> implements Palette<T> {
@Override
public void write(List<T> toList) {
for (int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++) {
T v = values.get(i);
toList.add(v);
}

View File

@@ -18,11 +18,7 @@
package com.volmit.iris.util.data.palette;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.nbt.tag.ListTag;
import java.util.List;
import java.util.function.Predicate;
public interface Palette<T> {
int idFor(T paramT);

View File

@@ -42,8 +42,7 @@ public interface PaletteType<T> {
int v = Varint.readUnsignedVarInt(din);
List<T> t = new ArrayList<>();
for(int i = 0; i < v; i++)
{
for (int i = 0; i < v; i++) {
t.add(readPaletteNode(din));
}

View File

@@ -21,8 +21,8 @@ package com.volmit.iris.util.data.palette;
import com.volmit.iris.Iris;
import com.volmit.iris.util.math.M;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import java.util.List;
import java.util.function.Predicate;
@SuppressWarnings("DuplicatedCode")
public class PalettedContainer<T> implements PaletteResize<T> {
@@ -43,8 +43,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
}
private void setBits(int var0) {
if (var0 == this.bits)
{
if (var0 == this.bits) {
return;
}
this.bits = var0;
@@ -65,8 +64,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
setBits(var0);
for (int var4 = 0; var4 < var2.getSize(); var4++) {
T var5 = var3.valueFor(var2.get(var4));
if (var5 != null)
{
if (var5 != null) {
set(var4, var5);
}
}
@@ -95,8 +93,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
private void set(int var0, T var1) {
int var2 = this.palette.idFor(var1);
if(M.r(0.003))
{
if (M.r(0.003)) {
Iris.info("ID for " + var1 + " is " + var2 + " Palette: " + palette.getSize());
}
@@ -113,8 +110,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
public void read(List<T> palette, long[] data) {
int var2 = Math.max(4, Mth.ceillog2(palette.size()));
if (var2 != this.bits)
{
if (var2 != this.bits) {
setBits(var2);
}
@@ -124,8 +120,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
System.arraycopy(data, 0, this.storage.getRaw(), 0, data.length);
} else {
BitStorage var4 = new BitStorage(var3, 4096, data);
for (int var5 = 0; var5 < 4096; var5++)
{
for (int var5 = 0; var5 < 4096; var5++) {
this.storage.set(var5, var4.get(var5));
}
}

View File

@@ -34,7 +34,6 @@ import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.plugin.CommandDummy;
import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.ChronoLatch;

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.format;
import com.volmit.iris.Iris;
import com.volmit.iris.util.math.RollingSequence;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.Looper;
@@ -30,14 +29,14 @@ public class MemoryMonitor {
private long garbageLast;
private long garbageBin;
private long pressure;
private ChronoLatch cl;
private RollingSequence pressureAvg;
private Runtime runtime;
private final ChronoLatch cl;
private final RollingSequence pressureAvg;
private final Runtime runtime;
public MemoryMonitor(int sampleDelay){
public MemoryMonitor(int sampleDelay) {
this.runtime = Runtime.getRuntime();
usedMemory = -1;
pressureAvg = new RollingSequence(Math.max(Math.min(100, 1000/sampleDelay), 3));
pressureAvg = new RollingSequence(Math.max(Math.min(100, 1000 / sampleDelay), 3));
garbageBin = 0;
garbageMemory = -1;
cl = new ChronoLatch(1000);
@@ -56,74 +55,55 @@ public class MemoryMonitor {
looper.start();
}
public long getGarbageBytes()
{
public long getGarbageBytes() {
return garbageMemory;
}
public long getUsedBytes()
{
public long getUsedBytes() {
return usedMemory;
}
public long getMaxBytes()
{
public long getMaxBytes() {
return runtime.maxMemory();
}
public long getPressure()
{
public long getPressure() {
return (long) pressureAvg.getAverage();
}
public double getUsagePercent()
{
return usedMemory / (double)getMaxBytes();
public double getUsagePercent() {
return usedMemory / (double) getMaxBytes();
}
private void sample() {
long used = getVMUse();
if(usedMemory == -1)
{
if (usedMemory == -1) {
usedMemory = used;
garbageMemory = 0;
return;
}
if(used < usedMemory)
{
if (used < usedMemory) {
usedMemory = used;
}
else
{
} else {
garbageMemory = used - usedMemory;
}
long g = garbageMemory - garbageLast;
if(g >= 0)
{
garbageBin+= g;
if (g >= 0) {
garbageBin += g;
garbageLast = garbageMemory;
}
else
{
} else {
garbageMemory = 0;
garbageLast = 0;
}
if(cl.flip())
{
if(garbageMemory > 0)
{
if (cl.flip()) {
if (garbageMemory > 0) {
pressure = garbageBin;
garbageBin = 0;
}
else
{
} else {
pressure = 0;
garbageBin = 0;
}
@@ -136,10 +116,8 @@ public class MemoryMonitor {
return runtime.totalMemory() - runtime.freeMemory();
}
public void close()
{
if(looper != null)
{
public void close() {
if (looper != null) {
looper.interrupt();
looper = null;
}

View File

@@ -18,8 +18,6 @@
package com.volmit.iris.util.hunk.bits;
import com.volmit.iris.Iris;
import com.volmit.iris.util.data.Varint;
import org.apache.commons.lang3.Validate;
import java.io.DataInputStream;
@@ -65,8 +63,7 @@ public class DataBits {
this(bits, length, (AtomicLongArray) null);
}
public DataBits(int bits, int length, DataInputStream din) throws IOException
{
public DataBits(int bits, int length, DataInputStream din) throws IOException {
this(bits, length, longs(din));
}
@@ -83,8 +80,7 @@ public class DataBits {
int var4 = (length + valuesPerLong - 1) / valuesPerLong;
if (data != null) {
if (data.length() != var4)
{
if (data.length() != var4) {
throw new RuntimeException("NO! Trying to load " + data.length() + " into actual size of " + var4 + " because length: " + length + " (bits: " + bits + ")");
}
this.data = data;
@@ -93,36 +89,30 @@ public class DataBits {
}
}
public String toString()
{
public String toString() {
return "DBits: " + size + "/" + bits + "[" + data.length() + "]";
}
private static int dataLength(int bits, int length)
{
private static int dataLength(int bits, int length) {
return (length + ((char) (64 / bits)) - 1) / ((char) (64 / bits));
}
private static AtomicLongArray longs(DataInputStream din) throws IOException{
private static AtomicLongArray longs(DataInputStream din) throws IOException {
AtomicLongArray a = new AtomicLongArray(din.readInt());
for(int i = 0; i < a.length(); i++)
{
for (int i = 0; i < a.length(); i++) {
a.set(i, din.readLong());
}
return a;
}
public DataBits setBits(int newBits)
{
if(bits != newBits)
{
public DataBits setBits(int newBits) {
if (bits != newBits) {
DataBits newData = new DataBits(newBits, size);
AtomicInteger c = new AtomicInteger(0);
for(int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++) {
newData.set(i, get(i));
}
@@ -183,14 +173,12 @@ public class DataBits {
public void getAll(IntConsumer var0) {
int var1 = 0;
for(int i = 0; i < data.length(); i++)
{
for (int i = 0; i < data.length(); i++) {
long var5 = data.get(i);
for (int var7 = 0; var7 < valuesPerLong; var7++) {
var0.accept((int) (var5 & mask));
var5 >>= bits;
if (++var1 >= size)
{
if (++var1 >= size) {
return;
}
}
@@ -200,8 +188,7 @@ public class DataBits {
public void write(DataOutputStream dos) throws IOException {
dos.writeInt(data.length());
for(int i = 0; i < data.length(); i++)
{
for (int i = 0; i < data.length(); i++) {
dos.writeLong(data.get(i));
}
}

View File

@@ -18,9 +18,6 @@
package com.volmit.iris.util.hunk.bits;
import com.volmit.iris.Iris;
import com.volmit.iris.util.data.Varint;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -40,8 +37,7 @@ public class DataContainer<T> {
private final int length;
private final Writable<T> writer;
public DataContainer(Writable<T> writer, int length, T empty)
{
public DataContainer(Writable<T> writer, int length, T empty) {
this.writer = writer;
this.length = length;
this.bits = new AtomicInteger(INITIAL_BITS);
@@ -58,25 +54,22 @@ public class DataContainer<T> {
this.bits = new AtomicInteger(palette.get().bits());
}
public String toString(){
return "DataContainer <" + length + " x " + bits + " bits> -> Palette<"+palette.get().getClass().getSimpleName().replaceAll("\\QPalette\\E", "")+">: " + palette.get().size() +
public String toString() {
return "DataContainer <" + length + " x " + bits + " bits> -> Palette<" + palette.get().getClass().getSimpleName().replaceAll("\\QPalette\\E", "") + ">: " + palette.get().size() +
" " + data.get().toString() + " PalBit: " + palette.get().bits();
}
public byte[] write() throws IOException
{
public byte[] write() throws IOException {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
write(boas);
return boas.toByteArray();
}
public void write(OutputStream out) throws IOException
{
public void write(OutputStream out) throws IOException {
writeDos(new DataOutputStream(out));
}
public void writeDos(DataOutputStream dos) throws IOException
{
public void writeDos(DataOutputStream dos) throws IOException {
dos.writeInt(length);
dos.writeInt(palette.get().size());
palette.get().iterateIO((data, __) -> writer.writeNodeData(dos, data));
@@ -91,38 +84,30 @@ public class DataContainer<T> {
return d;
}
private Palette<T> newPalette(int bits)
{
if(bits <= LINEAR_BITS_LIMIT)
{
private Palette<T> newPalette(int bits) {
if (bits <= LINEAR_BITS_LIMIT) {
return new LinearPalette<>(LINEAR_INITIAL_LENGTH);
}
return new HashPalette<>();
}
private void checkBits()
{
if(palette.get().size() >= BIT[bits.get()])
{
private void checkBits() {
if (palette.get().size() >= BIT[bits.get()]) {
setBits(bits.get() + 1);
}
}
public void ensurePaletted(T t)
{
if(palette.get().id(t) == -1)
{
public void ensurePaletted(T t) {
if (palette.get().id(t) == -1) {
checkBits();
}
}
public void set(int position, T t)
{
public void set(int position, T t) {
int id = palette.get().id(t);
if(id == -1)
{
if (id == -1) {
checkBits();
id = palette.get().add(t);
}
@@ -130,24 +115,19 @@ public class DataContainer<T> {
data.get().set(position, id);
}
public T get(int position)
{
int id = data.get().get(position)+1;
public T get(int position) {
int id = data.get().get(position) + 1;
if(id <= 0)
{
if (id <= 0) {
return null;
}
return palette.get().get(id-1);
return palette.get().get(id - 1);
}
public void setBits(int bits)
{
if(this.bits.get() != bits)
{
if(this.bits.get() <= LINEAR_BITS_LIMIT != bits <= LINEAR_BITS_LIMIT)
{
public void setBits(int bits) {
if (this.bits.get() != bits) {
if (this.bits.get() <= LINEAR_BITS_LIMIT != bits <= LINEAR_BITS_LIMIT) {
palette.set(newPalette(bits).from(palette.get()));
}
@@ -159,25 +139,20 @@ public class DataContainer<T> {
private static int[] computeBitLimits() {
int[] m = new int[16];
for(int i = 0; i < m.length; i++)
{
for (int i = 0; i < m.length; i++) {
m[i] = (int) Math.pow(2, i);
}
return m;
}
protected static int bits(int size)
{
if(DataContainer.BIT[INITIAL_BITS] >= size)
{
protected static int bits(int size) {
if (DataContainer.BIT[INITIAL_BITS] >= size) {
return INITIAL_BITS;
}
for(int i = 0; i < DataContainer.BIT.length; i++)
{
if(DataContainer.BIT[i] >= size)
{
for (int i = 0; i < DataContainer.BIT.length; i++) {
if (DataContainer.BIT[i] >= size) {
return i;
}
}

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.hunk.bits;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.function.Consumer2;
@@ -30,8 +29,7 @@ public class HashPalette<T> implements Palette<T> {
private final KMap<Integer, T> lookup;
private final AtomicInteger size;
public HashPalette()
{
public HashPalette() {
this.size = new AtomicInteger(0);
this.palette = new LinkedHashMap<>();
this.lookup = new KMap<>();
@@ -39,8 +37,7 @@ public class HashPalette<T> implements Palette<T> {
@Override
public T get(int id) {
if(id < 0 || id >= size.get())
{
if (id < 0 || id >= size.get()) {
return null;
}
@@ -52,8 +49,7 @@ public class HashPalette<T> implements Palette<T> {
int index = size.getAndIncrement();
palette.put(t, index);
if(t != null)
{
if (t != null) {
lookup.put(index, t);
}
@@ -73,8 +69,7 @@ public class HashPalette<T> implements Palette<T> {
@Override
public void iterate(Consumer2<T, Integer> c) {
for(T i : palette.keySet())
{
for (T i : palette.keySet()) {
c.accept(i, id(i));
}
}

View File

@@ -28,16 +28,14 @@ public class LinearPalette<T> implements Palette<T> {
private final AtomicReference<AtomicReferenceArray<T>> palette;
private final AtomicInteger size;
public LinearPalette(int initialSize)
{
public LinearPalette(int initialSize) {
this.size = new AtomicInteger(0);
this.palette = new AtomicReference<>(new AtomicReferenceArray<>(initialSize));
}
@Override
public T get(int id) {
if(id < 0 || id >= size.get())
{
if (id < 0 || id >= size.get()) {
return null;
}
@@ -53,12 +51,10 @@ public class LinearPalette<T> implements Palette<T> {
}
private void grow(int newLength) {
if(newLength > palette.get().length())
{
if (newLength > palette.get().length()) {
AtomicReferenceArray<T> a = new AtomicReferenceArray<>(newLength + size.get());
for(int i = 0; i < palette.get().length(); i++)
{
for (int i = 0; i < palette.get().length(); i++) {
a.set(i, palette.get().get(i));
}
@@ -68,15 +64,12 @@ public class LinearPalette<T> implements Palette<T> {
@Override
public int id(T t) {
for(int i = 0; i < size(); i++)
{
if(t == null && palette.get().get(i) == null)
{
for (int i = 0; i < size(); i++) {
if (t == null && palette.get().get(i) == null) {
return i;
}
if(t != null && t.equals(palette.get().get(i)))
{
if (t != null && t.equals(palette.get().get(i))) {
return i;
}
}
@@ -91,8 +84,7 @@ public class LinearPalette<T> implements Palette<T> {
@Override
public void iterate(Consumer2<T, Integer> c) {
for(int i = 0; i < size(); i++)
{
for (int i = 0; i < size(); i++) {
c.accept(palette.get().get(i), i);
}
}

View File

@@ -34,18 +34,16 @@ public interface Palette<T> {
int size();
default int bits()
{
default int bits() {
return DataContainer.bits(size());
}
void iterate(Consumer2<T, Integer> c);
default void iterateIO(Consumer2IO<T, Integer> c)
{
iterate((a,b)-> {
default void iterateIO(Consumer2IO<T, Integer> c) {
iterate((a, b) -> {
try {
c.accept(a,b);
c.accept(a, b);
} catch (IOException e) {
e.printStackTrace();
}
@@ -53,22 +51,19 @@ public interface Palette<T> {
}
default Palette<T> from(int size, Writable<T> writable, DataInputStream in) throws IOException {
for(int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++) {
add(writable.readNodeData(in));
}
return this;
}
default Palette<T> from(Palette<T> oldPalette)
{
oldPalette.iterate((k,v) -> add(k));
default Palette<T> from(Palette<T> oldPalette) {
oldPalette.iterate((k, v) -> add(k));
return this;
}
default KList<T> list()
{
default KList<T> list() {
KList<T> t = new KList<>();
iterate((tx, __) -> t.add(tx));
return t;

View File

@@ -27,7 +27,6 @@ import lombok.EqualsAndHashCode;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
@Data

View File

@@ -18,8 +18,6 @@
package com.volmit.iris.util.hunk.storage;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.data.palette.PalettedContainer;
import com.volmit.iris.util.function.Consumer4;
import com.volmit.iris.util.function.Consumer4IO;
import com.volmit.iris.util.hunk.Hunk;
@@ -29,7 +27,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.IOException;
import java.util.Map;
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
@Data
@@ -38,7 +35,7 @@ public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
private DataContainer<T> data;
public PaletteHunk(int w, int h, int d, Writable<T> writer, T e) {
super(w,h,d);
super(w, h, d);
data = new DataContainer<>(writer, w * h * d, e);
}
@@ -57,16 +54,12 @@ public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
@Override
public synchronized Hunk<T> iterateSync(Consumer4<Integer, Integer, Integer, T> c) {
for(int i = 0; i < getWidth(); i++)
{
for(int j = 0; j < getHeight(); j++)
{
for(int k = 0; k < getDepth(); k++)
{
T t = getRaw(i,j,k);
if(t != null)
{
c.accept(i,j,k,t);
for (int i = 0; i < getWidth(); i++) {
for (int j = 0; j < getHeight(); j++) {
for (int k = 0; k < getDepth(); k++) {
T t = getRaw(i, j, k);
if (t != null) {
c.accept(i, j, k, t);
}
}
}
@@ -76,16 +69,12 @@ public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
@Override
public synchronized Hunk<T> iterateSyncIO(Consumer4IO<Integer, Integer, Integer, T> c) throws IOException {
for(int i = 0; i < getWidth(); i++)
{
for(int j = 0; j < getHeight(); j++)
{
for(int k = 0; k < getDepth(); k++)
{
T t = getRaw(i,j,k);
if(t != null)
{
c.accept(i,j,k,t);
for (int i = 0; i < getWidth(); i++) {
for (int j = 0; j < getHeight(); j++) {
for (int k = 0; k < getDepth(); k++) {
T t = getRaw(i, j, k);
if (t != null) {
c.accept(i, j, k, t);
}
}
}

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.hunk.storage;
import com.volmit.iris.util.data.palette.PalettedContainer;
import com.volmit.iris.util.function.Consumer4;
import com.volmit.iris.util.function.Consumer4IO;
import com.volmit.iris.util.hunk.Hunk;
@@ -26,41 +25,38 @@ import com.volmit.iris.util.hunk.bits.DataContainer;
import com.volmit.iris.util.hunk.bits.Writable;
import java.io.IOException;
import java.util.Map;
import java.util.function.Supplier;
public abstract class PaletteOrHunk<T> extends StorageHunk<T> implements Hunk<T>, Writable<T> {
private final Hunk<T> hunk;
public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory, T e) {
super(width, height, depth);
hunk = (allow) ? new PaletteHunk<>(width, height, depth, this, e) : factory.get();
}
public DataContainer<T> palette()
{
return isPalette() ? ((PaletteHunk<T>)hunk).getData() : null;
public DataContainer<T> palette() {
return isPalette() ? ((PaletteHunk<T>) hunk).getData() : null;
}
public void setPalette(DataContainer<T> c) {
if(isPalette())
{
((PaletteHunk<T>)hunk).setPalette(c);
if (isPalette()) {
((PaletteHunk<T>) hunk).setPalette(c);
}
}
public boolean isPalette()
{
public boolean isPalette() {
return hunk instanceof PaletteHunk;
}
@Override
public void setRaw(int x, int y, int z, T t) {
hunk.setRaw(x,y,z,t);
hunk.setRaw(x, y, z, t);
}
@Override
public T getRaw(int x, int y, int z) {
return hunk.getRaw(x,y,z);
return hunk.getRaw(x, y, z);
}
public int getEntryCount() {

View File

@@ -25,7 +25,6 @@ import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.CharArrayWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -166,16 +165,15 @@ public class IO {
public static String longsToHex(long[] bytes) {
byte[] v = new byte[bytes.length * 8];
for(int i = 0; i < bytes.length; i++)
{
v[i * 8] = (byte)(bytes[i] >>> 56);
v[(i * 8) + 1] = (byte)(bytes[i] >>> 48);
v[(i * 8) + 2] = (byte)(bytes[i] >>> 40);
v[(i * 8) + 3] = (byte)(bytes[i] >>> 32);
v[(i * 8) + 4] = (byte)(bytes[i] >>> 24);
v[(i * 8) + 5] = (byte)(bytes[i] >>> 16);
v[(i * 8) + 6] = (byte)(bytes[i] >>> 8);
v[(i * 8) + 7] = (byte)(bytes[i] >>> 0);
for (int i = 0; i < bytes.length; i++) {
v[i * 8] = (byte) (bytes[i] >>> 56);
v[(i * 8) + 1] = (byte) (bytes[i] >>> 48);
v[(i * 8) + 2] = (byte) (bytes[i] >>> 40);
v[(i * 8) + 3] = (byte) (bytes[i] >>> 32);
v[(i * 8) + 4] = (byte) (bytes[i] >>> 24);
v[(i * 8) + 5] = (byte) (bytes[i] >>> 16);
v[(i * 8) + 6] = (byte) (bytes[i] >>> 8);
v[(i * 8) + 7] = (byte) (bytes[i] >>> 0);
}
return bytesToHex(v);

View File

@@ -38,7 +38,6 @@ import com.volmit.iris.util.matter.MatterSlice;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.HyperLock;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.J;
import lombok.Getter;
import org.bukkit.Chunk;

View File

@@ -20,12 +20,9 @@ package com.volmit.iris.util.mantle;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.matter.Matter;
import com.volmit.iris.util.nbt.mca.Section;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import lombok.Getter;

View File

@@ -18,13 +18,10 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.data.palette.PaletteType;
import com.volmit.iris.util.data.palette.PalettedContainer;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.hunk.bits.DataContainer;
import com.volmit.iris.util.hunk.bits.Writable;
@@ -38,8 +35,6 @@ import org.bukkit.util.BlockVector;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
Class<T> getType();
@@ -164,11 +159,10 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
default void write(DataOutputStream dos) throws IOException {
dos.writeUTF(getType().getCanonicalName());
if((this instanceof PaletteOrHunk f && f.isPalette()))
{
f.palette().writeDos(dos);
return;
}
if ((this instanceof PaletteOrHunk f && f.isPalette())) {
f.palette().writeDos(dos);
return;
}
int w = getWidth();
int h = getHeight();
@@ -189,8 +183,7 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
}
default void read(DataInputStream din) throws IOException {
if((this instanceof PaletteOrHunk f && f.isPalette()))
{
if ((this instanceof PaletteOrHunk f && f.isPalette())) {
f.setPalette(new DataContainer<>(din, this));
return;
}

View File

@@ -18,21 +18,8 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.Iris;
import com.volmit.iris.util.hunk.bits.DataContainer;
import com.volmit.iris.util.hunk.bits.Writable;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.math.RNG;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
public class MatterTest {
public static void test()
{
public static void test() {
}
}

View File

@@ -24,7 +24,6 @@ import com.volmit.iris.util.matter.Sliced;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@@ -20,7 +20,6 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@@ -21,7 +21,6 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.MatterCavern;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@@ -33,7 +33,6 @@ import com.volmit.iris.util.nbt.tag.CompoundTag;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.BoundingBox;
import java.io.DataInputStream;

View File

@@ -21,7 +21,6 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@@ -21,7 +21,6 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@@ -22,7 +22,6 @@ import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.MatterMarker;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@@ -20,10 +20,7 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.nbt.tag.IntTag;
import com.volmit.iris.util.nbt.tag.Tag;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@@ -19,7 +19,6 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.hunk.bits.Writable;
import com.volmit.iris.util.hunk.storage.MappedHunk;
import com.volmit.iris.util.hunk.storage.PaletteOrHunk;
import com.volmit.iris.util.matter.MatterReader;

View File

@@ -21,7 +21,6 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.core.loader.IrisRegistrant;
import com.volmit.iris.util.context.IrisContext;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.MatterTile;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@@ -20,7 +20,6 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.palette.GlobalPalette;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.MatterTile;
import com.volmit.iris.util.matter.MatterUpdate;
import com.volmit.iris.util.matter.Sliced;

View File

@@ -255,8 +255,7 @@ public class Chunk {
public CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) {
int s = MCAUtil.blockToChunk(blockY);
if(sections.length() <= s)
{
if (sections.length() <= s) {
return null;
}
@@ -282,8 +281,7 @@ public class Chunk {
public void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) {
int sectionIndex = MCAUtil.blockToChunk(blockY);
if(sections.length() <= sectionIndex)
{
if (sections.length() <= sectionIndex) {
return;
}

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.nbt.mca;
import com.volmit.iris.core.pregenerator.syndicate.SyndicateServer;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.Position2;
import com.volmit.iris.util.nbt.tag.CompoundTag;

View File

@@ -79,8 +79,7 @@ public class MCALinearPalette<T> implements MCAPalette<T> {
}
public void read(ListTag var0) {
for (int var1 = 0; var1 < var0.size(); var1++)
{
for (int var1 = 0; var1 < var0.size(); var1++) {
this.values[var1] = this.reader.apply((CompoundTag) var0.get(var1));
}
this.size = var0.size();

View File

@@ -156,17 +156,12 @@ public class MultiBurst {
try {
while (!service.awaitTermination(1, TimeUnit.SECONDS)) {
Iris.info("Still waiting to shutdown burster...");
if(p.getMilliseconds() > 7000)
{
if (p.getMilliseconds() > 7000) {
Iris.warn("Forcing Shutdown...");
try
{
try {
service.shutdownNow();
}
catch(Throwable e)
{
} catch (Throwable e) {
}

View File

@@ -72,8 +72,7 @@ public interface Job {
}, sender.isPlayer() ? 0 : 20);
f.whenComplete((fs, ff) -> {
J.car(c);
if(!silentMsg)
{
if (!silentMsg) {
sender.sendMessage(C.AQUA + "Completed " + getName() + " in " + Form.duration(p.getMilliseconds(), 1));
}
whenComplete.run();

View File

@@ -24,7 +24,6 @@ import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IRare;
import com.volmit.iris.engine.object.IrisStyledRange;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.data.ComplexCache;
import com.volmit.iris.util.function.Function2;
import com.volmit.iris.util.function.Function3;
import com.volmit.iris.util.function.Function4;

View File

@@ -18,16 +18,11 @@
package com.volmit.iris.util.stream.utility;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.service.PreservationSVC;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.data.ComplexCache;
import com.volmit.iris.util.data.KCache;
import com.volmit.iris.util.stream.BasicStream;
import com.volmit.iris.util.stream.ProceduralStream;
@@ -57,7 +52,7 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
@Override
public T get(double x, double z) {
return cache.get(Cache.key((int)x, (int)z));
return cache.get(Cache.key((int) x, (int) z));
}
@Override