Various debugging and cleaning

This commit is contained in:
MattBDev
2020-01-03 12:02:18 -05:00
parent a5ee0b197d
commit cfb6e3bca4
21 changed files with 247 additions and 253 deletions

View File

@ -1,8 +1,6 @@
package com.boydti.fawe;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.config.Caption;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.changeset.DiskStorageHistory;
@ -31,6 +29,7 @@ import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.World;
import java.io.File;
import java.io.IOException;
@ -152,13 +151,12 @@ public class FaweAPI {
* Remember to commit when you're done!<br>
*
* @param world The name of the world
* @param autoqueue If it should start dispatching before you enqueue it.
* @return
* @see IQueueExtent#enqueue()
* @param autoQueue If it should start dispatching before you enqueue it.
* @return the queue extent
*/
public static IQueueExtent createQueue(World world, boolean autoqueue) {
public static IQueueExtent createQueue(World world, boolean autoQueue) {
IQueueExtent queue = Fawe.get().getQueueHandler().getQueue(world);
if (!autoqueue) {
if (!autoQueue) {
queue.disableQueue();
}
return queue;
@ -189,10 +187,9 @@ public class FaweAPI {
/**
* Just forwards to ClipboardFormat.SCHEMATIC.load(file)
*
* @param file
* @return
* @param file the file to load
* @return a clipboard containing the schematic
* @see ClipboardFormat
* @see Schematic
*/
public static Clipboard load(File file) throws IOException {
return ClipboardFormats.findByFile(file).load(file);

View File

@ -4,11 +4,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import com.boydti.fawe.beta.Trimable;
import com.boydti.fawe.beta.implementation.filter.block.CharFilterBlock;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.collection.BitArray4096;
import com.boydti.fawe.object.collection.CleanableThreadLocal;
@ -18,6 +13,9 @@ import com.boydti.fawe.object.exception.FaweChunkLoadException;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.IOUtil;
import com.boydti.fawe.util.MathMan;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
@ -34,6 +32,7 @@ import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import java.lang.reflect.Field;
import java.util.ArrayList;
@ -192,7 +191,7 @@ public enum FaweCache implements Trimable {
} else {
pool = cache::get;
}
Pool previous = REGISTERED_POOLS.putIfAbsent(clazz, pool);
Pool<T> previous = REGISTERED_POOLS.putIfAbsent(clazz, pool);
if (previous != null) {
throw new IllegalStateException("Previous key");
}

View File

@ -1,9 +1,6 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.implementation.filter.block.CharFilterBlock;
import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock;
import com.boydti.fawe.beta.implementation.filter.block.FilterBlock;
import com.boydti.fawe.beta.implementation.processors.EmptyBatchProcessor;
import com.boydti.fawe.beta.implementation.processors.MultiBatchProcessor;
import com.sk89q.jnbt.CompoundTag;
@ -68,10 +65,12 @@ public interface IBatchProcessor {
}
}
}
for (int layer = (minY - 15) >> 4; layer < (maxY + 15) >> 4; layer++) {
int layer = (minY - 15) >> 4;
while (layer < (maxY + 15) >> 4) {
if (set.hasSection(layer)) {
return true;
}
layer++;
}
return false;
}

View File

@ -8,12 +8,9 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockID;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockRegistry;
import java.io.IOException;
import java.util.Map;
import java.util.Set;

View File

@ -4,13 +4,10 @@ import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.object.collection.MemBlockSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

View File

@ -1,9 +1,11 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IBlocks;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.jetbrains.annotations.Range;
public abstract class CharBlocks implements IBlocks {
@ -66,7 +68,7 @@ public abstract class CharBlocks implements IBlocks {
return null;
}
public void reset(int layer) {
public void reset(@Range(from = 0, to = 15) int layer) {
sections[layer] = EMPTY;
}
@ -81,12 +83,12 @@ public abstract class CharBlocks implements IBlocks {
}
@Override
public boolean hasSection(int layer) {
public boolean hasSection(@Range(from = 0, to = 15) int layer) {
return sections[layer] == FULL;
}
@Override
public char[] load(int layer) {
public char[] load(@Range(from = 0, to = 15) int layer) {
return sections[layer].get(this, layer);
}
@ -102,6 +104,7 @@ public abstract class CharBlocks implements IBlocks {
}
public void set(int x, int y, int z, char value) {
Fawe.imp().debug("Setting Block at x:" + x + ", y:" + y + " , z:" + z);
final int layer = y >> 4;
final int index = (y & 15) << 8 | z << 4 | x;
set(layer, index, value);
@ -111,11 +114,11 @@ public abstract class CharBlocks implements IBlocks {
Section
*/
public final char get(int layer, int index) {
public final char get(@Range(from = 0, to = 15)int layer, int index) {
return sections[layer].get(this, layer, index);
}
public final void set(int layer, int index, char value) {
public final void set(@Range(from = 0, to = 15) int layer, int index, char value) {
sections[layer].set(this, layer, index, value);
}

View File

@ -250,16 +250,14 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk {
}
@Override
public boolean setBiome(ChunkHolder chunk, int x, int y, int z,
BiomeType biome) {
public boolean setBiome(ChunkHolder chunk, int x, int y, int z, BiomeType biome) {
chunk.getOrCreateSet();
chunk.delegate = SET;
return chunk.setBiome(x, y, z, biome);
}
@Override
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
BlockStateHolder block) {
public boolean setBlock(ChunkHolder chunk, int x, int y, int z, BlockStateHolder block) {
chunk.getOrCreateSet();
chunk.delegate = SET;
return chunk.setBlock(x, y, z, block);
@ -471,11 +469,9 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk {
IChunkGet get(ChunkHolder chunk);
IChunkSet set(ChunkHolder chunk);
boolean setBiome(ChunkHolder chunk, int x, int y, int z,
BiomeType biome);
boolean setBiome(ChunkHolder chunk, int x, int y, int z, BiomeType biome);
boolean setBlock(ChunkHolder chunk, int x, int y, int z,
BlockStateHolder holder);
boolean setBlock(ChunkHolder chunk, int x, int y, int z, BlockStateHolder holder);
BiomeType getBiome(ChunkHolder chunk, int x, int y, int z);

View File

@ -33,8 +33,8 @@ import java.util.concurrent.Future;
*/
public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implements IQueueExtent<IQueueChunk> {
// // Pool discarded chunks for reuse (can safely be cleared by another thread)
// private static final ConcurrentLinkedQueue<IChunk> CHUNK_POOL = new ConcurrentLinkedQueue<>();
// Pool discarded chunks for reuse (can safely be cleared by another thread)
// private static final ConcurrentLinkedQueue<IChunk> CHUNK_POOL = new ConcurrentLinkedQueue<>();
// Chunks currently being queued / worked on
private final Long2ObjectLinkedOpenHashMap<IQueueChunk> chunks = new Long2ObjectLinkedOpenHashMap<>();

View File

@ -142,7 +142,7 @@ public class MCAChunk implements IChunk {
for (Map.Entry<String, String> entry : properties.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
Property property = type.getProperty(key);
Property<Object> property = type.getProperty(key);
state = state.with(property, property.getValueFor(value));
}
}
@ -246,8 +246,8 @@ public class MCAChunk implements IChunk {
int type = NBTConstants.TYPE_BYTE_ARRAY;
out.writeNamedTagName("Biomes", type);
out.writeInt(biomes.length);
for (int i = 0; i < biomes.length; i++) {
out.write(biomes[i].getLegacyId());
for (BiomeType biome : biomes) {
out.write(biome.getLegacyId());
}
}
int len = 0;
@ -430,9 +430,7 @@ public class MCAChunk implements IChunk {
if (tile != null) {
tiles.put(x, y, z, tile);
} else {
if (tiles.remove(x, y, z) == null) {
return false;
}
return tiles.remove(x, y, z) != null;
}
return true;
}
@ -520,18 +518,14 @@ public class MCAChunk implements IChunk {
@Override
public void setBlocks(int layer, char[] data) {
int offset = layer << 12;
for (int i = 0; i < 4096; i++) {
blocks[offset + i] = data[i];
}
System.arraycopy(data, 0, blocks, offset, 4096);
}
@Override
public char[] load(int layer) {
char[] tmp = FaweCache.IMP.SECTION_BITS_TO_CHAR.get();
int offset = layer << 12;
for (int i = 0; i < 4096; i++) {
tmp[i] = blocks[offset + i];
}
System.arraycopy(blocks, offset, tmp, 0, 4096);
return tmp;
}

View File

@ -34,6 +34,7 @@ import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.IntStream;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
@ -397,10 +398,8 @@ public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, ICh
}
public List<MCAChunk> getCachedChunks() {
int size = 0;
for (int i = 0; i < chunks.length; i++) {
if (chunks[i] != null && this.chunkInitialized[i]) size++;
}
int size = (int) IntStream.range(0, chunks.length)
.filter(i -> chunks[i] != null && this.chunkInitialized[i]).count();
ArrayList<MCAChunk> list = new ArrayList<>(size);
for (int i = 0; i < chunks.length; i++) {
MCAChunk chunk = chunks[i];

View File

@ -41,7 +41,6 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa
* The locations provided are relative to the clipboard min
*
* @param task
* @param air
*/
public abstract void streamBiomes(IntValueReader task);

View File

@ -1,8 +1,5 @@
package com.boydti.fawe.object.collection;
import java.util.function.Function;
import java.util.function.Supplier;
public class VariableThreadLocal extends CleanableThreadLocal<byte[]> {
public VariableThreadLocal() {
super(() -> null);

View File

@ -5,6 +5,7 @@ import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UTFDataFormatException;
import org.jetbrains.annotations.NotNull;
public class LittleEndianOutputStream extends FilterOutputStream implements DataOutput {
@ -18,7 +19,7 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* output stream specified by the out argument.
*
* @param out the underlying output stream.
* @see java.io.FilterOutputStream#out
* @see FilterOutputStream#out
*/
public LittleEndianOutputStream(OutputStream out) {
super(out);
@ -27,24 +28,26 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
/**
* Writes the specified byte value to the underlying output stream.
*
* @param b the <code>byte</code> value to be written.
* @param b the {@code byte} value to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public synchronized void write(int b) throws IOException {
out.write(b);
written++;
}
/**
* Writes <code>length</code> bytes from the specified byte array
* starting at <code>offset</code> to the underlying output stream.
* Writes {@code length} bytes from the specified byte array
* starting at {@code offset} to the underlying output stream.
*
* @param data the data.
* @param offset the start offset in the data.
* @param length the number of bytes to write.
* @exception IOException if the underlying stream throws an IOException.
*/
public synchronized void write(byte[] data, int offset, int length)
@Override
public synchronized void write(@NotNull byte[] data, int offset, int length)
throws IOException {
out.write(data, offset, length);
written += length;
@ -52,13 +55,14 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
/**
* Writes a <code>boolean</code> to the underlying output stream as
* Writes a {@code boolean} to the underlying output stream as
* a single byte. If the argument is true, the byte value 1 is written.
* If the argument is false, the byte value <code>0</code> in written.
* If the argument is false, the byte value {@code 0} in written.
*
* @param b the <code>boolean</code> value to be written.
* @param b the {@code boolean} value to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeBoolean(boolean b) throws IOException {
if (b) this.write(1);
@ -67,23 +71,25 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
}
/**
* Writes out a <code>byte</code> to the underlying output stream
* Writes out a {@code byte} to the underlying output stream
*
* @param b the <code>byte</code> value to be written.
* @param b the {@code byte} value to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeByte(int b) throws IOException {
out.write(b);
written++;
}
/**
* Writes a two byte <code>short</code> to the underlying output stream in
* Writes a two byte {@code short} to the underlying output stream in
* little endian order, low byte first.
*
* @param s the <code>short</code> to be written.
* @param s the {@code short} to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeShort(int s) throws IOException {
out.write(s & 0xFF);
@ -93,12 +99,13 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
}
/**
* Writes a two byte <code>char</code> to the underlying output stream
* Writes a two byte {@code char} to the underlying output stream
* in little endian order, low byte first.
*
* @param c the <code>char</code> value to be written.
* @param c the {@code char} value to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeChar(int c) throws IOException {
out.write(c & 0xFF);
@ -108,12 +115,13 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
}
/**
* Writes a four-byte <code>int</code> to the underlying output stream
* Writes a four-byte {@code int} to the underlying output stream
* in little endian order, low byte first, high byte last
*
* @param i the <code>int</code> to be written.
* @param i the {@code int} to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeInt(int i) throws IOException {
out.write(i & 0xFF);
@ -125,12 +133,13 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
}
/**
* Writes an eight-byte <code>long</code> to the underlying output stream
* Writes an eight-byte {@code long} to the underlying output stream
* in little endian order, low byte first, high byte last
*
* @param l the <code>long</code> to be written.
* @param l the {@code long} to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeLong(long l) throws IOException {
out.write((int) l & 0xFF);
@ -149,9 +158,10 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* Writes a 4 byte Java float to the underlying output stream in
* little endian order.
*
* @param f the <code>float</code> value to be written.
* @param f the {@code float} value to be written.
* @exception IOException if an I/O error occurs.
*/
@Override
public final void writeFloat(float f) throws IOException {
this.writeInt(Float.floatToIntBits(f));
@ -162,9 +172,10 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* Writes an 8 byte Java double to the underlying output stream in
* little endian order.
*
* @param d the <code>double</code> value to be written.
* @param d the {@code double} value to be written.
* @exception IOException if an I/O error occurs.
*/
@Override
public final void writeDouble(double d) throws IOException {
this.writeLong(Double.doubleToLongBits(d));
@ -174,13 +185,14 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
/**
* Writes a string to the underlying output stream as a sequence of
* bytes. Each character is written to the data output stream as
* if by the <code>writeByte()</code> method.
* if by the {@code writeByte()} method.
*
* @param s the <code>String</code> value to be written.
* @param s the {@code String} value to be written.
* @exception IOException if the underlying stream throws an IOException.
* @see java.io.DataOutputStream#writeByte(int)
* @see java.io.DataOutputStream#out
*/
@Override
public void writeBytes(String s) throws IOException {
int length = s.length();
@ -193,13 +205,14 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
/**
* Writes a string to the underlying output stream as a sequence of
* characters. Each character is written to the data output stream as
* if by the <code>writeChar</code> method.
* if by the {@code writeChar} method.
*
* @param s a <code>String</code> value to be written.
* @param s a {@code String} value to be written.
* @exception IOException if the underlying stream throws an IOException.
* @see java.io.DataOutputStream#writeChar(int)
* @see java.io.DataOutputStream#out
*/
@Override
public void writeChars(String s) throws IOException {
int length = s.length();
@ -227,6 +240,7 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* 65,535 characters.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeUTF(String s) throws IOException {
int numchars = s.length();
@ -270,11 +284,10 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* (This class is not thread-safe with respect to this method. It is
* possible that this number is temporarily less than the actual
* number of bytes written.)
* @return the value of the <code>written</code> field.
* @see java.io.DataOutputStream#written
* @return the value of the {@code written} field.
*/
public int size() {
return this.written;
}
}
}

View File

@ -33,7 +33,6 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import javax.annotation.Nullable;
public class PolyhedralRegion extends AbstractRegion {
@ -69,7 +68,7 @@ public class PolyhedralRegion extends AbstractRegion {
private BlockVector3 centerAccum = BlockVector3.ZERO;
/**
* The last triangle that caused a {@link #contains(Vector)} to classify a point as "outside". Used for optimization.
* The last triangle that caused a {@link #contains(BlockVector3)} to classify a point as "outside". Used for optimization.
*/
private Triangle lastTriangle;