idk, messing around with region filtering

This commit is contained in:
Jesse Boyd 2019-06-26 20:22:21 +10:00
parent 6bc5b4a823
commit de4dcc0dd5
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
20 changed files with 542 additions and 222 deletions

View File

@ -16,7 +16,6 @@ import javax.annotation.Nullable;
import static com.sk89q.worldedit.world.block.BlockTypes.states; import static com.sk89q.worldedit.world.block.BlockTypes.states;
public class CharFilterBlock extends ChunkFilterBlock { public class CharFilterBlock extends ChunkFilterBlock {
private CharGetBlocks get; private CharGetBlocks get;
private IChunkSet set; private IChunkSet set;
private char[] getArr; private char[] getArr;
@ -43,7 +42,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
public void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask) { public void flood(final IChunkGet iget, final IChunkSet iset, final 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)) { 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;
@ -62,10 +61,11 @@ public class CharFilterBlock extends ChunkFilterBlock {
} }
} }
private final boolean init(final IChunkGet iget, final IChunkSet iset, final int layer) { @Override
public final ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer) {
this.layer = layer; this.layer = layer;
final CharGetBlocks get = (CharGetBlocks) iget; final CharGetBlocks get = (CharGetBlocks) iget;
if (!get.hasSection(layer)) return false; 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)) {
@ -76,29 +76,44 @@ public class CharFilterBlock extends ChunkFilterBlock {
setArr = null; setArr = null;
} }
this.yy = layer << 4; this.yy = layer << 4;
return true; return this;
} }
@Override @Override
public final void filter(final IChunkGet iget, final IChunkSet iset, final int layer, final Filter filter, final @Nullable Region region, BlockVector3 min, BlockVector3 max) { public void filter(Filter filter, int x, int y, int z) {
if (init(iget, iset, layer)) { this.x = x;
if (region == null) { this.y = y;
if (min != null && max != null) { this.z = z;
iterate(min, max, layer, filter); this.index = x | (z << 4) | (y << 8);
} else { filter.applyBlock(this);
iterate(filter);
} }
} else {
if (min != null && max != null) { @Override
iterate(region, min, max, layer, filter); public void filter(Filter filter, int yStart, int yEnd) {
} else { for (y = yStart, index = (yStart << 8); y < yEnd; y++) {
iterate(region, filter); for (z = 0; z < 16; z++) {
for (x = 0; x < 16; x++, index++) {
filter.applyBlock(this);
} }
} }
} }
} }
private void iterate(final Region region, final Filter filter) { @Override
public void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
int yis = (minY << 8);
int zis = (minZ << 4);
for (y = minY, index = yis; y <= maxY; y++) {
for (z = minZ, index += zis; z <= maxZ; z++) {
for (x = minX, index += minX; x <= maxX; x++, index++) {
filter.applyBlock(this);
}
}
}
}
@Override
public final void filter(final Filter filter, final 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++) {
@ -113,51 +128,8 @@ public class CharFilterBlock extends ChunkFilterBlock {
} }
} }
private void iterate(final Region region, BlockVector3 min, BlockVector3 max, int layer, final Filter filter) { @Override
int by = Math.max(min.getY(), layer << 4) & 15; public final void filter(final Filter filter) {
int ty = Math.min(max.getY(), 15 + (layer << 4)) & 15;
int bx = min.getX();
int bz = min.getZ();
int tx = max.getX();
int tz = max.getZ();
for (y = by; y <= ty; y++) {
int yIndex = (y << 8);
int absY = yy + y;
for (z = bz; z <= tz; z++) {
int zIndex = yIndex + ((z) << 4);
int absZ = zz + z;
for (x = bx; x <= tx; x++) {
index = zIndex + x;
int absX = xx + x;
if (region.contains(absX, absY, absZ)) {
filter.applyBlock(this);
}
}
}
}
}
private void iterate(BlockVector3 min, BlockVector3 max, int layer, final Filter filter) {
int by = Math.max(min.getY(), layer << 4) & 15;
int ty = Math.min(max.getY(), 15 + (layer << 4)) & 15;
int bx = min.getX();
int bz = min.getZ();
int tx = max.getX();
int tz = max.getZ();
for (y = by; y <= ty; y++) {
int yIndex = (y << 8);
for (z = bz; z <= tz; z++) {
int zIndex = yIndex + ((z) << 4);
for (x = bx; x <= tx; x++) {
index = zIndex + x;
filter.applyBlock(this);
}
}
}
}
private final void iterate(final 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++) {

View File

@ -13,7 +13,18 @@ public abstract class ChunkFilterBlock extends SimpleFilterBlock {
public abstract ChunkFilterBlock init(int X, int Z, IChunkGet chunk); public abstract ChunkFilterBlock init(int X, int Z, IChunkGet chunk);
public abstract ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer);
public abstract void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask); public abstract void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask);
public abstract void filter(IChunkGet get, IChunkSet set, int layer, Filter filter, @Nullable Region region, BlockVector3 min, BlockVector3 max);
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);
public abstract void filter(Filter filter, int yStart, int yEnd);
public abstract void filter(final Filter filter, final Region region);
} }

View File

@ -6,5 +6,5 @@ package com.boydti.fawe.beta;
public interface IBlocks extends Trimable { public interface IBlocks extends Trimable {
boolean hasSection(int layer); boolean hasSection(int layer);
void reset(); IChunkSet reset();
} }

View File

@ -71,7 +71,7 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T> {
* @param unitialized a mutable block vector (buffer) * @param unitialized a mutable block vector (buffer)
* @param unitialized2 a mutable block vector (buffer) * @param unitialized2 a mutable block vector (buffer)
*/ */
void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region, MutableBlockVector3 unitialized, MutableBlockVector3 unitialized2); void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region);
void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block); void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block);

View File

@ -8,8 +8,6 @@ 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 javax.annotation.Nullable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -43,7 +41,7 @@ public interface IChunkSet extends IBlocks, OutputExtent {
Set<UUID> getEntityRemoves(); Set<UUID> getEntityRemoves();
@Override @Override
void reset(); IChunkSet reset();
@Nullable @Nullable
@Override @Override

View File

@ -3,7 +3,6 @@ package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
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;

View File

@ -1,14 +1,6 @@
package com.boydti.fawe.beta; package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
public abstract class SimpleFilterBlock extends FilterBlock { public abstract class SimpleFilterBlock extends FilterBlock {
private final Extent extent; private final Extent extent;

View File

@ -0,0 +1,113 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public interface DelegateChunkSet extends IChunkSet {
IChunkSet getParent();
@Override
default boolean setBiome(int x, int y, int z, BiomeType biome) {
return getParent().setBiome(x, y, z, biome);
}
@Override
default boolean setBlock(int x, int y, int z, BlockStateHolder holder) {
return getParent().setBlock(x, y, z, holder);
}
@Override
default boolean isEmpty() {
return getParent().isEmpty();
}
@Override
default void setTile(int x, int y, int z, CompoundTag tile) {
getParent().setTile(x, y, z, tile);
}
@Override
default void setEntity(CompoundTag tag) {
getParent().setEntity(tag);
}
@Override
default void removeEntity(UUID uuid) {
getParent().removeEntity(uuid);
}
@Override
default BlockState getBlock(int x, int y, int z) {
return getParent().getBlock(x, y, z);
}
@Override
default char[] getArray(int layer) {
return getParent().getArray(layer);
}
@Override
default BiomeType[] getBiomes() {
return getParent().getBiomes();
}
@Override
default Map<Short, CompoundTag> getTiles() {
return getParent().getTiles();
}
@Override
default Set<CompoundTag> getEntities() {
return getParent().getEntities();
}
@Override
default Set<UUID> getEntityRemoves() {
return getParent().getEntityRemoves();
}
@Override
default IChunkSet reset() {
IChunkSet parent = getParent();
parent.reset();
return parent;
}
@Override
@Nullable
default Operation commit() {
return getParent().commit();
}
@Override
default boolean hasSection(int layer) {
return getParent().hasSection(layer);
}
@Override
default boolean trim(boolean aggressive) {
return getParent().trim(aggressive);
}
@Override
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
return getParent().setBlock(position, block);
}
@Override
default boolean setBiome(BlockVector2 position, BiomeType biome) {
return getParent().setBiome(position, biome);
}
}

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.beta.implementation.blocks; package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IBlocks; import com.boydti.fawe.beta.IBlocks;
import com.boydti.fawe.beta.IChunkSet;
public class CharBlocks implements IBlocks { public class CharBlocks implements IBlocks {
public final char[][] blocks; public final char[][] blocks;
@ -9,14 +10,14 @@ 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] = NULL; for (int i = 0; i < 16; i++) sections[i] = EMPTY;
} }
@Override @Override
public boolean trim(final boolean aggressive) { public boolean trim(final 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] == NULL) { if (sections[i] == EMPTY) {
blocks[i] = null; blocks[i] = null;
} else { } else {
result = false; result = false;
@ -26,12 +27,13 @@ public class CharBlocks implements IBlocks {
} }
@Override @Override
public void reset() { public IChunkSet reset() {
for (int i = 0; i < 16; i++) sections[i] = NULL; for (int i = 0; i < 16; i++) sections[i] = EMPTY;
return null;
} }
public void reset(final int layer) { public void reset(final int layer) {
sections[layer] = NULL; sections[layer] = EMPTY;
} }
public char[] load(final int layer) { public char[] load(final int layer) {
@ -84,7 +86,7 @@ public class CharBlocks implements IBlocks {
} }
} }
public static final Section NULL = new Section() { public static final Section EMPTY = new Section() {
@Override @Override
public final char[] get(final CharBlocks blocks, final int layer) { public final char[] get(final CharBlocks blocks, final int layer) {
blocks.sections[layer] = FULL; blocks.sections[layer] = FULL;

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.beta.implementation.blocks; package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
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;
@ -19,14 +20,15 @@ public abstract class CharGetBlocks extends CharBlocks implements IChunkGet {
@Override @Override
public boolean trim(final boolean aggressive) { public boolean trim(final boolean aggressive) {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
sections[i] = NULL; sections[i] = EMPTY;
blocks[i] = null; blocks[i] = null;
} }
return true; return true;
} }
@Override @Override
public void reset() { public IChunkSet reset() {
super.reset(); super.reset();
return null;
} }
} }

View File

@ -102,11 +102,12 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
} }
@Override @Override
public void reset() { public IChunkSet reset() {
biomes = null; biomes = null;
tiles = null; tiles = null;
entities = null; entities = null;
entityRemoves = null; entityRemoves = null;
super.reset(); super.reset();
return null;
} }
} }

View File

@ -0,0 +1,77 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.implementation.DelegateChunkSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
public class RegionCharSetBlocks implements DelegateChunkSet {
private final Region region;
private final CharSetBlocks parent;
private final int X, Z;
public RegionCharSetBlocks(Region region, int X, int Z, CharSetBlocks parent) {
this.region = region;
this.parent = parent;
this.X = X;
this.Z = Z;
}
@Override
public CharSetBlocks getParent() {
return parent;
}
public Region getRegion() {
return region;
}
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
if (region.contains(x, y, z)) {
return parent.setBiome(x, y, z, biome);
}
return false;
}
public static final CharBlocks.Section EMPTY_REGION = new CharBlocks.Section() {
@Override
public final char[] get(final CharBlocks blocks, final int layer) {
RegionCharSetBlocks checked = (RegionCharSetBlocks) blocks;
Region region = checked.getRegion();
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 CharBlocks.Section NULL = new CharBlocks.Section() {
@Override
public final char[] get(final CharBlocks blocks, final int layer) {
return FaweCache.EMPTY_CHAR_4096;
}
};
// EMPTY_CHAR_4096
@Override
public boolean setBlock(final int x, final int y, final int z, final BlockStateHolder holder) {
}
@Override
public void setTile(final int x, final int y, final int z, final CompoundTag tile) {
if (region.contains(x, y, z)) {
super.setTile(x, y, z, tile);
}
}
}

View File

@ -2,16 +2,15 @@ package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.ChunkFilterBlock; import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter; import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.FilterBlockMask; import com.boydti.fawe.beta.FilterBlockMask;
import com.boydti.fawe.beta.Flood; import com.boydti.fawe.beta.Flood;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.blocks.CharSetBlocks;
import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet; import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent; import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent;
import com.boydti.fawe.beta.implementation.WorldChunkCache; import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.boydti.fawe.beta.implementation.blocks.CharSetBlocks;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
@ -47,38 +46,19 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
} }
@Override @Override
public void filterBlocks(final Filter filter, ChunkFilterBlock block, @Nullable Region region, @Nullable final MutableBlockVector3 min, @Nullable final MutableBlockVector3 max) { public void filterBlocks(final 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 {
if (region != null) { if (region != null) {
switch (region.getChunkBounds(X, Z, min, max)) { region.filter(this, filter, block, get, set);
case NONE: } else {
return;
case FULL:
if (min.getY() == 0 && max.getY() == 255) {
break;
}
case PARTIAL:
region = null;
case CHECKED:
default: {
int minLayer = min.getY() >> 4;
int maxLayer = max.getY() >> 4;
block = block.init(X, Z, get);
for (int layer = minLayer; layer <= maxLayer; layer++) {
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
block.filter(get, set, layer, filter, region, min, max);
}
return;
}
}
}
block = block.init(X, Z, get); block = block.init(X, Z, 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.filter(get, set, layer, filter, region, null, null); block.init(get, set, layer);
block.filter(filter);
}
} }
} finally { } finally {
filter.finishChunk(this); filter.finishChunk(this);

View File

@ -35,5 +35,4 @@ public interface RegionFunction {
* @throws WorldEditException thrown on an error * @throws WorldEditException thrown on an error
*/ */
boolean apply(BlockVector3 position) throws WorldEditException; boolean apply(BlockVector3 position) throws WorldEditException;
} }

View File

@ -19,29 +19,27 @@
package com.sk89q.worldedit.regions; package com.sk89q.worldedit.regions;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.object.collection.BlockVectorSet; import com.boydti.fawe.object.collection.BlockVectorSet;
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector2; import com.sk89q.worldedit.math.MutableBlockVector2;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.ChunkStore; import com.sk89q.worldedit.world.storage.ChunkStore;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.regions.Region.Contains.*;
/** /**
* An axis-aligned cuboid. It can be defined using two corners of the cuboid. * An axis-aligned cuboid. It can be defined using two corners of the cuboid.
@ -400,13 +398,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
public boolean contains(int x, int z) { public boolean contains(int x, int z) {
return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ; return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ;
} }
@Override
public boolean contains(BlockVector3 position) {
BlockVector3 min = getMinimumPoint();
BlockVector3 max = getMaximumPoint();
return position.containedWithin(min, max);
}
@Override @Override
public Iterator<BlockVector3> iterator() { public Iterator<BlockVector3> iterator() {
if (Settings.IMP.HISTORY.COMPRESSION_LEVEL >= 9 || useOldIterator) { if (Settings.IMP.HISTORY.COMPRESSION_LEVEL >= 9 || useOldIterator) {
@ -629,35 +621,49 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
} }
@Override @Override
public Contains getChunkBounds(int X, int Z, MutableBlockVector3 min, MutableBlockVector3 max) { public int getMinY() {
int minChunkX = minX >> 4; return minY;
if (minChunkX <= X) { }
int maxChunkX = maxX >> 4;
if (maxChunkX >= X) {
int minChunkZ = minZ >> 4;
if (minChunkZ <= Z) {
int maxChunkZ = maxZ >> 4;
if (maxChunkZ >= Z) {
int cx1 = X << 4;
int cx2 = cx1 + 15;
int cz1 = Z << 4;
int cz2 = cz1 + 15;
int bx = Math.max(cx1, minX); @Override
int bz = Math.max(cz1, minZ); public int getMaxY() {
int tx = Math.min(cx2, maxX); return maxY;
int tz = Math.min(cz2, maxZ); }
min.setComponents(bx & 15, minY, bz & 15); @Override
max.setComponents(tx & 15, maxY, tz & 15); public void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set) {
if (min.getX() == 0 && min.getZ() == 0 && max.getX() == 15 && max.getZ() == 15) { int X = chunk.getX();
return FULL; int Z = chunk.getZ();
block = block.init(X, Z, get);
if ((minX + 15) >> 4 <= X && (maxX - 15) >> 4 >= X && (minZ + 15) >> 4 <= Z && (maxZ - 15) >> 4 >= Z) {
filter(chunk, filter, block, get, set, minY, maxY);
return;
} }
return PARTIAL; int localMinX = Math.max(minX, X << 4) & 15;
int localMaxX = Math.min(maxX, 15 + X << 4) & 15;
int localMinZ = Math.max(minZ, Z << 4) & 15;
int localMaxZ = Math.min(maxZ, 15 + Z << 4) & 15;
int yStart = (minY & 15);
int yEnd = (maxY & 15);
int minSection = minY >> 4;
int maxSection = maxY >> 4;
if (minSection == maxSection) {
filter(chunk, filter, block, get, set, minSection, localMinX, yStart, localMinZ, localMaxX, yEnd, localMaxZ);
return;
}
if (yStart != 0) {
filter(chunk, filter, block, get, set, minSection, localMinX, yStart, localMinZ, localMaxX, 15, localMaxZ);
minSection++;
}
if (yEnd != 15) {
filter(chunk, filter, block, get, set, minSection, localMinX, 0, localMinZ, localMaxX, 15, localMaxZ);
maxSection--;
}
for (int layer = minSection; layer < maxSection; layer++) {
filter(chunk, filter, block, get, set, layer, localMinX, yStart, localMinZ, localMaxX, yEnd, localMaxZ);
} }
} }
} }
}
return NONE;
}
}

View File

@ -21,6 +21,11 @@ package com.sk89q.worldedit.regions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
@ -290,25 +295,22 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
minY += changeY; minY += changeY;
} }
/**
* Checks to see if a point is inside this region.
*/
@Override @Override
public boolean contains(BlockVector3 position) { public boolean contains(int x, int y, int z) {
final int blockY = position.getBlockY(); if (y < minY || y > maxY) {
if (blockY < minY || blockY > maxY) {
return false; return false;
} }
int px = position.getBlockX(); return contains(x, z);
int pz = position.getBlockZ(); }
double dx = Math.abs(px - center.getBlockX()) * radiusInverse.getX(); @Override
double dz = Math.abs(pz - center.getBlockZ()) * radiusInverse.getZ(); public boolean contains(int x, int z) {
double dx = Math.abs(x - center.getBlockX()) * radiusInverse.getX();
double dz = Math.abs(z - center.getBlockZ()) * radiusInverse.getZ();
return dx * dx + dz * dz <= 1; return dx * dx + dz * dz <= 1;
} }
/** /**
* Sets the height of the cylinder to fit the specified Y. * Sets the height of the cylinder to fit the specified Y.
* *
@ -363,6 +365,16 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
return Polygons.polygonizeCylinder(center, radius, maxPoints); return Polygons.polygonizeCylinder(center, radius, maxPoints);
} }
@Override
public int getMinY() {
return minY;
}
@Override
public int getMaxY() {
return maxY;
}
/** /**
* Return a new instance with the given center and radius in the X and Z * Return a new instance with the given center and radius in the X and Z
* axes with a Y that extends from the bottom of the extent to the top * axes with a Y that extends from the bottom of the extent to the top
@ -381,4 +393,17 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
int maxY = extent.getMaximumPoint().getBlockY(); int maxY = extent.getMaximumPoint().getBlockY();
return new CylinderRegion(center, radiusVec, minY, maxY); return new CylinderRegion(center, radiusVec, minY, maxY);
} }
@Override
public void filter(final IChunk chunk, final Filter filter, final ChunkFilterBlock block, final IChunkGet get, final IChunkSet set) {
int bcx = chunk.getX() >> 4;
int bcz = chunk.getZ() >> 4;
int tcx = bcx + 15;
int tcz = bcz + 15;
if (contains(bcx, bcz) && contains(tcx, tcz)) {
filter(chunk, filter, block, get, set, minY, maxY);
return;
}
super.filter(chunk, filter, block, get, set);
}
} }

View File

@ -20,6 +20,11 @@
package com.sk89q.worldedit.regions; package com.sk89q.worldedit.regions;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -216,18 +221,18 @@ public class EllipsoidRegion extends AbstractRegion {
} }
@Override @Override
public boolean contains(BlockVector3 position) { public boolean contains(int x, int y, int z) {
int cx = position.getBlockX() - center.getBlockX(); int cx = x - center.getBlockX();
int cx2 = cx * cx; int cx2 = cx * cx;
if (cx2 > radiusSqr.getBlockX()) { if (cx2 > radiusSqr.getBlockX()) {
return false; return false;
} }
int cz = position.getBlockZ() - center.getBlockZ(); int cz = z - center.getBlockZ();
int cz2 = cz * cz; int cz2 = cz * cz;
if (cz2 > radiusSqr.getBlockZ()) { if (cz2 > radiusSqr.getBlockZ()) {
return false; return false;
} }
int cy = position.getBlockY() - center.getBlockY(); int cy = y - center.getBlockY();
int cy2 = cy * cy; int cy2 = cy * cy;
if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) { if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) {
return false; return false;
@ -235,10 +240,30 @@ public class EllipsoidRegion extends AbstractRegion {
if (sphere) { if (sphere) {
return cx2 + cy2 + cz2 <= radiusLengthSqr; return cx2 + cy2 + cz2 <= radiusLengthSqr;
} }
double cxd = cx * inverseRadius.getX(); double cxd = cx2 * inverseRadius.getX();
double cyd = cy * inverseRadius.getY(); double cyd = cy2 * inverseRadius.getY();
double czd = cz * inverseRadius.getZ(); double czd = cz2 * inverseRadius.getZ();
return cxd * cxd + cyd * cyd + czd * czd <= 1; return cxd + cyd + czd <= 1;
}
@Override
public boolean contains(int x, int z) {
int cx = x - center.getBlockX();
int cx2 = cx * cx;
if (cx2 > radiusSqr.getBlockX()) {
return false;
}
int cz = z - center.getBlockZ();
int cz2 = cz * cz;
if (cz2 > radiusSqr.getBlockZ()) {
return false;
}
if (sphere) {
return cx2 + cz2 <= radiusLengthSqr;
}
double cxd = cx2 * inverseRadius.getX();
double czd = cz2 * inverseRadius.getZ();
return cxd + czd <= 1;
} }
/** /**
@ -260,4 +285,96 @@ public class EllipsoidRegion extends AbstractRegion {
public EllipsoidRegion clone() { public EllipsoidRegion clone() {
return (EllipsoidRegion) super.clone(); return (EllipsoidRegion) super.clone();
} }
@Override
public void filter(IChunk chunk, Filter filter, ChunkFilterBlock block, IChunkGet get, IChunkSet set) {
int bx = chunk.getX() << 4;
int bz = chunk.getZ() << 4;
int tx = bx + 15;
int tz = bz + 15;
int cx1 = bx - center.getBlockX();
int cx2 = tx - center.getBlockX();
int cxMax, cxMin;
if (cx1 < cx2) {
cxMin = cx1;
cxMax = cx2;
} else {
cxMin = cx2;
cxMax = cx1;
}
int cxMin2 = cxMin * cxMin;
int cxMax2 = cxMax * cxMax;
int cz1 = bz - center.getBlockZ();
int cz2 = tz - center.getBlockZ();
int czMax, czMin;
if (cz1 < cz2) {
czMin = cz1;
czMax = cz2;
} else {
czMin = cz2;
czMax = cz1;
}
int czMin2 = czMin * czMin;
int czMax2 = czMax * czMax;
if (sphere) {
if (cxMin2 + czMin2 >= radiusLengthSqr) {
return;
}
int diffY2 = radiusLengthSqr - cxMax2 - czMax2;
if (diffY2 > 0) {
diffy2
}
} else {
if (cxMin2 * inverseRadius.getX() + czMin2 * inverseRadius.getZ() > 1) {
return;
}
partial = cxMax2 * inverseRadius.getX() + czMax2 * inverseRadius.getZ() > 1;
}
if (partial) {
} else {
// get min y and max y
for (int layer = 0; layer < 16; layer++) {
// if contains all
{
filter(chunk, )
}
}
}
int cy1 = 0 - center.getBlockY();
int cy2 = 255 - center.getBlockY();
int cyMax, cyMin;
if (cy1 < cy2) {
cyMin = cy1;
cyMax = cy2;
} else {
cyMin = cy2;
cyMax = cy1;
}
int cyMin2 = cyMin * cyMin;
int cyMax2 = cyMax * cyMax;
boolean containsMin = contains(bx, bz);
boolean containsMax = contains(tx, tz);
if (containsMin && containsMax) {
// set all
return;
}
for (int layer = 0; layer < 16; layer++) {
if (contains())
}
TODO optimize;
int minY = getMinY();
int maxY = getMaxY();
contains()
}
} }

View File

@ -19,6 +19,12 @@
package com.sk89q.worldedit.regions; package com.sk89q.worldedit.regions;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3;
@ -26,12 +32,10 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static com.sk89q.worldedit.regions.Region.Contains.CHECKED;
import static com.sk89q.worldedit.regions.Region.Contains.NONE;
/** /**
* Represents a physical shape. * Represents a physical shape.
*/ */
@ -137,7 +141,9 @@ public interface Region extends Iterable<BlockVector3>, Cloneable {
* @param position the position * @param position the position
* @return true if contained * @return true if contained
*/ */
boolean contains(BlockVector3 position); default boolean contains(BlockVector3 position) {
return contains(position.getX(), position.getY(), position.getZ());
}
/** /**
* Get a list of chunks. * Get a list of chunks.
@ -183,32 +189,62 @@ public interface Region extends Iterable<BlockVector3>, Cloneable {
*/ */
List<BlockVector2> polygonize(int maxPoints); List<BlockVector2> polygonize(int maxPoints);
default Contains getChunkBounds(int X, int Z, MutableBlockVector3 min, MutableBlockVector3 max) { default int getMinY() {
BlockVector3 pos1 = getMinimumPoint(); return getMinimumPoint().getY();
BlockVector3 pos2 = getMaximumPoint();
int cx1 = X << 4;
int cx2 = cx1 + 15;
int cz1 = Z << 4;
int cz2 = cz1 + 15;
int bx = Math.max(cx1, pos1.getX());
int bz = Math.max(cz1, pos1.getZ());
int tx = Math.min(cx2, pos2.getX());
int tz = Math.min(cz2, pos2.getZ());
min.setComponents(bx & 15, pos1.getY(), bz & 15);
max.setComponents(tx & 15, pos2.getY(), tz & 15);
if (bx > cx2 || bz > cz2 || tx < cx1 || tz < cz1) {
return NONE;
}
return CHECKED;
} }
enum Contains { default int getMaxY() {
FULL, return getMaximumPoint().getY();
PARTIAL, }
CHECKED,
NONE; default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set) {
int minSection = Math.max(0, getMinY() >> 4);
int maxSection = Math.min(15, getMaxY() >> 4);
for (int layer = minSection; layer <= maxSection; layer++) {
if (!get.hasSection(layer) || !filter.appliesLayer(chunk, layer)) return;
block = block.init(get, set, layer);
block.filter(filter, this);
}
}
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, final int minY, final int maxY) {
int minSection = minY >> 4;
int maxSection = maxY >> 4;
int yStart = (minY & 15);
int yEnd = (maxY & 15);
if (minSection == maxSection) {
filter(chunk, filter, block, get, set, minSection, yStart, yEnd);
return;
}
if (yStart != 0) {
filter(chunk, filter, block, get, set, minSection, yStart, 15);
minSection++;
}
if (yEnd != 15) {
filter(chunk, filter, block, get, set, minSection, 0, yEnd);
maxSection--;
}
for (int layer = minSection; layer < maxSection; layer++) {
filter(chunk, filter, block, get, set, layer);
}
return;
}
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, int layer) {
if (!get.hasSection(layer) || !filter.appliesLayer(chunk, layer)) return;
block = block.init(get, set, layer);
block.filter(filter);
}
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, int layer, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
if (!get.hasSection(layer) || !filter.appliesLayer(chunk, layer)) return;
block = block.init(get, set, layer);
block.filter(filter, minX, minY, minZ, maxX, maxY, maxZ);
}
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, int layer, int yStart, int yEnd) {
if (!get.hasSection(layer) || !filter.appliesLayer(chunk, layer)) return;
block = block.init(get, set, layer);
block.filter(filter, yStart, yEnd);
} }
} }

View File

@ -19,16 +19,8 @@
package com.sk89q.worldedit.regions; package com.sk89q.worldedit.regions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.regions.Region.Contains.CHECKED;
import static com.sk89q.worldedit.regions.Region.Contains.FULL;
import static com.sk89q.worldedit.regions.Region.Contains.NONE;
import static com.sk89q.worldedit.regions.Region.Contains.PARTIAL;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import java.util.ArrayList; import java.util.ArrayList;
@ -36,6 +28,9 @@ import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* An intersection of several other regions. Any location that is contained in one * An intersection of several other regions. Any location that is contained in one
* of the child regions is considered as contained by this region. * of the child regions is considered as contained by this region.

View File

@ -148,11 +148,6 @@ public class RequestSelection implements Region {
return getRegion().polygonize(maxPoints); return getRegion().polygonize(maxPoints);
} }
@Override
public Contains getChunkBounds(int X, int Z, MutableBlockVector3 min, MutableBlockVector3 max) {
return getRegion().getChunkBounds(X, Z, min, max);
}
@Override @Override
public Iterator<BlockVector3> iterator() { public Iterator<BlockVector3> iterator() {
return getRegion().iterator(); return getRegion().iterator();