Search in sources :

Example 1 with ParallelQueueExtent

use of com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent in project FastAsyncWorldEdit by IntellectualSites.

the class ForwardExtentCopy method resume.

@Override
public Operation resume(RunContext run) throws WorldEditException {
    // FAWE start
    if (currentTransform == null) {
        currentTransform = transform;
    }
    // FAWE end
    if (lastBiomeVisitor != null) {
        affectedBiomeCols += lastBiomeVisitor.getAffected();
        lastBiomeVisitor = null;
    }
    if (lastEntityVisitor != null) {
        affectedEntities += lastEntityVisitor.getAffected();
        lastEntityVisitor = null;
    }
    // FAWE start
    Extent finalDest = destination;
    BlockVector3 translation = to.subtract(from);
    if (!translation.equals(BlockVector3.ZERO)) {
        finalDest = new BlockTranslateExtent(finalDest, translation.getBlockX(), translation.getBlockY(), translation.getBlockZ());
    }
    // FAWE end
    // FAWE start - RegionVisitor > ExtentBlockCopy
    RegionFunction copy;
    RegionVisitor blockCopy = null;
    PositionTransformExtent transExt = null;
    if (!currentTransform.isIdentity()) {
        if (!(currentTransform instanceof AffineTransform) || ((AffineTransform) currentTransform).isOffAxis()) {
            transExt = new PositionTransformExtent(source, currentTransform.inverse());
            transExt.setOrigin(from);
            copy = new SimpleBlockCopy(transExt, finalDest);
            if (this.filterFunction != null) {
                copy = new IntersectRegionFunction(filterFunction, copy);
            }
            if (sourceFunction != null) {
                copy = CombinedRegionFunction.combine(copy, sourceFunction);
            }
            if (sourceMask != Masks.alwaysTrue()) {
                new MaskTraverser(sourceMask).reset(transExt);
                copy = new RegionMaskingFilter(source, sourceMask, copy);
            }
            if (copyingBiomes && (source.isWorld() || region instanceof FlatRegion)) {
                copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
            }
            blockCopy = new BackwardsExtentBlockCopy(region, from, transform, copy);
        } else {
            transExt = new PositionTransformExtent(finalDest, currentTransform);
            transExt.setOrigin(from);
            finalDest = transExt;
        }
    }
    if (blockCopy == null) {
        RegionFunction maskFunc = null;
        if (sourceFunction != null) {
            BlockVector3 disAbs = translation.abs();
            BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
            boolean overlap = (disAbs.getBlockX() < size.getBlockX() && disAbs.getBlockY() < size.getBlockY() && disAbs.getBlockZ() < size.getBlockZ());
            RegionFunction copySrcFunc = sourceFunction;
            if (overlap && translation.length() != 0) {
                int x = translation.getBlockX();
                int y = translation.getBlockY();
                int z = translation.getBlockZ();
                maskFunc = position -> {
                    BlockVector3 bv = BlockVector3.at(position.getBlockX() + x, position.getBlockY() + y, position.getBlockZ() + z);
                    if (region.contains(bv)) {
                        return sourceFunction.apply(bv);
                    }
                    return false;
                };
                copySrcFunc = position -> {
                    BlockVector3 bv = BlockVector3.at(position.getBlockX() - x, position.getBlockY() - y, position.getBlockZ() - z);
                    if (!region.contains(bv)) {
                        return sourceFunction.apply(position);
                    }
                    return false;
                };
            }
            copy = new CombinedBlockCopy(source, finalDest, copySrcFunc);
        } else {
            copy = new SimpleBlockCopy(source, finalDest);
        }
        if (this.filterFunction != null) {
            copy = new IntersectRegionFunction(filterFunction, copy);
        }
        if (sourceMask != Masks.alwaysTrue()) {
            if (maskFunc != null) {
                copy = new RegionMaskTestFunction(sourceMask, copy, maskFunc);
            } else {
                copy = new RegionMaskingFilter(source, sourceMask, copy);
            }
        }
        if (copyingBiomes && (source.isWorld() || region instanceof FlatRegion)) {
            copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
        }
        ExtentTraverser<ParallelQueueExtent> queueTraverser = new ExtentTraverser<>(finalDest).find(ParallelQueueExtent.class);
        Extent preloader = queueTraverser != null ? queueTraverser.get() : source;
        blockCopy = new RegionVisitor(region, copy, preloader);
    }
    List<? extends Entity> entities;
    if (copyingEntities) {
        // filter players since they can't be copied
        entities = source.getEntities(region);
        entities.removeIf(entity -> {
            EntityProperties properties = entity.getFacet(EntityProperties.class);
            return properties != null && !properties.isPasteable();
        });
    } else {
        entities = Collections.emptyList();
    }
    for (int i = 0; i < repetitions; i++) {
        Operations.completeBlindly(blockCopy);
        if (!entities.isEmpty()) {
            ExtentEntityCopy entityCopy = new ExtentEntityCopy(source, from.toVector3(), destination, to.toVector3(), currentTransform);
            entityCopy.setRemoving(removingEntities);
            List<? extends Entity> entities2 = Lists.newArrayList(source.getEntities(region));
            entities2.removeIf(entity -> {
                EntityProperties properties = entity.getFacet(EntityProperties.class);
                return properties != null && !properties.isPasteable();
            });
            EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy);
            Operations.completeBlindly(entityVisitor);
            affectedEntities += entityVisitor.getAffected();
        }
        if (transExt != null) {
            currentTransform = currentTransform.combine(transform);
            transExt.setTransform(currentTransform);
        }
    }
    affectedBlocks += blockCopy.getAffected();
    // FAWE end
    return null;
}
Also used : PositionTransformExtent(com.fastasyncworldedit.core.extent.PositionTransformExtent) ParallelQueueExtent(com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent) BlockTranslateExtent(com.fastasyncworldedit.core.extent.BlockTranslateExtent) Extent(com.sk89q.worldedit.extent.Extent) RegionMaskTestFunction(com.fastasyncworldedit.core.function.RegionMaskTestFunction) EntityVisitor(com.sk89q.worldedit.function.visitor.EntityVisitor) SimpleBlockCopy(com.fastasyncworldedit.core.function.block.SimpleBlockCopy) CombinedBlockCopy(com.fastasyncworldedit.core.function.block.CombinedBlockCopy) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) ExtentEntityCopy(com.sk89q.worldedit.function.entity.ExtentEntityCopy) BiomeCopy(com.fastasyncworldedit.core.function.block.BiomeCopy) PositionTransformExtent(com.fastasyncworldedit.core.extent.PositionTransformExtent) EntityProperties(com.sk89q.worldedit.entity.metadata.EntityProperties) ParallelQueueExtent(com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent) RegionMaskingFilter(com.sk89q.worldedit.function.RegionMaskingFilter) RegionFunction(com.sk89q.worldedit.function.RegionFunction) CombinedRegionFunction(com.sk89q.worldedit.function.CombinedRegionFunction) IntersectRegionFunction(com.fastasyncworldedit.core.function.visitor.IntersectRegionFunction) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) IntersectRegionFunction(com.fastasyncworldedit.core.function.visitor.IntersectRegionFunction) BlockTranslateExtent(com.fastasyncworldedit.core.extent.BlockTranslateExtent)

Example 2 with ParallelQueueExtent

use of com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent in project FastAsyncWorldEdit by IntellectualSites.

the class EditSessionBuilder method compile.

/**
 * Compile the builder to the settings given. Prepares history, limits, lighting, etc.
 */
public EditSessionBuilder compile() {
    if (compiled) {
        return this;
    }
    compiled = true;
    wrapped = false;
    if (event == null) {
        event = new EditSessionEvent(world, actor, -1, null);
    }
    if (actor == null && event.getActor() != null) {
        actor = event.getActor();
    }
    if (limit == null) {
        if (actor == null) {
            limit = FaweLimit.MAX;
        } else {
            limit = actor.getLimit();
        }
    }
    if (fastMode == null) {
        if (actor == null) {
            fastMode = !Settings.settings().HISTORY.ENABLE_FOR_CONSOLE;
        } else {
            fastMode = actor.getSession().hasFastMode();
        }
    }
    if (checkMemory == null) {
        checkMemory = actor != null && !this.fastMode;
    }
    if (checkMemory) {
        if (MemUtil.isMemoryLimitedSlow()) {
            if (Permission.hasPermission(actor, "worldedit.fast")) {
                actor.print(Caption.of("fawe.info.worldedit.oom.admin"));
            }
            throw FaweCache.LOW_MEMORY;
        }
    }
    // this.originalLimit = limit;
    this.blockBag = limit.INVENTORY_MODE != 0 ? blockBag : null;
    this.limit = limit.copy();
    if (extent == null) {
        IQueueExtent<IQueueChunk> queue = null;
        World unwrapped = WorldWrapper.unwrap(world);
        boolean placeChunks = (this.fastMode || this.limit.FAST_PLACEMENT) && (wnaMode == null || !wnaMode);
        if (placeChunks) {
            wnaMode = false;
            if (unwrapped instanceof IQueueExtent) {
                extent = queue = (IQueueExtent) unwrapped;
            } else if (Settings.settings().QUEUE.PARALLEL_THREADS > 1 && !Fawe.isMainThread()) {
                ParallelQueueExtent parallel = new ParallelQueueExtent(Fawe.instance().getQueueHandler(), world, fastMode);
                queue = parallel.getExtent();
                extent = parallel;
            } else {
                extent = queue = Fawe.instance().getQueueHandler().getQueue(world);
            }
        } else {
            wnaMode = true;
            extent = world;
        }
        if (combineStages == null) {
            combineStages = // If it's enabled in the settings
            Settings.settings().HISTORY.COMBINE_STAGES && // If fast placement is disabled, it's slower to perform a copy on each chunk
            this.limit.FAST_PLACEMENT && // If the edit uses items from the inventory we can't use a delayed task
            this.blockBag == null;
        }
        extent = this.bypassAll = wrapExtent(extent, eventBus, event, EditSession.Stage.BEFORE_CHANGE);
        this.bypassHistory = this.extent = wrapExtent(bypassAll, eventBus, event, EditSession.Stage.BEFORE_REORDER);
        if (!this.fastMode || changeSet != null) {
            if (changeSet == null) {
                if (Settings.settings().HISTORY.USE_DISK) {
                    UUID uuid = actor == null ? Identifiable.CONSOLE : actor.getUniqueId();
                    if (Settings.settings().HISTORY.USE_DATABASE) {
                        changeSet = new RollbackOptimizedHistory(world, uuid);
                    } else {
                        changeSet = new DiskStorageHistory(world, uuid);
                    }
                // } else if (combineStages && Settings.settings().HISTORY.COMPRESSION_LEVEL == 0) {
                // changeSet = new CPUOptimizedChangeSet(world);
                } else {
                    if (combineStages && Settings.settings().HISTORY.COMPRESSION_LEVEL == 0) {
                    // TODO add CPUOptimizedChangeSet
                    }
                    changeSet = new MemoryOptimizedHistory(world);
                }
            }
            if (this.limit.SPEED_REDUCTION > 0) {
                this.extent = this.bypassHistory = new SlowExtent(this.bypassHistory, this.limit.SPEED_REDUCTION);
            }
            if (command != null && changeSet instanceof RollbackOptimizedHistory) {
                ((RollbackOptimizedHistory) changeSet).setCommand(this.command);
            }
            if (!(changeSet instanceof NullChangeSet)) {
                if (this.blockBag != null) {
                    // TODO implement block bag as IBatchProcessor
                    changeSet = new BlockBagChangeSet(changeSet, blockBag, limit.INVENTORY_MODE == 1);
                }
                if (combineStages) {
                    changeTask = changeSet;
                    this.extent = extent.enableHistory(changeSet);
                } else {
                    this.extent = new HistoryExtent(extent, changeSet);
                // if (this.blockBag != null) {
                // this.extent = new BlockBagExtent(this.extent, blockBag, limit.INVENTORY_MODE == 1);
                // }
                }
            }
        }
        if (allowedRegions == null && Settings.settings().REGION_RESTRICTIONS) {
            if (actor != null && !actor.hasPermission("fawe.bypass") && !actor.hasPermission("fawe.bypass.regions")) {
                if (actor instanceof Player) {
                    Player player = (Player) actor;
                    allowedRegions = player.getAllowedRegions();
                }
            }
        }
        if (disallowedRegions == null && Settings.settings().REGION_RESTRICTIONS && Settings.settings().REGION_RESTRICTIONS_OPTIONS.ALLOW_BLACKLISTS) {
            if (actor != null && !actor.hasPermission("fawe.bypass") && !actor.hasPermission("fawe.bypass.regions")) {
                if (actor instanceof Player) {
                    Player player = (Player) actor;
                    disallowedRegions = player.getDisallowedRegions();
                }
            }
        }
        FaweRegionExtent regionExtent = null;
        if (disallowedRegions != null) {
            // Always use MultiRegionExtent if we have blacklist regions
            regionExtent = new MultiRegionExtent(this.extent, this.limit, allowedRegions, disallowedRegions);
        } else if (allowedRegions == null) {
            allowedRegions = new Region[] { RegionWrapper.GLOBAL() };
        } else {
            if (allowedRegions.length == 0) {
                regionExtent = new NullExtent(this.extent, FaweCache.NO_REGION);
            } else {
                if (allowedRegions.length == 1) {
                    regionExtent = new SingleRegionExtent(this.extent, this.limit, allowedRegions[0]);
                } else {
                    regionExtent = new MultiRegionExtent(this.extent, this.limit, allowedRegions, null);
                }
            }
        }
        // There's no need to do lighting (and it'll also just be a pain to implement) if we're not placing chunks
        if (placeChunks) {
            if (((relightMode != null && relightMode != RelightMode.NONE) || (relightMode == null && Settings.settings().LIGHTING.MODE > 0))) {
                relighter = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getRelighterFactory().createRelighter(relightMode, world, queue);
                extent.addProcessor(new RelightProcessor(relighter));
            }
            extent.addProcessor(new HeightmapProcessor(world.getMinY(), world.getMaxY()));
        } else {
            relighter = NullRelighter.INSTANCE;
        }
        if (limit != null && !limit.isUnlimited() && regionExtent != null) {
            this.extent = new LimitExtent(regionExtent, limit);
        } else if (limit != null && !limit.isUnlimited()) {
            this.extent = new LimitExtent(this.extent, limit);
        } else if (regionExtent != null) {
            this.extent = regionExtent;
        }
        if (this.limit != null && this.limit.STRIP_NBT != null && !this.limit.STRIP_NBT.isEmpty()) {
            if (placeChunks) {
                extent.addProcessor(new StripNBTExtent(this.extent, this.limit.STRIP_NBT));
            } else {
                this.extent = new StripNBTExtent(this.extent, this.limit.STRIP_NBT);
            }
        }
        if (this.limit != null && !this.limit.isUnlimited()) {
            Set<String> limitBlocks = new HashSet<>();
            if ((getActor() == null || getActor().hasPermission("worldedit.anyblock") && this.limit.UNIVERSAL_DISALLOWED_BLOCKS)) {
                limitBlocks.addAll(WorldEdit.getInstance().getConfiguration().disallowedBlocks);
            }
            if (this.limit.DISALLOWED_BLOCKS != null && !this.limit.DISALLOWED_BLOCKS.isEmpty()) {
                limitBlocks.addAll(this.limit.DISALLOWED_BLOCKS);
            }
            Set<PropertyRemap<?>> remaps = this.limit.REMAP_PROPERTIES;
            if (!limitBlocks.isEmpty() || (remaps != null && !remaps.isEmpty())) {
                if (placeChunks) {
                    extent.addProcessor(new DisallowedBlocksExtent(this.extent, limitBlocks, remaps));
                } else {
                    this.extent = new DisallowedBlocksExtent(this.extent, limitBlocks, remaps);
                }
            }
        }
        this.extent = wrapExtent(this.extent, eventBus, event, EditSession.Stage.BEFORE_HISTORY);
    }
    return this;
}
Also used : LimitExtent(com.fastasyncworldedit.core.extent.LimitExtent) IQueueChunk(com.fastasyncworldedit.core.queue.IQueueChunk) BlockBagChangeSet(com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet) SingleRegionExtent(com.fastasyncworldedit.core.extent.SingleRegionExtent) PropertyRemap(com.fastasyncworldedit.core.limit.PropertyRemap) World(com.sk89q.worldedit.world.World) SlowExtent(com.fastasyncworldedit.core.extent.SlowExtent) DiskStorageHistory(com.fastasyncworldedit.core.history.DiskStorageHistory) MemoryOptimizedHistory(com.fastasyncworldedit.core.history.MemoryOptimizedHistory) MultiRegionExtent(com.fastasyncworldedit.core.extent.MultiRegionExtent) ParallelQueueExtent(com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent) UUID(java.util.UUID) RelightProcessor(com.fastasyncworldedit.core.extent.processor.lighting.RelightProcessor) HashSet(java.util.HashSet) Player(com.sk89q.worldedit.entity.Player) HeightmapProcessor(com.fastasyncworldedit.core.extent.processor.heightmap.HeightmapProcessor) StripNBTExtent(com.fastasyncworldedit.core.extent.StripNBTExtent) NullExtent(com.fastasyncworldedit.core.extent.NullExtent) NullChangeSet(com.fastasyncworldedit.core.history.changeset.NullChangeSet) FaweRegionExtent(com.fastasyncworldedit.core.extent.FaweRegionExtent) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) HistoryExtent(com.fastasyncworldedit.core.extent.HistoryExtent) IQueueExtent(com.fastasyncworldedit.core.queue.IQueueExtent) Region(com.sk89q.worldedit.regions.Region) EditSessionEvent(com.sk89q.worldedit.event.extent.EditSessionEvent) DisallowedBlocksExtent(com.fastasyncworldedit.core.extent.DisallowedBlocksExtent)

Aggregations

ParallelQueueExtent (com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent)2 BlockTranslateExtent (com.fastasyncworldedit.core.extent.BlockTranslateExtent)1 DisallowedBlocksExtent (com.fastasyncworldedit.core.extent.DisallowedBlocksExtent)1 FaweRegionExtent (com.fastasyncworldedit.core.extent.FaweRegionExtent)1 HistoryExtent (com.fastasyncworldedit.core.extent.HistoryExtent)1 LimitExtent (com.fastasyncworldedit.core.extent.LimitExtent)1 MultiRegionExtent (com.fastasyncworldedit.core.extent.MultiRegionExtent)1 NullExtent (com.fastasyncworldedit.core.extent.NullExtent)1 PositionTransformExtent (com.fastasyncworldedit.core.extent.PositionTransformExtent)1 SingleRegionExtent (com.fastasyncworldedit.core.extent.SingleRegionExtent)1 SlowExtent (com.fastasyncworldedit.core.extent.SlowExtent)1 StripNBTExtent (com.fastasyncworldedit.core.extent.StripNBTExtent)1 HeightmapProcessor (com.fastasyncworldedit.core.extent.processor.heightmap.HeightmapProcessor)1 RelightProcessor (com.fastasyncworldedit.core.extent.processor.lighting.RelightProcessor)1 RegionMaskTestFunction (com.fastasyncworldedit.core.function.RegionMaskTestFunction)1 BiomeCopy (com.fastasyncworldedit.core.function.block.BiomeCopy)1 CombinedBlockCopy (com.fastasyncworldedit.core.function.block.CombinedBlockCopy)1 SimpleBlockCopy (com.fastasyncworldedit.core.function.block.SimpleBlockCopy)1 IntersectRegionFunction (com.fastasyncworldedit.core.function.visitor.IntersectRegionFunction)1 DiskStorageHistory (com.fastasyncworldedit.core.history.DiskStorageHistory)1