Some code cleanup

- Simplify MaskFilter slightly
- Improve thread safety of LocalBlockVectorSet
- Simplify if statement in SingleThreadQueueExtent
- Better error in MathMan#tripleSearchCoords for handling of the error in some cases
Dieser Commit ist enthalten in:
dordsor21 2021-09-11 16:38:01 +01:00
Ursprung e85586db80
Commit 6e586da83e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
4 geänderte Dateien mit 9 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -7,7 +7,6 @@ import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.function.mask.Mask;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
/**
* Filter with an attached Mask used for deciding whether a block is eligible for being applied to.
@ -16,25 +15,15 @@ import java.util.function.Supplier;
*/
public class MaskFilter<T extends Filter> extends DelegateFilter<T> {
private final Supplier<Mask> supplier;
private final Mask mask;
private final AtomicInteger changes;
public MaskFilter(T other, Mask mask) {
this(other, () -> mask);
public MaskFilter(T other, Mask root) {
this(other, root, new AtomicInteger());
}
public MaskFilter(T other, Supplier<Mask> supplier) {
this(other, supplier, supplier.get());
}
public MaskFilter(T other, Supplier<Mask> supplier, Mask root) {
this(other, supplier, root, new AtomicInteger());
}
public MaskFilter(T other, Supplier<Mask> supplier, Mask root, AtomicInteger changes) {
public MaskFilter(T other, Mask root, AtomicInteger changes) {
super(other);
this.supplier = supplier;
this.mask = root;
this.changes = changes;
}
@ -63,12 +52,12 @@ public class MaskFilter<T extends Filter> extends DelegateFilter<T> {
@Override
public MaskFilter<?> newInstance(Filter other) {
return new MaskFilter<>(other, supplier);
return new MaskFilter<>(other, mask);
}
@Override
public Filter fork() {
return new MaskFilter<>(getParent().fork(), mask::copy, mask.copy(), changes);
return new MaskFilter<>(getParent().fork(), mask.copy(), changes);
}
}

Datei anzeigen

@ -17,8 +17,8 @@ import java.util.Set;
public class LocalBlockVectorSet implements Set<BlockVector3> {
private final SparseBitSet set;
private int offsetX;
private int offsetZ;
private volatile int offsetX;
private volatile int offsetZ;
public LocalBlockVectorSet() {
offsetX = offsetZ = Integer.MAX_VALUE;
@ -211,7 +211,7 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
}
public boolean add(int x, int y, int z) {
if (offsetX == Integer.MAX_VALUE) {
if (offsetX == Integer.MAX_VALUE || offsetZ == Integer.MAX_VALUE) {
offsetX = x;
offsetZ = z;
}

Datei anzeigen

@ -305,8 +305,6 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen
if (chunk != null) {
lastPair = pair;
lastChunk = chunk;
}
if (chunk != null) {
return chunk;
}
final int size = chunks.size();

Datei anzeigen

@ -201,7 +201,7 @@ public class MathMan {
*/
public static int tripleSearchCoords(int x, int y, int z) {
if (x > 1023 || x < -1024 || y > 255 || y < -256 || z > 1023 || z < -1024) {
throw new IndexOutOfBoundsException(String.format("Check range on x=%s, y=%s and z=%s!", x, y, z));
throw new UnsupportedOperationException(String.format("Check range on x=%s, y=%s and z=%s!", x, y, z));
}
int b1 = Math.abs(y) & 0xff;
int b3 = x & 0xff;