mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
Fix lag caused when generating augmented worlds with roads (#3614)
- Begin by implementing forceSync to the queue system as we know the chunk will be accessible to edits in some cases (i.e. population). - Also implement custom SideEffectSets to override any decided by the default chunk consumer, as we do NOT want to update neighbours in population (this caused infinite generation to be required causing the lag and server death). We also do not want to enqueue the QueueCoordinator in AugmentedUtils as this would write to the world and update neighbours before we might want to (plus it's just used to restrict and offset the blocks being set) - Then implement disabling any biomes from being saved/set to the queue to prevent augmented worlds having their biomes overridden in roads - Consequently fix ScopedQueueCoordinator, preventing the y value of blocks being set from needlessly being changed, fixing road heights in augmented worlds - Finally we do not need a method with chunkObject in the signature in AugmentedUtils as this is no longer used by the method
This commit is contained in:
@ -25,7 +25,11 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
@ -52,7 +56,14 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
|
||||
|
||||
@Override
|
||||
public void populate(@NonNull World world, @NonNull Random random, @NonNull Chunk source) {
|
||||
AugmentedUtils.generate(source, world.getName(), source.getX(), source.getZ(), null);
|
||||
QueueCoordinator queue = PlotSquared.platform().globalBlockQueue().getNewQueue(BukkitAdapter.adapt(world));
|
||||
// The chunk is already loaded and we do not want to load the chunk in "fully" by using any PaperLib methods.
|
||||
queue.setForceSync(true);
|
||||
queue.setSideEffectSet(SideEffectSet.none());
|
||||
queue.setBiomesEnabled(false);
|
||||
queue.setChunkObject(source);
|
||||
AugmentedUtils.generateChunk(world.getName(), source.getX(), source.getZ(), queue);
|
||||
queue.enqueue();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,10 +76,11 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
private final int totalSize;
|
||||
private final AtomicInteger expectedSize;
|
||||
private final AtomicInteger loadingChunks = new AtomicInteger();
|
||||
private final boolean forceSync;
|
||||
|
||||
private int batchSize;
|
||||
private PlotSquaredTask task;
|
||||
private boolean shouldCancel;
|
||||
private volatile boolean shouldCancel;
|
||||
private boolean finished;
|
||||
|
||||
@Inject
|
||||
@ -92,7 +93,8 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
@Assisted final @NonNull Runnable whenDone,
|
||||
@Assisted final @NonNull Consumer<Throwable> throwableConsumer,
|
||||
@Assisted final boolean unloadAfter,
|
||||
@Assisted final @NonNull Collection<ProgressSubscriber> progressSubscribers
|
||||
@Assisted final @NonNull Collection<ProgressSubscriber> progressSubscribers,
|
||||
@Assisted final boolean forceSync
|
||||
) {
|
||||
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
||||
this.availableChunks = new LinkedBlockingQueue<>();
|
||||
@ -107,14 +109,27 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
this.plugin = JavaPlugin.getPlugin(BukkitPlatform.class);
|
||||
this.bukkitWorld = Bukkit.getWorld(world.getName());
|
||||
this.progressSubscribers.addAll(progressSubscribers);
|
||||
this.forceSync = forceSync;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
// Request initial batch
|
||||
this.requestBatch();
|
||||
// Wait until next tick to give the chunks a chance to be loaded
|
||||
TaskManager.runTaskLater(() -> task = TaskManager.runTaskRepeat(this, TaskTime.ticks(1)), TaskTime.ticks(1));
|
||||
if (!forceSync) {
|
||||
// Request initial batch
|
||||
this.requestBatch();
|
||||
// Wait until next tick to give the chunks a chance to be loaded
|
||||
TaskManager.runTaskLater(() -> task = TaskManager.runTaskRepeat(this, TaskTime.ticks(1)), TaskTime.ticks(1));
|
||||
} else {
|
||||
try {
|
||||
while (!shouldCancel && !requestedChunks.isEmpty()) {
|
||||
chunkConsumer.accept(requestedChunks.poll());
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
throwableConsumer.accept(t);
|
||||
} finally {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -131,7 +146,9 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
for (final ProgressSubscriber subscriber : this.progressSubscribers) {
|
||||
subscriber.notifyEnd();
|
||||
}
|
||||
task.cancel();
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
|
@ -63,10 +63,27 @@ import java.util.function.Consumer;
|
||||
|
||||
public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
|
||||
private final SideEffectSet noSideEffectSet;
|
||||
private final SideEffectSet lightingSideEffectSet;
|
||||
private final SideEffectSet edgeSideEffectSet;
|
||||
private final SideEffectSet edgeLightingSideEffectSet;
|
||||
private static final SideEffectSet NO_SIDE_EFFECT_SET;
|
||||
private static final SideEffectSet EDGE_SIDE_EFFECT_SET;
|
||||
private static final SideEffectSet LIGHTING_SIDE_EFFECT_SET;
|
||||
private static final SideEffectSet EDGE_LIGHTING_SIDE_EFFECT_SET;
|
||||
|
||||
static {
|
||||
NO_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(
|
||||
SideEffect.NEIGHBORS,
|
||||
SideEffect.State.OFF
|
||||
);
|
||||
EDGE_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.UPDATE, SideEffect.State.ON).with(
|
||||
SideEffect.NEIGHBORS,
|
||||
SideEffect.State.ON
|
||||
);
|
||||
LIGHTING_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||
EDGE_LIGHTING_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.UPDATE, SideEffect.State.ON).with(
|
||||
SideEffect.NEIGHBORS,
|
||||
SideEffect.State.ON
|
||||
);
|
||||
}
|
||||
|
||||
private org.bukkit.World bukkitWorld;
|
||||
@Inject
|
||||
private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
||||
@ -77,19 +94,6 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
@Inject
|
||||
public BukkitQueueCoordinator(@NonNull World world) {
|
||||
super(world);
|
||||
noSideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(
|
||||
SideEffect.NEIGHBORS,
|
||||
SideEffect.State.OFF
|
||||
);
|
||||
lightingSideEffectSet = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||
edgeSideEffectSet = noSideEffectSet.with(SideEffect.UPDATE, SideEffect.State.ON).with(
|
||||
SideEffect.NEIGHBORS,
|
||||
SideEffect.State.ON
|
||||
);
|
||||
edgeLightingSideEffectSet = noSideEffectSet.with(SideEffect.UPDATE, SideEffect.State.ON).with(
|
||||
SideEffect.NEIGHBORS,
|
||||
SideEffect.State.ON
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -202,7 +206,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
localChunk.getTiles().forEach((blockVector3, tag) -> {
|
||||
try {
|
||||
BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag);
|
||||
getWorld().setBlock(blockVector3, block, noSideEffectSet);
|
||||
getWorld().setBlock(blockVector3, block, getSideEffectSet(SideEffectState.NONE));
|
||||
} catch (WorldEditException ignored) {
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
|
||||
@ -259,9 +263,9 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
}
|
||||
SideEffectSet sideEffectSet;
|
||||
if (lighting) {
|
||||
sideEffectSet = edge ? edgeLightingSideEffectSet : lightingSideEffectSet;
|
||||
sideEffectSet = getSideEffectSet(edge ? SideEffectState.EDGE_LIGHTING : SideEffectState.LIGHTING);
|
||||
} else {
|
||||
sideEffectSet = edge ? edgeSideEffectSet : noSideEffectSet;
|
||||
sideEffectSet = getSideEffectSet(edge ? SideEffectState.EDGE : SideEffectState.NONE);
|
||||
}
|
||||
getWorld().setBlock(loc, block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
@ -382,4 +386,23 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
return false;
|
||||
}
|
||||
|
||||
private SideEffectSet getSideEffectSet(SideEffectState state) {
|
||||
if (getSideEffectSet() != null) {
|
||||
return getSideEffectSet();
|
||||
}
|
||||
return switch (state) {
|
||||
case NONE -> NO_SIDE_EFFECT_SET;
|
||||
case EDGE -> EDGE_SIDE_EFFECT_SET;
|
||||
case LIGHTING -> LIGHTING_SIDE_EFFECT_SET;
|
||||
case EDGE_LIGHTING -> EDGE_LIGHTING_SIDE_EFFECT_SET;
|
||||
};
|
||||
}
|
||||
|
||||
private enum SideEffectState {
|
||||
NONE,
|
||||
EDGE,
|
||||
LIGHTING,
|
||||
EDGE_LIGHTING
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user