Make road schematic stuff slightly more efficient by sharing queues

This commit is contained in:
dordsor21 2022-01-26 17:45:15 +00:00 committed by Jordan
parent 4367be9ad0
commit 7d15cc3ba3
2 changed files with 62 additions and 21 deletions

View File

@ -106,6 +106,11 @@ public class HybridPlotManager extends ClassicPlotManager {
@Override
public boolean createRoadEast(final @NonNull Plot plot, @Nullable QueueCoordinator queue) {
boolean enqueue = false;
if (queue == null) {
queue = hybridPlotWorld.getQueue();
enqueue = true;
}
super.createRoadEast(plot, queue);
PlotId id = plot.getId();
PlotId id2 = PlotId.of(id.getX() + 1, id.getY());
@ -127,11 +132,6 @@ public class HybridPlotManager extends ClassicPlotManager {
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
return true;
}
boolean enqueue = false;
if (queue == null) {
queue = hybridPlotWorld.getQueue();
enqueue = true;
}
createSchemAbs(queue, pos1, pos2, true);
return !enqueue || queue.enqueue();
}
@ -200,6 +200,11 @@ public class HybridPlotManager extends ClassicPlotManager {
@Override
public boolean createRoadSouth(final @NonNull Plot plot, @Nullable QueueCoordinator queue) {
boolean enqueue = false;
if (queue == null) {
enqueue = true;
queue = hybridPlotWorld.getQueue();
}
super.createRoadSouth(plot, queue);
PlotId id = plot.getId();
PlotId id2 = PlotId.of(id.getX(), id.getY() + 1);
@ -211,27 +216,22 @@ public class HybridPlotManager extends ClassicPlotManager {
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
return true;
}
boolean enqueue = false;
if (queue == null) {
enqueue = true;
queue = hybridPlotWorld.getQueue();
}
createSchemAbs(queue, pos1, pos2, true);
return !enqueue || queue.enqueue();
}
@Override
public boolean createRoadSouthEast(final @NonNull Plot plot, @Nullable QueueCoordinator queue) {
super.createRoadSouthEast(plot, queue);
PlotId id = plot.getId();
PlotId id2 = PlotId.of(id.getX() + 1, id.getY() + 1);
Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1);
Location pos2 = getPlotBottomLocAbs(id2);
boolean enqueue = false;
if (queue == null) {
enqueue = true;
queue = hybridPlotWorld.getQueue();
}
super.createRoadSouthEast(plot, queue);
PlotId id = plot.getId();
PlotId id2 = PlotId.of(id.getX() + 1, id.getY() + 1);
Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1);
Location pos2 = getPlotBottomLocAbs(id2);
createSchemAbs(queue, pos1, pos2, true);
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
createSchemAbs(queue, pos1, pos2, true);

View File

@ -65,6 +65,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.File;
import java.util.ArrayDeque;
@ -443,8 +444,9 @@ public class HybridUtils {
while (iter.hasNext()) {
BlockVector2 chunk = iter.next();
iter.remove();
boolean regenedRoad = regenerateRoad(area, chunk, extend);
if (!regenedRoad) {
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
boolean regenedRoad = regenerateRoad(area, chunk, extend, queue);
if (!regenedRoad || !queue.enqueue()) {
LOGGER.info("Failed to regenerate roads");
}
}
@ -480,11 +482,12 @@ public class HybridUtils {
TaskManager.getPlatformImplementation().sync(() -> {
long start = System.currentTimeMillis();
Iterator<BlockVector2> iterator = chunks.iterator();
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
while (System.currentTimeMillis() - start < 20 && !chunks.isEmpty()) {
final BlockVector2 chunk = iterator.next();
iterator.remove();
boolean regenedRoads = regenerateRoad(area, chunk, extend);
if (!regenedRoads) {
boolean regenedRoads = regenerateRoad(area, chunk, extend, queue);
if (!regenedRoads || !queue.enqueue()) {
LOGGER.info("Failed to regenerate road");
}
}
@ -572,7 +575,35 @@ public class HybridUtils {
return ey;
}
/**
* Regenerate the road in a chunk in a plot area.
*
* @param area Plot area to regenerate road for
* @param chunk Chunk location to regenerate
* @param extend How far to extend setting air above the road
* @return if successful
* @deprecated use {@link HybridUtils#regenerateRoad(PlotArea, BlockVector2, int, QueueCoordinator)}
*/
@Deprecated(forRemoval = true, since = "TODO")
public boolean regenerateRoad(final PlotArea area, final BlockVector2 chunk, int extend) {
return regenerateRoad(area, chunk, extend, null);
}
/**
* Regenerate the road in a chunk in a plot area.
*
* @param area Plot area to regenerate road for
* @param chunk Chunk location to regenerate
* @param extend How far to extend setting air above the road
* @param queueCoordinator {@link QueueCoordinator} to use to set the blocks. Null if one should be created and enqueued
* @return if successful
*/
public boolean regenerateRoad(
final PlotArea area,
final BlockVector2 chunk,
int extend,
@Nullable QueueCoordinator queueCoordinator
) {
int x = chunk.getX() << 4;
int z = chunk.getZ() << 4;
int ex = x + 15;
@ -598,7 +629,15 @@ public class HybridUtils {
z -= plotWorld.ROAD_OFFSET_Z;
final int finalX = x;
final int finalZ = z;
QueueCoordinator queue = this.blockQueue.getNewQueue(worldUtil.getWeWorld(plotWorld.getWorldName()));
final boolean enqueue;
final QueueCoordinator queue;
if (queueCoordinator == null) {
queue = this.blockQueue.getNewQueue(worldUtil.getWeWorld(plotWorld.getWorldName()));
enqueue = true;
} else {
queue = queueCoordinator;
enqueue = false;
}
if (id1 == null || id2 == null || id1 != id2) {
this.chunkManager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> {
if (id1 != null) {
@ -682,7 +721,9 @@ public class HybridUtils {
}
}
}
if (enqueue) {
queue.enqueue();
}
});
return true;
}