mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Further non-standard selection fixes as per #393
- Fix incorrect usage of initChunk (it's run in the right place now) - Fix poorly implemented //sel sphere "improvements"
This commit is contained in:
parent
b52fc46f19
commit
330fc39dde
@ -148,7 +148,7 @@ public interface IQueueExtent<T extends IChunk> extends Flushable, Trimable, ICh
|
|||||||
if (newChunk != null) {
|
if (newChunk != null) {
|
||||||
chunk = newChunk;
|
chunk = newChunk;
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
block = this.initFilterBlock().initChunk(chunkX, chunkZ);
|
block = this.initFilterBlock();
|
||||||
}
|
}
|
||||||
chunk.filterBlocks(filter, block, region, full);
|
chunk.filterBlocks(filter, block, region, full);
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
package com.sk89q.worldedit.regions;
|
package com.sk89q.worldedit.regions;
|
||||||
|
|
||||||
|
|
||||||
import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock;
|
|
||||||
import com.boydti.fawe.beta.Filter;
|
import com.boydti.fawe.beta.Filter;
|
||||||
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.implementation.filter.block.ChunkFilterBlock;
|
||||||
import com.boydti.fawe.util.MathMan;
|
import com.boydti.fawe.util.MathMan;
|
||||||
import com.sk89q.worldedit.math.BlockVector2;
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
@ -34,7 +34,6 @@ import com.sk89q.worldedit.world.storage.ChunkStore;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an ellipsoid region.
|
* Represents an ellipsoid region.
|
||||||
@ -95,7 +94,8 @@ public class EllipsoidRegion extends AbstractRegion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getArea() {
|
public int getArea() {
|
||||||
return (int) Math.floor((4.0 / 3.0) * Math.PI * radius.getX() * radius.getY() * radius.getZ());
|
return (int) Math
|
||||||
|
.floor((4.0 / 3.0) * Math.PI * radius.getX() * radius.getY() * radius.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -185,15 +185,10 @@ public class EllipsoidRegion extends AbstractRegion {
|
|||||||
* @param radius the radius
|
* @param radius the radius
|
||||||
*/
|
*/
|
||||||
public void setRadius(Vector3 radius) {
|
public void setRadius(Vector3 radius) {
|
||||||
this.radius = radius;
|
this.radius = radius.add(0.5, 0.5, 0.5);
|
||||||
radiusSqr = radius.multiply(radius);
|
radiusSqr = radius.multiply(radius);
|
||||||
radiusLengthSqr = (int) radiusSqr.getX();
|
radiusLengthSqr = (int) radiusSqr.getX();
|
||||||
this.sphere = radius.getY() == radius.getX() && radius.getX() == radius.getZ();
|
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);
|
inverseRadius = Vector3.ONE.divide(radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,14 +202,12 @@ public class EllipsoidRegion extends AbstractRegion {
|
|||||||
|
|
||||||
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
|
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
|
||||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
|
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
|
||||||
if (!contains(BlockVector3.at(x, centerY, z))) {
|
if (!contains(x, centerY, z)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
chunks.add(BlockVector2.at(
|
chunks.add(
|
||||||
x >> ChunkStore.CHUNK_SHIFTS,
|
BlockVector2.at(x >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS));
|
||||||
z >> ChunkStore.CHUNK_SHIFTS
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,9 +265,6 @@ public class EllipsoidRegion extends AbstractRegion {
|
|||||||
if (cz2 > radiusSqr.getBlockZ()) {
|
if (cz2 > radiusSqr.getBlockZ()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (sphere) {
|
|
||||||
return cx2 + cz2 <= radiusLengthSqr;
|
|
||||||
}
|
|
||||||
double cxd = cx2 * inverseRadius.getX();
|
double cxd = cx2 * inverseRadius.getX();
|
||||||
double czd = cz2 * inverseRadius.getZ();
|
double czd = cz2 * inverseRadius.getZ();
|
||||||
return cxd + czd <= 1;
|
return cxd + czd <= 1;
|
||||||
@ -300,18 +290,34 @@ public class EllipsoidRegion extends AbstractRegion {
|
|||||||
return (EllipsoidRegion) super.clone();
|
return (EllipsoidRegion) super.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterSpherePartial(int y1, int y2, int bx, int bz, Filter filter, ChunkFilterBlock block, IChunkGet get, IChunkSet set) {
|
private void filterSpherePartial(int y1, int y2, int bx, int bz, Filter filter,
|
||||||
int sectionStart = y1 >> 4;
|
ChunkFilterBlock block, IChunkGet get, IChunkSet set) {
|
||||||
int sectionEnd = y2 >> 4;
|
int minSection = y1 >> 4;
|
||||||
|
int maxSection = y2 >> 4;
|
||||||
|
int yStart = (y1 & 15);
|
||||||
|
int yEnd = (y2 & 15);
|
||||||
|
|
||||||
for (int layer = sectionStart; layer < sectionEnd; layer++) {
|
if (minSection == maxSection) {
|
||||||
int yStart = Math.max(layer << 4, y1);
|
filterSpherePartial(minSection, 0, 15, bx, bz, filter, block, get, set);
|
||||||
int yEnd = Math.min((layer << 4) + 15, y2);
|
}
|
||||||
filterSpherePartial(layer, yStart, yEnd, bx, bz, filter, block, get, set);
|
|
||||||
|
if (yStart != 0) {
|
||||||
|
filterSpherePartial(minSection, yStart, 15, bx, bz, filter, block, get, set);
|
||||||
|
minSection++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (yEnd != 15) {
|
||||||
|
filterSpherePartial(maxSection, 0, yEnd, bx, bz, filter, block, get, set);
|
||||||
|
maxSection--;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int layer = minSection; layer <= maxSection; layer++) {
|
||||||
|
filterSpherePartial(layer, 0, 15, bx, bz, filter, block, get, set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterSpherePartial(int layer, int y1, int y2, int bx, int bz, Filter filter, ChunkFilterBlock block, IChunkGet get, IChunkSet set) {
|
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 cx = center.getBlockX();
|
||||||
int cy = center.getBlockY();
|
int cy = center.getBlockY();
|
||||||
int cz = center.getBlockZ();
|
int cz = center.getBlockZ();
|
||||||
@ -323,26 +329,29 @@ public class EllipsoidRegion extends AbstractRegion {
|
|||||||
for (int y = y1, yy = by + y1; y <= y2; y++, yy++) {
|
for (int y = y1, yy = by + y1; y <= y2; y++, yy++) {
|
||||||
diffY = cy - yy;
|
diffY = cy - yy;
|
||||||
int remainderY = radiusLengthSqr - (diffY * diffY);
|
int remainderY = radiusLengthSqr - (diffY * diffY);
|
||||||
if (remainderY >= 0) {
|
if (remainderY < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
int zz = z + bz;
|
int zz = z + bz;
|
||||||
int diffZ = cz - zz;
|
int diffZ = cz - zz;
|
||||||
int remainderZ = remainderY - (diffZ * diffZ);
|
int remainderZ = remainderY - (diffZ * diffZ);
|
||||||
if (remainderZ >= 0) {
|
if (remainderZ < 0) {
|
||||||
int diffX = MathMan.usqrt(remainderZ);
|
continue;
|
||||||
int minX = Math.max(0, cx - diffX - bx);
|
}
|
||||||
int maxX = Math.min(15, cx + diffX - bx);
|
int diffX, minX, maxX;
|
||||||
if (minX != maxX) {
|
diffX = (int) Math.floor(Math.sqrt(remainderZ));
|
||||||
|
minX = Math.max(0, cx - diffX - bx);
|
||||||
|
maxX = Math.min(15, cx + diffX - bx);
|
||||||
block.filter(filter, minX, y, z, maxX, y, z);
|
block.filter(filter, minX, y, z, maxX, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void filter(IChunk chunk, Filter filter, ChunkFilterBlock block, IChunkGet get, IChunkSet set, boolean full) {
|
public void filter(IChunk chunk, Filter filter, ChunkFilterBlock block, IChunkGet get,
|
||||||
|
IChunkSet set, boolean full) {
|
||||||
// Check bounds
|
// Check bounds
|
||||||
// This needs to be able to perform 50M blocks/sec otherwise it becomes a bottleneck
|
// This needs to be able to perform 50M blocks/sec otherwise it becomes a bottleneck
|
||||||
int cx = center.getBlockX();
|
int cx = center.getBlockX();
|
||||||
@ -351,52 +360,60 @@ public class EllipsoidRegion extends AbstractRegion {
|
|||||||
int bz = chunk.getZ() << 4;
|
int bz = chunk.getZ() << 4;
|
||||||
int tx = bx + 15;
|
int tx = bx + 15;
|
||||||
int tz = bz + 15;
|
int tz = bz + 15;
|
||||||
int cx1 = bx - cx;
|
|
||||||
int cx2 = tx - cx;
|
int cx1 = Math.abs(bx - cx);
|
||||||
|
int cx2 = Math.abs(tx - cx);
|
||||||
int cxMax, cxMin;
|
int cxMax, cxMin;
|
||||||
if (cx1 < cx2) {
|
cxMin = Math.min(cx1, cx2);
|
||||||
cxMin = cx1;
|
cxMax = Math.max(cx1, cx2);
|
||||||
cxMax = cx2;
|
|
||||||
} else {
|
|
||||||
cxMin = cx2;
|
|
||||||
cxMax = cx1;
|
|
||||||
}
|
|
||||||
int cxMin2 = cxMin * cxMin;
|
int cxMin2 = cxMin * cxMin;
|
||||||
int cxMax2 = cxMax * cxMax;
|
int cxMax2 = cxMax * cxMax;
|
||||||
int cz1 = bz - cz;
|
|
||||||
int cz2 = tz - cz;
|
int cz1 = Math.abs(bz - cz);
|
||||||
|
int cz2 = Math.abs(tz - cz);
|
||||||
int czMax, czMin;
|
int czMax, czMin;
|
||||||
if (cz1 < cz2) {
|
czMin = Math.min(cz1, cz2);
|
||||||
czMin = cz1;
|
czMax = Math.max(cz1, cz2);
|
||||||
czMax = cz2;
|
|
||||||
} else {
|
|
||||||
czMin = cz2;
|
|
||||||
czMax = cz1;
|
|
||||||
}
|
|
||||||
int czMin2 = czMin * czMin;
|
int czMin2 = czMin * czMin;
|
||||||
int czMax2 = czMax * czMax;
|
int czMax2 = czMax * czMax;
|
||||||
|
|
||||||
|
|
||||||
if (sphere) {
|
if (sphere) {
|
||||||
// Does not contain chunk
|
// Does not contain whole chunk
|
||||||
if (cxMin2 + czMin2 >= radiusLengthSqr) {
|
if (cxMin2 + czMin2 >= radiusLengthSqr) {
|
||||||
|
super.filter(chunk, filter, block, get, set, full);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int diffY2 = radiusLengthSqr - cxMax2 - czMax2;
|
int diffY2 = radiusLengthSqr - cxMax2 - czMax2;
|
||||||
// (shortcut) Contains all of certain layers
|
|
||||||
if (diffY2 >= 0) {
|
// Does not contain whole chunk
|
||||||
|
if (diffY2 < 0) {
|
||||||
|
super.filter(chunk, filter, block, get, set, full);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
block = block.initChunk(chunk.getX(), chunk.getZ());
|
||||||
|
|
||||||
// Get the solid layers
|
// Get the solid layers
|
||||||
int cy = center.getBlockY();
|
int cy = center.getBlockY();
|
||||||
int diffYFull = MathMan.usqrt(diffY2);
|
int diffYFull = MathMan.usqrt(diffY2);
|
||||||
|
|
||||||
int yBotFull = Math.max(0, cy - diffYFull);
|
int yBotFull = Math.max(0, cy - diffYFull);
|
||||||
int yTopFull = Math.min(255, cy + diffYFull);
|
int yTopFull = Math.min(255, cy + diffYFull);
|
||||||
|
|
||||||
|
if (yBotFull == yTopFull || yBotFull > yTopFull) {
|
||||||
|
System.out.println("aa");
|
||||||
|
}
|
||||||
// Set those layers
|
// Set those layers
|
||||||
filter(chunk, filter, block, get, set, yBotFull, yTopFull, full);
|
filter(chunk, filter, block, get, set, yBotFull, yTopFull, full);
|
||||||
|
|
||||||
// Fill the remaining layers
|
if (yBotFull == 0 && yTopFull == 255) {
|
||||||
if (yBotFull != 0 || yTopFull != 255) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int diffYPartial = MathMan.usqrt(radiusLengthSqr - cxMin * cxMin - czMin * czMin);
|
int diffYPartial = MathMan.usqrt(radiusLengthSqr - cxMin * cxMin - czMin * czMin);
|
||||||
|
|
||||||
|
//Fill the remaining layers
|
||||||
if (yBotFull != 0) {
|
if (yBotFull != 0) {
|
||||||
int yBotPartial = Math.max(0, cy - diffYPartial);
|
int yBotPartial = Math.max(0, cy - diffYPartial);
|
||||||
filterSpherePartial(yBotPartial, yBotFull - 1, bx, bz, filter, block, get, set);
|
filterSpherePartial(yBotPartial, yBotFull - 1, bx, bz, filter, block, get, set);
|
||||||
@ -404,14 +421,11 @@ public class EllipsoidRegion extends AbstractRegion {
|
|||||||
|
|
||||||
if (yTopFull != 255) {
|
if (yTopFull != 255) {
|
||||||
int yTopPartial = Math.min(255, cy + diffYPartial);
|
int yTopPartial = Math.min(255, cy + diffYPartial);
|
||||||
filterSpherePartial(yTopFull + 1, yTopPartial - 1, bx, bz, filter, block, get, set);
|
filterSpherePartial(yTopFull + 1, yTopPartial, bx, bz, filter, block, get, set);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
super.filter(chunk, filter, block, get, set, full); // TODO optimize non spheres
|
super.filter(chunk, filter, block, get, set, full);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,6 +203,7 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
|
|||||||
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, boolean full) {
|
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, boolean full) {
|
||||||
int minSection = Math.max(0, getMinimumY() >> 4);
|
int minSection = Math.max(0, getMinimumY() >> 4);
|
||||||
int maxSection = Math.min(15, getMaximumY() >> 4);
|
int maxSection = Math.min(15, getMaximumY() >> 4);
|
||||||
|
block = block.initChunk(chunk.getX(), chunk.getZ());
|
||||||
for (int layer = minSection; layer <= maxSection; layer++) {
|
for (int layer = minSection; layer <= maxSection; layer++) {
|
||||||
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) return;
|
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) return;
|
||||||
block = block.initLayer(get, set, layer);
|
block = block.initLayer(get, set, layer);
|
||||||
|
Loading…
Reference in New Issue
Block a user