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 { public class BukkitChunkHolder<T extends Future<T>> extends ChunkHolder {
@Override @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) {
super.init(extent, X, Z); super.init(extent, x, z);
} }
@Override @Override

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,7 +1,5 @@
package com.boydti.fawe.beta.filters; 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.FilterBlock;
import com.boydti.fawe.beta.FilterBlockMask; import com.boydti.fawe.beta.FilterBlockMask;
@ -9,18 +7,18 @@ import java.awt.image.BufferedImage;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public class ArrayImageMask implements FilterBlockMask { public class ArrayImageMask implements FilterBlockMask {
private final ThreadLocalRandom r; private final ThreadLocalRandom random;
private final boolean white; private final boolean white;
private final BufferedImage img; private final BufferedImage image;
public ArrayImageMask(BufferedImage img, boolean white) { public ArrayImageMask(BufferedImage image, boolean white) {
this.img = img; this.image = image;
this.white = white; this.white = white;
this.r = ThreadLocalRandom.current(); this.random = ThreadLocalRandom.current();
} }
@Override @Override
public boolean applyBlock(FilterBlock block) { public boolean applyBlock(FilterBlock block) {
int height = img.getRGB(block.getX(), block.getZ()) & 0xFF; int height = image.getRGB(block.getX(), block.getZ()) & 0xFF;
return ((height == 255 || height > 0 && !white && r.nextInt(256) <= height)); 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 forkJoinPoolPrimary = new ForkJoinPool();
private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool(); private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool();
private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor(); 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 Map<World, WeakReference<WorldChunkCache>> chunkCache = new HashMap<>();
private IterableThreadLocal<IQueueExtent> queuePool = new IterableThreadLocal<IQueueExtent>() { private IterableThreadLocal<IQueueExtent> queuePool = new IterableThreadLocal<IQueueExtent>() {
@ -114,9 +114,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
while (task != null) { while (task != null) {
task = task.get(); task = task.get();
} }
} catch (InterruptedException e) { } catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

Datei anzeigen

@ -1,5 +1,7 @@
package com.boydti.fawe.beta.implementation; package com.boydti.fawe.beta.implementation;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkGet;
@ -10,14 +12,11 @@ import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.MemUtil; import com.boydti.fawe.util.MemUtil;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.function.Supplier; import java.util.function.Supplier;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Single threaded implementation for IQueueExtent (still abstract) * Single threaded implementation for IQueueExtent (still abstract)
* - Does not implement creation of chunks (that has to implemented by the platform e.g. Bukkit) * - 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<>(); 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 * - Can be removed later
*/ */
private void checkThread() { private void checkThread() {
@ -45,7 +44,7 @@ public abstract class SingleThreadQueueExtent implements IQueueExtent {
} }
/** /**
* Reset the queue * Resets the queue.
*/ */
protected synchronized void reset() { protected synchronized void reset() {
checkThread(); checkThread();

Datei anzeigen

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

Datei anzeigen

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