Search in sources :

Example 1 with ChunkFilterBlock

use of com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock in project FastAsyncWorldEdit by IntellectualSites.

the class IQueueExtent method apply.

@Override
default <T extends Filter> T apply(Region region, T filter, boolean full) {
    final Set<BlockVector2> chunks = region.getChunks();
    ChunkFilterBlock block = null;
    for (BlockVector2 chunk : chunks) {
        block = apply(block, filter, region, chunk.getX(), chunk.getZ(), full);
    }
    flush();
    return filter;
}
Also used : ChunkFilterBlock(com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 2 with ChunkFilterBlock

use of com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock in project FastAsyncWorldEdit by IntellectualSites.

the class ParallelQueueExtent method apply.

@Override
@SuppressWarnings("rawtypes")
public <T extends Filter> T apply(Region region, T filter, boolean full) {
    // The chunks positions to iterate over
    final Set<BlockVector2> chunks = region.getChunks();
    final Iterator<BlockVector2> chunksIter = chunks.iterator();
    // Get a pool, to operate on the chunks in parallel
    final int size = Math.min(chunks.size(), Settings.settings().QUEUE.PARALLEL_THREADS);
    if (size <= 1 && chunksIter.hasNext()) {
        BlockVector2 pos = chunksIter.next();
        getExtent().apply(null, filter, region, pos.getX(), pos.getZ(), full);
    } else {
        final ForkJoinTask[] tasks = IntStream.range(0, size).mapToObj(i -> handler.submit(() -> {
            try {
                final Filter newFilter = filter.fork();
                // Create a chunk that we will reuse/reset for each operation
                final SingleThreadQueueExtent queue = (SingleThreadQueueExtent) getNewQueue();
                queue.setFastMode(fastmode);
                queue.setFaweExceptionArray(faweExceptionReasonsUsed);
                synchronized (queue) {
                    try {
                        ChunkFilterBlock block = null;
                        while (true) {
                            // Get the next chunk posWeakChunk
                            final int chunkX;
                            final int chunkZ;
                            synchronized (chunksIter) {
                                if (!chunksIter.hasNext()) {
                                    break;
                                }
                                final BlockVector2 pos = chunksIter.next();
                                chunkX = pos.getX();
                                chunkZ = pos.getZ();
                            }
                            block = queue.apply(block, newFilter, region, chunkX, chunkZ, full);
                        }
                        queue.flush();
                    } catch (Throwable t) {
                        if (t instanceof FaweException) {
                            Fawe.handleFaweException(faweExceptionReasonsUsed, (FaweException) t, LOGGER);
                        } else if (t.getCause() instanceof FaweException) {
                            Fawe.handleFaweException(faweExceptionReasonsUsed, (FaweException) t.getCause(), LOGGER);
                        } else {
                            throw t;
                        }
                    }
                }
            } catch (Throwable e) {
                String message = e.getMessage();
                int hash = message.hashCode();
                if (lastException != hash) {
                    lastException = hash;
                    exceptionCount = 0;
                    LOGGER.catching(e);
                } else if (exceptionCount < Settings.settings().QUEUE.PARALLEL_THREADS) {
                    exceptionCount++;
                    LOGGER.warn(message);
                }
            }
        })).toArray(ForkJoinTask[]::new);
        // Join filters
        for (ForkJoinTask task : tasks) {
            if (task != null) {
                task.quietlyJoin();
            }
        }
        filter.join();
    }
    return filter;
}
Also used : IntStream(java.util.stream.IntStream) BlockVector2(com.sk89q.worldedit.math.BlockVector2) BlockVector3(com.sk89q.worldedit.math.BlockVector3) World(com.sk89q.worldedit.world.World) ChunkFilterBlock(com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock) Fawe(com.fastasyncworldedit.core.Fawe) LinkedFilter(com.fastasyncworldedit.core.extent.filter.LinkedFilter) Filter(com.fastasyncworldedit.core.queue.Filter) DistrFilter(com.fastasyncworldedit.core.extent.filter.DistrFilter) BlockMask(com.sk89q.worldedit.function.mask.BlockMask) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException) PassthroughExtent(com.fastasyncworldedit.core.extent.PassthroughExtent) BlockPattern(com.sk89q.worldedit.function.pattern.BlockPattern) Region(com.sk89q.worldedit.regions.Region) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) ForkJoinTask(java.util.concurrent.ForkJoinTask) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) LogManagerCompat(com.sk89q.worldedit.internal.util.LogManagerCompat) BlockType(com.sk89q.worldedit.world.block.BlockType) Iterator(java.util.Iterator) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) Set(java.util.Set) CountFilter(com.fastasyncworldedit.core.extent.filter.CountFilter) Settings(com.fastasyncworldedit.core.configuration.Settings) NullExtent(com.fastasyncworldedit.core.extent.NullExtent) BlockMaskBuilder(com.fastasyncworldedit.core.function.mask.BlockMaskBuilder) IQueueChunk(com.fastasyncworldedit.core.queue.IQueueChunk) MultiBatchProcessor(com.fastasyncworldedit.core.extent.processor.MultiBatchProcessor) List(java.util.List) Logger(org.apache.logging.log4j.Logger) BatchProcessorHolder(com.fastasyncworldedit.core.extent.processor.BatchProcessorHolder) FaweCache(com.fastasyncworldedit.core.FaweCache) Countable(com.sk89q.worldedit.util.Countable) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Mask(com.sk89q.worldedit.function.mask.Mask) BlockState(com.sk89q.worldedit.world.block.BlockState) WorldCopyClipboard(com.fastasyncworldedit.core.extent.clipboard.WorldCopyClipboard) IQueueExtent(com.fastasyncworldedit.core.queue.IQueueExtent) Pattern(com.sk89q.worldedit.function.pattern.Pattern) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException) ForkJoinTask(java.util.concurrent.ForkJoinTask) BlockVector2(com.sk89q.worldedit.math.BlockVector2) ChunkFilterBlock(com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock) LinkedFilter(com.fastasyncworldedit.core.extent.filter.LinkedFilter) Filter(com.fastasyncworldedit.core.queue.Filter) DistrFilter(com.fastasyncworldedit.core.extent.filter.DistrFilter) CountFilter(com.fastasyncworldedit.core.extent.filter.CountFilter)

Aggregations

ChunkFilterBlock (com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock)2 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)2 Fawe (com.fastasyncworldedit.core.Fawe)1 FaweCache (com.fastasyncworldedit.core.FaweCache)1 Settings (com.fastasyncworldedit.core.configuration.Settings)1 NullExtent (com.fastasyncworldedit.core.extent.NullExtent)1 PassthroughExtent (com.fastasyncworldedit.core.extent.PassthroughExtent)1 WorldCopyClipboard (com.fastasyncworldedit.core.extent.clipboard.WorldCopyClipboard)1 CountFilter (com.fastasyncworldedit.core.extent.filter.CountFilter)1 DistrFilter (com.fastasyncworldedit.core.extent.filter.DistrFilter)1 LinkedFilter (com.fastasyncworldedit.core.extent.filter.LinkedFilter)1 BatchProcessorHolder (com.fastasyncworldedit.core.extent.processor.BatchProcessorHolder)1 MultiBatchProcessor (com.fastasyncworldedit.core.extent.processor.MultiBatchProcessor)1 BlockMaskBuilder (com.fastasyncworldedit.core.function.mask.BlockMaskBuilder)1 FaweException (com.fastasyncworldedit.core.internal.exception.FaweException)1 Filter (com.fastasyncworldedit.core.queue.Filter)1 IQueueChunk (com.fastasyncworldedit.core.queue.IQueueChunk)1 IQueueExtent (com.fastasyncworldedit.core.queue.IQueueExtent)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1