From 8840973a1e569542fa6a5ffc43d5c403eee67f84 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Fri, 9 Jul 2021 22:57:32 -0500 Subject: [PATCH] Fix #41 (leaving a world causing Lod generation to break) --- .../worldGeneration/LodChunkGenWorker.java | 27 +++++++++++++++++-- .../com/seibel/lod/proxy/ClientProxy.java | 9 ++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/worldGeneration/LodChunkGenWorker.java b/src/main/java/com/seibel/lod/builders/worldGeneration/LodChunkGenWorker.java index 749a1e067..45aaeb53d 100644 --- a/src/main/java/com/seibel/lod/builders/worldGeneration/LodChunkGenWorker.java +++ b/src/main/java/com/seibel/lod/builders/worldGeneration/LodChunkGenWorker.java @@ -70,11 +70,11 @@ import net.minecraftforge.common.WorldWorkerManager.IWorker; * This is used to generate a LodChunk at a given ChunkPos. * * @author James Seibel - * @version 7-5-2021 + * @version 7-9-2021 */ public class LodChunkGenWorker implements IWorker { - public static final ExecutorService genThreads = Executors.newFixedThreadPool(LodConfig.CLIENT.numberOfWorldGenerationThreads.get()); + public static ExecutorService genThreads = Executors.newFixedThreadPool(LodConfig.CLIENT.numberOfWorldGenerationThreads.get()); private boolean threadStarted = false; private LodChunkGenThread thread; @@ -124,6 +124,7 @@ public class LodChunkGenWorker implements IWorker // useful for debugging // ClientProxy.LOGGER.info(thread.lodDim.getNumberOfLods()); +// ClientProxy.LOGGER.info(genThreads.toString()); } return false; @@ -573,6 +574,28 @@ public class LodChunkGenWorker implements IWorker } + /** + * Stops the current genThreads if they are running + * and then recreates the Executer service.

+ * + * This is done to clear any outstanding tasks + * that may exist after the player leaves their current world. + * If this isn't done unfinished tasks may be left in the queue + * preventing new LodChunks form being generated. + */ + public static void restartExecuterService() + { + if (genThreads != null && !genThreads.isShutdown()) + { + genThreads.shutdownNow(); + } + genThreads = Executors.newFixedThreadPool(LodConfig.CLIENT.numberOfWorldGenerationThreads.get()); + } + + + + + /* * performance/generation tests related to * serverWorld.getChunk(x, z, ChunkStatus. *** ) diff --git a/src/main/java/com/seibel/lod/proxy/ClientProxy.java b/src/main/java/com/seibel/lod/proxy/ClientProxy.java index 54939c77f..34a82be7d 100644 --- a/src/main/java/com/seibel/lod/proxy/ClientProxy.java +++ b/src/main/java/com/seibel/lod/proxy/ClientProxy.java @@ -22,6 +22,7 @@ import org.apache.logging.log4j.Logger; import com.seibel.lod.builders.LodBufferBuilder; import com.seibel.lod.builders.LodChunkBuilder; +import com.seibel.lod.builders.worldGeneration.LodChunkGenWorker; import com.seibel.lod.handlers.LodConfig; import com.seibel.lod.objects.LodChunk; import com.seibel.lod.objects.LodDimension; @@ -42,7 +43,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; * and is the starting point for most of this program. * * @author James_Seibel - * @version 06-27-2021 + * @version 7-9-2021 */ public class ClientProxy { @@ -111,6 +112,7 @@ public class ClientProxy // for testing +// LodConfig.CLIENT.drawLODs.set(true); // LodConfig.CLIENT.debugMode.set(false); // LodConfig.CLIENT.lodDetail.set(LodDetail.DOUBLE); @@ -120,6 +122,7 @@ public class ClientProxy // LodConfig.CLIENT.distanceGenerationMode.set(DistanceGenerationMode.FEATURES); // LodConfig.CLIENT.allowUnstableFeatureGeneration.set(false); +// LOGGER.info(lodBufferBuilder.numberOfChunksWaitingToGenerate.get()); // Note to self: @@ -167,6 +170,10 @@ public class ClientProxy if(mc.getConnection().getLevel() == null) { + // if this isn't done unfinished tasks may be left in the queue + // preventing new LodChunks form being generated + LodChunkGenWorker.restartExecuterService(); + lodBufferBuilder.numberOfChunksWaitingToGenerate.set(0); // the player has disconnected from a server lodWorld.deselectWorld();