mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 13:46:45 +01:00
Make road schematic stuff slightly more efficient by sharing queues
This commit is contained in:
parent
4367be9ad0
commit
7d15cc3ba3
@ -106,6 +106,11 @@ public class HybridPlotManager extends ClassicPlotManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean createRoadEast(final @NonNull Plot plot, @Nullable QueueCoordinator queue) {
|
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);
|
super.createRoadEast(plot, queue);
|
||||||
PlotId id = plot.getId();
|
PlotId id = plot.getId();
|
||||||
PlotId id2 = PlotId.of(id.getX() + 1, id.getY());
|
PlotId id2 = PlotId.of(id.getX() + 1, id.getY());
|
||||||
@ -127,11 +132,6 @@ public class HybridPlotManager extends ClassicPlotManager {
|
|||||||
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
boolean enqueue = false;
|
|
||||||
if (queue == null) {
|
|
||||||
queue = hybridPlotWorld.getQueue();
|
|
||||||
enqueue = true;
|
|
||||||
}
|
|
||||||
createSchemAbs(queue, pos1, pos2, true);
|
createSchemAbs(queue, pos1, pos2, true);
|
||||||
return !enqueue || queue.enqueue();
|
return !enqueue || queue.enqueue();
|
||||||
}
|
}
|
||||||
@ -200,6 +200,11 @@ public class HybridPlotManager extends ClassicPlotManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean createRoadSouth(final @NonNull Plot plot, @Nullable QueueCoordinator queue) {
|
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);
|
super.createRoadSouth(plot, queue);
|
||||||
PlotId id = plot.getId();
|
PlotId id = plot.getId();
|
||||||
PlotId id2 = PlotId.of(id.getX(), id.getY() + 1);
|
PlotId id2 = PlotId.of(id.getX(), id.getY() + 1);
|
||||||
@ -211,27 +216,22 @@ public class HybridPlotManager extends ClassicPlotManager {
|
|||||||
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
boolean enqueue = false;
|
|
||||||
if (queue == null) {
|
|
||||||
enqueue = true;
|
|
||||||
queue = hybridPlotWorld.getQueue();
|
|
||||||
}
|
|
||||||
createSchemAbs(queue, pos1, pos2, true);
|
createSchemAbs(queue, pos1, pos2, true);
|
||||||
return !enqueue || queue.enqueue();
|
return !enqueue || queue.enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean createRoadSouthEast(final @NonNull Plot plot, @Nullable QueueCoordinator queue) {
|
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;
|
boolean enqueue = false;
|
||||||
if (queue == null) {
|
if (queue == null) {
|
||||||
enqueue = true;
|
enqueue = true;
|
||||||
queue = hybridPlotWorld.getQueue();
|
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);
|
createSchemAbs(queue, pos1, pos2, true);
|
||||||
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||||
createSchemAbs(queue, pos1, pos2, true);
|
createSchemAbs(queue, pos1, pos2, true);
|
||||||
|
@ -65,6 +65,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
@ -443,8 +444,9 @@ public class HybridUtils {
|
|||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
BlockVector2 chunk = iter.next();
|
BlockVector2 chunk = iter.next();
|
||||||
iter.remove();
|
iter.remove();
|
||||||
boolean regenedRoad = regenerateRoad(area, chunk, extend);
|
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
|
||||||
if (!regenedRoad) {
|
boolean regenedRoad = regenerateRoad(area, chunk, extend, queue);
|
||||||
|
if (!regenedRoad || !queue.enqueue()) {
|
||||||
LOGGER.info("Failed to regenerate roads");
|
LOGGER.info("Failed to regenerate roads");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -480,11 +482,12 @@ public class HybridUtils {
|
|||||||
TaskManager.getPlatformImplementation().sync(() -> {
|
TaskManager.getPlatformImplementation().sync(() -> {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Iterator<BlockVector2> iterator = chunks.iterator();
|
Iterator<BlockVector2> iterator = chunks.iterator();
|
||||||
|
QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
|
||||||
while (System.currentTimeMillis() - start < 20 && !chunks.isEmpty()) {
|
while (System.currentTimeMillis() - start < 20 && !chunks.isEmpty()) {
|
||||||
final BlockVector2 chunk = iterator.next();
|
final BlockVector2 chunk = iterator.next();
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
boolean regenedRoads = regenerateRoad(area, chunk, extend);
|
boolean regenedRoads = regenerateRoad(area, chunk, extend, queue);
|
||||||
if (!regenedRoads) {
|
if (!regenedRoads || !queue.enqueue()) {
|
||||||
LOGGER.info("Failed to regenerate road");
|
LOGGER.info("Failed to regenerate road");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -572,7 +575,35 @@ public class HybridUtils {
|
|||||||
return ey;
|
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) {
|
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 x = chunk.getX() << 4;
|
||||||
int z = chunk.getZ() << 4;
|
int z = chunk.getZ() << 4;
|
||||||
int ex = x + 15;
|
int ex = x + 15;
|
||||||
@ -598,7 +629,15 @@ public class HybridUtils {
|
|||||||
z -= plotWorld.ROAD_OFFSET_Z;
|
z -= plotWorld.ROAD_OFFSET_Z;
|
||||||
final int finalX = x;
|
final int finalX = x;
|
||||||
final int finalZ = z;
|
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) {
|
if (id1 == null || id2 == null || id1 != id2) {
|
||||||
this.chunkManager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> {
|
this.chunkManager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> {
|
||||||
if (id1 != null) {
|
if (id1 != null) {
|
||||||
@ -682,7 +721,9 @@ public class HybridUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queue.enqueue();
|
if (enqueue) {
|
||||||
|
queue.enqueue();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user