diff --git a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/override/worldGenerator/IDhApiWorldGenerator.java b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/override/worldGenerator/IDhApiWorldGenerator.java index 501349520..4419b8686 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/override/worldGenerator/IDhApiWorldGenerator.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/override/worldGenerator/IDhApiWorldGenerator.java @@ -90,11 +90,17 @@ public interface IDhApiWorldGenerator extends Closeable, IDhApiOverrideable */ default byte getMaxGenerationGranularity() { return (byte) (EDhApiDetailLevel.CHUNK.detailLevel + 2); } - /** - * @return true if the generator is unable to accept new generation requests. + /** + * Starting in API 3.0.0 DH now handles future queuing/management internally.

+ * + * Previous description:
+ * true if the generator is unable to accept new generation requests.
+ * * @since API 1.0.0 + * @deprecated API 3.0.0 */ - boolean isBusy(); + @Deprecated + default boolean isBusy() { return false; } /** * Only used if {@link #getReturnType()} returns {@link EDhApiWorldGeneratorReturnType#API_CHUNKS}.
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/BatchGenerator.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/BatchGenerator.java index 598687bfe..655797a2a 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/BatchGenerator.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/BatchGenerator.java @@ -47,15 +47,6 @@ public class BatchGenerator implements IDhApiWorldGenerator private static final IWrapperFactory FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class); private static final Logger LOGGER = DhLoggerBuilder.getLogger(); - /** - * Defines how many tasks can be queued per thread.

- * - * TODO the multiplier here should change dynamically based on how fast the generator is vs the queuing thread, - * if this is too high it may cause issues when moving, - * but if it is too low the generator threads won't have enough tasks to work on - */ - private static final int MAX_QUEUED_TASKS_PER_THREAD = 3; - public AbstractBatchGenerationEnvironmentWrapper generationEnvironment; public IDhLevel targetDhLevel; @@ -147,14 +138,6 @@ public class BatchGenerator implements IDhApiWorldGenerator @Override public void preGeneratorTaskStart() { this.generationEnvironment.updateAllFutures(); } - @Override - public boolean isBusy() - { - int worldGenThreadCount = Math.max(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads.get(), 1); - int maxWorldGenTaskCount = worldGenThreadCount * MAX_QUEUED_TASKS_PER_THREAD; - return this.generationEnvironment.getEventCount() > maxWorldGenTaskCount; - } - //=========// diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java index f335f5107..286ee5d72 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldGenerationQueue.java @@ -55,6 +55,16 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb private static final Logger LOGGER = DhLoggerBuilder.getLogger(); private static final IWrapperFactory WRAPPER_FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class); + /** + * Defines how many tasks can be queued per thread.

+ * + * TODO the multiplier here should change dynamically based on how fast the generator is vs the queuing thread, + * if this is too high it may cause issues when moving, + * but if it is too low the generator threads won't have enough tasks to work on + */ + private static final int MAX_QUEUED_TASKS_PER_THREAD = 3; + + private final IDhApiWorldGenerator generator; /** contains the positions that need to be generated */ @@ -206,7 +216,7 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb // queue generation tasks until the generator is full, or there are no more tasks to generate boolean taskStarted = true; - while (!this.generator.isBusy() && taskStarted) + while (!this.isGeneratorBusy() && taskStarted) { taskStarted = this.startNextWorldGenTask(this.generationTargetPos); if (!taskStarted) @@ -233,6 +243,19 @@ public class WorldGenerationQueue implements IFullDataSourceRetrievalQueue, IDeb } }); } + public boolean isGeneratorBusy() + { + ThreadPoolExecutor executor = ThreadPoolUtil.getWorldGenExecutor(); + if (executor == null) + { + // shouldn't happen, but just in case, don't queue more tasks + return true; + } + + int worldGenThreadCount = Math.max(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads.get(), 1); + int maxWorldGenTaskCount = worldGenThreadCount * MAX_QUEUED_TASKS_PER_THREAD; + return executor.getQueue().size() > maxWorldGenTaskCount; + } /** * @param targetPos the position to center the generation around