From a249631d763ec55b7dca0b0de2acf63e1faf7651 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 22 Jan 2023 17:09:10 -0600 Subject: [PATCH] Rename world generator task objects --- .../core/generation/WorldGenerationQueue.java | 46 +++++++++---------- ....java => InProgressWorldGenTaskGroup.java} | 6 +-- ...{TaskGroup.java => WorldGenTaskGroup.java} | 4 +- .../lod/core/level/DhClientServerLevel.java | 1 - .../java/com/seibel/lod/core/pos/Pos2D.java | 1 + 5 files changed, 29 insertions(+), 29 deletions(-) rename core/src/main/java/com/seibel/lod/core/generation/tasks/{InProgressWorldGenTask.java => InProgressWorldGenTaskGroup.java} (61%) rename core/src/main/java/com/seibel/lod/core/generation/tasks/{TaskGroup.java => WorldGenTaskGroup.java} (90%) diff --git a/core/src/main/java/com/seibel/lod/core/generation/WorldGenerationQueue.java b/core/src/main/java/com/seibel/lod/core/generation/WorldGenerationQueue.java index 352a66e0f..e7f1d98a2 100644 --- a/core/src/main/java/com/seibel/lod/core/generation/WorldGenerationQueue.java +++ b/core/src/main/java/com/seibel/lod/core/generation/WorldGenerationQueue.java @@ -39,7 +39,7 @@ public class WorldGenerationQueue implements Closeable private final ConcurrentLinkedQueue looseTasks = new ConcurrentLinkedQueue<>(); // FIXME: Concurrency issue on close! // FIXME: This is using up a TONS of time to process! - private final ConcurrentSkipListMap taskGroups = new ConcurrentSkipListMap<>( + private final ConcurrentSkipListMap taskGroups = new ConcurrentSkipListMap<>( (a, b) -> { if (a.detailLevel != b.detailLevel) return a.detailLevel - b.detailLevel; @@ -53,7 +53,7 @@ public class WorldGenerationQueue implements Closeable } ); // Accessed by poller only - private final ConcurrentHashMap inProgress = new ConcurrentHashMap<>(); + private final ConcurrentHashMap inProgress = new ConcurrentHashMap<>(); // granularity is the detail level for batching world generator requests together private final byte maxGranularity; @@ -190,7 +190,7 @@ public class WorldGenerationQueue implements Closeable } } - private void addAndCombineGroup(TaskGroup target) + private void addAndCombineGroup(WorldGenTaskGroup target) { byte granularity = (byte) (target.pos.detailLevel - target.dataDetail); LodUtil.assertTrue(granularity <= this.maxGranularity && granularity >= this.minGranularity); @@ -200,10 +200,10 @@ public class WorldGenerationQueue implements Closeable if (granularity > this.minGranularity) { // TODO: Optimize this check - Iterator groupIter = this.taskGroups.values().iterator(); + Iterator groupIter = this.taskGroups.values().iterator(); while (groupIter.hasNext()) { - TaskGroup group = groupIter.next(); + WorldGenTaskGroup group = groupIter.next(); if (group.dataDetail != target.dataDetail) continue; if (!group.pos.overlaps(target.pos)) @@ -228,7 +228,7 @@ public class WorldGenerationQueue implements Closeable { if (i == targetChildId) continue; - TaskGroup group = this.taskGroups.get(parentPos.getChildByIndex(i)); + WorldGenTaskGroup group = this.taskGroups.get(parentPos.getChildByIndex(i)); if (group == null || group.dataDetail != target.dataDetail) { allPassed = false; @@ -238,7 +238,7 @@ public class WorldGenerationQueue implements Closeable if (allPassed) { LodUtil.assertTrue(!this.taskGroups.containsKey(parentPos) || this.taskGroups.get(parentPos).dataDetail != target.dataDetail); - TaskGroup[] groups = new TaskGroup[4]; + WorldGenTaskGroup[] groups = new WorldGenTaskGroup[4]; for (int i = 0; i < 4; i++) { if (i == targetChildId) @@ -248,14 +248,14 @@ public class WorldGenerationQueue implements Closeable LodUtil.assertTrue(groups[i] != null && groups[i].dataDetail == target.dataDetail); } - TaskGroup newGroup = this.taskGroups.get(parentPos); + WorldGenTaskGroup newGroup = this.taskGroups.get(parentPos); if (newGroup != null) { LodUtil.assertTrue(newGroup.dataDetail != target.dataDetail); // if it is equal, we should have been merged ages ago if (newGroup.dataDetail < target.dataDetail) { // We can just append us into the existing list. - for (TaskGroup g : groups) + for (WorldGenTaskGroup g : groups) newGroup.generatorTasks.addAll(g.generatorTasks); } else @@ -264,7 +264,7 @@ public class WorldGenerationQueue implements Closeable newGroup.dataDetail = target.dataDetail; boolean worked = this.taskGroups.remove(parentPos, newGroup); // Pop it off for later proper merge check LodUtil.assertTrue(worked); - for (TaskGroup g : groups) + for (WorldGenTaskGroup g : groups) newGroup.generatorTasks.addAll(g.generatorTasks); this.addAndCombineGroup(newGroup); // Recursive check the new group } @@ -272,8 +272,8 @@ public class WorldGenerationQueue implements Closeable else { // There should not be any higher granularity to check, as otherwise we would have merged ages ago - newGroup = new TaskGroup(parentPos, target.dataDetail); - for (TaskGroup g : groups) + newGroup = new WorldGenTaskGroup(parentPos, target.dataDetail); + for (WorldGenTaskGroup g : groups) newGroup.generatorTasks.addAll(g.generatorTasks); this.addAndCombineGroup(newGroup); // Recursive check the new group } @@ -282,7 +282,7 @@ public class WorldGenerationQueue implements Closeable } // Finally, we should be safe to add the target group into the list - TaskGroup v = this.taskGroups.put(target.pos, target); + WorldGenTaskGroup v = this.taskGroups.put(target.pos, target); LodUtil.assertTrue(v == null); // should never be replacing other things } @@ -299,7 +299,7 @@ public class WorldGenerationQueue implements Closeable LodUtil.assertTrue(taskGranularity >= LodUtil.CHUNK_DETAIL_LEVEL && taskGranularity >= this.minGranularity && taskGranularity <= this.maxGranularity); // Check existing one - TaskGroup group = this.taskGroups.get(task.pos); + WorldGenTaskGroup group = this.taskGroups.get(task.pos); if (group != null) { if (group.dataDetail <= taskDataDetail) @@ -337,7 +337,7 @@ public class WorldGenerationQueue implements Closeable if (!didAnything) { - group = new TaskGroup(task.pos, taskDataDetail); + group = new WorldGenTaskGroup(task.pos, taskDataDetail); group.generatorTasks.add(task); this.addAndCombineGroup(group); } @@ -357,13 +357,13 @@ public class WorldGenerationQueue implements Closeable private void removeOutdatedGroups() { // Remove all invalid genTasks and groups - Iterator groupIter = this.taskGroups.values().iterator(); + Iterator groupIter = this.taskGroups.values().iterator(); // go through each TaskGroup while (groupIter.hasNext()) { // go through each WorldGenTask in the TaskGroup - TaskGroup group = groupIter.next(); + WorldGenTaskGroup group = groupIter.next(); Iterator taskIter = group.generatorTasks.iterator(); while (taskIter.hasNext()) { @@ -383,13 +383,13 @@ public class WorldGenerationQueue implements Closeable private void pollAndStartNext(DhBlockPos2D targetPos) { // Select the one with the highest data detail level and closest to the target pos - TaskGroup best = null; + WorldGenTaskGroup best = null; long cachedDist = Long.MAX_VALUE; int lastChebDist = Integer.MIN_VALUE; boolean continueNextRound = true; byte currentDetailChecking = -1; - for (TaskGroup group : this.taskGroups.values()) + for (WorldGenTaskGroup group : this.taskGroups.values()) { if (currentDetailChecking == -1) currentDetailChecking = group.dataDetail; @@ -412,8 +412,8 @@ public class WorldGenerationQueue implements Closeable if (best != null) { - InProgressWorldGenTask startedTask = new InProgressWorldGenTask(best); - InProgressWorldGenTask casTask = this.inProgress.putIfAbsent(best.pos, startedTask); + InProgressWorldGenTaskGroup startedTask = new InProgressWorldGenTaskGroup(best); + InProgressWorldGenTaskGroup casTask = this.inProgress.putIfAbsent(best.pos, startedTask); boolean worked = this.taskGroups.remove(best.pos, best); // Remove the selected task from the group LodUtil.assertTrue(worked); if (casTask != null) @@ -421,7 +421,7 @@ public class WorldGenerationQueue implements Closeable // Note: Due to concurrency reasons, even if the currently running task is compatible with selected task, // we cannot use it, as some chunks may have already been written into. this.pollAndStartNext(targetPos); // Poll next one. - TaskGroup exchange = this.taskGroups.put(best.pos, best); // put back the task. + WorldGenTaskGroup exchange = this.taskGroups.put(best.pos, best); // put back the task. LodUtil.assertTrue(exchange == null); } else @@ -454,7 +454,7 @@ public class WorldGenerationQueue implements Closeable } } - private void startTaskGroup(InProgressWorldGenTask task) + private void startTaskGroup(InProgressWorldGenTaskGroup task) { byte dataDetail = task.group.dataDetail; DhLodPos pos = task.group.pos; diff --git a/core/src/main/java/com/seibel/lod/core/generation/tasks/InProgressWorldGenTask.java b/core/src/main/java/com/seibel/lod/core/generation/tasks/InProgressWorldGenTaskGroup.java similarity index 61% rename from core/src/main/java/com/seibel/lod/core/generation/tasks/InProgressWorldGenTask.java rename to core/src/main/java/com/seibel/lod/core/generation/tasks/InProgressWorldGenTaskGroup.java index e4f997a1c..1c8bd2024 100644 --- a/core/src/main/java/com/seibel/lod/core/generation/tasks/InProgressWorldGenTask.java +++ b/core/src/main/java/com/seibel/lod/core/generation/tasks/InProgressWorldGenTaskGroup.java @@ -6,13 +6,13 @@ import java.util.concurrent.CompletableFuture; * @author Leetom * @version 2022-11-25 */ -public final class InProgressWorldGenTask +public final class InProgressWorldGenTaskGroup { - public final TaskGroup group; + public final WorldGenTaskGroup group; public CompletableFuture genFuture = null; - public InProgressWorldGenTask(TaskGroup group) + public InProgressWorldGenTaskGroup(WorldGenTaskGroup group) { this.group = group; } diff --git a/core/src/main/java/com/seibel/lod/core/generation/tasks/TaskGroup.java b/core/src/main/java/com/seibel/lod/core/generation/tasks/WorldGenTaskGroup.java similarity index 90% rename from core/src/main/java/com/seibel/lod/core/generation/tasks/TaskGroup.java rename to core/src/main/java/com/seibel/lod/core/generation/tasks/WorldGenTaskGroup.java index 7282f5493..42959394b 100644 --- a/core/src/main/java/com/seibel/lod/core/generation/tasks/TaskGroup.java +++ b/core/src/main/java/com/seibel/lod/core/generation/tasks/WorldGenTaskGroup.java @@ -11,7 +11,7 @@ import java.util.function.Consumer; * @author Leetom * @version 2022-11-25 */ -public final class TaskGroup +public final class WorldGenTaskGroup { public final DhLodPos pos; public byte dataDetail; @@ -20,7 +20,7 @@ public final class TaskGroup - public TaskGroup(DhLodPos pos, byte dataDetail) + public WorldGenTaskGroup(DhLodPos pos, byte dataDetail) { this.pos = pos; this.dataDetail = dataDetail; diff --git a/core/src/main/java/com/seibel/lod/core/level/DhClientServerLevel.java b/core/src/main/java/com/seibel/lod/core/level/DhClientServerLevel.java index cf4e0e943..f2ec0e729 100644 --- a/core/src/main/java/com/seibel/lod/core/level/DhClientServerLevel.java +++ b/core/src/main/java/com/seibel/lod/core/level/DhClientServerLevel.java @@ -35,7 +35,6 @@ import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper; import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.lod.core.wrapperInterfaces.world.IServerLevelWrapper; import org.apache.logging.log4j.Logger; -import org.lwjgl.system.CallbackI; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicReference; diff --git a/core/src/main/java/com/seibel/lod/core/pos/Pos2D.java b/core/src/main/java/com/seibel/lod/core/pos/Pos2D.java index 1da76a223..7ed5dda58 100644 --- a/core/src/main/java/com/seibel/lod/core/pos/Pos2D.java +++ b/core/src/main/java/com/seibel/lod/core/pos/Pos2D.java @@ -27,6 +27,7 @@ import java.util.Objects; public class Pos2D { public static final Pos2D ZERO = new Pos2D(0, 0); + public final int x; public final int y;