API improvements

This commit is contained in:
MattBDev
2020-01-15 20:38:46 -05:00
parent da7c21d32a
commit 0cad7f229b
29 changed files with 38 additions and 96 deletions

View File

@ -1,5 +1,6 @@
package com.boydti.fawe;
import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.RegionWrapper;
@ -155,8 +156,8 @@ public class FaweAPI {
* @param autoQueue If it should start dispatching before you enqueue it.
* @return the queue extent
*/
public static IQueueExtent createQueue(World world, boolean autoQueue) {
IQueueExtent queue = Fawe.get().getQueueHandler().getQueue(world);
public static IQueueExtent<IQueueChunk> createQueue(World world, boolean autoQueue) {
IQueueExtent<IQueueChunk> queue = Fawe.get().getQueueHandler().getQueue(world);
if (!autoQueue) {
queue.disableQueue();
}

View File

@ -38,7 +38,7 @@ public class Flood {
public synchronized void run(World world) {
QueueHandler queueHandler = Fawe.get().getQueueHandler();
IQueueExtent fq = queueHandler.getQueue(world);
IQueueExtent<IQueueChunk> fq = queueHandler.getQueue(world);
while (!chunkQueues.isEmpty()) {
long firstKey = chunkQueues.firstLongKey();
int x = MathMan.unpairIntX(firstKey);

View File

@ -3,7 +3,6 @@ package com.boydti.fawe.beta.implementation.queue;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IBatchProcessor;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.IQueueChunk;
@ -46,7 +45,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
private ConcurrentLinkedQueue<FutureTask> syncWhenFree = new ConcurrentLinkedQueue<>();
private Map<World, WeakReference<IChunkCache<IChunkGet>>> chunkGetCache = new HashMap<>();
private CleanableThreadLocal<IQueueExtent> queuePool = new CleanableThreadLocal<>(QueueHandler.this::create);
private CleanableThreadLocal<IQueueExtent<IQueueChunk>> queuePool = new CleanableThreadLocal<>(QueueHandler.this::create);
/**
* Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the
* server
@ -263,16 +262,16 @@ public abstract class QueueHandler implements Trimable, Runnable {
}
}
public IQueueExtent create() {
public IQueueExtent<IQueueChunk> create() {
return new SingleThreadQueueExtent();
}
public void uncache() {
public void unCache() {
queuePool.set(null);
}
private IQueueExtent pool() {
IQueueExtent queue = queuePool.get();
private IQueueExtent<IQueueChunk> pool() {
IQueueExtent<IQueueChunk> queue = queuePool.get();
if (queue == null) {
queuePool.set(queue = queuePool.init());
}
@ -283,12 +282,12 @@ public abstract class QueueHandler implements Trimable, Runnable {
public abstract void endSet(boolean parallel);
public IQueueExtent getQueue(World world) {
public IQueueExtent<IQueueChunk> getQueue(World world) {
return getQueue(world, null);
}
public IQueueExtent getQueue(World world, IBatchProcessor processor) {
final IQueueExtent queue = pool();
public IQueueExtent<IQueueChunk> getQueue(World world, IBatchProcessor processor) {
final IQueueExtent<IQueueChunk> queue = pool();
IChunkCache<IChunkGet> cacheGet = getOrCreateWorldCache(world);
IChunkCache<IChunkSet> set = null; // TODO cache?
queue.init(world, cacheGet, set);

View File

@ -37,12 +37,12 @@ public abstract class ReadOnlyClipboard extends SimpleClipboard {
}
public static ReadOnlyClipboard of(Extent extent, final Region region) {
Fawe.get().getQueueHandler().uncache();
Fawe.get().getQueueHandler().unCache();
return of(() -> extent, region);
}
public static ReadOnlyClipboard of(Extent extent, final Region region, boolean copyEntities, boolean copyBiomes) {
Fawe.get().getQueueHandler().uncache();
Fawe.get().getQueueHandler().unCache();
return of(() -> extent, region, copyEntities, copyBiomes);
}

View File

@ -3,6 +3,7 @@ package com.boydti.fawe.regions.general.integrations.plotquared;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.sk89q.jnbt.CompoundTag;
@ -13,12 +14,11 @@ import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.registry.LegacyMapper;
// TODO FIXME
public class FaweLocalBlockQueue extends LocalBlockQueue {
public final IQueueExtent IMP;
public final IQueueExtent<IQueueChunk> IMP;
private final World world;
private BlockVector3 mutable = new MutableBlockVector3();
@ -26,7 +26,7 @@ public class FaweLocalBlockQueue extends LocalBlockQueue {
super(worldName);
this.world = FaweAPI.getWorld(worldName);
IMP = Fawe.get().getQueueHandler().getQueue(world);
Fawe.get().getQueueHandler().uncache();
Fawe.get().getQueueHandler().unCache();
}
@Override

View File

@ -6,6 +6,7 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IBatchProcessor;
import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.processors.LimitProcessor;
import com.boydti.fawe.beta.implementation.queue.ParallelQueueExtent;
@ -323,7 +324,7 @@ public class EditSessionBuilder {
this.limit = limit.copy();
if (extent == null) {
IQueueExtent queue = null;
IQueueExtent<IQueueChunk> queue = null;
World unwrapped = WorldWrapper.unwrap(world);
boolean placeChunks = this.fastmode || this.limit.FAST_PLACEMENT;