From 706a423c5f13ff82b970db4f41226facda466152 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 9 Dec 2023 17:46:12 -0600 Subject: [PATCH] Start world gen refactoring --- .../core/generation/BatchGenerator.java | 6 ++- .../core/generation/WorldGenerationQueue.java | 44 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) 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 ec7cde3cc..598687bfe 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 @@ -54,7 +54,7 @@ public class BatchGenerator implements IDhApiWorldGenerator * 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 = 3; + private static final int MAX_QUEUED_TASKS_PER_THREAD = 3; public AbstractBatchGenerationEnvironmentWrapper generationEnvironment; public IDhLevel targetDhLevel; @@ -150,7 +150,9 @@ public class BatchGenerator implements IDhApiWorldGenerator @Override public boolean isBusy() { - return this.generationEnvironment.getEventCount() > Math.max(Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads.get().intValue(), 1) * MAX_QUEUED_TASKS; + 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 3a4510aed..e0d99e001 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 @@ -220,18 +220,6 @@ public class WorldGenerationQueue implements IWorldGenerationQueue, IDebugRender } }); } - - private static class Mapper - { - public final WorldGenTask task; - public final int dist; - public Mapper(WorldGenTask task, int dist) - { - this.task = task; - this.dist = dist; - } - - } /** * @param targetPos the position to center the generation around @@ -549,6 +537,19 @@ public class WorldGenerationQueue implements IWorldGenerationQueue, IDebugRender + //=======// + // debug // + //=======// + + @Override + public void debugRender(DebugRenderer renderer) + { + this.waitingTasks.keySet().forEach((pos) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.blue)); }); + this.inProgressGenTasksByLodPos.forEach((pos, t) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.red)); }); + } + + + //================// // helper methods // //================// @@ -586,15 +587,20 @@ public class WorldGenerationQueue implements IWorldGenerationQueue, IDebugRender - //=======// - // debug // - //=======// + //================// + // helper classes // + //================// - @Override - public void debugRender(DebugRenderer renderer) + private static class Mapper { - this.waitingTasks.keySet().forEach((pos) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.blue)); }); - this.inProgressGenTasksByLodPos.forEach((pos, t) -> { renderer.renderBox(new DebugRenderer.Box(pos, -32f, 64f, 0.05f, Color.red)); }); + public final WorldGenTask task; + public final int dist; + public Mapper(WorldGenTask task, int dist) + { + this.task = task; + this.dist = dist; + } + } }