Skip to content
Permalink
Browse files

Remove containedBlocks fields, not very efficient

  • Loading branch information...
kenzierocks committed Jul 18, 2019
1 parent 20024dc commit 3d2b6eaa7e59ec2e27e3427daec8d903ffb01f43
@@ -19,20 +19,19 @@

package com.sk89q.worldedit.extent.reorder;

import com.google.common.collect.ImmutableSortedSet;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.AbstractBufferingExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.RegionOptimizedLongComparator;
import com.sk89q.worldedit.math.RegionOptimizedComparator;
import com.sk89q.worldedit.util.collection.BlockMap;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import it.unimi.dsi.fastutil.longs.LongAVLTreeSet;
import it.unimi.dsi.fastutil.longs.LongIterator;
import it.unimi.dsi.fastutil.longs.LongSet;

import java.util.Iterator;
import java.util.List;
import java.util.Optional;

@@ -45,7 +44,6 @@
public class ChunkBatchingExtent extends AbstractBufferingExtent {

private final BlockMap blockMap = BlockMap.create();
private final LongSet containedBlocks = new LongAVLTreeSet(RegionOptimizedLongComparator.INSTANCE);
private boolean enabled;

public ChunkBatchingExtent(Extent extent) {
@@ -75,7 +73,6 @@ public boolean commitRequired() {
return setDelegateBlock(location, block);
}
blockMap.put(location, block.toBaseBlock());
containedBlocks.add(location.toLongPackedForm());
return true;
}

@@ -92,19 +89,20 @@ protected Operation commitBefore() {
return new Operation() {

// we get modified between create/resume -- only create this on resume to prevent CME
private LongIterator iterator;
private Iterator<BlockVector3> iterator;

@Override
public Operation resume(RunContext run) throws WorldEditException {
if (iterator == null) {
iterator = containedBlocks.iterator();
iterator = ImmutableSortedSet.copyOf(RegionOptimizedComparator.INSTANCE,
blockMap.keySet()).iterator();
}
while (iterator.hasNext()) {
BlockVector3 position = BlockVector3.fromLongPackedForm(iterator.nextLong());
BlockVector3 position = iterator.next();
BaseBlock block = blockMap.get(position);
getExtent().setBlock(position, block);
iterator.remove();
}
blockMap.clear();
return null;
}

@@ -34,8 +34,6 @@
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;

import java.util.ArrayList;
import java.util.HashMap;
@@ -144,7 +142,6 @@
priorityMap.put(BlockTypes.MOVING_PISTON, PlacementPriority.FINAL);
}

private final LongSet containedBlocks = new LongOpenHashSet();
private Map<PlacementPriority, BlockMap> stages = new HashMap<>();

private boolean enabled;
@@ -246,15 +243,11 @@ public boolean commitRequired() {
}

stages.get(priority).put(location, block.toBaseBlock());
containedBlocks.add(location.toLongPackedForm());
return !existing.equalsFuzzy(block);
}

@Override
protected Optional<BaseBlock> getBufferedBlock(BlockVector3 position) {
if (!containedBlocks.contains(position.toLongPackedForm())) {
return Optional.empty();
}
return stages.values().stream()
.map(blocks -> blocks.get(position))
.filter(Objects::nonNull)
@@ -273,7 +266,7 @@ public Operation commitBefore() {
@Override
public Operation resume(RunContext run) throws WorldEditException {
Operation operation = super.resume(run);
if (operation != null) {
if (operation == null) {
blocks.clear();
}
return operation;
@@ -0,0 +1,41 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.math;

import java.util.Comparator;

import static com.sk89q.worldedit.math.BlockVector2.COMPARING_GRID_ARRANGEMENT;

/**
* Sort block positions by region, then chunk.
*/
public class RegionOptimizedChunkComparator {

private static final Comparator<BlockVector2> CHUNK_COMPARATOR =
Comparator.comparing((BlockVector2 chunkPos) -> chunkPos.shr(5), COMPARING_GRID_ARRANGEMENT)
.thenComparing(COMPARING_GRID_ARRANGEMENT);

public static final Comparator<BlockVector3> INSTANCE
= Comparator.comparing(blockPos -> blockPos.toBlockVector2().shr(4), CHUNK_COMPARATOR);

private RegionOptimizedChunkComparator() {
}

}

This file was deleted.

@@ -0,0 +1,36 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.math;

import java.util.Comparator;

/**
* Sort block positions by region, chunk, and finally Y-Z-X.
*/
public class RegionOptimizedComparator {

public static final Comparator<BlockVector3> INSTANCE
= RegionOptimizedChunkComparator.INSTANCE
.thenComparing(BlockVector3.sortByCoordsYzx());

private RegionOptimizedComparator() {
}

}

This file was deleted.

0 comments on commit 3d2b6ea

Please sign in to comment.
You can’t perform that action at this time.