mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-14 19:56:25 +00:00
BITS BITS EVERYWHERE
This commit is contained in:
@@ -26,6 +26,8 @@ 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;
|
||||
import com.volmit.iris.util.hunk.storage.PaletteOrHunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -39,7 +41,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface MatterSlice<T> extends Hunk<T>, PaletteType<T> {
|
||||
public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
|
||||
Class<T> getType();
|
||||
|
||||
Palette<T> getGlobalPalette();
|
||||
@@ -49,11 +51,21 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T> {
|
||||
writeNode(s, dos);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void writeNodeData(DataOutputStream dos, T s) throws IOException {
|
||||
writeNode(s, dos);
|
||||
}
|
||||
|
||||
@Override
|
||||
default T readPaletteNode(DataInputStream din) throws IOException {
|
||||
return readNode(din);
|
||||
}
|
||||
|
||||
@Override
|
||||
default T readNodeData(DataInputStream din) throws IOException {
|
||||
return readNode(din);
|
||||
}
|
||||
|
||||
default void applyFilter(MatterFilter<T> filter) {
|
||||
updateSync(filter::update);
|
||||
}
|
||||
@@ -154,22 +166,7 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T> {
|
||||
dos.writeUTF(getType().getCanonicalName());
|
||||
if((this instanceof PaletteOrHunk f && f.isPalette()))
|
||||
{
|
||||
PalettedContainer<T> c = f.palette();
|
||||
List<T> palette = new ArrayList<>();
|
||||
long[] data = c.write(palette);
|
||||
|
||||
Varint.writeUnsignedVarInt(palette.size(), dos);
|
||||
for(T i : palette)
|
||||
{
|
||||
writeNode(i, dos);
|
||||
}
|
||||
|
||||
Varint.writeUnsignedVarInt(data.length, dos);
|
||||
for(long i : data)
|
||||
{
|
||||
dos.writeLong(i);
|
||||
}
|
||||
|
||||
f.palette().writeDos(dos);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -194,24 +191,7 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T> {
|
||||
default void read(DataInputStream din) throws IOException {
|
||||
if((this instanceof PaletteOrHunk f && f.isPalette()))
|
||||
{
|
||||
PalettedContainer<T> c = new PalettedContainer<>();
|
||||
List<T> palette = new ArrayList<>();
|
||||
int ps = Varint.readUnsignedVarInt(din);
|
||||
|
||||
for(int i = 0; i < ps; i++)
|
||||
{
|
||||
palette.add(readNode(din));
|
||||
}
|
||||
|
||||
int ds = Varint.readUnsignedVarInt(din);
|
||||
long[] data = new long[ds];
|
||||
for(int i = 0; i < ds; i++)
|
||||
{
|
||||
data[i] = din.readLong();
|
||||
}
|
||||
|
||||
c.read(palette, data);
|
||||
|
||||
f.setPalette(DataContainer.readDin(din, this));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
74
src/main/java/com/volmit/iris/util/matter/MatterTest.java
Normal file
74
src/main/java/com/volmit/iris/util/matter/MatterTest.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.matter;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.NoiseStyle;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.data.palette.PalettedContainer;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatterTest {
|
||||
public static void test()
|
||||
{
|
||||
CNG cng = NoiseStyle.STATIC.create(new RNG(1337));
|
||||
PalettedContainer<Integer> p = new PalettedContainer<>();
|
||||
|
||||
for(int i = 0; i < 16; i++)
|
||||
{
|
||||
for(int j = 0; j < 16; j++)
|
||||
{
|
||||
for(int k = 0; k < 16; k++)
|
||||
{
|
||||
p.set(i,j,k,cng.fit(1, 3, i,j,k));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KList<Integer> palette = new KList<>();
|
||||
long[] data = p.write(palette);
|
||||
|
||||
Iris.info("RAW PALE: " + palette.toString(","));
|
||||
Iris.info("RAW DATA: " + IO.longsToHex(data));
|
||||
|
||||
PalettedContainer<Integer> px = new PalettedContainer<>();
|
||||
px.read(palette, data);
|
||||
|
||||
KList<Integer> palette2 = new KList<>();
|
||||
long[] data2 = px.write(palette);
|
||||
|
||||
if(Arrays.equals(data, data2))
|
||||
{
|
||||
Iris.info("Correct! All data matches!");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Iris.warn("No match");
|
||||
Iris.error("RAW PALE: " + palette2.toString(","));
|
||||
Iris.error("RAW DATA: " + IO.longsToHex(data2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public abstract class RawMatter<T> extends PaletteOrHunk<T> implements MatterSli
|
||||
private final Class<T> type;
|
||||
|
||||
public RawMatter(int width, int height, int depth, Class<T> type) {
|
||||
super(width, height, depth, true, () -> new MappedHunk<>(width, height, depth));
|
||||
super(width, height, depth, false, this, () -> new MappedHunk<>(width, height, depth));
|
||||
writers = new KMap<>();
|
||||
readers = new KMap<>();
|
||||
this.type = type;
|
||||
|
||||
Reference in New Issue
Block a user