Data fixes for tec plates

This commit is contained in:
cyberpwn 2021-09-25 18:25:00 -04:00
parent b6d9eb3dcc
commit a80031c3c5
26 changed files with 184 additions and 71 deletions

View File

@ -38,13 +38,13 @@ import com.volmit.iris.util.exceptions.IrisException;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.function.NastyRunnable;
import com.volmit.iris.util.hunk.bits.TecTest;
import com.volmit.iris.util.io.FileWatcher;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.io.InstanceState;
import com.volmit.iris.util.io.JarScanner;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.MatterTest;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.plugin.IrisService;
import com.volmit.iris.util.plugin.Metrics;
@ -454,9 +454,9 @@ public class Iris extends VolmitPlugin implements Listener {
J.ar(this::checkConfigHotload, 60);
J.sr(this::tickQueue, 0);
J.s(this::setupPapi);
J.s(TecTest::go);
J.a(ServerConfigurator::configure, 20);
splash();
J.a(MatterTest::test, 20);
if (IrisSettings.get().getStudio().isAutoStartDefaultStudio()) {
Iris.info("Starting up auto Studio!");

View File

@ -524,7 +524,15 @@ public class MantleWriter implements IObjectPlacer {
}
public <T> void set(IrisPosition pos, T data) {
setData(pos.getX(), pos.getY(), pos.getZ(), data);
try
{
setData(pos.getX(), pos.getY(), pos.getZ(), data);
}
catch(Throwable e)
{
Iris.error("No set? " + data.toString() + " for " + pos.toString());
}
}
public <T> void set(List<IrisPosition> positions, T data) {

View File

@ -24,9 +24,11 @@ import com.volmit.iris.util.math.RollingSequence;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
@ -158,6 +160,40 @@ public class Form {
return wrap(s, len, newLineSep, soft, " ");
}
public static String hardWrap(String s, int len) {
StringBuilder ss = new StringBuilder();
for(int i = 0; i < s.length(); i+= len)
{
if(i + len > s.length())
{
ss.append(s, i, s.length());
break;
}
ss.append(s, i, i + len).append("\n");
}
return ss.toString();
}
public static List<String> hardWrapList(String s, int len) {
List<String> l = new ArrayList<>();
for(int i = 0; i < s.length(); i+= len)
{
if(i + len > s.length())
{
l.add(s.substring(i));
break;
}
l.add(s.substring(i, i + len));
}
return l;
}
/**
* Wrap words
*

View File

@ -18,6 +18,7 @@
package com.volmit.iris.util.hunk.bits;
import com.volmit.iris.Iris;
import org.apache.commons.lang3.Validate;
import java.io.DataInputStream;

View File

@ -18,6 +18,8 @@
package com.volmit.iris.util.hunk.bits;
import com.volmit.iris.Iris;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -25,9 +27,10 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;
public class DataContainer<T> {
protected static final int INITIAL_BITS = 3;
protected static final int INITIAL_BITS = 2;
protected static final int LINEAR_BITS_LIMIT = 5;
protected static final int LINEAR_INITIAL_LENGTH = (int) Math.pow(2, LINEAR_BITS_LIMIT) + 1;
protected static final int[] BIT = computeBitLimits();
@ -37,13 +40,12 @@ 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) {
this.writer = writer;
this.length = length;
this.bits = new AtomicInteger(INITIAL_BITS);
this.data = new AtomicReference<>(new DataBits(INITIAL_BITS, length));
this.palette = new AtomicReference<>(newPalette(INITIAL_BITS));
this.ensurePaletted(empty);
}
public DataContainer(DataInputStream din, Writable<T> writer) throws IOException {
@ -54,6 +56,16 @@ public class DataContainer<T> {
this.bits = new AtomicInteger(palette.get().bits());
}
public DataBits getData()
{
return data.get();
}
public Palette<T> getPalette()
{
return palette.get();
}
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();
@ -79,7 +91,7 @@ public class DataContainer<T> {
private Palette<T> newPalette(DataInputStream din) throws IOException {
int paletteSize = din.readInt();
Palette<T> d = newPalette(bits(paletteSize));
Palette<T> d = newPalette(bits(paletteSize+1));
d.from(paletteSize, writer, din);
return d;
}
@ -105,24 +117,36 @@ public class DataContainer<T> {
}
public void set(int position, T t) {
int id = palette.get().id(t);
synchronized (this)
{
int id = palette.get().id(t);
if (id == -1) {
checkBits();
id = palette.get().add(t);
if (id == -1) {
expandOne();
id = palette.get().add(t);
}
data.get().set(position, id);
}
}
data.get().set(position, id);
private void expandOne() {
if (palette.get().size()+1 >= BIT[bits.get()]) {
setBits(bits.get() + 1);
}
}
public T get(int position) {
int id = data.get().get(position) + 1;
synchronized (this)
{
int id = data.get().get(position) + 1;
if (id <= 0) {
return null;
if (id <= 0) {
return null;
}
return palette.get().get(id - 1);
}
return palette.get().get(id - 1);
}
public void setBits(int bits) {
@ -159,4 +183,8 @@ public class DataContainer<T> {
return DataContainer.BIT.length - 1;
}
public int size() {
return getData().getSize();
}
}

View File

@ -33,6 +33,7 @@ public class HashPalette<T> implements Palette<T> {
this.size = new AtomicInteger(0);
this.palette = new LinkedHashMap<>();
this.lookup = new KMap<>();
add(null);
}
@Override
@ -58,18 +59,28 @@ public class HashPalette<T> implements Palette<T> {
@Override
public int id(T t) {
if(t == null)
{
return 0;
}
Integer v = palette.get(t);
return v != null ? v : -1;
}
@Override
public int size() {
return size.get();
return size.get() - 1;
}
@Override
public void iterate(Consumer2<T, Integer> c) {
for (T i : palette.keySet()) {
if(i == null)
{
continue;
}
c.accept(i, id(i));
}
}

View File

@ -31,6 +31,7 @@ public class LinearPalette<T> implements Palette<T> {
public LinearPalette(int initialSize) {
this.size = new AtomicInteger(0);
this.palette = new AtomicReference<>(new AtomicReferenceArray<>(initialSize));
palette.get().set(size.getAndIncrement(), null);
}
@Override
@ -64,12 +65,13 @@ 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) {
return i;
}
if(t == null)
{
return 0;
}
if (t != null && t.equals(palette.get().get(i))) {
for (int i = 0; i < size(); i++) {
if (t.equals(palette.get().get(i))) {
return i;
}
}
@ -79,12 +81,12 @@ public class LinearPalette<T> implements Palette<T> {
@Override
public int size() {
return size.get();
return size.get()-1;
}
@Override
public void iterate(Consumer2<T, Integer> c) {
for (int i = 0; i < size(); i++) {
for (int i = 1; i < size()+1; i++) {
c.accept(palette.get().get(i), i);
}
}

View File

@ -35,7 +35,7 @@ public interface Palette<T> {
int size();
default int bits() {
return DataContainer.bits(size());
return DataContainer.bits(size()+1);
}
void iterate(Consumer2<T, Integer> c);

View File

@ -0,0 +1,53 @@
/*
* 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.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 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);
}
}

View File

@ -27,6 +27,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.IOException;
import java.util.concurrent.locks.ReentrantLock;
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
@Data
@ -34,16 +35,15 @@ import java.io.IOException;
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) {
public PaletteHunk(int w, int h, int d, Writable<T> writer) {
super(w, h, d);
data = new DataContainer<>(writer, w * h * d, e);
data = new DataContainer<>(writer, w * h * d);
}
public void setPalette(DataContainer<T> c) {
data = c;
}
public boolean isMapped() {
return false;
}

View File

@ -30,9 +30,9 @@ 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) {
public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory) {
super(width, height, depth);
hunk = (allow) ? new PaletteHunk<>(width, height, depth, this, e) : factory.get();
hunk = (allow) ? new PaletteHunk<>(width, height, depth, this) : factory.get();
}
public DataContainer<T> palette() {

View File

@ -19,7 +19,6 @@
package com.volmit.iris.util.matter;
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.hunk.Hunk;

View File

@ -1,25 +0,0 @@
/*
* 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;
public class MatterTest {
public static void test() {
}
}

View File

@ -43,7 +43,7 @@ public class BlockMatter extends RawMatter<BlockData> {
}
public BlockMatter(int width, int height, int depth) {
super(width, height, depth, BlockData.class, AIR);
super(width, height, depth, BlockData.class);
registerWriter(World.class, ((w, d, x, y, z) -> w.getBlockAt(x, y, z).setBlockData(d)));
registerReader(World.class, (w, x, y, z) -> {
BlockData d = w.getBlockAt(x, y, z).getBlockData();

View File

@ -37,7 +37,7 @@ public class BooleanMatter extends RawMatter<Boolean> {
}
public BooleanMatter(int width, int height, int depth) {
super(width, height, depth, Boolean.class, false);
super(width, height, depth, Boolean.class);
}
@Override

View File

@ -40,7 +40,7 @@ public class CavernMatter extends RawMatter<MatterCavern> {
}
public CavernMatter(int width, int height, int depth) {
super(width, height, depth, MatterCavern.class, EMPTY);
super(width, height, depth, MatterCavern.class);
}
public static MatterCavern get(String customBiome, int liquid) {

View File

@ -54,7 +54,7 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
}
public EntityMatter(int width, int height, int depth) {
super(width, height, depth, MatterEntityGroup.class, EMPTY);
super(width, height, depth, MatterEntityGroup.class);
registerWriter(World.class, ((w, d, x, y, z) -> {
for (MatterEntity i : d.getEntities()) {
Location realPosition = new Location(w, x + i.getXOff(), y + i.getYOff(), z + i.getZOff());

View File

@ -38,7 +38,7 @@ public class IntMatter extends RawMatter<Integer> {
}
public IntMatter(int width, int height, int depth) {
super(width, height, depth, Integer.class, 0);
super(width, height, depth, Integer.class);
}
@Override

View File

@ -38,7 +38,7 @@ public class LongMatter extends RawMatter<Long> {
}
public LongMatter(int width, int height, int depth) {
super(width, height, depth, Long.class, 0L);
super(width, height, depth, Long.class);
}
@Override

View File

@ -44,7 +44,7 @@ public class MarkerMatter extends RawMatter<MatterMarker> {
}
public MarkerMatter(int width, int height, int depth) {
super(width, height, depth, MatterMarker.class, NONE);
super(width, height, depth, MatterMarker.class);
}
@Override

View File

@ -28,7 +28,7 @@ import java.io.IOException;
public class NBTMatter<T extends Tag<?>> extends RawMatter<T> {
public NBTMatter(int width, int height, int depth, Class<T> c, T e) {
super(width, height, depth, c, e);
super(width, height, depth, c);
}
@Override

View File

@ -36,8 +36,8 @@ public abstract class RawMatter<T> extends PaletteOrHunk<T> implements MatterSli
@Getter
private final Class<T> type;
public RawMatter(int width, int height, int depth, Class<T> type, T e) {
super(width, height, depth, false, () -> new MappedHunk<>(width, height, depth), e);
public RawMatter(int width, int height, int depth, Class<T> type) {
super(width, height, depth, true, () -> new MappedHunk<>(width, height, depth));
writers = new KMap<>();
readers = new KMap<>();
this.type = type;

View File

@ -28,7 +28,7 @@ import java.io.IOException;
public class RegistryMatter<T extends IrisRegistrant> extends RawMatter<T> {
public RegistryMatter(int width, int height, int depth, Class<T> c, T e) {
super(width, height, depth, c, e);
super(width, height, depth, c);
}
@Override

View File

@ -32,7 +32,7 @@ public class StringMatter extends RawMatter<String> {
}
public StringMatter(int width, int height, int depth) {
super(width, height, depth, String.class, "");
super(width, height, depth, String.class);
}
@Override

View File

@ -45,7 +45,7 @@ public class TileMatter extends RawMatter<MatterTile> {
}
public TileMatter(int width, int height, int depth) {
super(width, height, depth, MatterTile.class, EMPTY);
super(width, height, depth, MatterTile.class);
registerWriter(World.class, ((w, d, x, y, z) -> INMS.get().deserializeTile(d.getTileData(), new Location(w, x, y, z))));
registerReader(World.class, (w, x, y, z) -> {
Location l = new Location(w, x, y, z);

View File

@ -43,7 +43,7 @@ public class UpdateMatter extends RawMatter<MatterUpdate> {
}
public UpdateMatter(int width, int height, int depth) {
super(width, height, depth, MatterUpdate.class, OFF);
super(width, height, depth, MatterUpdate.class);
}
@Override