mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Data bits
This commit is contained in:
parent
c7a8cb566b
commit
f2a5489363
@ -19,6 +19,7 @@
|
|||||||
package com.volmit.iris.util.hunk.bits;
|
package com.volmit.iris.util.hunk.bits;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.util.data.Varint;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
@ -65,7 +66,7 @@ public class DataBits {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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));
|
this(bits, length, longs(din, dataLength(bits, length)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataBits(int bits, int length, AtomicLongArray data) {
|
public DataBits(int bits, int length, AtomicLongArray data) {
|
||||||
@ -98,11 +99,11 @@ public class DataBits {
|
|||||||
return (length + ((char) (64 / bits)) - 1) / ((char) (64 / bits));
|
return (length + ((char) (64 / bits)) - 1) / ((char) (64 / bits));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AtomicLongArray longs(DataInputStream din) throws IOException {
|
private static AtomicLongArray longs(DataInputStream din, int longSize) throws IOException {
|
||||||
AtomicLongArray a = new AtomicLongArray(din.readInt());
|
AtomicLongArray a = new AtomicLongArray(longSize);
|
||||||
|
|
||||||
for (int i = 0; i < a.length(); i++) {
|
for (int i = 0; i < a.length(); i++) {
|
||||||
a.set(i, din.readLong());
|
a.set(i, Varint.readUnsignedVarLong(din));
|
||||||
}
|
}
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
@ -187,10 +188,8 @@ public class DataBits {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutputStream dos) throws IOException {
|
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));
|
Varint.writeUnsignedVarLong(data.get(i), dos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package com.volmit.iris.util.hunk.bits;
|
package com.volmit.iris.util.hunk.bits;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.util.data.Varint;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
@ -27,7 +28,6 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
public class DataContainer<T> {
|
public class DataContainer<T> {
|
||||||
protected static final int INITIAL_BITS = 2;
|
protected static final int INITIAL_BITS = 2;
|
||||||
@ -50,7 +50,7 @@ public class DataContainer<T> {
|
|||||||
|
|
||||||
public DataContainer(DataInputStream din, Writable<T> writer) throws IOException {
|
public DataContainer(DataInputStream din, Writable<T> writer) throws IOException {
|
||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
this.length = din.readInt();
|
this.length = Varint.readUnsignedVarInt(din);
|
||||||
this.palette = new AtomicReference<>(newPalette(din));
|
this.palette = new AtomicReference<>(newPalette(din));
|
||||||
this.data = new AtomicReference<>(new DataBits(palette.get().bits(), length, din));
|
this.data = new AtomicReference<>(new DataBits(palette.get().bits(), length, din));
|
||||||
this.bits = new AtomicInteger(palette.get().bits());
|
this.bits = new AtomicInteger(palette.get().bits());
|
||||||
@ -82,15 +82,15 @@ public class DataContainer<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeDos(DataOutputStream dos) throws IOException {
|
public void writeDos(DataOutputStream dos) throws IOException {
|
||||||
dos.writeInt(length);
|
Varint.writeUnsignedVarInt(length, dos);
|
||||||
dos.writeInt(palette.get().size());
|
Varint.writeUnsignedVarInt(palette.get().size(), dos);
|
||||||
palette.get().iterateIO((data, __) -> writer.writeNodeData(dos, data));
|
palette.get().iterateIO((data, __) -> writer.writeNodeData(dos, data));
|
||||||
data.get().write(dos);
|
data.get().write(dos);
|
||||||
dos.flush();
|
dos.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Palette<T> newPalette(DataInputStream din) throws IOException {
|
private Palette<T> newPalette(DataInputStream din) throws IOException {
|
||||||
int paletteSize = din.readInt();
|
int paletteSize = Varint.readUnsignedVarInt(din);
|
||||||
Palette<T> d = newPalette(bits(paletteSize+1));
|
Palette<T> d = newPalette(bits(paletteSize+1));
|
||||||
d.from(paletteSize, writer, din);
|
d.from(paletteSize, writer, din);
|
||||||
return d;
|
return d;
|
||||||
@ -104,15 +104,9 @@ public class DataContainer<T> {
|
|||||||
return new HashPalette<>();
|
return new HashPalette<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkBits() {
|
|
||||||
if (palette.get().size() >= BIT[bits.get()]) {
|
|
||||||
setBits(bits.get() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ensurePaletted(T t) {
|
public void ensurePaletted(T t) {
|
||||||
if (palette.get().id(t) == -1) {
|
if (palette.get().id(t) == -1) {
|
||||||
checkBits();
|
expandOne();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +125,7 @@ public class DataContainer<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void expandOne() {
|
private void expandOne() {
|
||||||
if (palette.get().size()+1 >= BIT[bits.get()]) {
|
if (palette.get().size() + 1 >= BIT[bits.get()] - 1) {
|
||||||
setBits(bits.get() + 1);
|
setBits(bits.get() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
package com.volmit.iris.util.hunk.bits;
|
package com.volmit.iris.util.hunk.bits;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.util.function.Consumer2;
|
import com.volmit.iris.util.function.Consumer2;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
@ -70,7 +72,7 @@ public class LinearPalette<T> implements Palette<T> {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size(); i++) {
|
for (int i = 1; i < size() + 1; i++) {
|
||||||
if (t.equals(palette.get().get(i))) {
|
if (t.equals(palette.get().get(i))) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -18,36 +18,10 @@
|
|||||||
|
|
||||||
package com.volmit.iris.util.hunk.bits;
|
package com.volmit.iris.util.hunk.bits;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
|
||||||
import com.volmit.iris.util.io.IO;
|
|
||||||
import com.volmit.iris.util.mantle.Mantle;
|
|
||||||
import com.volmit.iris.util.math.RNG;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class TecTest {
|
public class TecTest {
|
||||||
public static void go()
|
public static void go()
|
||||||
{
|
{
|
||||||
Mantle m = new Mantle(new File("dummy"), 256);
|
|
||||||
|
|
||||||
int size = 255;
|
|
||||||
int mx = (int) Math.pow(size, 3);
|
|
||||||
|
|
||||||
for(int i = 0; i < mx; i++)
|
|
||||||
{
|
|
||||||
int[] p = Cache.to3D(i, size, size);
|
|
||||||
m.set(p[0], p[1], p[2], RNG.r.s(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
m.close();
|
|
||||||
|
|
||||||
m = new Mantle(new File("dummy"), 256);
|
|
||||||
m.get(0,0,0, String.class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public abstract class PaletteOrHunk<T> extends StorageHunk<T> implements Hunk<T>
|
|||||||
|
|
||||||
public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory) {
|
public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory) {
|
||||||
super(width, height, depth);
|
super(width, height, depth);
|
||||||
hunk = (allow) ? new PaletteHunk<>(width, height, depth, this) : factory.get();
|
hunk = (allow && (width * height * depth <= 4096)) ? new PaletteHunk<>(width, height, depth, this) : factory.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataContainer<T> palette() {
|
public DataContainer<T> palette() {
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package com.volmit.iris.util.io;
|
package com.volmit.iris.util.io;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.util.format.Form;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@ -162,6 +163,10 @@ public class IO {
|
|||||||
return new String(hexChars).toUpperCase();
|
return new String(hexChars).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String print(byte[] bytes) {
|
||||||
|
return Form.memSize(bytes.length, 2) + "[" + bytesToHex(bytes) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
public static String longsToHex(long[] bytes) {
|
public static String longsToHex(long[] bytes) {
|
||||||
byte[] v = new byte[bytes.length * 8];
|
byte[] v = new byte[bytes.length * 8];
|
||||||
|
|
||||||
|
@ -487,6 +487,7 @@ public class Mantle {
|
|||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Iris.error("Failed to read Tectonic Plate " + file.getAbsolutePath() + " creating a new chunk instead.");
|
Iris.error("Failed to read Tectonic Plate " + file.getAbsolutePath() + " creating a new chunk instead.");
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
|
e.printStackTrace();
|
||||||
region = new TectonicPlate(worldHeight, x, z);
|
region = new TectonicPlate(worldHeight, x, z);
|
||||||
loadedRegions.put(k, region);
|
loadedRegions.put(k, region);
|
||||||
Iris.debug("Created new Tectonic Plate (Due to Load Failure) " + C.DARK_GREEN + x + " " + z);
|
Iris.debug("Created new Tectonic Plate (Due to Load Failure) " + C.DARK_GREEN + x + " " + z);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package com.volmit.iris.util.matter;
|
package com.volmit.iris.util.matter;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
import com.volmit.iris.util.data.Varint;
|
import com.volmit.iris.util.data.Varint;
|
||||||
import com.volmit.iris.util.data.palette.Palette;
|
import com.volmit.iris.util.data.palette.Palette;
|
||||||
@ -184,7 +185,15 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
|
|||||||
|
|
||||||
default void read(DataInputStream din) throws IOException {
|
default void read(DataInputStream din) throws IOException {
|
||||||
if ((this instanceof PaletteOrHunk f && f.isPalette())) {
|
if ((this instanceof PaletteOrHunk f && f.isPalette())) {
|
||||||
|
try {
|
||||||
f.setPalette(new DataContainer<>(din, this));
|
f.setPalette(new DataContainer<>(din, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
Iris.error("Failed to read " + getType() + " Matter! ?? ");
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user