mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Data palettes
This commit is contained in:
parent
dcda5741f1
commit
56eb0b8ef1
@ -0,0 +1,71 @@
|
||||
package com.volmit.iris.gen.v2.scaffold.data;
|
||||
|
||||
import com.volmit.iris.util.KList;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DataPalette<T> {
|
||||
private final KList<T> palette;
|
||||
|
||||
public DataPalette()
|
||||
{
|
||||
this(new KList<>(16));
|
||||
}
|
||||
|
||||
public DataPalette(KList<T> palette)
|
||||
{
|
||||
this.palette = palette;
|
||||
}
|
||||
|
||||
public KList<T> getPalette()
|
||||
{
|
||||
return palette;
|
||||
}
|
||||
|
||||
public int getIndex(T t)
|
||||
{
|
||||
int v = 0;
|
||||
|
||||
synchronized (palette)
|
||||
{
|
||||
v = palette.indexOf(t);
|
||||
|
||||
if(v == -1)
|
||||
{
|
||||
v = palette.size();
|
||||
palette.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public void write(IOAdapter<T> adapter, DataOutputStream dos) throws IOException
|
||||
{
|
||||
synchronized (palette)
|
||||
{
|
||||
dos.writeShort(getPalette().size() + Short.MIN_VALUE);
|
||||
|
||||
for(int i = 0; i < palette.size(); i++)
|
||||
{
|
||||
adapter.write(palette.get(i), dos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> DataPalette<T> getPalette(IOAdapter<T> adapter, DataInputStream din) throws IOException
|
||||
{
|
||||
KList<T> palette = new KList<>();
|
||||
int s = din.readShort() - Short.MIN_VALUE;
|
||||
|
||||
for(int i = 0; i < s; i++)
|
||||
{
|
||||
palette.add(adapter.read(din));
|
||||
}
|
||||
|
||||
return new DataPalette<>(palette);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.volmit.iris.gen.v2.scaffold.data;
|
||||
|
||||
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
|
||||
import com.volmit.iris.util.Function3;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public interface IOAdapter<T>
|
||||
{
|
||||
public void write(T t, DataOutputStream dos) throws IOException;
|
||||
|
||||
public T read(DataInputStream din) throws IOException;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user