resolve conflicts

This commit is contained in:
Jesse Boyd
2019-07-18 16:56:57 +10:00
parent dd38cbe750
commit be8213d8ee
49 changed files with 1819 additions and 1722 deletions

View File

@ -22,6 +22,11 @@ package com.sk89q.worldedit.regions;
import static com.google.common.base.Preconditions.checkArgument;
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.boydti.fawe.config.Settings;
import com.boydti.fawe.object.collection.BlockVectorSet;
import com.sk89q.worldedit.math.BlockVector2;
@ -387,7 +392,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
return chunks;
}
@Override
public boolean contains(int x, int y, int z) {
return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ && y >= this.minY && y <= this.maxY;
@ -398,14 +402,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
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
public Iterator<BlockVector3> iterator() {
if (Settings.IMP.HISTORY.COMPRESSION_LEVEL >= 9 || useOldIterator) {
@ -610,4 +606,51 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
BlockVector3 size = BlockVector3.ONE.multiply(apothem);
return new CuboidRegion(origin.subtract(size), origin.add(size));
}
@Override
public int getMinY() {
return minY;
}
@Override
public int getMaxY() {
return maxY;
}
@Override
public void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set) {
int X = chunk.getX();
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;
}
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);
}
}
}

View File

@ -21,6 +21,11 @@ package com.sk89q.worldedit.regions;
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.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
@ -288,26 +293,22 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
minY += changeY;
}
/**
* Checks to see if a point is inside this region.
*/
@Override
public boolean contains(BlockVector3 position) {
final int blockY = position.getBlockY();
if (blockY < minY || blockY > maxY) {
public boolean contains(int x, int y, int z) {
if (y < minY || y > maxY) {
return false;
}
//todo the following lines can possibly be removed and replaced with upstream
int px = position.getBlockX();
int pz = position.getBlockZ();
return contains(x, z);
}
double dx = Math.abs(px - center.getBlockX()) * radiusInverse.getX();
double dz = Math.abs(pz - center.getBlockZ()) * radiusInverse.getZ();
@Override
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;
}
/**
* Sets the height of the cylinder to fit the specified Y.
*
@ -362,6 +363,16 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
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
* axes with a Y that extends from the bottom of the extent to the top
@ -381,4 +392,16 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
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

@ -19,6 +19,13 @@
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.util.MathMan;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -44,6 +51,7 @@ public class EllipsoidRegion extends AbstractRegion {
private Vector3 radius;
private Vector3 radiusSqr;
private Vector3 inverseRadius;
private int radiusLengthSqr;
private boolean sphere;
@ -180,6 +188,12 @@ public class EllipsoidRegion extends AbstractRegion {
radiusSqr = radius.multiply(radius);
radiusLengthSqr = (int) radiusSqr.getX();
this.sphere = radius.getY() == radius.getX() && radius.getX() == radius.getZ();
if (radius.getY() == radius.getX() && radius.getX() == radius.getZ()) {
this.sphere = true;
} else {
this.sphere = false;
}
inverseRadius = Vector3.ONE.divide(radius);
}
@Override
@ -206,30 +220,50 @@ public class EllipsoidRegion extends AbstractRegion {
return chunks;
}
@Override
public boolean contains(int x, int y, 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;
}
int cy = y - center.getBlockY();
int cy2 = cy * cy;
if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) {
return false;
}
if (sphere) {
return cx2 + cy2 + cz2 <= radiusLengthSqr;
}
double cxd = cx2 * inverseRadius.getX();
double cyd = cy2 * inverseRadius.getY();
double czd = cz2 * inverseRadius.getZ();
return cxd + cyd + czd <= 1;
}
@Override
public boolean contains(BlockVector3 position) {
int cx = position.getBlockX() - center.getBlockX();
public boolean contains(int x, int z) {
int cx = x - center.getBlockX();
int cx2 = cx * cx;
if (cx2 > radiusSqr.getBlockX()) {
return false;
}
int cz = position.getBlockZ() - center.getBlockZ();
int cz = z - center.getBlockZ();
int cz2 = cz * cz;
if (cz2 > radiusSqr.getBlockZ()) {
return false;
}
int cy = position.getBlockY() - center.getBlockY();
int cy2 = cy * cy;
if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) {
return false;
}
if (sphere) {
return cx2 + cy2 + cz2 <= radiusLengthSqr;
return cx2 + cz2 <= radiusLengthSqr;
}
double cxd = (double) cx / radius.getBlockX();
double cyd = (double) cy / radius.getBlockY();
double czd = (double) cz / radius.getBlockZ();
return cxd * cxd + cyd * cyd + czd * czd <= 1;
double cxd = cx2 * inverseRadius.getX();
double czd = cz2 * inverseRadius.getZ();
return cxd + czd <= 1;
}
/**
@ -252,4 +286,113 @@ public class EllipsoidRegion extends AbstractRegion {
return (EllipsoidRegion) super.clone();
}
private void filterSpherePartial(int y1, int y2, int bx, int bz, Filter filter, ChunkFilterBlock block, IChunkGet get, IChunkSet set) {
int sectionStart = y1 >> 4;
int sectionEnd = y2 >> 4;
}
private void filterSpherePartial(int layer, int y1, int y2, int bx, int bz, Filter filter, ChunkFilterBlock block, IChunkGet get, IChunkSet set) {
int cx = center.getBlockX();
int cy = center.getBlockY();
int cz = center.getBlockZ();
block.init(get, set, layer);
int by = layer << 4;
int diffY;
for (int y = y1, yy = by + y1; y <= y2; y++, yy++) {
diffY = cy - yy;
int remainderY = radiusLengthSqr - (diffY * diffY);
if (remainderY >= 0) {
for (int z = 0; z < 16; z++) {
int zz = z + bz;
int diffZ = cz - zz;
int remainderZ = remainderY - (diffZ * diffZ);
if (remainderZ >= 0) {
int diffX = MathMan.usqrt(remainderZ);
int minX = Math.max(0, cx - diffX - bx);
int maxX = Math.min(15, cx + diffX - bx);
if (minX != maxX) {
block.filter(filter, minX, y, z, maxX, y, z);
}
}
}
}
}
}
@Override
public void filter(IChunk chunk, Filter filter, ChunkFilterBlock block, IChunkGet get, IChunkSet set) {
// Check bounds
// This needs to be able to perform 50M blocks/sec otherwise it becomes a bottleneck
int cx = center.getBlockX();
int cz = center.getBlockZ();
int bx = chunk.getX() << 4;
int bz = chunk.getZ() << 4;
int tx = bx + 15;
int tz = bz + 15;
int cx1 = bx - cx;
int cx2 = tx - cx;
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 - cz;
int cz2 = tz - cz;
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) {
// Does not contain chunk
if (cxMin2 + czMin2 >= radiusLengthSqr) {
return;
}
int diffY2 = radiusLengthSqr - cxMax2 - czMax2;
// (shortcut) Contains all of certain layers
if (diffY2 >= 0) {
// Get the solid layers
int cy = center.getBlockY();
int diffYFull = MathMan.usqrt(diffY2);
int yBotFull = Math.max(0, cy - diffYFull);
int yTopFull = Math.min(255, cy + diffYFull);
// Set those layers
filter(chunk, filter, block, get, set, yBotFull, yTopFull);
// Fill the remaining layers
if (yBotFull != 0 || yTopFull != 255) {
int diffYPartial = MathMan.usqrt(radiusLengthSqr - cxMin * cxMin - czMin * czMin);
if (yBotFull != 0) {
int yBotPartial = Math.max(0, cy - diffYPartial);
filterSpherePartial(yBotPartial, yBotFull - 1, bx, bz, filter, block, get, set);
}
if (yTopFull != 255) {
int yTopPartial = Math.min(255, cy + diffYPartial);
filterSpherePartial(yTopFull + 1, yTopPartial - 1, bx, bz, filter, block, get, set);
}
}
}
} else {
super.filter(chunk, filter, block, get, set); // TODO optimize non spheres
}
}
}