mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-16 03:14:04 +00:00
Introduce Resettable interface
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package com.boydti.fawe;
|
||||
|
||||
public interface Resettable {
|
||||
|
||||
void reset();
|
||||
}
|
@@ -3,7 +3,7 @@ package com.boydti.fawe.beta;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
|
||||
public interface IQueueWrapper {
|
||||
default IQueueExtent wrapQueue(IQueueExtent queue) {
|
||||
default IQueueExtent<IQueueChunk> wrapQueue(IQueueExtent<IQueueChunk> queue) {
|
||||
return queue;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.boydti.fawe.beta.implementation.queue;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.beta.IQueueChunk;
|
||||
import com.boydti.fawe.beta.IQueueWrapper;
|
||||
import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock;
|
||||
import com.boydti.fawe.beta.Filter;
|
||||
@@ -64,12 +65,12 @@ public class ParallelQueueExtent extends PassthroughExtent implements IQueueWrap
|
||||
return false;
|
||||
}
|
||||
|
||||
private IQueueExtent getNewQueue() {
|
||||
private IQueueExtent<IQueueChunk> getNewQueue() {
|
||||
return wrapQueue(handler.getQueue(this.world, this.processor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQueueExtent wrapQueue(IQueueExtent queue) {
|
||||
public IQueueExtent<IQueueChunk> wrapQueue(IQueueExtent<IQueueChunk> queue) {
|
||||
// TODO wrap
|
||||
queue.setProcessor(this.processor);
|
||||
return queue;
|
||||
@@ -91,22 +92,22 @@ public class ParallelQueueExtent extends PassthroughExtent implements IQueueWrap
|
||||
try {
|
||||
final Filter newFilter = filter.fork();
|
||||
// Create a chunk that we will reuse/reset for each operation
|
||||
final IQueueExtent queue = getNewQueue();
|
||||
final IQueueExtent<IQueueChunk> queue = getNewQueue();
|
||||
synchronized (queue) {
|
||||
ChunkFilterBlock block = null;
|
||||
|
||||
while (true) {
|
||||
// Get the next chunk posWeakChunk
|
||||
final int X, Z;
|
||||
final int chunkX, chunkZ;
|
||||
synchronized (chunksIter) {
|
||||
if (!chunksIter.hasNext()) {
|
||||
break;
|
||||
}
|
||||
final BlockVector2 pos = chunksIter.next();
|
||||
X = pos.getX();
|
||||
Z = pos.getZ();
|
||||
chunkX = pos.getX();
|
||||
chunkZ = pos.getZ();
|
||||
}
|
||||
block = queue.apply(block, newFilter, region, X, Z, full);
|
||||
block = queue.apply(block, newFilter, region, chunkX, chunkZ, full);
|
||||
}
|
||||
queue.flush();
|
||||
}
|
||||
|
@@ -29,10 +29,6 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public SparseBitSet getBitSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return set.cardinality();
|
||||
@@ -69,10 +65,10 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
if (size() < length * length * length) {
|
||||
int index = -1;
|
||||
while ((index = set.nextSetBit(index + 1)) != -1) {
|
||||
int b1 = (index & 0xFF);
|
||||
int b2 = ((byte) (index >> 8)) & 0x7F;
|
||||
int b3 = ((byte) (index >> 15)) & 0xFF;
|
||||
int b4 = ((byte) (index >> 23)) & 0xFF;
|
||||
int b1 = (byte) (index >> 0) & 0xFF;
|
||||
int b2 = (byte) (index >> 8) & 0x7F;
|
||||
int b3 = (byte) (index >> 15) & 0xFF;
|
||||
int b4 = (byte) (index >> 23) & 0xFF;
|
||||
if (Math.abs((offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21)) - x) <= radius && Math.abs((offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21)) - z) <= radius && Math.abs((b1) - y) <= radius) {
|
||||
return true;
|
||||
}
|
||||
@@ -111,12 +107,12 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
index = set.nextSetBit(index + 1);
|
||||
}
|
||||
if (index != -1) {
|
||||
int b1 = (index & 0xFF);
|
||||
int b2 = ((byte) (index >> 8)) & 0x7F;
|
||||
int b3 = ((byte) (index >> 15)) & 0xFF;
|
||||
int b4 = ((byte) (index >> 23)) & 0xFF;
|
||||
int x = offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21);
|
||||
int z = offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21);
|
||||
int b1 = (byte) (index >> 0) & 0xFF;
|
||||
int b2 = (byte) (index >> 8) & 0x7F;
|
||||
int b3 = (byte) (index >> 15) & 0xFF;
|
||||
int b4 = (byte) (index >> 23) & 0xFF;
|
||||
int x = offsetX + (((b3 + (MathMan.unpair8x(b2) << 8)) << 21) >> 21);
|
||||
int z = offsetZ + (((b4 + (MathMan.unpair8y(b2) << 8)) << 21) >> 21);
|
||||
return MutableBlockVector3.get(x, b1, z);
|
||||
}
|
||||
return null;
|
||||
@@ -146,9 +142,9 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
int b2 = ((byte) (index >> 8)) & 0x7F;
|
||||
int b3 = ((byte) (index >> 15)) & 0xFF;
|
||||
int b4 = ((byte) (index >> 23)) & 0xFF;
|
||||
mutable.mutX(offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21));
|
||||
mutable.mutX(offsetX + (((b3 + (MathMan.unpair8x(b2) << 8)) << 21) >> 21));
|
||||
mutable.mutY(b1);
|
||||
mutable.mutZ(offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21));
|
||||
mutable.mutZ(offsetZ + (((b4 + (MathMan.unpair8y(b2) << 8)) << 21) >> 21));
|
||||
previous = index;
|
||||
index = set.nextSetBit(index + 1);
|
||||
return mutable;
|
||||
@@ -193,10 +189,7 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
if (relX > 1023 || relX < -1024 || relZ > 1023 || relZ < -1024) {
|
||||
return false;
|
||||
}
|
||||
if (y < 0 || y > 256) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return y >= 0 && y <= 256;
|
||||
}
|
||||
|
||||
public boolean add(int x, int y, int z) {
|
||||
|
@@ -21,7 +21,8 @@ public class MemoryCheckingExtent extends PassthroughExtent {
|
||||
public Extent getExtent() {
|
||||
if (MemUtil.isMemoryLimited()) {
|
||||
if (this.player != null) {
|
||||
player.print(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason", (TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.low.memory"))));
|
||||
player.print(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason",
|
||||
TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason.low.memory")));
|
||||
if (Permission.hasPermission(this.player, "worldedit.fast")) {
|
||||
this.player.print(TranslatableComponent.of("fawe.info.worldedit.oom.admin"));
|
||||
}
|
||||
|
@@ -1,5 +1,9 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
public interface ResettableMask {
|
||||
import com.boydti.fawe.Resettable;
|
||||
|
||||
public interface ResettableMask extends Resettable {
|
||||
|
||||
@Override
|
||||
void reset();
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.pattern;
|
||||
|
||||
import com.boydti.fawe.Resettable;
|
||||
import com.boydti.fawe.object.mask.ResettableMask;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@@ -21,11 +22,8 @@ public class PatternTraverser {
|
||||
if (pattern == null) {
|
||||
return;
|
||||
}
|
||||
if (pattern instanceof ResettablePattern) {
|
||||
((ResettablePattern) pattern).reset();
|
||||
}
|
||||
if (pattern instanceof ResettableMask) {
|
||||
((ResettableMask) pattern).reset();
|
||||
if (pattern instanceof Resettable) {
|
||||
((Resettable) pattern).reset();
|
||||
}
|
||||
Class<?> current = pattern.getClass();
|
||||
while (current.getSuperclass() != null) {
|
||||
|
@@ -1,5 +1,9 @@
|
||||
package com.boydti.fawe.object.pattern;
|
||||
|
||||
public interface ResettablePattern {
|
||||
import com.boydti.fawe.Resettable;
|
||||
|
||||
public interface ResettablePattern extends Resettable {
|
||||
|
||||
@Override
|
||||
void reset();
|
||||
}
|
||||
|
@@ -266,7 +266,6 @@ public class EditSessionBuilder {
|
||||
}
|
||||
|
||||
private AbstractChangeSet changeTask;
|
||||
private int maxY;
|
||||
private Extent bypassHistory;
|
||||
private Extent bypassAll;
|
||||
private Extent extent;
|
||||
@@ -409,7 +408,6 @@ public class EditSessionBuilder {
|
||||
allowedRegions = player.getCurrentRegions();
|
||||
}
|
||||
}
|
||||
this.maxY = world == null ? 255 : world.getMaxY();
|
||||
FaweRegionExtent regionExtent = null;
|
||||
if (allowedRegions != null) {
|
||||
if (allowedRegions.length == 0) {
|
||||
@@ -423,7 +421,7 @@ public class EditSessionBuilder {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// this.extent = new HeightBoundExtent(this.extent, this.limit, 0, maxY);
|
||||
// this.extent = new HeightBoundExtent(this.extent, this.limit, 0, world.getMaxY());
|
||||
}
|
||||
IBatchProcessor limitProcessor = regionExtent;
|
||||
if (limit != null && !limit.isUnlimited()) {
|
||||
@@ -495,7 +493,4 @@ public class EditSessionBuilder {
|
||||
return blockBag;
|
||||
}
|
||||
|
||||
public int getMaxY() {
|
||||
return maxY;
|
||||
}
|
||||
}
|
||||
|
@@ -4,16 +4,17 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ExtentTraverser<T extends Extent> {
|
||||
private T root;
|
||||
private ExtentTraverser<T> parent;
|
||||
private final T root;
|
||||
private final ExtentTraverser<T> parent;
|
||||
|
||||
public ExtentTraverser(T root) {
|
||||
public ExtentTraverser(@NotNull T root) {
|
||||
this(root, null);
|
||||
}
|
||||
|
||||
public ExtentTraverser(T root, ExtentTraverser<T> parent) {
|
||||
public ExtentTraverser(@NotNull T root, ExtentTraverser<T> parent) {
|
||||
this.root = root;
|
||||
this.parent = parent;
|
||||
}
|
||||
@@ -61,7 +62,7 @@ public class ExtentTraverser<T extends Extent> {
|
||||
}
|
||||
|
||||
public <U> U findAndGet(Class<U> clazz) {
|
||||
ExtentTraverser<Extent> traverser = find((Class) clazz);
|
||||
ExtentTraverser<Extent> traverser = find( clazz);
|
||||
return (traverser != null) ? (U) traverser.get() : null;
|
||||
}
|
||||
|
||||
@@ -104,9 +105,8 @@ public class ExtentTraverser<T extends Extent> {
|
||||
public ExtentTraverser<T> next() {
|
||||
try {
|
||||
if (root instanceof AbstractDelegateExtent) {
|
||||
Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
field.setAccessible(true);
|
||||
T value = (T) field.get(root);
|
||||
AbstractDelegateExtent root = (AbstractDelegateExtent) this.root;
|
||||
T value = (T) root.getExtent();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -5,12 +5,12 @@ import java.util.Arrays;
|
||||
public class FaweTimer implements Runnable {
|
||||
|
||||
private final double[] history = new double[]{20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d, 20d};
|
||||
private int historyIndex = 0;
|
||||
private int historyIndex;
|
||||
private long lastPoll = System.currentTimeMillis();
|
||||
private long tickStart = System.currentTimeMillis();
|
||||
private final long tickInterval = 5;
|
||||
private long tick = 0;
|
||||
private long tickMod = 0;
|
||||
private long tick;
|
||||
private long tickMod;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -21,7 +21,7 @@ public class FaweTimer implements Runnable {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
long timeSpent = (tickStart - lastPoll);
|
||||
long timeSpent = tickStart - lastPoll;
|
||||
if (timeSpent == 0) {
|
||||
timeSpent = 1;
|
||||
}
|
||||
@@ -34,15 +34,14 @@ public class FaweTimer implements Runnable {
|
||||
lastPoll = tickStart;
|
||||
}
|
||||
|
||||
private long lastGetTPSTick = 0;
|
||||
private long lastGetTPSTick;
|
||||
private double lastGetTPSValue = 20d;
|
||||
|
||||
public double getTPS() {
|
||||
if (tick < lastGetTPSTick + tickInterval) {
|
||||
return lastGetTPSValue;
|
||||
}
|
||||
double total = 0;
|
||||
for (double v : history) total += v;
|
||||
double total = Arrays.stream(history).sum();
|
||||
lastGetTPSValue = total / history.length;
|
||||
lastGetTPSTick = tick;
|
||||
return lastGetTPSValue;
|
||||
|
@@ -9,6 +9,7 @@ import com.boydti.fawe.util.image.ImageUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
Reference in New Issue
Block a user