3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-07 12:00:07 +01:00
Dieser Commit ist enthalten in:
MattBDev 2019-07-25 15:09:12 -04:00
Ursprung 3a3efb8117
Commit 9a4473b73f
11 geänderte Dateien mit 57 neuen und 63 gelöschten Zeilen

Datei anzeigen

@ -41,8 +41,8 @@ import java.util.concurrent.Future;
public class BukkitChunkHolder<T extends Future<T>> extends ChunkHolder {
@Override
public void init(final IQueueExtent extent, final int X, final int Z) {
super.init(extent, X, Z);
public void init(final IQueueExtent extent, final int x, final int z) {
super.init(extent, x, z);
}
@Override
@ -353,4 +353,4 @@ public class BukkitChunkHolder<T extends Future<T>> extends ChunkHolder {
return null;
}
}
}
}

Datei anzeigen

@ -1,8 +1,6 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock;
import javax.annotation.Nullable;
/**
@ -10,13 +8,13 @@ import javax.annotation.Nullable;
*/
public interface Filter {
/**
* Check whether a chunk should be read
* Checks whether a chunk should be read.
*
* @param cx
* @param cz
* @param chunkX
* @param chunkZ
* @return
*/
default boolean appliesChunk(final int cx, final int cz) {
default boolean appliesChunk(final int chunkX, final int chunkZ) {
return true;
}

Datei anzeigen

@ -2,12 +2,10 @@ package com.boydti.fawe.beta;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.World;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
@ -22,7 +20,9 @@ public class Flood {
private int[][] queues;
private long[][] visits;
private int X, Y, Z;
private int x;
private int y;
private int z;
private ConcurrentLinkedQueue<int[]> queuePool = new ConcurrentLinkedQueue<>();
private final Long2ObjectLinkedOpenHashMap<long[][]> chunkVisits;
@ -45,17 +45,17 @@ public class Flood {
IQueueExtent fq = queueHandler.getQueue(world);
while (!chunkQueues.isEmpty()) {
long firstKey = chunkQueues.firstLongKey();
int X = MathMan.unpairIntX(firstKey);
int Z = MathMan.unpairIntY(firstKey);
int x = MathMan.unpairIntX(firstKey);
int z = MathMan.unpairIntY(firstKey);
int[][] chunkQueue = chunkQueues.get(firstKey);
// apply
}
}
private void init(int X, int Y, int Z) {
this.X = X;
this.Y = Y;
this.Z = Z;
private void init(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public void start(int x, int y, int z) {
@ -63,9 +63,9 @@ public class Flood {
}
private void push(int x, int y, int z, int depth) {
int X = x >> 4;
int Z = z >> 4;
long pair = MathMan.pairInt(X, Z);
int chunkX = x >> 4;
int chunkZ = z >> 4;
long pair = MathMan.pairInt(chunkX, chunkZ);
int layer = y >> 4;
int[] section = getOrCreateQueue(pair, layer);
int val = (x & 15) + ((z & 15) << 4) + ((y & 15) << 8) + (depth << 12);
@ -154,8 +154,8 @@ public class Flood {
visit = visits[sectionIndex];
queue = queues[sectionIndex];
if (visit == null || queue == null) {
long pair = MathMan.pairInt(X + nextX, Z + nextZ);
int layer = Y + nextY;
long pair = MathMan.pairInt(this.x + nextX, this.z + nextZ);
int layer = this.y + nextY;
if (layer < 0 || layer > 15) {
continue;
}

Datei anzeigen

@ -1,17 +1,15 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
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.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.annotation.Nullable;
/**
* Represents a chunk in the queue {@link IQueueExtent}
@ -21,10 +19,10 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
/**
* Initialize at the location
* @param extent
* @param X
* @param Z
* @param x
* @param z
*/
void init(IQueueExtent extent, int X, int Z);
void init(IQueueExtent extent, int x, int z);
IQueueExtent getQueue();

Datei anzeigen

@ -73,8 +73,8 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
}
@Override
default void init(final IQueueExtent extent, final int X, final int Z) {
getParent().init(extent, X, Z);
default void init(final IQueueExtent extent, final int x, final int z) {
getParent().init(extent, x, z);
}
@Override

Datei anzeigen

@ -8,8 +8,8 @@ public interface IDelegateFilter extends Filter {
Filter getParent();
@Override
default boolean appliesChunk(int cx, int cz) {
return getParent().appliesChunk(cx, cz);
default boolean appliesChunk(int chunkX, int chunkZ) {
return getParent().appliesChunk(chunkX, chunkZ);
}
@Override

Datei anzeigen

@ -1,7 +1,5 @@
package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.DelegateFilter;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.FilterBlockMask;
@ -9,18 +7,18 @@ import java.awt.image.BufferedImage;
import java.util.concurrent.ThreadLocalRandom;
public class ArrayImageMask implements FilterBlockMask {
private final ThreadLocalRandom r;
private final ThreadLocalRandom random;
private final boolean white;
private final BufferedImage img;
private final BufferedImage image;
public ArrayImageMask(BufferedImage img, boolean white) {
this.img = img;
public ArrayImageMask(BufferedImage image, boolean white) {
this.image = image;
this.white = white;
this.r = ThreadLocalRandom.current();
this.random = ThreadLocalRandom.current();
}
@Override
public boolean applyBlock(FilterBlock block) {
int height = img.getRGB(block.getX(), block.getZ()) & 0xFF;
return ((height == 255 || height > 0 && !white && r.nextInt(256) <= height));
int height = image.getRGB(block.getX(), block.getZ()) & 0xFF;
return ((height == 255 || height > 0 && !white && random.nextInt(256) <= height));
}
}

Datei anzeigen

@ -34,7 +34,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool();
private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool();
private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor();
private ConcurrentLinkedQueue<FutureTask> syncTasks = new ConcurrentLinkedQueue();
private ConcurrentLinkedQueue<FutureTask> syncTasks = new ConcurrentLinkedQueue<>();
private Map<World, WeakReference<WorldChunkCache>> chunkCache = new HashMap<>();
private IterableThreadLocal<IQueueExtent> queuePool = new IterableThreadLocal<IQueueExtent>() {
@ -114,9 +114,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
while (task != null) {
task = task.get();
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
@ -244,4 +242,4 @@ public abstract class QueueHandler implements Trimable, Runnable {
}
return result;
}
}
}

Datei anzeigen

@ -1,5 +1,7 @@
package com.boydti.fawe.beta.implementation;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
@ -10,14 +12,11 @@ import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.MemUtil;
import com.google.common.util.concurrent.Futures;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.function.Supplier;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Single threaded implementation for IQueueExtent (still abstract)
* - Does not implement creation of chunks (that has to implemented by the platform e.g. Bukkit)
@ -30,7 +29,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
private ConcurrentLinkedQueue<Future> submissions = new ConcurrentLinkedQueue<>();
/**
* Safety check to ensure that the thread being used matches the one being initialized on
* Safety check to ensure that the thread being used matches the one being initialized on.
* - Can be removed later
*/
private void checkThread() {
@ -45,7 +44,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
}
/**
* Reset the queue
* Resets the queue.
*/
protected synchronized void reset() {
checkThread();
@ -261,4 +260,4 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
pollSubmissions(0, true);
reset();
}
}
}

Datei anzeigen

@ -28,7 +28,8 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
private IChunkSet set;
private IBlockDelegate delegate;
private IQueueExtent extent;
private int X,Z;
private int x;
private int z;
public ChunkHolder() {
this.delegate = NULL;
@ -61,7 +62,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
if (region != null) {
region.filter(this, filter, block, get, set);
} else {
block = block.init(X, Z, get);
block = block.init(x, z, get);
for (int layer = 0; layer < 16; layer++) {
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
block.init(get, set, layer);
@ -118,7 +119,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
private IChunkGet newGet() {
if (extent instanceof SingleThreadQueueExtent) {
IChunkGet newGet = extent.getCachedGet(X, Z, this);
IChunkGet newGet = extent.getCachedGet(x, z, this);
if (newGet != null) {
return newGet;
}
@ -127,10 +128,10 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
}
@Override
public void init(final IQueueExtent extent, final int X, final int Z) {
public void init(final IQueueExtent extent, final int x, final int z) {
this.extent = extent;
this.X = X;
this.Z = Z;
this.x = x;
this.z = z;
if (set != null) {
set.reset();
delegate = SET;
@ -146,12 +147,12 @@ public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
@Override
public int getX() {
return X;
return x;
}
@Override
public int getZ() {
return Z;
return z;
}
@Override

Datei anzeigen

@ -7,7 +7,8 @@ import com.sk89q.worldedit.math.BlockVector3;
public class SkyLightMask extends AbstractExtentMask {
private final int min, max;
private final int min;
private final int max;
public SkyLightMask(Extent extent, int min, int max) {
super(extent);
@ -18,7 +19,8 @@ public class SkyLightMask extends AbstractExtentMask {
@Override
public boolean test(BlockVector3 vector) {
if (getExtent() instanceof LightingExtent) {
int light = ((LightingExtent) getExtent()).getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
int light = ((LightingExtent) getExtent())
.getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
return light >= min && light <= max;
}
return false;