geforkt von Mirrors/FastAsyncWorldEdit
Docs, command, and formatting changes.
Dieser Commit ist enthalten in:
Ursprung
21a8899ba8
Commit
5c6c41a95a
@ -42,6 +42,10 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
public class BukkitQueue extends SimpleCharQueueExtent {
|
public class BukkitQueue extends SimpleCharQueueExtent {
|
||||||
@ -94,7 +98,7 @@ public class BukkitQueue extends SimpleCharQueueExtent {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IChunk create(boolean full) {
|
public IChunk create(boolean isFull) {
|
||||||
// if (full) {
|
// if (full) {
|
||||||
// //TODO implement
|
// //TODO implement
|
||||||
// return FULL_CHUNKS.get();
|
// return FULL_CHUNKS.get();
|
||||||
|
@ -5,18 +5,19 @@ import com.sk89q.worldedit.extent.Extent;
|
|||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class ArrayFilterBlock extends SimpleFilterBlock {
|
public class ArrayFilterBlock extends SimpleFilterBlock {
|
||||||
|
|
||||||
private final char[] blocks;
|
private final char[] blocks;
|
||||||
private final byte[] heights;
|
private final byte[] heights;
|
||||||
private final int yOffset;
|
private final int yOffset;
|
||||||
|
private final int width, length;
|
||||||
private int x, z, index;
|
private int x, z, index;
|
||||||
private char ordinal;
|
private char ordinal;
|
||||||
private final int width, length;
|
|
||||||
|
|
||||||
public ArrayFilterBlock(Extent extent, char[] blocks, byte[] heights, int width, int length, int yOffset) {
|
public ArrayFilterBlock(Extent extent, char[] blocks, byte[] heights, int width, int length,
|
||||||
|
int yOffset) {
|
||||||
super(extent);
|
super(extent);
|
||||||
this.blocks = blocks;
|
this.blocks = blocks;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
@ -34,43 +35,44 @@ public class ArrayFilterBlock extends SimpleFilterBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOrdinal(int ordinal) {
|
|
||||||
blocks[index] = (char) ordinal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBlock(BlockState state) {
|
|
||||||
blocks[index] = state.getOrdinalChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFullBlock(BaseBlock block) {
|
|
||||||
blocks[index] = block.getOrdinalChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getOrdinal() {
|
public int getOrdinal() {
|
||||||
return ordinal;
|
return ordinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOrdinal(int ordinal) {
|
||||||
|
blocks[index] = (char) ordinal;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock() {
|
public BlockState getBlock() {
|
||||||
return BlockTypes.states[ordinal];
|
return BlockTypes.states[ordinal];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlock(BlockState state) {
|
||||||
|
blocks[index] = state.getOrdinalChar();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseBlock getFullBlock() {
|
public BaseBlock getFullBlock() {
|
||||||
return getBlock().toBaseBlock();
|
return getBlock().toBaseBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFullBlock(BaseBlock block) {
|
||||||
|
blocks[index] = block.getOrdinalChar();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getNbtData() {
|
public CompoundTag getNbtData() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNbtData(@Nullable CompoundTag nbtData) {}
|
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getX() {
|
public int getX() {
|
||||||
|
@ -12,39 +12,54 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class CharFilterBlock extends ChunkFilterBlock {
|
public class CharFilterBlock extends ChunkFilterBlock {
|
||||||
|
|
||||||
|
private static final SetDelegate FULL = new SetDelegate() {
|
||||||
|
@Override
|
||||||
|
public final void set(CharFilterBlock block, char value) {
|
||||||
|
block.setArr[block.index] = value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private static final SetDelegate NULL = new SetDelegate() {
|
||||||
|
@Override
|
||||||
|
public void set(CharFilterBlock block, char value) {
|
||||||
|
block.initSet().set(block, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
private CharGetBlocks get;
|
private CharGetBlocks get;
|
||||||
private IChunkSet set;
|
private IChunkSet set;
|
||||||
|
|
||||||
private char[] getArr;
|
private char[] getArr;
|
||||||
private @Nullable char[] setArr;
|
private @Nullable
|
||||||
|
char[] setArr;
|
||||||
private SetDelegate delegate;
|
private SetDelegate delegate;
|
||||||
|
|
||||||
// local
|
// local
|
||||||
private int layer, index, x, y, z, xx, yy, zz, X, Z;
|
private int layer, index, x, y, z, xx, yy, zz, chunkX, chunkZ;
|
||||||
|
|
||||||
public CharFilterBlock(IQueueExtent queueExtent) {
|
public CharFilterBlock(IQueueExtent queueExtent) {
|
||||||
super(queueExtent);
|
super(queueExtent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ChunkFilterBlock init(final int chunkX, final int chunkZ, final IChunkGet chunk) {
|
public final ChunkFilterBlock init(int chunkX, int chunkZ, IChunkGet chunk) {
|
||||||
this.get = (CharGetBlocks) chunk;
|
this.get = (CharGetBlocks) chunk;
|
||||||
this.X = chunkX;
|
this.chunkX = chunkX;
|
||||||
this.Z = chunkZ;
|
this.chunkZ = chunkZ;
|
||||||
this.xx = chunkX << 4;
|
this.xx = chunkX << 4;
|
||||||
this.zz = chunkZ << 4;
|
this.zz = chunkZ << 4;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask) {
|
@Override
|
||||||
|
public void flood(IChunkGet iget, IChunkSet iset, int layer, Flood flood,
|
||||||
|
FilterBlockMask mask) {
|
||||||
final int maxDepth = flood.getMaxDepth();
|
final int maxDepth = flood.getMaxDepth();
|
||||||
final boolean checkDepth = maxDepth < Character.MAX_VALUE;
|
final boolean checkDepth = maxDepth < Character.MAX_VALUE;
|
||||||
if (init(iget, iset, layer) != null) {
|
if (init(iget, iset, layer) != null) {
|
||||||
while ((index = flood.poll()) != -1) {
|
while ((index = flood.poll()) != -1) {
|
||||||
x = index & 15;
|
x = index & 15;
|
||||||
z = (index >> 4) & 15;
|
z = index >> 4 & 15;
|
||||||
y = (index >> 8) & 15;
|
y = index >> 8 & 15;
|
||||||
|
|
||||||
if (mask.applyBlock(this)) {
|
if (mask.applyBlock(this)) {
|
||||||
int depth = index >> 12;
|
int depth = index >> 12;
|
||||||
@ -60,10 +75,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer) {
|
public final ChunkFilterBlock init(IChunkGet iget, IChunkSet iset,
|
||||||
|
int layer) {
|
||||||
this.layer = layer;
|
this.layer = layer;
|
||||||
final CharGetBlocks get = (CharGetBlocks) iget;
|
final CharGetBlocks get = (CharGetBlocks) iget;
|
||||||
if (!get.hasSection(layer)) return null;
|
if (!get.hasSection(layer)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
this.set = iset;
|
this.set = iset;
|
||||||
getArr = get.sections[layer].get(get, layer);
|
getArr = get.sections[layer].get(get, layer);
|
||||||
if (set.hasSection(layer)) {
|
if (set.hasSection(layer)) {
|
||||||
@ -82,13 +100,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.index = x | (z << 4) | (y << 8);
|
this.index = x | z << 4 | y << 8;
|
||||||
filter.applyBlock(this);
|
filter.applyBlock(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void filter(Filter filter, int yStart, int yEnd) {
|
public void filter(Filter filter, int yStart, int yEnd) {
|
||||||
for (y = yStart, index = (yStart << 8); y < yEnd; y++) {
|
for (y = yStart, index = yStart << 8; y < yEnd; y++) {
|
||||||
for (z = 0; z < 16; z++) {
|
for (z = 0; z < 16; z++) {
|
||||||
for (x = 0; x < 16; x++, index++) {
|
for (x = 0; x < 16; x++, index++) {
|
||||||
filter.applyBlock(this);
|
filter.applyBlock(this);
|
||||||
@ -99,8 +117,8 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
public void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||||
int yis = (minY << 8);
|
int yis = minY << 8;
|
||||||
int zis = (minZ << 4);
|
int zis = minZ << 4;
|
||||||
for (y = minY, index = yis; y <= maxY; y++) {
|
for (y = minY, index = yis; y <= maxY; y++) {
|
||||||
for (z = minZ, index += zis; z <= maxZ; z++) {
|
for (z = minZ, index += zis; z <= maxZ; z++) {
|
||||||
for (x = minX, index += minX; x <= maxX; x++, index++) {
|
for (x = minX, index += minX; x <= maxX; x++, index++) {
|
||||||
@ -111,7 +129,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void filter(final Filter filter, final Region region) {
|
public final void filter(Filter filter, Region region) {
|
||||||
for (y = 0, index = 0; y < 16; y++) {
|
for (y = 0, index = 0; y < 16; y++) {
|
||||||
int absY = yy + y;
|
int absY = yy + y;
|
||||||
for (z = 0; z < 16; z++) {
|
for (z = 0; z < 16; z++) {
|
||||||
@ -127,7 +145,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void filter(final Filter filter) {
|
public final void filter(Filter filter) {
|
||||||
for (y = 0, index = 0; y < 16; y++) {
|
for (y = 0, index = 0; y < 16; y++) {
|
||||||
for (z = 0; z < 16; z++) {
|
for (z = 0; z < 16; z++) {
|
||||||
for (x = 0; x < 16; x++, index++) {
|
for (x = 0; x < 16; x++, index++) {
|
||||||
@ -142,25 +160,6 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
set.setBiome(x, y, z, biome);
|
set.setBiome(x, y, z, biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOrdinal(final int ordinal) {
|
|
||||||
delegate.set(this, (char) ordinal);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBlock(final BlockState state) {
|
|
||||||
delegate.set(this, state.getOrdinalChar());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFullBlock(final BaseBlock block) {
|
|
||||||
delegate.set(this, block.getOrdinalChar());
|
|
||||||
final CompoundTag nbt = block.getNbtData();
|
|
||||||
if (nbt != null) { // TODO optimize check via ImmutableBaseBlock
|
|
||||||
set.setTile(x, yy + y, z, nbt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getX() {
|
public final int getX() {
|
||||||
return xx + x;
|
return xx + x;
|
||||||
@ -193,12 +192,12 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getChunkX() {
|
public final int getChunkX() {
|
||||||
return X;
|
return chunkX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getChunkZ() {
|
public final int getChunkZ() {
|
||||||
return Z;
|
return chunkZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final char getOrdinalChar() {
|
public final char getOrdinalChar() {
|
||||||
@ -210,12 +209,22 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
return getArr[index];
|
return getArr[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOrdinal(int ordinal) {
|
||||||
|
delegate.set(this, (char) ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final BlockState getBlock() {
|
public final BlockState getBlock() {
|
||||||
final int ordinal = getArr[index];
|
final int ordinal = getArr[index];
|
||||||
return BlockTypes.states[ordinal];
|
return BlockTypes.states[ordinal];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlock(BlockState state) {
|
||||||
|
delegate.set(this, state.getOrdinalChar());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final BaseBlock getFullBlock() {
|
public final BaseBlock getFullBlock() {
|
||||||
final BlockState state = getBlock();
|
final BlockState state = getBlock();
|
||||||
@ -227,10 +236,25 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
return state.toBaseBlock();
|
return state.toBaseBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFullBlock(BaseBlock block) {
|
||||||
|
delegate.set(this, block.getOrdinalChar());
|
||||||
|
final CompoundTag nbt = block.getNbtData();
|
||||||
|
if (nbt != null) { // TODO optimize check via ImmutableBaseBlock
|
||||||
|
set.setTile(x, yy + y, z, nbt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final CompoundTag getNbtData() {
|
public final CompoundTag getNbtData() {
|
||||||
return get.getTag(x, y + (layer << 4), z);
|
return get.getTag(x, y + (layer << 4), z);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1),
|
||||||
|
EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2),
|
||||||
|
SOUTH(Vector3.at(0, 0, 1), Flag.CARDINAL, 1, 3),
|
||||||
|
WEST(Vector3.at(-1, 0, 0), Flag.CARDINAL, 2, 0),
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNbtData(CompoundTag tag) {
|
public void setNbtData(CompoundTag tag) {
|
||||||
@ -245,19 +269,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
final BlockMaterial material = state.getMaterial();
|
final BlockMaterial material = state.getMaterial();
|
||||||
return material.hasContainer();
|
return material.hasContainer();
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1),
|
|
||||||
EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2),
|
|
||||||
SOUTH(Vector3.at(0, 0, 1), Flag.CARDINAL, 1, 3),
|
|
||||||
WEST(Vector3.at(-1, 0, 0), Flag.CARDINAL, 2, 0),
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final BlockState getBlockNorth() {
|
public final BlockState getBlockNorth() {
|
||||||
if (z > 0) {
|
if (z > 0) {
|
||||||
return states[getArr[index - 16]];
|
return states[getArr[index - 16]];
|
||||||
}
|
}
|
||||||
return getExtent().getBlock(getX(), getY(), getZ() - 1);
|
return getExtent().getBlock(getX(), getY(), getZ() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -265,7 +283,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
if (x < 15) {
|
if (x < 15) {
|
||||||
return states[getArr[index + 1]];
|
return states[getArr[index + 1]];
|
||||||
}
|
}
|
||||||
return getExtent().getBlock(getX() + 1, getY(), getZ());
|
return getExtent().getBlock(getX() + 1, getY(), getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -273,7 +291,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
if (z < 15) {
|
if (z < 15) {
|
||||||
return states[getArr[index + 16]];
|
return states[getArr[index + 16]];
|
||||||
}
|
}
|
||||||
return getExtent().getBlock(getX(), getY(), getZ() + 1);
|
return getExtent().getBlock(getX(), getY(), getZ() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -281,7 +299,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
if (x > 0) {
|
if (x > 0) {
|
||||||
return states[getArr[index - 1]];
|
return states[getArr[index - 1]];
|
||||||
}
|
}
|
||||||
return getExtent().getBlock(getX() - 1, getY(), getZ());
|
return getExtent().getBlock(getX() - 1, getY(), getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -311,7 +329,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final BlockState getBlockRelativeY(final int y) {
|
public final BlockState getBlockRelativeY(int y) {
|
||||||
final int newY = this.y + y;
|
final int newY = this.y + y;
|
||||||
final int layerAdd = newY >> 4;
|
final int layerAdd = newY >> 4;
|
||||||
switch (layerAdd) {
|
switch (layerAdd) {
|
||||||
@ -353,14 +371,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
case -12:
|
case -12:
|
||||||
case -13:
|
case -13:
|
||||||
case -14:
|
case -14:
|
||||||
case -15: {
|
case -15:
|
||||||
final int newLayer = layer + layerAdd;
|
final int newLayer = layer + layerAdd;
|
||||||
if (newLayer >= 0) {
|
if (newLayer >= 0) {
|
||||||
final int index = this.index + ((y & 15) << 8);
|
final int index = this.index + ((y & 15) << 8);
|
||||||
return states[get.sections[newLayer].get(get, newLayer, index)];
|
return states[get.sections[newLayer].get(get, newLayer, index)];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return BlockTypes.__RESERVED__.getDefaultState();
|
return BlockTypes.__RESERVED__.getDefaultState();
|
||||||
}
|
}
|
||||||
@ -383,7 +400,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BiomeType getBiomeType(int x, int z) {
|
public BiomeType getBiomeType(int x, int z) {
|
||||||
if ((x >> 4) == X && (z >> 4) == Z) {
|
if (x >> 4 == chunkX && z >> 4 == chunkZ) {
|
||||||
return get.getBiomeType(x & 15, z & 15);
|
return get.getBiomeType(x & 15, z & 15);
|
||||||
}
|
}
|
||||||
return getExtent().getBiomeType(x, z);
|
return getExtent().getBiomeType(x, z);
|
||||||
@ -391,27 +408,14 @@ public class CharFilterBlock extends ChunkFilterBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||||
if ((x >> 4) == X && (z >> 4) == Z) {
|
if (x >> 4 == chunkX && z >> 4 == chunkZ) {
|
||||||
return set.setBiome(x & 15, y, z & 15, biome);
|
return set.setBiome(x & 15, y, z & 15, biome);
|
||||||
}
|
}
|
||||||
return getExtent().setBiome(x, y, z, biome);
|
return getExtent().setBiome(x, y, z, biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface SetDelegate {
|
private interface SetDelegate {
|
||||||
|
|
||||||
void set(CharFilterBlock block, char value);
|
void set(CharFilterBlock block, char value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final SetDelegate NULL = new SetDelegate() {
|
|
||||||
@Override
|
|
||||||
public void set(final CharFilterBlock block, final char value) {
|
|
||||||
block.initSet().set(block, value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final SetDelegate FULL = new SetDelegate() {
|
|
||||||
@Override
|
|
||||||
public final void set(final CharFilterBlock block, final char value) {
|
|
||||||
block.setArr[block.index] = value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -4,24 +4,28 @@ import com.sk89q.worldedit.extent.Extent;
|
|||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
|
|
||||||
public abstract class ChunkFilterBlock extends SimpleFilterBlock {
|
public abstract class ChunkFilterBlock extends SimpleFilterBlock {
|
||||||
|
|
||||||
public ChunkFilterBlock(Extent extent) {
|
public ChunkFilterBlock(Extent extent) {
|
||||||
super(extent);
|
super(extent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract ChunkFilterBlock init(int chunkX, int chunkZ, IChunkGet chunk);
|
public abstract ChunkFilterBlock init(int chunkX, int chunkZ, IChunkGet chunk);
|
||||||
|
|
||||||
public abstract ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer);
|
public abstract ChunkFilterBlock init(IChunkGet iget, IChunkSet iset,
|
||||||
|
int layer);
|
||||||
|
|
||||||
public abstract void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask);
|
public abstract void flood(IChunkGet iget, IChunkSet iset, int layer,
|
||||||
|
Flood flood, FilterBlockMask mask);
|
||||||
|
|
||||||
|
|
||||||
public abstract void filter(Filter filter, int x, int y, int z);
|
public abstract void filter(Filter filter, int x, int y, int z);
|
||||||
|
|
||||||
public abstract void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ);
|
public abstract void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY,
|
||||||
|
int maxZ);
|
||||||
|
|
||||||
public abstract void filter(Filter filter);
|
public abstract void filter(Filter filter);
|
||||||
|
|
||||||
public abstract void filter(Filter filter, int yStart, int yEnd);
|
public abstract void filter(Filter filter, int yStart, int yEnd);
|
||||||
|
|
||||||
public abstract void filter(final Filter filter, final Region region);
|
public abstract void filter(Filter filter, Region region);
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,12 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
public class ChunkFuture implements Future<Void> {
|
public class ChunkFuture implements Future<Void> {
|
||||||
|
|
||||||
private final IChunk chunk;
|
private final IChunk chunk;
|
||||||
private volatile boolean cancelled;
|
private volatile boolean cancelled;
|
||||||
private volatile boolean done;
|
private volatile boolean done;
|
||||||
|
|
||||||
public ChunkFuture(final IChunk chunk) {
|
public ChunkFuture(IChunk chunk) {
|
||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,10 +20,9 @@ public class ChunkFuture implements Future<Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cancel(final boolean mayInterruptIfRunning) {
|
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
if (done) return false;
|
return !done;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,7 +46,8 @@ public class ChunkFuture implements Future<Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
public Void get(long timeout, TimeUnit unit)
|
||||||
|
throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
synchronized (chunk) {
|
synchronized (chunk) {
|
||||||
if (!done) {
|
if (!done) {
|
||||||
this.wait(unit.toMillis(timeout));
|
this.wait(unit.toMillis(timeout));
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
public class DelegateFilter<T extends Filter> implements IDelegateFilter {
|
public class DelegateFilter<T extends Filter> implements IDelegateFilter {
|
||||||
|
|
||||||
private final Filter parent;
|
private final Filter parent;
|
||||||
|
|
||||||
public DelegateFilter(T parent) {
|
public DelegateFilter(T parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T getParent() {
|
public T getParent() {
|
||||||
return (T) parent;
|
return (T) parent;
|
||||||
|
@ -24,43 +24,35 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
|||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class DelegateFilterBlock extends FilterBlock {
|
public class DelegateFilterBlock extends FilterBlock {
|
||||||
|
|
||||||
private final FilterBlock parent;
|
private final FilterBlock parent;
|
||||||
|
|
||||||
public DelegateFilterBlock(FilterBlock parent) {
|
public DelegateFilterBlock(FilterBlock parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BlockVector3 at(double x, double y, double z) {
|
||||||
|
return BlockVector3.at(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlockVector3 at(int x, int y, int z) {
|
||||||
|
return BlockVector3.at(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Comparator<BlockVector3> sortByCoordsYzx() {
|
||||||
|
return BlockVector3.sortByCoordsYzx();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Extent getExtent() {
|
public Extent getExtent() {
|
||||||
return parent.getExtent();
|
return parent.getExtent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOrdinal(int ordinal) {
|
|
||||||
parent.setOrdinal(ordinal);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBlock(BlockState state) {
|
|
||||||
parent.setBlock(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFullBlock(BaseBlock block) {
|
|
||||||
parent.setFullBlock(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
|
||||||
parent.setNbtData(nbtData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNbtData() {
|
public boolean hasNbtData() {
|
||||||
return parent.hasNbtData();
|
return parent.hasNbtData();
|
||||||
@ -76,21 +68,41 @@ public class DelegateFilterBlock extends FilterBlock {
|
|||||||
return parent.getOrdinal();
|
return parent.getOrdinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOrdinal(int ordinal) {
|
||||||
|
parent.setOrdinal(ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock() {
|
public BlockState getBlock() {
|
||||||
return parent.getBlock();
|
return parent.getBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlock(BlockState state) {
|
||||||
|
parent.setBlock(state);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseBlock getFullBlock() {
|
public BaseBlock getFullBlock() {
|
||||||
return parent.getFullBlock();
|
return parent.getFullBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFullBlock(BaseBlock block) {
|
||||||
|
parent.setFullBlock(block);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getNbtData() {
|
public CompoundTag getNbtData() {
|
||||||
return parent.getNbtData();
|
return parent.getNbtData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||||
|
parent.setNbtData(nbtData);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockVector3 getMinimumPoint() {
|
public BlockVector3 getMinimumPoint() {
|
||||||
return parent.getMinimumPoint();
|
return parent.getMinimumPoint();
|
||||||
@ -241,18 +253,6 @@ public class DelegateFilterBlock extends FilterBlock {
|
|||||||
return parent.getStateRelativeY(orDefault, y);
|
return parent.getStateRelativeY(orDefault, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockVector3 at(double x, double y, double z) {
|
|
||||||
return BlockVector3.at(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BlockVector3 at(int x, int y, int z) {
|
|
||||||
return BlockVector3.at(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Comparator<BlockVector3> sortByCoordsYzx() {
|
|
||||||
return BlockVector3.sortByCoordsYzx();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MutableBlockVector3 setComponents(double x, double y, double z) {
|
public MutableBlockVector3 setComponents(double x, double y, double z) {
|
||||||
return parent.setComponents(x, y, z);
|
return parent.setComponents(x, y, z);
|
||||||
@ -479,7 +479,8 @@ public class DelegateFilterBlock extends FilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
|
public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX,
|
||||||
|
double translateZ) {
|
||||||
return parent.transform2D(angle, aboutX, aboutZ, translateX, translateZ);
|
return parent.transform2D(angle, aboutX, aboutZ, translateX, translateZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,7 +561,8 @@ public class DelegateFilterBlock extends FilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) {
|
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY,
|
||||||
|
boolean ignoreAir) {
|
||||||
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir);
|
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,18 +572,23 @@ public class DelegateFilterBlock extends FilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) {
|
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin,
|
||||||
|
int failedMax) {
|
||||||
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax);
|
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) {
|
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin,
|
||||||
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask);
|
int failedMax, Mask mask) {
|
||||||
|
return parent
|
||||||
|
.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) {
|
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin,
|
||||||
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir);
|
int failedMax, boolean ignoreAir) {
|
||||||
|
return parent
|
||||||
|
.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -595,12 +602,14 @@ public class DelegateFilterBlock extends FilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException {
|
public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity,
|
||||||
|
boolean rotate) throws WorldEditException {
|
||||||
parent.addSchems(region, mask, clipboards, rarity, rotate);
|
parent.addSchems(region, mask, clipboards, rarity, rotate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void spawnResource(Region region, Resource gen, int rarity, int frequency) throws WorldEditException {
|
public void spawnResource(Region region, Resource gen, int rarity, int frequency)
|
||||||
|
throws WorldEditException {
|
||||||
parent.spawnResource(region, gen, rarity, frequency);
|
parent.spawnResource(region, gen, rarity, frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,7 +619,8 @@ public class DelegateFilterBlock extends FilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException {
|
public void addOre(Region region, Mask mask, Pattern material, int size, int frequency,
|
||||||
|
int rarity, int minY, int maxY) throws WorldEditException {
|
||||||
parent.addOre(region, mask, material, size, frequency, rarity, minY, maxY);
|
parent.addOre(region, mask, material, size, frequency, rarity, minY, maxY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,12 +681,14 @@ public class DelegateFilterBlock extends FilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
|
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block)
|
||||||
|
throws WorldEditException {
|
||||||
return parent.setBlock(position, block);
|
return parent.setBlock(position, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
|
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block)
|
||||||
|
throws WorldEditException {
|
||||||
return parent.setBlock(x, y, z, block);
|
return parent.setBlock(x, y, z, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
public interface DirectionMask {
|
public interface DirectionMask {
|
||||||
|
|
||||||
boolean apply(int fromX, int fromY, int fromZ, int toX, int toY, int toZ);
|
boolean apply(int fromX, int fromY, int fromZ, int toX, int toY, int toZ);
|
||||||
}
|
}
|
||||||
|
@ -2,31 +2,33 @@ package com.boydti.fawe.beta;
|
|||||||
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A filter is an interface used for setting blocks
|
* A filter is an interface used for setting blocks.
|
||||||
*/
|
*/
|
||||||
public interface Filter {
|
public interface Filter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a chunk should be read.
|
* Checks whether a chunk should be read.
|
||||||
*
|
*
|
||||||
* @param chunkX
|
* @param chunkX the x coordinate in the chunk
|
||||||
* @param chunkZ
|
* @param chunkZ the z coordinate in the chunk
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
default boolean appliesChunk(final int chunkX, final int chunkZ) {
|
default boolean appliesChunk(@Range(from = 0, to = 15) int chunkX,
|
||||||
|
@Range(from = 0, to = 15) int chunkZ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do something with the IChunk<br>
|
* Do something with the IChunk<br> - Return null if you don't want to filter blocks<br> -
|
||||||
* - Return null if you don't want to filter blocks<br>
|
* Return the chunk if you do want to filter blocks<br>
|
||||||
* - Return the chunk if you do want to filter blocks<br>
|
|
||||||
*
|
*
|
||||||
* @param chunk
|
* @param chunk
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
default IChunk applyChunk(final IChunk chunk, @Nullable Region region) {
|
default IChunk applyChunk(IChunk chunk, @Nullable Region region) {
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,27 +37,27 @@ public interface Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make changes to the block here<br>
|
* Make changes to the block here<br> - e.g. block.setId(...)<br> - Note: Performance is
|
||||||
* - e.g. block.setId(...)<br>
|
* critical here<br>
|
||||||
* - Note: Performance is critical here<br>
|
|
||||||
*
|
*
|
||||||
* @param block
|
* @param block
|
||||||
*/
|
*/
|
||||||
default void applyBlock(final FilterBlock block) {
|
default void applyBlock(FilterBlock block) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do something with the IChunk after block filtering<br>
|
* Do something with the IChunk after block filtering.
|
||||||
*
|
*
|
||||||
* @param chunk
|
* @param chunk
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
default void finishChunk(final IChunk chunk) {
|
default void finishChunk(IChunk chunk) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fork this for use by another thread
|
* Fork this for use by another thread - Typically filters are simple and don't need to create
|
||||||
* - Typically filters are simple and don't need to create another copy to be thread safe here
|
* another copy to be thread safe here
|
||||||
|
*
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
default Filter fork() {
|
default Filter fork() {
|
||||||
|
@ -7,34 +7,35 @@ import com.sk89q.worldedit.math.BlockVector3;
|
|||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static com.sk89q.worldedit.world.block.BlockTypes.states;
|
|
||||||
|
|
||||||
public abstract class FilterBlock extends BlockVector3 implements Extent, TileEntityBlock {
|
public abstract class FilterBlock extends BlockVector3 implements Extent, TileEntityBlock {
|
||||||
|
|
||||||
public abstract Extent getExtent();
|
public abstract Extent getExtent();
|
||||||
|
|
||||||
public abstract void setOrdinal(int ordinal);
|
|
||||||
|
|
||||||
public abstract void setBlock(BlockState state);
|
|
||||||
|
|
||||||
public abstract void setFullBlock(BaseBlock block);
|
|
||||||
|
|
||||||
public void setBiome(BiomeType biome) {
|
public void setBiome(BiomeType biome) {
|
||||||
setBiome(getX(), getY(), getZ(), biome);
|
setBiome(getX(), getY(), getZ(), biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract int getOrdinal();
|
public abstract int getOrdinal();
|
||||||
|
|
||||||
|
public abstract void setOrdinal(int ordinal);
|
||||||
|
|
||||||
public abstract BlockState getBlock();
|
public abstract BlockState getBlock();
|
||||||
|
|
||||||
|
public abstract void setBlock(BlockState state);
|
||||||
|
|
||||||
public abstract BaseBlock getFullBlock();
|
public abstract BaseBlock getFullBlock();
|
||||||
|
|
||||||
|
public abstract void setFullBlock(BaseBlock block);
|
||||||
|
|
||||||
|
@Override
|
||||||
public abstract CompoundTag getNbtData();
|
public abstract CompoundTag getNbtData();
|
||||||
|
|
||||||
|
@Override
|
||||||
public abstract void setNbtData(@Nullable CompoundTag nbtData);
|
public abstract void setNbtData(@Nullable CompoundTag nbtData);
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasNbtData() {
|
public boolean hasNbtData() {
|
||||||
return getNbtData() != null;
|
return getNbtData() != null;
|
||||||
}
|
}
|
||||||
@ -83,8 +84,8 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
|
|||||||
return getBlock(getX() - 1, getY(), getZ());
|
return getBlock(getX() - 1, getY(), getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockState getBlockRelativeY(final int y) {
|
public BlockState getBlockRelativeY(int y) {
|
||||||
return getBlock(getX(), getY() + y , getZ());
|
return getBlock(getX(), getY() + y, getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -119,51 +120,62 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
|
|||||||
/*
|
/*
|
||||||
Extent
|
Extent
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean setOrdinal(Extent orDefault, int ordinal) {
|
public boolean setOrdinal(Extent orDefault, int ordinal) {
|
||||||
setOrdinal(ordinal);
|
setOrdinal(ordinal);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setBlock(Extent orDefault, BlockState state) {
|
public boolean setBlock(Extent orDefault, BlockState state) {
|
||||||
setBlock(state);
|
setBlock(state);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
|
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
|
||||||
setFullBlock(block);
|
setFullBlock(block);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setBiome(Extent orDefault, BiomeType biome) {
|
public boolean setBiome(Extent orDefault, BiomeType biome) {
|
||||||
setBiome(biome);
|
setBiome(biome);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getOrdinal(Extent orDefault) {
|
public int getOrdinal(Extent orDefault) {
|
||||||
return getOrdinal();
|
return getOrdinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BlockState getBlock(Extent orDefault) {
|
public BlockState getBlock(Extent orDefault) {
|
||||||
return getBlock();
|
return getBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BaseBlock getFullBlock(Extent orDefault) {
|
public BaseBlock getFullBlock(Extent orDefault) {
|
||||||
return getFullBlock();
|
return getFullBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public CompoundTag getNbtData(Extent orDefault) {
|
public CompoundTag getNbtData(Extent orDefault) {
|
||||||
return getNbtData();
|
return getNbtData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BlockState getOrdinalBelow(Extent orDefault) {
|
public BlockState getOrdinalBelow(Extent orDefault) {
|
||||||
return getBlockBelow();
|
return getBlockBelow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BlockState getStateAbove(Extent orDefault) {
|
public BlockState getStateAbove(Extent orDefault) {
|
||||||
return getBlockAbove();
|
return getBlockAbove();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockState getStateRelativeY(Extent orDefault, final int y) {
|
@Override
|
||||||
|
public BlockState getStateRelativeY(Extent orDefault, int y) {
|
||||||
return getBlockRelativeY(y);
|
return getBlockRelativeY(y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
public interface FilterBlockMask {
|
public interface FilterBlockMask {
|
||||||
boolean applyBlock(final FilterBlock block);
|
|
||||||
|
boolean applyBlock(FilterBlock block);
|
||||||
}
|
}
|
@ -6,27 +6,23 @@ import com.boydti.fawe.util.MathMan;
|
|||||||
import com.sk89q.worldedit.util.Direction;
|
import com.sk89q.worldedit.util.Direction;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
public class Flood {
|
public class Flood {
|
||||||
|
|
||||||
private final int maxBranch;
|
private final int maxBranch;
|
||||||
private final int maxDepth;
|
private final int maxDepth;
|
||||||
private final Direction[] directions;
|
private final Direction[] directions;
|
||||||
|
private final Long2ObjectLinkedOpenHashMap<long[][]> chunkVisits;
|
||||||
|
private final Long2ObjectLinkedOpenHashMap<int[][]> chunkQueues;
|
||||||
private int[] queue;
|
private int[] queue;
|
||||||
private long[] visit;
|
private long[] visit;
|
||||||
|
|
||||||
private int[][] queues;
|
private int[][] queues;
|
||||||
private long[][] visits;
|
private long[][] visits;
|
||||||
|
|
||||||
private int chunkX;
|
private int chunkX;
|
||||||
private int chunkYLayer;
|
private int chunkYLayer;
|
||||||
private int chunkZ;
|
private int chunkZ;
|
||||||
|
|
||||||
private ConcurrentLinkedQueue<int[]> queuePool = new ConcurrentLinkedQueue<>();
|
private ConcurrentLinkedQueue<int[]> queuePool = new ConcurrentLinkedQueue<>();
|
||||||
private final Long2ObjectLinkedOpenHashMap<long[][]> chunkVisits;
|
|
||||||
private final Long2ObjectLinkedOpenHashMap<int[][]> chunkQueues;
|
|
||||||
|
|
||||||
public Flood(int maxBranch, int maxDepth, Direction[] directions) {
|
public Flood(int maxBranch, int maxDepth, Direction[] directions) {
|
||||||
this.maxBranch = maxBranch;
|
this.maxBranch = maxBranch;
|
||||||
@ -68,7 +64,7 @@ public class Flood {
|
|||||||
long pair = MathMan.pairInt(chunkX, chunkZ);
|
long pair = MathMan.pairInt(chunkX, chunkZ);
|
||||||
int layer = y >> 4;
|
int layer = y >> 4;
|
||||||
int[] section = getOrCreateQueue(pair, layer);
|
int[] section = getOrCreateQueue(pair, layer);
|
||||||
int val = (x & 15) + ((z & 15) << 4) + ((y & 15) << 8) + (depth << 12);
|
int val = (x & 15) + ((z & 15) << 4) + ((y & 15) << 8) + (depth << 12);
|
||||||
push(section, val);
|
push(section, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,12 +167,12 @@ public class Flood {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void set(long[] bits, int i) {
|
public void set(long[] bits, int i) {
|
||||||
bits[i >> 6] |= (1L << (i & 0x3F));
|
bits[i >> 6] |= 1L << (i & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean getAndSet(long[] bits, int i) {
|
public final boolean getAndSet(long[] bits, int i) {
|
||||||
int index = i >> 6;
|
int index = i >> 6;
|
||||||
long offset = (1L << (i & 0x3F));
|
long offset = 1L << (i & 0x3F);
|
||||||
long val = bits[index];
|
long val = bits[index];
|
||||||
if ((val & offset) != 0) {
|
if ((val & offset) != 0) {
|
||||||
return true;
|
return true;
|
||||||
@ -186,7 +182,7 @@ public class Flood {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean get(long[] bits, final int i) {
|
public boolean get(long[] bits, int i) {
|
||||||
return (bits[i >> 6] & (1L << (i & 0x3F))) != 0;
|
return (bits[i >> 6] & 1L << (i & 0x3F)) != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ package com.boydti.fawe.beta;
|
|||||||
* Shared interface for IGetBlocks and ISetBlocks
|
* Shared interface for IGetBlocks and ISetBlocks
|
||||||
*/
|
*/
|
||||||
public interface IBlocks extends Trimable {
|
public interface IBlocks extends Trimable {
|
||||||
|
|
||||||
boolean hasSection(int layer);
|
boolean hasSection(int layer);
|
||||||
|
|
||||||
IBlocks reset();
|
IBlocks reset();
|
||||||
|
@ -12,12 +12,14 @@ import java.util.concurrent.Future;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a chunk in the queue {@link IQueueExtent}
|
* Represents a chunk in the queue {@link IQueueExtent} Used for getting and setting blocks / biomes
|
||||||
* Used for getting and setting blocks / biomes / entities
|
* / entities
|
||||||
*/
|
*/
|
||||||
public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChunkGet {
|
public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChunkGet {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize at the location
|
* Initialize at the location
|
||||||
|
*
|
||||||
* @param extent
|
* @param extent
|
||||||
* @param x
|
* @param x
|
||||||
* @param z
|
* @param z
|
||||||
@ -31,7 +33,8 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
|
|||||||
int getZ();
|
int getZ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the chunk is a delegate, returns it's paren'ts root
|
* If the chunk is a delegate, returns it's parent's root
|
||||||
|
*
|
||||||
* @return root IChunk
|
* @return root IChunk
|
||||||
*/
|
*/
|
||||||
default IChunk getRoot() {
|
default IChunk getRoot() {
|
||||||
@ -39,20 +42,25 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Checks if there are any queued changes for this chunk.
|
||||||
|
*
|
||||||
* @return true if no changes are queued for this chunk
|
* @return true if no changes are queued for this chunk
|
||||||
*/
|
*/
|
||||||
boolean isEmpty();
|
boolean isEmpty();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the queued changes to the world<br>
|
* Apply the queued changes to the world containing this chunk.
|
||||||
* The future returned may return another future<br>
|
* <p>The future returned may return another future. To ensure completion keep calling {@link
|
||||||
* To ensure completion keep calling {@link Future#get()} on each result
|
* Future#get()} on each result.</p>
|
||||||
|
*
|
||||||
* @return Futures
|
* @return Futures
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
T call();
|
T call();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call and join
|
* Call and join
|
||||||
|
*
|
||||||
* @throws ExecutionException
|
* @throws ExecutionException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
@ -66,11 +74,10 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter
|
* Filter
|
||||||
|
*
|
||||||
* @param filter the filter
|
* @param filter the filter
|
||||||
* @param block The filter block
|
* @param block The filter block
|
||||||
* @param region The region allowed to filter (may be null)
|
* @param region The region allowed to filter (may be null)
|
||||||
* @param unitialized a mutable block vector (buffer)
|
|
||||||
* @param unitialized2 a mutable block vector (buffer)
|
|
||||||
*/
|
*/
|
||||||
void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region);
|
void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region);
|
||||||
|
|
||||||
@ -81,13 +88,16 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
|
|||||||
|
|
||||||
boolean setBlock(int x, int y, int z, BlockStateHolder block);
|
boolean setBlock(int x, int y, int z, BlockStateHolder block);
|
||||||
|
|
||||||
/* get - from the world */
|
@Override
|
||||||
BiomeType getBiomeType(int x, int z);
|
BiomeType getBiomeType(int x, int z);
|
||||||
|
|
||||||
|
@Override
|
||||||
BlockState getBlock(int x, int y, int z);
|
BlockState getBlock(int x, int y, int z);
|
||||||
|
|
||||||
|
@Override
|
||||||
BaseBlock getFullBlock(int x, int y, int z);
|
BaseBlock getFullBlock(int x, int y, int z);
|
||||||
|
|
||||||
|
@Override
|
||||||
CompoundTag getTag(int x, int y, int z);
|
CompoundTag getTag(int x, int y, int z);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,9 +7,10 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
|||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for getting blocks
|
* An interface for getting blocks.
|
||||||
*/
|
*/
|
||||||
public interface IChunkGet extends IBlocks, Trimable, InputExtent {
|
public interface IChunkGet extends IBlocks, Trimable, InputExtent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
BaseBlock getFullBlock(int x, int y, int z);
|
BaseBlock getFullBlock(int x, int y, int z);
|
||||||
|
|
||||||
|
@ -6,16 +6,16 @@ import com.sk89q.worldedit.function.operation.Operation;
|
|||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for setting blocks
|
* Interface for setting blocks
|
||||||
*/
|
*/
|
||||||
public interface IChunkSet extends IBlocks, OutputExtent {
|
public interface IChunkSet extends IBlocks, OutputExtent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean setBiome(int x, int y, int z, BiomeType biome);
|
boolean setBiome(int x, int y, int z, BiomeType biome);
|
||||||
|
|
||||||
|
@ -6,18 +6,20 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
|||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate for IChunk
|
* Delegate for IChunk
|
||||||
|
*
|
||||||
* @param <U> parent class
|
* @param <U> parent class
|
||||||
*/
|
*/
|
||||||
public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
||||||
|
|
||||||
U getParent();
|
U getParent();
|
||||||
|
|
||||||
|
@Override
|
||||||
default IChunk getRoot() {
|
default IChunk getRoot() {
|
||||||
IChunk root = getParent();
|
IChunk root = getParent();
|
||||||
while (root instanceof IDelegateChunk) {
|
while (root instanceof IDelegateChunk) {
|
||||||
@ -48,32 +50,32 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
|
default boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||||
return getParent().setBiome(x, y, z, biome);
|
return getParent().setBiome(x, y, z, biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder holder) {
|
default boolean setBlock(int x, int y, int z, BlockStateHolder holder) {
|
||||||
return getParent().setBlock(x, y, z, holder);
|
return getParent().setBlock(x, y, z, holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default BiomeType getBiomeType(final int x, final int z) {
|
default BiomeType getBiomeType(int x, int z) {
|
||||||
return getParent().getBiomeType(x, z);
|
return getParent().getBiomeType(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default BlockState getBlock(final int x, final int y, final int z) {
|
default BlockState getBlock(int x, int y, int z) {
|
||||||
return getParent().getBlock(x, y, z);
|
return getParent().getBlock(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default BaseBlock getFullBlock(final int x, final int y, final int z) {
|
default BaseBlock getFullBlock(int x, int y, int z) {
|
||||||
return getParent().getFullBlock(x, y, z);
|
return getParent().getFullBlock(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void init(final IQueueExtent extent, final int chunkX, final int chunkZ) {
|
default void init(IQueueExtent extent, int chunkX, int chunkZ) {
|
||||||
getParent().init(extent, chunkX, chunkZ);
|
getParent().init(extent, chunkX, chunkZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +91,7 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean trim(final boolean aggressive) {
|
default boolean trim(boolean aggressive) {
|
||||||
return getParent().trim(aggressive);
|
return getParent().trim(aggressive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,12 +115,16 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
|||||||
return getParent().isEmpty();
|
return getParent().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
default <T extends IChunk> T findParent(final Class<T> clazz) {
|
default <T extends IChunk> T findParent(Class<T> clazz) {
|
||||||
IChunk root = getParent();
|
IChunk root = getParent();
|
||||||
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
|
if (clazz.isAssignableFrom(root.getClass())) {
|
||||||
|
return (T) root;
|
||||||
|
}
|
||||||
while (root instanceof IDelegateChunk) {
|
while (root instanceof IDelegateChunk) {
|
||||||
root = ((IDelegateChunk) root).getParent();
|
root = ((IDelegateChunk) root).getParent();
|
||||||
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
|
if (clazz.isAssignableFrom(root.getClass())) {
|
||||||
|
return (T) root;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public interface IDelegateFilter extends Filter {
|
public interface IDelegateFilter extends Filter {
|
||||||
|
|
||||||
Filter getParent();
|
Filter getParent();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,37 +1,37 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
import com.boydti.fawe.beta.implementation.WorldChunkCache;
|
import com.boydti.fawe.beta.implementation.WorldChunkCache;
|
||||||
|
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate for IQueueExtent
|
* Delegate for IQueueExtent
|
||||||
*/
|
*/
|
||||||
public interface IDelegateQueueExtent extends IQueueExtent {
|
public interface IDelegateQueueExtent extends IQueueExtent {
|
||||||
|
|
||||||
IQueueExtent getParent();
|
IQueueExtent getParent();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void init(final WorldChunkCache cache) {
|
default void init(WorldChunkCache cache) {
|
||||||
getParent().init(cache);
|
getParent().init(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default IChunk getCachedChunk(final int x, final int z) {
|
default IChunk getCachedChunk(int x, int z) {
|
||||||
return getParent().getCachedChunk(x, z);
|
return getParent().getCachedChunk(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default Future<?> submit(final IChunk chunk) {
|
default Future<?> submit(IChunk chunk) {
|
||||||
return getParent().submit(chunk);
|
return getParent().submit(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default IChunk create(final boolean full) {
|
default IChunk create(boolean isFull) {
|
||||||
return getParent().create(full);
|
return getParent().create(isFull);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default IChunk wrap(final IChunk root) {
|
default IChunk wrap(IChunk root) {
|
||||||
return getParent().wrap(root);
|
return getParent().wrap(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public interface IDelegateQueueExtent extends IQueueExtent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean trim(final boolean aggressive) {
|
default boolean trim(boolean aggressive) {
|
||||||
return getParent().trim(aggressive);
|
return getParent().trim(aggressive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,13 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
|||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
import java.io.Flushable;
|
import java.io.Flushable;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: implement Extent (need to refactor Extent first)
|
* TODO: implement Extent (need to refactor Extent first) Interface for a queue based extent which
|
||||||
* Interface for a queue based extent which uses chunks
|
* uses chunks
|
||||||
*/
|
*/
|
||||||
public interface IQueueExtent extends Flushable, Trimable, Extent {
|
public interface IQueueExtent extends Flushable, Trimable, Extent {
|
||||||
|
|
||||||
@ -40,12 +39,14 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link WorldChunkCache}
|
* Get the {@link WorldChunkCache}
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IChunkGet getCachedGet(int x, int z, Supplier<IChunkGet> supplier);
|
IChunkGet getCachedGet(int x, int z, Supplier<IChunkGet> supplier);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the IChunk at a position (and cache it if it's not already)
|
* Get the IChunk at a position (and cache it if it's not already)
|
||||||
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* @param z
|
* @param z
|
||||||
* @return IChunk
|
* @return IChunk
|
||||||
@ -54,24 +55,26 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit the chunk so that it's changes are applied to the world
|
* Submit the chunk so that it's changes are applied to the world
|
||||||
|
*
|
||||||
* @param chunk
|
* @param chunk
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
<T extends Future<T>> T submit(IChunk<T> chunk);
|
<T extends Future<T>> T submit(IChunk<T> chunk);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder state) {
|
default boolean setBlock(int x, int y, int z, BlockStateHolder state) {
|
||||||
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
||||||
return chunk.setBlock(x & 15, y, z & 15, state);
|
return chunk.setBlock(x & 15, y, z & 15, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
|
default boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||||
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
||||||
return chunk.setBiome(x & 15, y, z & 15, biome);
|
return chunk.setBiome(x & 15, y, z & 15, biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
default BlockState getBlock(final int x, final int y, final int z) {
|
@Override
|
||||||
|
default BlockState getBlock(int x, int y, int z) {
|
||||||
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
||||||
return chunk.getBlock(x & 15, y, z & 15);
|
return chunk.getBlock(x & 15, y, z & 15);
|
||||||
}
|
}
|
||||||
@ -82,7 +85,7 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
|
|||||||
return chunk.getFullBlock(x & 15, y, z & 15);
|
return chunk.getFullBlock(x & 15, y, z & 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
default BiomeType getBiome(final int x, final int z) {
|
default BiomeType getBiome(int x, int z) {
|
||||||
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
|
||||||
return chunk.getBiomeType(x & 15, z & 15);
|
return chunk.getBiomeType(x & 15, z & 15);
|
||||||
}
|
}
|
||||||
@ -98,26 +101,27 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new root IChunk object<br>
|
* Create a new root IChunk object<br> - Full chunks will be reused, so a more optimized chunk
|
||||||
* - Full chunks will be reused, so a more optimized chunk can be returned in that case<br>
|
* can be returned in that case<br> - Don't wrap the chunk, that should be done in {@link
|
||||||
* - Don't wrap the chunk, that should be done in {@link #wrap(IChunk)}
|
* #wrap(IChunk)}
|
||||||
* @param full
|
*
|
||||||
|
* @param isFull true if a more optimized chunk should be returned
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IChunk create(boolean full);
|
IChunk create(boolean isFull);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap the chunk object (i.e. for region restrictions / limits etc.)
|
* Wrap the chunk object (i.e. for region restrictions / limits etc.)
|
||||||
|
*
|
||||||
* @param root
|
* @param root
|
||||||
* @return wrapped chunk
|
* @return wrapped chunk
|
||||||
*/
|
*/
|
||||||
default IChunk wrap(final IChunk root) {
|
default IChunk wrap(IChunk root) {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flush all changes to the world
|
* Flush all changes to the world - Best to call this async so it doesn't hang the server
|
||||||
* - Best to call this async so it doesn't hang the server
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
void flush();
|
void flush();
|
||||||
|
@ -8,6 +8,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
|||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
|
|
||||||
public class NorthVector extends BlockVector3 {
|
public class NorthVector extends BlockVector3 {
|
||||||
|
|
||||||
private final BlockVector3 parent;
|
private final BlockVector3 parent;
|
||||||
|
|
||||||
public NorthVector(BlockVector3 parent) {
|
public NorthVector(BlockVector3 parent) {
|
||||||
@ -34,55 +35,67 @@ public class NorthVector extends BlockVector3 {
|
|||||||
return parent.getZ();
|
return parent.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setOrdinal(Extent orDefault, int ordinal) {
|
public boolean setOrdinal(Extent orDefault, int ordinal) {
|
||||||
return orDefault.setBlock(this, BlockState.getFromOrdinal(ordinal));
|
return orDefault.setBlock(this, BlockState.getFromOrdinal(ordinal));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setBlock(Extent orDefault, BlockState state) {
|
public boolean setBlock(Extent orDefault, BlockState state) {
|
||||||
return orDefault.setBlock(this, state);
|
return orDefault.setBlock(this, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
|
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
|
||||||
return orDefault.setBlock(this, block);
|
return orDefault.setBlock(this, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setBiome(Extent orDefault, BiomeType biome) {
|
public boolean setBiome(Extent orDefault, BiomeType biome) {
|
||||||
return orDefault.setBiome(getX(), getY(), getZ(), biome);
|
return orDefault.setBiome(getX(), getY(), getZ(), biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getOrdinal(Extent orDefault) {
|
public int getOrdinal(Extent orDefault) {
|
||||||
return getBlock(orDefault).getOrdinal();
|
return getBlock(orDefault).getOrdinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public char getOrdinalChar(Extent orDefault) {
|
public char getOrdinalChar(Extent orDefault) {
|
||||||
return (char) getOrdinal(orDefault);
|
return (char) getOrdinal(orDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BlockState getBlock(Extent orDefault) {
|
public BlockState getBlock(Extent orDefault) {
|
||||||
return orDefault.getBlock(this);
|
return orDefault.getBlock(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BaseBlock getFullBlock(Extent orDefault) {
|
public BaseBlock getFullBlock(Extent orDefault) {
|
||||||
return orDefault.getFullBlock(this);
|
return orDefault.getFullBlock(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public CompoundTag getNbtData(Extent orDefault) {
|
public CompoundTag getNbtData(Extent orDefault) {
|
||||||
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData();
|
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BlockState getOrdinalBelow(Extent orDefault) {
|
public BlockState getOrdinalBelow(Extent orDefault) {
|
||||||
return getStateRelative(orDefault, 0, -1, 0);
|
return getStateRelative(orDefault, 0, -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BlockState getStateAbove(Extent orDefault) {
|
public BlockState getStateAbove(Extent orDefault) {
|
||||||
return getStateRelative(orDefault, 0, 1, 0);
|
return getStateRelative(orDefault, 0, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockState getStateRelativeY(Extent orDefault, final int y) {
|
@Override
|
||||||
|
public BlockState getStateRelativeY(Extent orDefault, int y) {
|
||||||
return getStateRelative(orDefault, 0, y, 0);
|
return getStateRelative(orDefault, 0, y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockState getStateRelative(Extent orDefault, final int x, final int y, final int z) {
|
public BlockState getStateRelative(Extent orDefault, int x, int y, int z) {
|
||||||
return getFullBlockRelative(orDefault, x, y, z).toBlockState();
|
return getFullBlockRelative(orDefault, x, y, z).toBlockState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.beta;
|
|||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
|
|
||||||
public abstract class SimpleFilterBlock extends FilterBlock {
|
public abstract class SimpleFilterBlock extends FilterBlock {
|
||||||
|
|
||||||
private final Extent extent;
|
private final Extent extent;
|
||||||
|
|
||||||
public SimpleFilterBlock(Extent extent) {
|
public SimpleFilterBlock(Extent extent) {
|
||||||
|
@ -5,7 +5,6 @@ import com.sk89q.worldedit.extent.Extent;
|
|||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class SingleFilterBlock extends FilterBlock {
|
public class SingleFilterBlock extends FilterBlock {
|
||||||
@ -26,29 +25,29 @@ public class SingleFilterBlock extends FilterBlock {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrdinal() {
|
||||||
|
return block.getOrdinal();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOrdinal(int ordinal) {
|
public void setOrdinal(int ordinal) {
|
||||||
setBlock(BlockState.getFromOrdinal(ordinal));
|
setBlock(BlockState.getFromOrdinal(ordinal));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlock() {
|
||||||
|
return block.toBlockState();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBlock(BlockState state) {
|
public void setBlock(BlockState state) {
|
||||||
setFullBlock(state.toBaseBlock(block.getNbtData()));
|
setFullBlock(state.toBaseBlock(block.getNbtData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFullBlock(BaseBlock block) {
|
public BaseBlock getFullBlock() {
|
||||||
this.block = block;
|
return block;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
|
||||||
block = block.toBaseBlock(nbtData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getOrdinal() {
|
|
||||||
return block.getOrdinal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
@ -57,13 +56,8 @@ public class SingleFilterBlock extends FilterBlock {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock() {
|
public void setFullBlock(BaseBlock block) {
|
||||||
return block.toBlockState();
|
this.block = block;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BaseBlock getFullBlock() {
|
|
||||||
return block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,6 +65,11 @@ public class SingleFilterBlock extends FilterBlock {
|
|||||||
return block.getNbtData();
|
return block.getNbtData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||||
|
block = block.toBaseBlock(nbtData);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return x;
|
return x;
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for objects that can be trimmed (memory related)<br>
|
* Interface for objects that can be trimmed (memory related)<br> - Trimming will reduce it's memory
|
||||||
* - Trimming will reduce it's memory footprint
|
* footprint
|
||||||
*/
|
*/
|
||||||
public interface Trimable {
|
public interface Trimable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trim the object, reducing it's memory footprint
|
* Trim the object, reducing it's memory footprint
|
||||||
* @param aggressive if trimming should be aggressive e.g. Not return early when the first element cannot be trimmed
|
*
|
||||||
|
* @param aggressive if trimming should be aggressive e.g. Not return early when the first
|
||||||
|
* element cannot be trimmed
|
||||||
* @return if this object is empty at the end of the trim, and can therefore be deleted
|
* @return if this object is empty at the end of the trim, and can therefore be deleted
|
||||||
*/
|
*/
|
||||||
boolean trim(boolean aggressive);
|
boolean trim(boolean aggressive);
|
||||||
|
@ -2,11 +2,11 @@ package com.boydti.fawe.beta.filters;
|
|||||||
|
|
||||||
import com.boydti.fawe.beta.FilterBlock;
|
import com.boydti.fawe.beta.FilterBlock;
|
||||||
import com.boydti.fawe.beta.FilterBlockMask;
|
import com.boydti.fawe.beta.FilterBlockMask;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class ArrayImageMask implements FilterBlockMask {
|
public class ArrayImageMask implements FilterBlockMask {
|
||||||
|
|
||||||
private final ThreadLocalRandom random;
|
private final ThreadLocalRandom random;
|
||||||
private final boolean white;
|
private final boolean white;
|
||||||
private final BufferedImage image;
|
private final BufferedImage image;
|
||||||
@ -16,9 +16,10 @@ public class ArrayImageMask implements FilterBlockMask {
|
|||||||
this.white = white;
|
this.white = white;
|
||||||
this.random = ThreadLocalRandom.current();
|
this.random = ThreadLocalRandom.current();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applyBlock(FilterBlock block) {
|
public boolean applyBlock(FilterBlock block) {
|
||||||
int height = image.getRGB(block.getX(), block.getZ()) & 0xFF;
|
int height = image.getRGB(block.getX(), block.getZ()) & 0xFF;
|
||||||
return ((height == 255 || height > 0 && !white && random.nextInt(256) <= height));
|
return height == 255 || height > 0 && !white && random.nextInt(256) <= height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.beta.filters;
|
|||||||
import com.boydti.fawe.beta.FilterBlock;
|
import com.boydti.fawe.beta.FilterBlock;
|
||||||
|
|
||||||
public class CountFilter extends ForkedFilter<CountFilter> {
|
public class CountFilter extends ForkedFilter<CountFilter> {
|
||||||
|
|
||||||
private int total;
|
private int total;
|
||||||
|
|
||||||
public CountFilter() {
|
public CountFilter() {
|
||||||
@ -23,12 +24,8 @@ public class CountFilter extends ForkedFilter<CountFilter> {
|
|||||||
this.total += filter.getTotal();
|
this.total += filter.getTotal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Implementation
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void applyBlock(final FilterBlock block) {
|
public final void applyBlock(FilterBlock block) {
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,12 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DistrFilter extends ForkedFilter<DistrFilter> {
|
public class DistrFilter extends ForkedFilter<DistrFilter> {
|
||||||
|
|
||||||
private final int[] counter = new int[BlockTypes.states.length];
|
private final int[] counter = new int[BlockTypes.states.length];
|
||||||
|
|
||||||
public DistrFilter() {
|
public DistrFilter() {
|
||||||
@ -34,12 +36,8 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Implementation
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void applyBlock(final FilterBlock block) {
|
public final void applyBlock(FilterBlock block) {
|
||||||
counter[block.getOrdinal()]++;
|
counter[block.getOrdinal()]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,9 +53,7 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getTotal() {
|
public int getTotal() {
|
||||||
int total = 0;
|
return Arrays.stream(counter).sum();
|
||||||
for (int value : counter) total += value;
|
|
||||||
return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Countable<BlockState>> getDistribution() {
|
public List<Countable<BlockState>> getDistribution() {
|
||||||
@ -92,13 +88,13 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
|
|||||||
return distribution;
|
return distribution;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print(final Actor actor, final long size) {
|
public void print(Actor actor, long size) {
|
||||||
for (Countable c : getDistribution()) {
|
for (Countable c : getDistribution()) {
|
||||||
final String name = c.getID().toString();
|
final String name = c.getID().toString();
|
||||||
final String str = String.format("%-7s (%.3f%%) %s",
|
final String str = String.format("%-7s (%.3f%%) %s",
|
||||||
String.valueOf(c.getAmount()),
|
String.valueOf(c.getAmount()),
|
||||||
c.getAmount() / (double) size * 100,
|
c.getAmount() / (double) size * 100,
|
||||||
name);
|
name);
|
||||||
actor.print(str);
|
actor.print(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,11 @@
|
|||||||
package com.boydti.fawe.beta.filters;
|
package com.boydti.fawe.beta.filters;
|
||||||
|
|
||||||
import com.boydti.fawe.beta.Filter;
|
import com.boydti.fawe.beta.Filter;
|
||||||
import com.boydti.fawe.beta.FilterBlock;
|
|
||||||
import com.boydti.fawe.config.BBC;
|
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
|
||||||
import com.sk89q.worldedit.util.Countable;
|
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public abstract class ForkedFilter<T extends ForkedFilter<T>> implements Filter {
|
public abstract class ForkedFilter<T extends ForkedFilter<T>> implements Filter {
|
||||||
|
|
||||||
protected final Map<Thread, T> children;
|
protected final Map<Thread, T> children;
|
||||||
|
|
||||||
public ForkedFilter(T root) {
|
public ForkedFilter(T root) {
|
||||||
|
@ -5,14 +5,15 @@ import com.boydti.fawe.beta.FilterBlock;
|
|||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
|
|
||||||
public class SetFilter implements Filter {
|
public class SetFilter implements Filter {
|
||||||
|
|
||||||
private final BlockState state;
|
private final BlockState state;
|
||||||
|
|
||||||
public SetFilter(final BlockState state) {
|
public SetFilter(BlockState state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyBlock(final FilterBlock block) {
|
public void applyBlock(FilterBlock block) {
|
||||||
block.setBlock(state);
|
block.setBlock(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,13 @@ import com.sk89q.worldedit.math.BlockVector3;
|
|||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public interface DelegateChunkSet extends IChunkSet {
|
public interface DelegateChunkSet extends IChunkSet {
|
||||||
|
|
||||||
IChunkSet getParent();
|
IChunkSet getParent();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -102,7 +102,8 @@ public interface DelegateChunkSet extends IChunkSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
|
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block)
|
||||||
|
throws WorldEditException {
|
||||||
return getParent().setBlock(position, block);
|
return getParent().setBlock(position, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.beta.implementation;
|
|||||||
import com.boydti.fawe.beta.IQueueExtent;
|
import com.boydti.fawe.beta.IQueueExtent;
|
||||||
|
|
||||||
public interface IQueueWrapper {
|
public interface IQueueWrapper {
|
||||||
|
|
||||||
default IQueueExtent wrapQueue(IQueueExtent queue) {
|
default IQueueExtent wrapQueue(IQueueExtent queue) {
|
||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,14 @@ import com.sk89q.worldedit.world.World;
|
|||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ForkJoinTask;
|
import java.util.concurrent.ForkJoinTask;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueueWrapper {
|
public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueueWrapper {
|
||||||
|
|
||||||
private final World world;
|
private final World world;
|
||||||
private final QueueHandler handler;
|
private final QueueHandler handler;
|
||||||
|
|
||||||
@ -39,56 +40,53 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
|
|||||||
return handler.getQueue(this.world);
|
return handler.getQueue(this.world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Filter> T apply(final Region region, final T filter) {
|
public <T extends Filter> T apply(Region region, T filter) {
|
||||||
// The chunks positions to iterate over
|
// The chunks positions to iterate over
|
||||||
final Set<BlockVector2> chunks = region.getChunks();
|
final Set<BlockVector2> chunks = region.getChunks();
|
||||||
final Iterator<BlockVector2> chunksIter = chunks.iterator();
|
final Iterator<BlockVector2> chunksIter = chunks.iterator();
|
||||||
|
|
||||||
// Get a pool, to operate on the chunks in parallel
|
// Get a pool, to operate on the chunks in parallel
|
||||||
final int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS);
|
final int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS);
|
||||||
final ForkJoinTask[] tasks = new ForkJoinTask[size];
|
final ForkJoinTask[] tasks = IntStream.range(0, size).mapToObj(i -> handler.submit(() -> {
|
||||||
for (int i = 0; i < size; i++) {
|
final Filter newFilter = filter.fork();
|
||||||
tasks[i] = handler.submit(new Runnable() {
|
// Create a chunk that we will reuse/reset for each operation
|
||||||
@Override
|
final IQueueExtent queue = wrapQueue(getQueue());
|
||||||
public void run() {
|
synchronized (queue) {
|
||||||
final Filter newFilter = filter.fork();
|
ChunkFilterBlock block = null;
|
||||||
// Create a chunk that we will reuse/reset for each operation
|
|
||||||
final IQueueExtent queue = wrapQueue(getQueue());
|
|
||||||
synchronized (queue) {
|
|
||||||
ChunkFilterBlock block = null;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Get the next chunk posWeakChunk
|
// Get the next chunk posWeakChunk
|
||||||
final int X, Z;
|
final int X, Z;
|
||||||
synchronized (chunksIter) {
|
synchronized (chunksIter) {
|
||||||
if (!chunksIter.hasNext()) break;
|
if (!chunksIter.hasNext()) {
|
||||||
final BlockVector2 pos = chunksIter.next();
|
break;
|
||||||
X = pos.getX();
|
|
||||||
Z = pos.getZ();
|
|
||||||
}
|
|
||||||
if (!newFilter.appliesChunk(X, Z)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
IChunk chunk = queue.getCachedChunk(X, Z);
|
|
||||||
// Initialize
|
|
||||||
chunk.init(queue, X, Z);
|
|
||||||
|
|
||||||
IChunk newChunk = newFilter.applyChunk(chunk, region);
|
|
||||||
if (newChunk != null) {
|
|
||||||
chunk = newChunk;
|
|
||||||
if (block == null) block = queue.initFilterBlock();
|
|
||||||
chunk.filterBlocks(newFilter, block, region);
|
|
||||||
}
|
|
||||||
queue.submit(chunk);
|
|
||||||
}
|
}
|
||||||
queue.flush();
|
final BlockVector2 pos = chunksIter.next();
|
||||||
|
X = pos.getX();
|
||||||
|
Z = pos.getZ();
|
||||||
}
|
}
|
||||||
|
if (!newFilter.appliesChunk(X, Z)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
IChunk chunk = queue.getCachedChunk(X, Z);
|
||||||
|
// Initialize
|
||||||
|
chunk.init(queue, X, Z);
|
||||||
|
|
||||||
|
IChunk newChunk = newFilter.applyChunk(chunk, region);
|
||||||
|
if (newChunk != null) {
|
||||||
|
chunk = newChunk;
|
||||||
|
if (block == null) {
|
||||||
|
block = queue.initFilterBlock();
|
||||||
|
}
|
||||||
|
chunk.filterBlocks(newFilter, block, region);
|
||||||
|
}
|
||||||
|
queue.submit(chunk);
|
||||||
}
|
}
|
||||||
});
|
queue.flush();
|
||||||
}
|
}
|
||||||
|
})).toArray(ForkJoinTask[]::new);
|
||||||
// Join filters
|
// Join filters
|
||||||
for (int i = 0; i < tasks.length; i++) {
|
for (ForkJoinTask task : tasks) {
|
||||||
final ForkJoinTask task = tasks[i];
|
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
task.quietlyJoin();
|
task.quietlyJoin();
|
||||||
}
|
}
|
||||||
@ -102,17 +100,18 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int countBlocks(final Region region, final Mask searchMask) {
|
public int countBlocks(Region region, Mask searchMask) {
|
||||||
return
|
return
|
||||||
// Apply a filter over a region
|
// Apply a filter over a region
|
||||||
apply(region, searchMask
|
apply(region, searchMask
|
||||||
.toFilter(new CountFilter())) // Adapt the mask to a filter which counts
|
.toFilter(new CountFilter())) // Adapt the mask to a filter which counts
|
||||||
.getParent() // Get the counter of this mask
|
.getParent() // Get the counter of this mask
|
||||||
.getTotal(); // Get the total from the counter
|
.getTotal(); // Get the total from the counter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException {
|
public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block)
|
||||||
|
throws MaxChangedBlocksException {
|
||||||
apply(region, block);
|
apply(region, block);
|
||||||
return getChanges();
|
return getChanges();
|
||||||
}
|
}
|
||||||
@ -135,7 +134,8 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
|
public int replaceBlocks(Region region, Mask mask, Pattern pattern)
|
||||||
|
throws MaxChangedBlocksException {
|
||||||
apply(region, mask.toFilter(pattern));
|
apply(region, mask.toFilter(pattern));
|
||||||
return getChanges();
|
return getChanges();
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import com.boydti.fawe.util.TaskManager;
|
|||||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -31,6 +30,7 @@ import java.util.function.Supplier;
|
|||||||
* Class which handles all the queues {@link IQueueExtent}
|
* Class which handles all the queues {@link IQueueExtent}
|
||||||
*/
|
*/
|
||||||
public abstract class QueueHandler implements Trimable, Runnable {
|
public abstract class QueueHandler implements Trimable, Runnable {
|
||||||
|
|
||||||
private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool();
|
private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool();
|
||||||
private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool();
|
private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool();
|
||||||
private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor();
|
private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor();
|
||||||
@ -43,17 +43,16 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
return create();
|
return create();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public QueueHandler() {
|
|
||||||
TaskManager.IMP.repeat(this, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the server
|
* Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the
|
||||||
|
* server
|
||||||
*/
|
*/
|
||||||
private long last;
|
private long last;
|
||||||
private long allocate = 50;
|
private long allocate = 50;
|
||||||
private double targetTPS = 18;
|
private double targetTPS = 18;
|
||||||
|
public QueueHandler() {
|
||||||
|
TaskManager.IMP.repeat(this, 1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -63,7 +62,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
if (!syncTasks.isEmpty()) {
|
if (!syncTasks.isEmpty()) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
targetTPS = 18 - Math.max(Settings.IMP.QUEUE.EXTRA_TIME_MS * 0.05, 0);
|
targetTPS = 18 - Math.max(Settings.IMP.QUEUE.EXTRA_TIME_MS * 0.05, 0);
|
||||||
long diff = (50 + this.last) - (this.last = now);
|
long diff = 50 + this.last - (this.last = now);
|
||||||
long absDiff = Math.abs(diff);
|
long absDiff = Math.abs(diff);
|
||||||
if (diff == 0) {
|
if (diff == 0) {
|
||||||
allocate = Math.min(50, allocate + 1);
|
allocate = Math.min(50, allocate + 1);
|
||||||
@ -105,7 +104,9 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
}
|
}
|
||||||
while (!syncTasks.isEmpty()) {
|
while (!syncTasks.isEmpty()) {
|
||||||
final FutureTask task = syncTasks.poll();
|
final FutureTask task = syncTasks.poll();
|
||||||
if (task != null) task.run();
|
if (task != null) {
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,23 +120,23 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> Future<T> async(final Runnable run, final T value) {
|
public <T> Future<T> async(Runnable run, T value) {
|
||||||
return forkJoinPoolSecondary.submit(run, value);
|
return forkJoinPoolSecondary.submit(run, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Future<?> async(final Runnable run) {
|
public Future<?> async(Runnable run) {
|
||||||
return forkJoinPoolSecondary.submit(run);
|
return forkJoinPoolSecondary.submit(run);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> Future<T> async(final Callable<T> call) {
|
public <T> Future<T> async(Callable<T> call) {
|
||||||
return forkJoinPoolSecondary.submit(call);
|
return forkJoinPoolSecondary.submit(call);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForkJoinTask submit(final Runnable call) {
|
public ForkJoinTask submit(Runnable call) {
|
||||||
return forkJoinPoolPrimary.submit(call);
|
return forkJoinPoolPrimary.submit(call);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> Future<T> sync(final Runnable run, final T value) {
|
public <T> Future<T> sync(Runnable run, T value) {
|
||||||
if (Fawe.isMainThread()) {
|
if (Fawe.isMainThread()) {
|
||||||
run.run();
|
run.run();
|
||||||
return Futures.immediateFuture(value);
|
return Futures.immediateFuture(value);
|
||||||
@ -146,7 +147,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> Future<T> sync(final Runnable run) {
|
public <T> Future<T> sync(Runnable run) {
|
||||||
if (Fawe.isMainThread()) {
|
if (Fawe.isMainThread()) {
|
||||||
run.run();
|
run.run();
|
||||||
return Futures.immediateCancelledFuture();
|
return Futures.immediateCancelledFuture();
|
||||||
@ -157,7 +158,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> Future<T> sync(final Callable<T> call) throws Exception {
|
public <T> Future<T> sync(Callable<T> call) throws Exception {
|
||||||
if (Fawe.isMainThread()) {
|
if (Fawe.isMainThread()) {
|
||||||
return Futures.immediateFuture(call.call());
|
return Futures.immediateFuture(call.call());
|
||||||
}
|
}
|
||||||
@ -167,7 +168,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> Future<T> sync(final Supplier<T> call) {
|
public <T> Future<T> sync(Supplier<T> call) {
|
||||||
if (Fawe.isMainThread()) {
|
if (Fawe.isMainThread()) {
|
||||||
return Futures.immediateFuture(call.get());
|
return Futures.immediateFuture(call.get());
|
||||||
}
|
}
|
||||||
@ -183,7 +184,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Future<T>> T submit(final IChunk<T> chunk) {
|
public <T extends Future<T>> T submit(IChunk<T> chunk) {
|
||||||
// if (MemUtil.isMemoryFree()) { TODO NOT IMPLEMENTED - optimize this
|
// if (MemUtil.isMemoryFree()) { TODO NOT IMPLEMENTED - optimize this
|
||||||
// return (T) forkJoinPoolSecondary.submit(chunk);
|
// return (T) forkJoinPoolSecondary.submit(chunk);
|
||||||
// }
|
// }
|
||||||
@ -192,6 +193,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get or create the WorldChunkCache for a world
|
* Get or create the WorldChunkCache for a world
|
||||||
|
*
|
||||||
* @param world
|
* @param world
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -218,17 +220,18 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
|
|
||||||
public abstract void endSet(boolean parallel);
|
public abstract void endSet(boolean parallel);
|
||||||
|
|
||||||
public IQueueExtent getQueue(final World world) {
|
public IQueueExtent getQueue(World world) {
|
||||||
final IQueueExtent queue = queuePool.get();
|
final IQueueExtent queue = queuePool.get();
|
||||||
queue.init(getOrCreate(world));
|
queue.init(getOrCreate(world));
|
||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean trim(final boolean aggressive) {
|
public boolean trim(boolean aggressive) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
synchronized (chunkCache) {
|
synchronized (chunkCache) {
|
||||||
final Iterator<Map.Entry<World, WeakReference<WorldChunkCache>>> iter = chunkCache.entrySet().iterator();
|
final Iterator<Map.Entry<World, WeakReference<WorldChunkCache>>> iter = chunkCache
|
||||||
|
.entrySet().iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
final Map.Entry<World, WeakReference<WorldChunkCache>> entry = iter.next();
|
final Map.Entry<World, WeakReference<WorldChunkCache>> entry = iter.next();
|
||||||
final WeakReference<WorldChunkCache> value = entry.getValue();
|
final WeakReference<WorldChunkCache> value = entry.getValue();
|
||||||
|
@ -2,9 +2,9 @@ package com.boydti.fawe.beta.implementation;
|
|||||||
|
|
||||||
import com.boydti.fawe.beta.CharFilterBlock;
|
import com.boydti.fawe.beta.CharFilterBlock;
|
||||||
import com.boydti.fawe.beta.ChunkFilterBlock;
|
import com.boydti.fawe.beta.ChunkFilterBlock;
|
||||||
import com.boydti.fawe.beta.FilterBlock;
|
|
||||||
|
|
||||||
public abstract class SimpleCharQueueExtent extends SingleThreadQueueExtent {
|
public abstract class SimpleCharQueueExtent extends SingleThreadQueueExtent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkFilterBlock initFilterBlock() {
|
public ChunkFilterBlock initFilterBlock() {
|
||||||
return new CharFilterBlock(this);
|
return new CharFilterBlock(this);
|
||||||
|
@ -18,23 +18,32 @@ import java.util.concurrent.Future;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single threaded implementation for IQueueExtent (still abstract)
|
* Single threaded implementation for IQueueExtent (still abstract) - Does not implement creation of
|
||||||
* - Does not implement creation of chunks (that has to implemented by the platform e.g. Bukkit)
|
* chunks (that has to implemented by the platform e.g. Bukkit)
|
||||||
*
|
* <p>
|
||||||
* This queue is reusable {@link #init(WorldChunkCache)}
|
* This queue is reusable {@link #init(WorldChunkCache)}
|
||||||
*/
|
*/
|
||||||
public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
||||||
|
|
||||||
|
// 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<IChunk> chunks = new Long2ObjectLinkedOpenHashMap<>();
|
||||||
private WorldChunkCache cache;
|
private WorldChunkCache cache;
|
||||||
private Thread currentThread;
|
private Thread currentThread;
|
||||||
private ConcurrentLinkedQueue<Future> submissions = new ConcurrentLinkedQueue<>();
|
private ConcurrentLinkedQueue<Future> submissions = new ConcurrentLinkedQueue<>();
|
||||||
|
// Last access pointers
|
||||||
|
private IChunk lastChunk;
|
||||||
|
private long lastPair = Long.MAX_VALUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Safety check to ensure that the thread being used matches the one being initialized on.
|
* Safety check to ensure that the thread being used matches the one being initialized on. - Can
|
||||||
* - Can be removed later
|
* be removed later
|
||||||
*/
|
*/
|
||||||
private void checkThread() {
|
private void checkThread() {
|
||||||
if (Thread.currentThread() != currentThread && currentThread != null) {
|
if (Thread.currentThread() != currentThread && currentThread != null) {
|
||||||
throw new UnsupportedOperationException("This class must be used from a single thread. Use multiple queues for concurrent operations");
|
throw new UnsupportedOperationException(
|
||||||
|
"This class must be used from a single thread. Use multiple queues for concurrent operations");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,10 +69,11 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the queue
|
* Initialize the queue
|
||||||
|
*
|
||||||
* @param cache
|
* @param cache
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void init(final WorldChunkCache cache) {
|
public synchronized void init(WorldChunkCache cache) {
|
||||||
if (this.cache != null) {
|
if (this.cache != null) {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
@ -72,15 +82,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last access pointers
|
public void returnToPool(IChunk chunk) {
|
||||||
private IChunk lastChunk;
|
|
||||||
private long lastPair = Long.MAX_VALUE;
|
|
||||||
// Chunks currently being queued / worked on
|
|
||||||
private final Long2ObjectLinkedOpenHashMap<IChunk> chunks = new Long2ObjectLinkedOpenHashMap<>();
|
|
||||||
// Pool discarded chunks for reuse (can safely be cleared by another thread)
|
|
||||||
private static final ConcurrentLinkedQueue<IChunk> CHUNK_POOL = new ConcurrentLinkedQueue<>();
|
|
||||||
|
|
||||||
public void returnToPool(final IChunk chunk) {
|
|
||||||
CHUNK_POOL.add(chunk);
|
CHUNK_POOL.add(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +97,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Future<T>> T submit(final IChunk<T> chunk) {
|
public <T extends Future<T>> T submit(IChunk<T> chunk) {
|
||||||
if (lastChunk == chunk) {
|
if (lastChunk == chunk) {
|
||||||
lastPair = Long.MAX_VALUE;
|
lastPair = Long.MAX_VALUE;
|
||||||
lastChunk = null;
|
lastChunk = null;
|
||||||
@ -107,11 +109,12 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit without first checking that it has been removed from the chunk map
|
* Submit without first checking that it has been removed from the chunk map
|
||||||
|
*
|
||||||
* @param chunk
|
* @param chunk
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private <T extends Future<T>> T submitUnchecked(final IChunk<T> chunk) {
|
private <T extends Future<T>> T submitUnchecked(IChunk<T> chunk) {
|
||||||
if (chunk.isEmpty()) {
|
if (chunk.isEmpty()) {
|
||||||
CHUNK_POOL.add(chunk);
|
CHUNK_POOL.add(chunk);
|
||||||
return (T) (Future) Futures.immediateFuture(null);
|
return (T) (Future) Futures.immediateFuture(null);
|
||||||
@ -125,7 +128,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean trim(final boolean aggressive) {
|
public synchronized boolean trim(boolean aggressive) {
|
||||||
// TODO trim individial chunk sections
|
// TODO trim individial chunk sections
|
||||||
CHUNK_POOL.clear();
|
CHUNK_POOL.clear();
|
||||||
if (Thread.currentThread() == currentThread) {
|
if (Thread.currentThread() == currentThread) {
|
||||||
@ -146,13 +149,14 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a new IChunk from either the pool, or create a new one<br>
|
* Get a new IChunk from either the pool, or create a new one<br> + Initialize it at the
|
||||||
* + Initialize it at the coordinates
|
* coordinates
|
||||||
|
*
|
||||||
* @param X
|
* @param X
|
||||||
* @param Z
|
* @param Z
|
||||||
* @return IChunk
|
* @return IChunk
|
||||||
*/
|
*/
|
||||||
private IChunk poolOrCreate(final int X, final int Z) {
|
private IChunk poolOrCreate(int X, int Z) {
|
||||||
IChunk next = CHUNK_POOL.poll();
|
IChunk next = CHUNK_POOL.poll();
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
next = create(false);
|
next = create(false);
|
||||||
@ -162,21 +166,23 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final IChunk getCachedChunk(final int x, final int z) {
|
public final IChunk getCachedChunk(int x, int z) {
|
||||||
final long pair = (((long) x) << 32) | (z & 0xffffffffL);
|
final long pair = (long) x << 32 | z & 0xffffffffL;
|
||||||
if (pair == lastPair) {
|
if (pair == lastPair) {
|
||||||
return lastChunk;
|
return lastChunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
IChunk chunk = chunks.get(pair);
|
IChunk chunk = chunks.get(pair);
|
||||||
if (chunk instanceof ReferenceChunk) {
|
if (chunk instanceof ReferenceChunk) {
|
||||||
chunk = ((ReferenceChunk) (chunk)).getParent();
|
chunk = ((ReferenceChunk) chunk).getParent();
|
||||||
}
|
}
|
||||||
if (chunk != null) {
|
if (chunk != null) {
|
||||||
lastPair = pair;
|
lastPair = pair;
|
||||||
lastChunk = chunk;
|
lastChunk = chunk;
|
||||||
}
|
}
|
||||||
if (chunk != null) return chunk;
|
if (chunk != null) {
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
checkThread();
|
checkThread();
|
||||||
final int size = chunks.size();
|
final int size = chunks.size();
|
||||||
@ -205,14 +211,15 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pollSubmissions(final int targetSize, final boolean aggressive) {
|
private void pollSubmissions(int targetSize, boolean aggressive) {
|
||||||
final int overflow = submissions.size() - targetSize;
|
final int overflow = submissions.size() - targetSize;
|
||||||
if (aggressive) {
|
if (aggressive) {
|
||||||
for (int i = 0; i < overflow; i++) {
|
for (int i = 0; i < overflow; i++) {
|
||||||
Future first = submissions.poll();
|
Future first = submissions.poll();
|
||||||
try {
|
try {
|
||||||
while ((first = (Future) first.get()) != null) ;
|
while ((first = (Future) first.get()) != null) {
|
||||||
} catch (final InterruptedException | ExecutionException e) {
|
}
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,7 +230,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
if (next.isDone()) {
|
if (next.isDone()) {
|
||||||
try {
|
try {
|
||||||
next = (Future) next.get();
|
next = (Future) next.get();
|
||||||
} catch (final InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -240,7 +247,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
checkThread();
|
checkThread();
|
||||||
if (!chunks.isEmpty()) {
|
if (!chunks.isEmpty()) {
|
||||||
if (MemUtil.isMemoryLimited()) {
|
if (MemUtil.isMemoryLimited()) {
|
||||||
for (final IChunk chunk : chunks.values()) {
|
for (IChunk chunk : chunks.values()) {
|
||||||
final Future future = submitUnchecked(chunk);
|
final Future future = submitUnchecked(chunk);
|
||||||
if (future != null && !future.isDone()) {
|
if (future != null && !future.isDone()) {
|
||||||
pollSubmissions(Settings.IMP.QUEUE.PARALLEL_THREADS, true);
|
pollSubmissions(Settings.IMP.QUEUE.PARALLEL_THREADS, true);
|
||||||
@ -248,7 +255,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (final IChunk chunk : chunks.values()) {
|
for (IChunk chunk : chunks.values()) {
|
||||||
final Future future = submitUnchecked(chunk);
|
final Future future = submitUnchecked(chunk);
|
||||||
if (future != null && !future.isDone()) {
|
if (future != null && !future.isDone()) {
|
||||||
submissions.add(future);
|
submissions.add(future);
|
||||||
|
@ -6,19 +6,19 @@ import com.sk89q.worldedit.world.World;
|
|||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IGetBlocks may be cached by the WorldChunkCache so that it can be used between multiple IQueueExtents
|
* IGetBlocks may be cached by the WorldChunkCache so that it can be used between multiple
|
||||||
* - avoids conversion between palette and raw data on every block get
|
* IQueueExtents - avoids conversion between palette and raw data on every block get
|
||||||
*/
|
*/
|
||||||
public class WorldChunkCache implements Trimable {
|
public class WorldChunkCache implements Trimable {
|
||||||
|
|
||||||
protected final Long2ObjectLinkedOpenHashMap<WeakReference<IChunkGet>> getCache;
|
protected final Long2ObjectLinkedOpenHashMap<WeakReference<IChunkGet>> getCache;
|
||||||
private final World world;
|
private final World world;
|
||||||
|
|
||||||
protected WorldChunkCache(final World world) {
|
protected WorldChunkCache(World world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.getCache = new Long2ObjectLinkedOpenHashMap<>();
|
this.getCache = new Long2ObjectLinkedOpenHashMap<>();
|
||||||
}
|
}
|
||||||
@ -33,15 +33,18 @@ public class WorldChunkCache implements Trimable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get or create the IGetBlocks
|
* Get or create the IGetBlocks
|
||||||
* @param index chunk index {@link com.boydti.fawe.util.MathMan#pairInt(int, int)}
|
*
|
||||||
|
* @param index chunk index {@link com.boydti.fawe.util.MathMan#pairInt(int, int)}
|
||||||
* @param provider used to create if it isn't already cached
|
* @param provider used to create if it isn't already cached
|
||||||
* @return cached IGetBlocks
|
* @return cached IGetBlocks
|
||||||
*/
|
*/
|
||||||
public synchronized IChunkGet get(final long index, final Supplier<IChunkGet> provider) {
|
public synchronized IChunkGet get(long index, Supplier<IChunkGet> provider) {
|
||||||
final WeakReference<IChunkGet> ref = getCache.get(index);
|
final WeakReference<IChunkGet> ref = getCache.get(index);
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
final IChunkGet blocks = ref.get();
|
final IChunkGet blocks = ref.get();
|
||||||
if (blocks != null) return blocks;
|
if (blocks != null) {
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final IChunkGet blocks = provider.get();
|
final IChunkGet blocks = provider.get();
|
||||||
getCache.put(index, new WeakReference<>(blocks));
|
getCache.put(index, new WeakReference<>(blocks));
|
||||||
@ -49,18 +52,22 @@ public class WorldChunkCache implements Trimable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean trim(final boolean aggressive) {
|
public synchronized boolean trim(boolean aggressive) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
if (!getCache.isEmpty()) {
|
if (!getCache.isEmpty()) {
|
||||||
final ObjectIterator<Long2ObjectMap.Entry<WeakReference<IChunkGet>>> iter = getCache.long2ObjectEntrySet().fastIterator();
|
final ObjectIterator<Long2ObjectMap.Entry<WeakReference<IChunkGet>>> iter = getCache
|
||||||
|
.long2ObjectEntrySet().fastIterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
final Long2ObjectMap.Entry<WeakReference<IChunkGet>> entry = iter.next();
|
final Long2ObjectMap.Entry<WeakReference<IChunkGet>> entry = iter.next();
|
||||||
final WeakReference<IChunkGet> value = entry.getValue();
|
final WeakReference<IChunkGet> value = entry.getValue();
|
||||||
final IChunkGet igb = value.get();
|
final IChunkGet igb = value.get();
|
||||||
if (igb == null) iter.remove();
|
if (igb == null) {
|
||||||
else {
|
iter.remove();
|
||||||
|
} else {
|
||||||
result = false;
|
result = false;
|
||||||
if (!aggressive) return result;
|
if (!aggressive) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
synchronized (igb) {
|
synchronized (igb) {
|
||||||
igb.trim(aggressive);
|
igb.trim(aggressive);
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,17 @@
|
|||||||
package com.boydti.fawe.beta.implementation.blocks;
|
package com.boydti.fawe.beta.implementation.blocks;
|
||||||
|
|
||||||
import com.boydti.fawe.FaweCache;
|
|
||||||
import com.boydti.fawe.beta.IChunkSet;
|
import com.boydti.fawe.beta.IChunkSet;
|
||||||
import com.boydti.fawe.object.collection.BitArray4096;
|
|
||||||
import com.boydti.fawe.object.collection.BlockSet;
|
|
||||||
import com.boydti.fawe.object.collection.MemBlockSet;
|
import com.boydti.fawe.object.collection.MemBlockSet;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BitSetBlocks implements IChunkSet {
|
public class BitSetBlocks implements IChunkSet {
|
||||||
|
|
||||||
private final MemBlockSet.RowZ row;
|
private final MemBlockSet.RowZ row;
|
||||||
private final BlockState blockState;
|
private final BlockState blockState;
|
||||||
|
|
||||||
@ -43,13 +38,16 @@ public class BitSetBlocks implements IChunkSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTile(int x, int y, int z, CompoundTag tile) {}
|
public void setTile(int x, int y, int z, CompoundTag tile) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEntity(CompoundTag tag) {}
|
public void setEntity(CompoundTag tag) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeEntity(UUID uuid) {}
|
public void removeEntity(UUID uuid) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock(int x, int y, int z) {
|
public BlockState getBlock(int x, int y, int z) {
|
||||||
|
@ -4,6 +4,26 @@ import com.boydti.fawe.beta.IBlocks;
|
|||||||
import com.boydti.fawe.beta.IChunkSet;
|
import com.boydti.fawe.beta.IChunkSet;
|
||||||
|
|
||||||
public class CharBlocks implements IBlocks {
|
public class CharBlocks implements IBlocks {
|
||||||
|
|
||||||
|
public static final Section FULL = new Section() {
|
||||||
|
@Override
|
||||||
|
public final char[] get(CharBlocks blocks, int layer) {
|
||||||
|
return blocks.blocks[layer];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Section EMPTY = new Section() {
|
||||||
|
@Override
|
||||||
|
public final char[] get(CharBlocks blocks, int layer) {
|
||||||
|
blocks.sections[layer] = FULL;
|
||||||
|
char[] arr = blocks.blocks[layer];
|
||||||
|
if (arr == null) {
|
||||||
|
arr = blocks.blocks[layer] = blocks.load(layer);
|
||||||
|
} else {
|
||||||
|
blocks.blocks[layer] = blocks.load(layer, arr);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
};
|
||||||
public final char[][] blocks;
|
public final char[][] blocks;
|
||||||
public final Section[] sections;
|
public final Section[] sections;
|
||||||
|
|
||||||
@ -15,11 +35,13 @@ public class CharBlocks implements IBlocks {
|
|||||||
public CharBlocks() {
|
public CharBlocks() {
|
||||||
blocks = new char[16][];
|
blocks = new char[16][];
|
||||||
sections = new Section[16];
|
sections = new Section[16];
|
||||||
for (int i = 0; i < 16; i++) sections[i] = EMPTY;
|
for (int i = 0; i < 16; i++) {
|
||||||
|
sections[i] = EMPTY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean trim(final boolean aggressive) {
|
public boolean trim(boolean aggressive) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (sections[i] == EMPTY) {
|
if (sections[i] == EMPTY) {
|
||||||
@ -33,82 +55,67 @@ public class CharBlocks implements IBlocks {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IChunkSet reset() {
|
public IChunkSet reset() {
|
||||||
for (int i = 0; i < 16; i++) sections[i] = EMPTY;
|
for (int i = 0; i < 16; i++) {
|
||||||
|
sections[i] = EMPTY;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset(final int layer) {
|
public void reset(int layer) {
|
||||||
sections[layer] = EMPTY;
|
sections[layer] = EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public char[] load(final int layer) {
|
public char[] load(int layer) {
|
||||||
return new char[4096];
|
return new char[4096];
|
||||||
}
|
}
|
||||||
|
|
||||||
public char[] load(final int layer, final char[] data) {
|
public char[] load(int layer, char[] data) {
|
||||||
for (int i = 0; i < 4096; i++) data[i] = 0;
|
for (int i = 0; i < 4096; i++) {
|
||||||
|
data[i] = 0;
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasSection(final int layer) {
|
public boolean hasSection(int layer) {
|
||||||
return sections[layer] == FULL;
|
return sections[layer] == FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public char get(final int x, final int y, final int z) {
|
public char get(int x, int y, int z) {
|
||||||
final int layer = y >> 4;
|
final int layer = y >> 4;
|
||||||
final int index = ((y & 15) << 8) | (z << 4) | (x);
|
final int index = (y & 15) << 8 | z << 4 | x;
|
||||||
return sections[layer].get(this, layer, index);
|
return sections[layer].get(this, layer, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(final int x, final int y, final int z, final char value) {
|
public void set(int x, int y, int z, char value) {
|
||||||
final int layer = y >> 4;
|
final int layer = y >> 4;
|
||||||
final int index = ((y & 15) << 8) | (z << 4) | (x);
|
final int index = (y & 15) << 8 | z << 4 | x;
|
||||||
set(layer, index, value);
|
set(layer, index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final char get(final int layer, final int index) {
|
|
||||||
return sections[layer].get(this, layer, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void set(final int layer, final int index, final char value) {
|
|
||||||
sections[layer].set(this, layer, index, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Section
|
Section
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public final char get(int layer, int index) {
|
||||||
|
return sections[layer].get(this, layer, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void set(int layer, int index, char value) {
|
||||||
|
sections[layer].set(this, layer, index, value);
|
||||||
|
}
|
||||||
|
|
||||||
public static abstract class Section {
|
public static abstract class Section {
|
||||||
|
|
||||||
public abstract char[] get(CharBlocks blocks, int layer);
|
public abstract char[] get(CharBlocks blocks, int layer);
|
||||||
|
|
||||||
public final char get(final CharBlocks blocks, final int layer, final int index) {
|
public final char get(CharBlocks blocks, int layer, int index) {
|
||||||
return get(blocks, layer)[index];
|
return get(blocks, layer)[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void set(final CharBlocks blocks, final int layer, final int index, final char value) {
|
public final void set(CharBlocks blocks, int layer, int index,
|
||||||
|
char value) {
|
||||||
get(blocks, layer)[index] = value;
|
get(blocks, layer)[index] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Section EMPTY = new Section() {
|
|
||||||
@Override
|
|
||||||
public final char[] get(final CharBlocks blocks, final int layer) {
|
|
||||||
blocks.sections[layer] = FULL;
|
|
||||||
char[] arr = blocks.blocks[layer];
|
|
||||||
if (arr == null) {
|
|
||||||
arr = blocks.blocks[layer] = blocks.load(layer);
|
|
||||||
} else {
|
|
||||||
blocks.blocks[layer] = blocks.load(layer, arr);
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final Section FULL = new Section() {
|
|
||||||
@Override
|
|
||||||
public final char[] get(final CharBlocks blocks, final int layer) {
|
|
||||||
return blocks.blocks[layer];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -7,18 +7,19 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
|
||||||
public abstract class CharGetBlocks extends CharBlocks implements IChunkGet {
|
public abstract class CharGetBlocks extends CharBlocks implements IChunkGet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseBlock getFullBlock(final int x, final int y, final int z) {
|
public BaseBlock getFullBlock(int x, int y, int z) {
|
||||||
return BlockTypes.states[get(x, y, z)].toBaseBlock();
|
return BlockTypes.states[get(x, y, z)].toBaseBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock(final int x, final int y, final int z) {
|
public BlockState getBlock(int x, int y, int z) {
|
||||||
return BlockTypes.states[get(x, y, z)];
|
return BlockTypes.states[get(x, y, z)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean trim(final boolean aggressive) {
|
public boolean trim(boolean aggressive) {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
sections[i] = EMPTY;
|
sections[i] = EMPTY;
|
||||||
blocks[i] = null;
|
blocks[i] = null;
|
||||||
|
@ -7,7 +7,6 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
|||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -15,6 +14,7 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
||||||
|
|
||||||
public BiomeType[] biomes;
|
public BiomeType[] biomes;
|
||||||
public HashMap<Short, CompoundTag> tiles;
|
public HashMap<Short, CompoundTag> tiles;
|
||||||
public HashSet<CompoundTag> entities;
|
public HashSet<CompoundTag> entities;
|
||||||
@ -57,7 +57,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
|
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||||
if (biomes == null) {
|
if (biomes == null) {
|
||||||
biomes = new BiomeType[256];
|
biomes = new BiomeType[256];
|
||||||
}
|
}
|
||||||
@ -71,13 +71,13 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setBlock(final int x, final int y, final int z, final BlockStateHolder holder) {
|
public boolean setBlock(int x, int y, int z, BlockStateHolder holder) {
|
||||||
set(x, y, z, holder.getOrdinalChar());
|
set(x, y, z, holder.getOrdinalChar());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTile(final int x, final int y, final int z, final CompoundTag tile) {
|
public void setTile(int x, int y, int z, CompoundTag tile) {
|
||||||
if (tiles == null) {
|
if (tiles == null) {
|
||||||
tiles = new HashMap<>();
|
tiles = new HashMap<>();
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEntity(final CompoundTag tag) {
|
public void setEntity(CompoundTag tag) {
|
||||||
if (entities == null) {
|
if (entities == null) {
|
||||||
entities = new HashSet<>();
|
entities = new HashSet<>();
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeEntity(final UUID uuid) {
|
public void removeEntity(UUID uuid) {
|
||||||
if (entityRemoves == null) {
|
if (entityRemoves == null) {
|
||||||
entityRemoves = new HashSet<>();
|
entityRemoves = new HashSet<>();
|
||||||
}
|
}
|
||||||
@ -103,7 +103,9 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
if (biomes != null) return false;
|
if (biomes != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (hasSection(i)) {
|
if (hasSection(i)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -16,14 +16,150 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
|||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract IChunk class that implements basic get/set blocks
|
* An abstract {@link IChunk} class that implements basic get/set blocks
|
||||||
*/
|
*/
|
||||||
public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
||||||
|
|
||||||
|
public static final IBlockDelegate BOTH = new IBlockDelegate() {
|
||||||
|
@Override
|
||||||
|
public boolean setBiome(ChunkHolder chunk, int x, int y, int z,
|
||||||
|
BiomeType biome) {
|
||||||
|
return chunk.set.setBiome(x, y, z, biome);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||||
|
BlockStateHolder block) {
|
||||||
|
return chunk.set.setBlock(x, y, z, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeType getBiome(ChunkHolder chunk, int x, int z) {
|
||||||
|
return chunk.get.getBiomeType(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlock(ChunkHolder chunk, int x, int y, int z) {
|
||||||
|
return chunk.get.getBlock(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock getFullBlock(ChunkHolder chunk, int x, int y,
|
||||||
|
int z) {
|
||||||
|
return chunk.get.getFullBlock(x, y, z);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final IBlockDelegate GET = new IBlockDelegate() {
|
||||||
|
@Override
|
||||||
|
public boolean setBiome(ChunkHolder chunk, int x, int y, int z,
|
||||||
|
BiomeType biome) {
|
||||||
|
chunk.getOrCreateSet();
|
||||||
|
chunk.delegate = BOTH;
|
||||||
|
return chunk.setBiome(x, y, z, biome);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||||
|
BlockStateHolder block) {
|
||||||
|
chunk.getOrCreateSet();
|
||||||
|
chunk.delegate = BOTH;
|
||||||
|
return chunk.setBlock(x, y, z, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeType getBiome(ChunkHolder chunk, int x, int z) {
|
||||||
|
return chunk.get.getBiomeType(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlock(ChunkHolder chunk, int x, int y, int z) {
|
||||||
|
return chunk.get.getBlock(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock getFullBlock(ChunkHolder chunk, int x, int y,
|
||||||
|
int z) {
|
||||||
|
return chunk.get.getFullBlock(x, y, z);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final IBlockDelegate SET = new IBlockDelegate() {
|
||||||
|
@Override
|
||||||
|
public boolean setBiome(ChunkHolder chunk, int x, int y, int z,
|
||||||
|
BiomeType biome) {
|
||||||
|
return chunk.set.setBiome(x, y, z, biome);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||||
|
BlockStateHolder block) {
|
||||||
|
return chunk.set.setBlock(x, y, z, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeType getBiome(ChunkHolder chunk, int x, int z) {
|
||||||
|
chunk.getOrCreateGet();
|
||||||
|
chunk.delegate = BOTH;
|
||||||
|
return chunk.getBiomeType(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlock(ChunkHolder chunk, int x, int y, int z) {
|
||||||
|
chunk.getOrCreateGet();
|
||||||
|
chunk.delegate = BOTH;
|
||||||
|
return chunk.getBlock(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock getFullBlock(ChunkHolder chunk, int x, int y,
|
||||||
|
int z) {
|
||||||
|
chunk.getOrCreateGet();
|
||||||
|
chunk.delegate = BOTH;
|
||||||
|
return chunk.getFullBlock(x, y, z);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final IBlockDelegate NULL = new IBlockDelegate() {
|
||||||
|
@Override
|
||||||
|
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) {
|
||||||
|
chunk.getOrCreateSet();
|
||||||
|
chunk.delegate = SET;
|
||||||
|
return chunk.setBlock(x, y, z, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeType getBiome(ChunkHolder chunk, int x, int z) {
|
||||||
|
chunk.getOrCreateGet();
|
||||||
|
chunk.delegate = GET;
|
||||||
|
return chunk.getBiomeType(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlock(ChunkHolder chunk, int x, int y, int z) {
|
||||||
|
chunk.getOrCreateGet();
|
||||||
|
chunk.delegate = GET;
|
||||||
|
return chunk.getBlock(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock getFullBlock(ChunkHolder chunk, int x, int y,
|
||||||
|
int z) {
|
||||||
|
chunk.getOrCreateGet();
|
||||||
|
chunk.delegate = GET;
|
||||||
|
return chunk.getFullBlock(x, y, z);
|
||||||
|
}
|
||||||
|
};
|
||||||
private IChunkGet get;
|
private IChunkGet get;
|
||||||
private IChunkSet set;
|
private IChunkSet set;
|
||||||
private IBlockDelegate delegate;
|
private IBlockDelegate delegate;
|
||||||
@ -35,7 +171,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
|||||||
this.delegate = NULL;
|
this.delegate = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChunkHolder(final IBlockDelegate delegate) {
|
public ChunkHolder(IBlockDelegate delegate) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +182,8 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getTag(int x, int y, int z) {
|
public CompoundTag getTag(int x, int y, int z) {
|
||||||
return delegate.getFullBlock(this, x, y, z).getNbtData(); // TODO NOT IMPLEMENTED (add getTag delegate)
|
return delegate.getFullBlock(this, x, y, z)
|
||||||
|
.getNbtData(); // TODO NOT IMPLEMENTED (add getTag delegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,7 +192,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void filterBlocks(final Filter filter, ChunkFilterBlock block, @Nullable Region region) {
|
public void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region) {
|
||||||
final IChunkGet get = getOrCreateGet();
|
final IChunkGet get = getOrCreateGet();
|
||||||
final IChunkSet set = getOrCreateSet();
|
final IChunkSet set = getOrCreateSet();
|
||||||
try {
|
try {
|
||||||
@ -64,7 +201,9 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
|||||||
} else {
|
} else {
|
||||||
block = block.init(chunkX, chunkZ, get);
|
block = block.init(chunkX, chunkZ, get);
|
||||||
for (int layer = 0; layer < 16; layer++) {
|
for (int layer = 0; layer < 16; layer++) {
|
||||||
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
|
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
block.init(get, set, layer);
|
block.init(get, set, layer);
|
||||||
block.filter(filter);
|
block.filter(filter);
|
||||||
}
|
}
|
||||||
@ -75,7 +214,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean trim(final boolean aggressive) {
|
public boolean trim(boolean aggressive) {
|
||||||
if (set != null) {
|
if (set != null) {
|
||||||
final boolean result = set.trim(aggressive);
|
final boolean result = set.trim(aggressive);
|
||||||
if (result) {
|
if (result) {
|
||||||
@ -104,12 +243,16 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final IChunkGet getOrCreateGet() {
|
public final IChunkGet getOrCreateGet() {
|
||||||
if (get == null) get = newGet();
|
if (get == null) {
|
||||||
|
get = newGet();
|
||||||
|
}
|
||||||
return get;
|
return get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final IChunkSet getOrCreateSet() {
|
public final IChunkSet getOrCreateSet() {
|
||||||
if (set == null) set = set();
|
if (set == null) {
|
||||||
|
set = set();
|
||||||
|
}
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +271,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(final IQueueExtent extent, final int chunkX, final int chunkZ) {
|
public void init(IQueueExtent extent, int chunkX, int chunkZ) {
|
||||||
this.extent = extent;
|
this.extent = extent;
|
||||||
this.chunkX = chunkX;
|
this.chunkX = chunkX;
|
||||||
this.chunkZ = chunkZ;
|
this.chunkZ = chunkZ;
|
||||||
@ -156,167 +299,42 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
|
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||||
return delegate.setBiome(this, x, y, z, biome);
|
return delegate.setBiome(this, x, y, z, biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setBlock(final int x, final int y, final int z, final BlockStateHolder block) {
|
public boolean setBlock(int x, int y, int z, BlockStateHolder block) {
|
||||||
return delegate.setBlock(this, x, y, z, block);
|
return delegate.setBlock(this, x, y, z, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BiomeType getBiomeType(final int x, final int z) {
|
public BiomeType getBiomeType(int x, int z) {
|
||||||
return delegate.getBiome(this, x, z);
|
return delegate.getBiome(this, x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getBlock(final int x, final int y, final int z) {
|
public BlockState getBlock(int x, int y, int z) {
|
||||||
return delegate.getBlock(this, x, y, z);
|
return delegate.getBlock(this, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseBlock getFullBlock(final int x, final int y, final int z) {
|
public BaseBlock getFullBlock(int x, int y, int z) {
|
||||||
return delegate.getFullBlock(this, x, y, z);
|
return delegate.getFullBlock(this, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IBlockDelegate {
|
public interface IBlockDelegate {
|
||||||
boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome);
|
|
||||||
|
|
||||||
boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder holder);
|
boolean setBiome(ChunkHolder chunk, int x, int y, int z,
|
||||||
|
BiomeType biome);
|
||||||
|
|
||||||
BiomeType getBiome(final ChunkHolder chunk, final int x, final int z);
|
boolean setBlock(ChunkHolder chunk, int x, int y, int z,
|
||||||
|
BlockStateHolder holder);
|
||||||
|
|
||||||
BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z);
|
BiomeType getBiome(ChunkHolder chunk, int x, int z);
|
||||||
|
|
||||||
BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z);
|
BlockState getBlock(ChunkHolder chunk, int x, int y, int z);
|
||||||
|
|
||||||
|
BaseBlock getFullBlock(ChunkHolder chunk, int x, int y, int z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final IBlockDelegate NULL = new IBlockDelegate() {
|
|
||||||
@Override
|
|
||||||
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
|
|
||||||
chunk.getOrCreateSet();
|
|
||||||
chunk.delegate = SET;
|
|
||||||
return chunk.setBiome(x, y, z, biome);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
|
|
||||||
chunk.getOrCreateSet();
|
|
||||||
chunk.delegate = SET;
|
|
||||||
return chunk.setBlock(x, y, z, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
|
|
||||||
chunk.getOrCreateGet();
|
|
||||||
chunk.delegate = GET;
|
|
||||||
return chunk.getBiomeType(x, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
|
||||||
chunk.getOrCreateGet();
|
|
||||||
chunk.delegate = GET;
|
|
||||||
return chunk.getBlock(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
|
||||||
chunk.getOrCreateGet();
|
|
||||||
chunk.delegate = GET;
|
|
||||||
return chunk.getFullBlock(x, y, z);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final IBlockDelegate GET = new IBlockDelegate() {
|
|
||||||
@Override
|
|
||||||
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
|
|
||||||
chunk.getOrCreateSet();
|
|
||||||
chunk.delegate = BOTH;
|
|
||||||
return chunk.setBiome(x, y, z, biome);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
|
|
||||||
chunk.getOrCreateSet();
|
|
||||||
chunk.delegate = BOTH;
|
|
||||||
return chunk.setBlock(x, y, z, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
|
|
||||||
return chunk.get.getBiomeType(x, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
|
||||||
return chunk.get.getBlock(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
|
||||||
return chunk.get.getFullBlock(x, y, z);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final IBlockDelegate SET = new IBlockDelegate() {
|
|
||||||
@Override
|
|
||||||
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
|
|
||||||
return chunk.set.setBiome(x, y, z, biome);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
|
|
||||||
return chunk.set.setBlock(x, y, z, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
|
|
||||||
chunk.getOrCreateGet();
|
|
||||||
chunk.delegate = BOTH;
|
|
||||||
return chunk.getBiomeType(x, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
|
||||||
chunk.getOrCreateGet();
|
|
||||||
chunk.delegate = BOTH;
|
|
||||||
return chunk.getBlock(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
|
||||||
chunk.getOrCreateGet();
|
|
||||||
chunk.delegate = BOTH;
|
|
||||||
return chunk.getFullBlock(x, y, z);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final IBlockDelegate BOTH = new IBlockDelegate() {
|
|
||||||
@Override
|
|
||||||
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
|
|
||||||
return chunk.set.setBiome(x, y, z, biome);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
|
|
||||||
return chunk.set.setBlock(x, y, z, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
|
|
||||||
return chunk.get.getBiomeType(x, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
|
||||||
return chunk.get.getBlock(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
|
|
||||||
return chunk.get.getFullBlock(x, y, z);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,27 @@
|
|||||||
package com.boydti.fawe.beta.implementation.holder;
|
package com.boydti.fawe.beta.implementation.holder;
|
||||||
|
|
||||||
import com.boydti.fawe.beta.ChunkFilterBlock;
|
|
||||||
import com.boydti.fawe.beta.Filter;
|
|
||||||
import com.boydti.fawe.beta.FilterBlock;
|
|
||||||
import com.boydti.fawe.beta.FilterBlockMask;
|
|
||||||
import com.boydti.fawe.beta.Flood;
|
|
||||||
import com.boydti.fawe.beta.IChunk;
|
import com.boydti.fawe.beta.IChunk;
|
||||||
import com.boydti.fawe.beta.IDelegateChunk;
|
import com.boydti.fawe.beta.IDelegateChunk;
|
||||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of IDelegateChunk
|
* Implementation of IDelegateChunk
|
||||||
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public class DelegateChunk<T extends IChunk> implements IDelegateChunk {
|
public class DelegateChunk<T extends IChunk> implements IDelegateChunk {
|
||||||
|
|
||||||
private T parent;
|
private T parent;
|
||||||
|
|
||||||
public DelegateChunk(final T parent) {
|
public DelegateChunk(T parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final T getParent() {
|
public final T getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setParent(final T parent) {
|
public final void setParent(T parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,22 +1,24 @@
|
|||||||
package com.boydti.fawe.beta.implementation.holder;
|
package com.boydti.fawe.beta.implementation.holder;
|
||||||
|
|
||||||
import com.boydti.fawe.beta.IQueueExtent;
|
|
||||||
import com.boydti.fawe.beta.IChunk;
|
import com.boydti.fawe.beta.IChunk;
|
||||||
|
import com.boydti.fawe.beta.IQueueExtent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by {@link ReferenceChunk} to allow the chunk to be garbage collected
|
* Used by {@link ReferenceChunk} to allow the chunk to be garbage collected. - When the object is
|
||||||
* - When the object is finalized, add it to the queue
|
* finalized, add it to the queue
|
||||||
*/
|
*/
|
||||||
public class FinalizedChunk extends DelegateChunk {
|
public class FinalizedChunk extends DelegateChunk {
|
||||||
|
|
||||||
private final IQueueExtent queueExtent;
|
private final IQueueExtent queueExtent;
|
||||||
|
|
||||||
public FinalizedChunk(final IChunk parent, final IQueueExtent queueExtent) {
|
public FinalizedChunk(IChunk parent, IQueueExtent queueExtent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.queueExtent = queueExtent;
|
this.queueExtent = queueExtent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit the chunk to the queue
|
* Submit the chunk to the queue
|
||||||
|
*
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,26 +3,26 @@ package com.boydti.fawe.beta.implementation.holder;
|
|||||||
import com.boydti.fawe.beta.IChunk;
|
import com.boydti.fawe.beta.IChunk;
|
||||||
import com.boydti.fawe.beta.IDelegateChunk;
|
import com.boydti.fawe.beta.IDelegateChunk;
|
||||||
import com.boydti.fawe.beta.IQueueExtent;
|
import com.boydti.fawe.beta.IQueueExtent;
|
||||||
|
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An IChunk may be wrapped by a ReferenceChunk if there is low memory<br>
|
* An {@link IChunk} may be wrapped by a ReferenceChunk if there is low memory. This class stores a
|
||||||
* A reference chunk stores a reference (for garbage collection purposes)<br>
|
* reference for garbage collection purposes. If it cleaned by garbage collection, the {@link
|
||||||
* - If it is garbage collected, the {@link FinalizedChunk} logic is run
|
* FinalizedChunk} logic is run.
|
||||||
*/
|
*/
|
||||||
public abstract class ReferenceChunk implements IDelegateChunk {
|
public abstract class ReferenceChunk implements IDelegateChunk {
|
||||||
private final Reference<FinalizedChunk> ref;
|
|
||||||
|
|
||||||
public ReferenceChunk(final IChunk parent, final IQueueExtent queueExtent) {
|
private final Reference<FinalizedChunk> reference;
|
||||||
this.ref = toRef(new FinalizedChunk(parent, queueExtent));
|
|
||||||
|
public ReferenceChunk(IChunk parent, IQueueExtent queueExtent) {
|
||||||
|
this.reference = toReference(new FinalizedChunk(parent, queueExtent));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Reference<FinalizedChunk> toRef(FinalizedChunk parent);
|
protected abstract Reference<FinalizedChunk> toReference(FinalizedChunk parent);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IChunk getParent() {
|
public IChunk getParent() {
|
||||||
final FinalizedChunk finalized = ref.get();
|
final FinalizedChunk finalized = reference.get();
|
||||||
return finalized != null ? finalized.getParent() : null;
|
return finalized != null ? finalized.getParent() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.boydti.fawe.beta.implementation.holder;
|
|||||||
|
|
||||||
import com.boydti.fawe.beta.IChunk;
|
import com.boydti.fawe.beta.IChunk;
|
||||||
import com.boydti.fawe.beta.IQueueExtent;
|
import com.boydti.fawe.beta.IQueueExtent;
|
||||||
|
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
|
|
||||||
@ -11,12 +10,12 @@ import java.lang.ref.SoftReference;
|
|||||||
*/
|
*/
|
||||||
public class SoftChunk extends ReferenceChunk {
|
public class SoftChunk extends ReferenceChunk {
|
||||||
|
|
||||||
public SoftChunk(final IChunk parent, final IQueueExtent queueExtent) {
|
public SoftChunk(IChunk parent, IQueueExtent queueExtent) {
|
||||||
super(parent, queueExtent);
|
super(parent, queueExtent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
|
protected Reference<FinalizedChunk> toReference(FinalizedChunk parent) {
|
||||||
return new SoftReference<>(parent);
|
return new SoftReference<>(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,20 @@ package com.boydti.fawe.beta.implementation.holder;
|
|||||||
|
|
||||||
import com.boydti.fawe.beta.IChunk;
|
import com.boydti.fawe.beta.IChunk;
|
||||||
import com.boydti.fawe.beta.IQueueExtent;
|
import com.boydti.fawe.beta.IQueueExtent;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
|
||||||
|
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Weak reference implementation of {@link ReferenceChunk}
|
* A {@link ReferenceChunk} using {@link WeakReference} to hold the chunk.
|
||||||
*/
|
*/
|
||||||
public class WeakChunk extends ReferenceChunk {
|
public class WeakChunk extends ReferenceChunk {
|
||||||
public WeakChunk(final IChunk parent, final IQueueExtent queueExtent) {
|
|
||||||
|
public WeakChunk(IChunk parent, IQueueExtent queueExtent) {
|
||||||
super(parent, queueExtent);
|
super(parent, queueExtent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
|
protected Reference<FinalizedChunk> toReference(FinalizedChunk parent) {
|
||||||
return new WeakReference<>(parent);
|
return new WeakReference<>(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ import java.util.List;
|
|||||||
import org.enginehub.piston.annotation.Command;
|
import org.enginehub.piston.annotation.Command;
|
||||||
import org.enginehub.piston.annotation.CommandContainer;
|
import org.enginehub.piston.annotation.CommandContainer;
|
||||||
import org.enginehub.piston.annotation.param.Arg;
|
import org.enginehub.piston.annotation.param.Arg;
|
||||||
|
import org.enginehub.piston.annotation.param.ArgFlag;
|
||||||
import org.enginehub.piston.annotation.param.Switch;
|
import org.enginehub.piston.annotation.param.Switch;
|
||||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||||
|
|
||||||
@ -547,7 +548,7 @@ public class RegionCommands {
|
|||||||
boolean skipEntities,
|
boolean skipEntities,
|
||||||
@Switch(name = 'a', desc = "Ignore air blocks")
|
@Switch(name = 'a', desc = "Ignore air blocks")
|
||||||
boolean ignoreAirBlocks,
|
boolean ignoreAirBlocks,
|
||||||
@ArgFlag(name = "m", desc = "Source mask")
|
@ArgFlag(name = 'm', desc = "Source mask")
|
||||||
Mask sourceMask,
|
Mask sourceMask,
|
||||||
InjectedValueAccess context) throws WorldEditException {
|
InjectedValueAccess context) throws WorldEditException {
|
||||||
player.checkConfirmationStack(() -> {
|
player.checkConfirmationStack(() -> {
|
||||||
@ -677,7 +678,7 @@ public class RegionCommands {
|
|||||||
int thickness,
|
int thickness,
|
||||||
@Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air")
|
@Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
@ArgFlag(name = "m", desc = "Mask to hollow with") Mask mask,
|
@ArgFlag(name = 'm', desc = "Mask to hollow with") Mask mask,
|
||||||
InjectedValueAccess context) throws WorldEditException {
|
InjectedValueAccess context) throws WorldEditException {
|
||||||
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
|
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
|
||||||
Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask;
|
Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren