This commit is contained in:
Daniel Mills
2021-08-04 21:50:10 -04:00
parent ad324df937
commit baa3cfa636
176 changed files with 500 additions and 592 deletions

View File

@@ -20,15 +20,9 @@ package com.volmit.iris.util.matter;
import com.volmit.iris.Iris;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.io.JarScanner;
import com.volmit.iris.util.matter.slices.BlockMatter;
import com.volmit.iris.util.matter.slices.BooleanMatter;
import lombok.Getter;
import org.bukkit.block.data.BlockData;
import java.util.Map;
public class IrisMatter implements Matter{
public class IrisMatter implements Matter {
private static final KMap<Class<?>, MatterSlice<?>> slicers = buildSlicers();
@Getter
@@ -46,8 +40,7 @@ public class IrisMatter implements Matter{
@Getter
private KMap<Class<?>, MatterSlice<?>> sliceMap;
public IrisMatter(int width, int height, int depth)
{
public IrisMatter(int width, int height, int depth) {
this.width = width;
this.height = height;
this.depth = depth;
@@ -58,8 +51,7 @@ public class IrisMatter implements Matter{
public <T> MatterSlice<T> createSlice(Class<T> type, Matter m) {
MatterSlice<?> slice = slicers.get(type);
if(slice == null)
{
if (slice == null) {
return null;
}
@@ -68,8 +60,7 @@ public class IrisMatter implements Matter{
private static KMap<Class<?>, MatterSlice<?>> buildSlicers() {
KMap<Class<?>, MatterSlice<?>> c = new KMap<>();
for(Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class))
{
for (Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class)) {
MatterSlice<?> s = (MatterSlice<?>) i;
c.put(s.getType(), s);
}

View File

@@ -28,7 +28,7 @@ import java.util.function.Function;
/**
* When Red Matter isn't enough
*
* <p>
* UVI width
* UVI height
* UVI depth
@@ -36,135 +36,136 @@ import java.util.function.Function;
* UTF author
* UVL createdAt
* UVI version
* UTF sliceType (canonical class name)
* UVI nodeCount (for each slice)
* UVI position [(z * w * h) + (y * w) + x]
* ??? nodeData
*
* UTF sliceType (canonical class name)
* UVI nodeCount (for each slice)
* UVI position [(z * w * h) + (y * w) + x]
* ??? nodeData
*/
public interface Matter {
int VERSION = 1;
/**
* Get the header information
*
* @return the header info
*/
MatterHeader getHeader();
/**
* Get the width of this matter
*
* @return the width
*/
int getWidth();
/**
* Get the height of this matter
*
* @return the height
*/
int getHeight();
/**
* Get the depth of this matter
*
* @return the depth
*/
int getDepth();
/**
* Get the center of this matter
*
* @return the center
*/
default BlockPosition getCenter()
{
default BlockPosition getCenter() {
return new BlockPosition(getCenterX(), getCenterY(), getCenterZ());
}
/**
* Create a slice from the given type
* @param type the type class
*
* @param type the type class
* @param matter the matter this slice will go into (size provider)
* @param <T> the type
* @param <T> the type
* @return the slice (or null if not supported)
*/
<T> MatterSlice<T> createSlice(Class<T> type, Matter matter);
/**
* Get the size of this matter
*
* @return the size
*/
default BlockPosition getSize()
{
default BlockPosition getSize() {
return new BlockPosition(getWidth(), getHeight(), getDepth());
}
/**
* Get the center X of this matter
*
* @return the center X
*/
default int getCenterX()
{
default int getCenterX() {
return Math.round(getWidth() / 2);
}
/**
* Get the center Y of this matter
*
* @return the center Y
*/
default int getCenterY()
{
default int getCenterY() {
return Math.round(getHeight() / 2);
}
/**
* Get the center Z of this matter
*
* @return the center Z
*/
default int getCenterZ()
{
default int getCenterZ() {
return Math.round(getDepth() / 2);
}
/**
* Return the slice for the given type
* @param t the type class
*
* @param t the type class
* @param <T> the type
* @return the slice or null
*/
default <T> MatterSlice<T> getSlice(Class<T> t)
{
default <T> MatterSlice<T> getSlice(Class<T> t) {
return (MatterSlice<T>) getSliceMap().get(t);
}
/**
* Delete the slice for the given type
* @param c the type class
*
* @param c the type class
* @param <T> the type
* @return the deleted slice, or null if it diddn't exist
*/
default <T> MatterSlice<T> deleteSlice(Class<?> c)
{
default <T> MatterSlice<T> deleteSlice(Class<?> c) {
return (MatterSlice<T>) getSliceMap().remove(c);
}
/**
* Put a given slice type
* @param c the slice type class
*
* @param c the slice type class
* @param slice the slice to assign to the type
* @param <T> the slice type
* @param <T> the slice type
* @return the overwritten slice if there was an existing slice of that type
*/
default <T> MatterSlice<T> putSlice(Class<?> c, MatterSlice<T> slice)
{
default <T> MatterSlice<T> putSlice(Class<?> c, MatterSlice<T> slice) {
return (MatterSlice<T>) getSliceMap().put(c, slice);
}
default <T> MatterSlice<T> slice(Class<?> c)
{
if(!hasSlice(c))
{
default <T> MatterSlice<T> slice(Class<?> c) {
if (!hasSlice(c)) {
MatterSlice<?> s = createSlice(c, this);
if(s == null)
{
if (s == null) {
return null;
}
@@ -176,33 +177,33 @@ public interface Matter {
/**
* Check if a slice exists for a given type
*
* @param c the slice class type
* @return true if it exists
*/
default boolean hasSlice(Class<?> c)
{
default boolean hasSlice(Class<?> c) {
return getSlice(c) != null;
}
/**
* Remove all slices
*/
default void clearSlices()
{
default void clearSlices() {
getSliceMap().clear();
}
/**
* Get the set backing the slice map keys (slice types)
*
* @return the slice types
*/
default Set<Class<?>> getSliceTypes()
{
default Set<Class<?>> getSliceTypes() {
return getSliceMap().keySet();
}
/**
* Get all slices
*
* @return the real slice map
*/
Map<Class<?>, MatterSlice<?>> getSliceMap();
@@ -210,11 +211,11 @@ public interface Matter {
/**
* Writes the data to the output stream. The data will be flushed to the provided output
* stream however the provided stream will NOT BE CLOSED, so be sure to actually close it
*
* @param out the output stream
* @throws IOException shit happens yo
*/
default void write(OutputStream out) throws IOException
{
default void write(OutputStream out) throws IOException {
DataOutputStream dos = new DataOutputStream(out);
// Write size
Varint.writeUnsignedVarInt(getWidth(), dos);
@@ -223,8 +224,7 @@ public interface Matter {
dos.writeByte(getSliceTypes().size() + Byte.MIN_VALUE);
getHeader().write(dos);
for(Class<?> i : getSliceTypes())
{
for (Class<?> i : getSliceTypes()) {
getSlice(i).write(dos);
}
@@ -234,7 +234,8 @@ public interface Matter {
/**
* Reads the input stream into a matter object using a matter factory.
* Does not close the input stream. Be a man, close it yourself.
* @param in the input stream
*
* @param in the input stream
* @param matterFactory the matter factory (size) -> new MatterImpl(size);
* @return the matter object
* @throws IOException shit happens yo
@@ -249,8 +250,7 @@ public interface Matter {
int sliceCount = din.readByte() - Byte.MIN_VALUE;
matter.getHeader().read(din);
while(sliceCount-- > 0)
{
while (sliceCount-- > 0) {
Class<?> type = Class.forName(din.readUTF());
MatterSlice<?> slice = matter.createSlice(type, matter);
slice.read(din);

View File

@@ -32,15 +32,13 @@ public class MatterHeader {
private long createdAt = M.ms();
private int version = Matter.VERSION;
public void write(DataOutputStream out) throws IOException
{
public void write(DataOutputStream out) throws IOException {
out.writeUTF(author);
Varint.writeUnsignedVarLong(createdAt, out);
Varint.writeUnsignedVarInt(version, out);
}
public void read(DataInputStream din) throws IOException
{
public void read(DataInputStream din) throws IOException {
setAuthor(din.readUTF());
setCreatedAt(Varint.readUnsignedVarLong(din));
setVersion(Varint.readUnsignedVarInt(din));

View File

@@ -18,10 +18,10 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.hunk.storage.StorageHunk;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.function.Consumer4;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.hunk.storage.StorageHunk;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -38,8 +38,7 @@ public class MatterHunk<T> extends StorageHunk<T> implements Hunk<T> {
data = new KMap<>();
}
public int getCount()
{
public int getCount() {
return data.size();
}

View File

@@ -18,10 +18,8 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.data.DataPalette;
import com.volmit.iris.util.data.IOAdapter;
import com.volmit.iris.util.data.NibbleDataPalette;
import com.volmit.iris.util.data.Varint;
import java.io.DataInputStream;
@@ -32,8 +30,7 @@ public class MatterPalette<T> implements IOAdapter<T> {
private final MatterSlice<T> slice;
private final DataPalette<T> palette;
public MatterPalette(MatterSlice<T> slice)
{
public MatterPalette(MatterSlice<T> slice) {
this.slice = slice;
palette = new DataPalette<T>();
}

View File

@@ -19,38 +19,35 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.hunk.Hunk;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public interface MatterSlice<T> extends Hunk<T>
{
public interface MatterSlice<T> extends Hunk<T> {
Class<T> getType();
void writeNode(T b, DataOutputStream dos) throws IOException;
T readNode(DataInputStream din) throws IOException;
default void write(DataOutputStream dos) throws IOException
{
default void write(DataOutputStream dos) throws IOException {
int w = getWidth();
int h = getHeight();
dos.writeUTF(getType().getCanonicalName());
MatterPalette<T> palette = new MatterPalette<T>(this);
iterateSync((x,y,z,b) -> palette.assign(b));
iterateSync((x, y, z, b) -> palette.assign(b));
palette.writePalette(dos);
Varint.writeUnsignedVarInt(((MatterHunk<?>) this).getCount(), dos);
iterateSyncIO((x,y,z,b) -> {
iterateSyncIO((x, y, z, b) -> {
Varint.writeUnsignedVarInt((z * w * h) + (y * w) + x, dos);
palette.writeNode(b, dos);
});
}
default void read(DataInputStream din) throws IOException
{
default void read(DataInputStream din) throws IOException {
int w = getWidth();
int h = getHeight();
@@ -59,8 +56,7 @@ public interface MatterSlice<T> extends Hunk<T>
int nodes = Varint.readUnsignedVarInt(din);
int[] pos;
while(nodes-- > 0)
{
while (nodes-- > 0) {
pos = Cache.to3D(Varint.readUnsignedVarInt(din), w, h);
setRaw(pos[0], pos[1], pos[2], palette.readNode(din));
}

View File

@@ -29,11 +29,9 @@ import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class BlockMatter extends RawMatter<BlockData>
{
public BlockMatter()
{
this(1,1,1);
public class BlockMatter extends RawMatter<BlockData> {
public BlockMatter() {
this(1, 1, 1);
}
public BlockMatter(int width, int height, int depth) {

View File

@@ -25,11 +25,9 @@ import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class BooleanMatter extends RawMatter<Boolean>
{
public BooleanMatter()
{
this(1,1,1);
public class BooleanMatter extends RawMatter<Boolean> {
public BooleanMatter() {
this(1, 1, 1);
}
public BooleanMatter(int width, int height, int depth) {

View File

@@ -22,11 +22,9 @@ import com.volmit.iris.util.matter.Sliced;
import com.volmit.iris.util.nbt.tag.CompoundTag;
@Sliced
public class CompoundMatter extends NBTMatter<CompoundTag>
{
public CompoundMatter()
{
this(1,1,1);
public class CompoundMatter extends NBTMatter<CompoundTag> {
public CompoundMatter() {
this(1, 1, 1);
}
public CompoundMatter(int width, int height, int depth) {

View File

@@ -26,12 +26,11 @@ import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class IntMatter extends RawMatter<Integer>
{
public IntMatter()
{
this(1,1,1);
public class IntMatter extends RawMatter<Integer> {
public IntMatter() {
this(1, 1, 1);
}
public IntMatter(int width, int height, int depth) {
super(width, height, depth, Integer.class);
}

View File

@@ -26,12 +26,11 @@ import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class LongMatter extends RawMatter<Long>
{
public LongMatter()
{
this(1,1,1);
public class LongMatter extends RawMatter<Long> {
public LongMatter() {
this(1, 1, 1);
}
public LongMatter(int width, int height, int depth) {
super(width, height, depth, Long.class);
}

View File

@@ -19,16 +19,13 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.io.NamedTag;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.nbt.tag.Tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class NBTMatter<T extends Tag<?>> extends RawMatter<T>
{
public class NBTMatter<T extends Tag<?>> extends RawMatter<T> {
public NBTMatter(int width, int height, int depth, Class<T> c) {
super(width, height, depth, c);
}

View File

@@ -20,8 +20,6 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.matter.MatterHunk;
import com.volmit.iris.util.matter.MatterSlice;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import java.io.DataInputStream;
@@ -32,8 +30,7 @@ public abstract class RawMatter<T> extends MatterHunk<T> implements MatterSlice<
@Getter
private final Class<T> type;
public RawMatter(int width, int height, int depth, Class<T> type)
{
public RawMatter(int width, int height, int depth, Class<T> type) {
super(width, height, depth);
this.type = type;
}

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.matter.MatterSlice;
import com.volmit.iris.util.matter.Sliced;
import java.io.DataInputStream;
@@ -26,12 +25,11 @@ import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class StringMatter extends RawMatter<String>
{
public StringMatter()
{
this(1,1,1);
public class StringMatter extends RawMatter<String> {
public StringMatter() {
this(1, 1, 1);
}
public StringMatter(int width, int height, int depth) {
super(width, height, depth, String.class);
}