From b53c33e454f463fefa641279b0ce505a67d74f55 Mon Sep 17 00:00:00 2001 From: s809 <43530948+s809@users.noreply.github.com> Date: Thu, 27 Feb 2025 21:08:02 +0500 Subject: [PATCH] Make generation info text a bit clearer --- .../core/level/WorldGenModule.java | 56 +++++-------------- .../distanthorizons/core/util/FormatUtil.java | 16 ++++++ 2 files changed, 30 insertions(+), 42 deletions(-) create mode 100644 core/src/main/java/com/seibel/distanthorizons/core/util/FormatUtil.java diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/WorldGenModule.java b/core/src/main/java/com/seibel/distanthorizons/core/level/WorldGenModule.java index e97005a4d..6b8baf7b8 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/WorldGenModule.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/WorldGenModule.java @@ -27,6 +27,7 @@ import com.seibel.distanthorizons.core.generation.IFullDataSourceRetrievalQueue; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.logging.f3.F3Screen; import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D; +import com.seibel.distanthorizons.core.util.FormatUtil; import com.seibel.distanthorizons.core.util.ThreadUtil; import com.seibel.distanthorizons.core.util.objects.RollingAverage; import com.seibel.distanthorizons.core.util.threading.PriorityTaskPicker; @@ -35,6 +36,7 @@ import com.seibel.distanthorizons.core.world.DhApiWorldProxy; import org.apache.logging.log4j.Logger; import java.io.Closeable; +import java.time.Duration; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; @@ -288,18 +290,7 @@ public class WorldGenModule implements Closeable remainingChunkCount += this.worldGenerationQueue.getQueuedChunkCount(); String remainingChunkCountStr = F3Screen.NUMBER_FORMAT.format(remainingChunkCount); - String message = "DH Gen/Import: " + remainingChunkCountStr + " chunks"; - - - // add the remaining time estimate if available - double chunksPerSec = this.getEstimatedChunksPerSecond(); - if (chunksPerSec > 0) - { - long estimatedRemainingTime = (long) (remainingChunkCount / chunksPerSec); - message += " Estimated Time: " + formatSeconds(estimatedRemainingTime);//+ " at " + F3Screen.NUMBER_FORMAT.format(chunksPerSec) + " chunks/sec"; - } - - + String message = "DH Gen/Import: " + remainingChunkCountStr + " chunks left."; // show a message about how to disable progress logging if requested int msToShowDisableInstructions = Config.Common.WorldGenerator.generationProgressDisableMessageDisplayTimeInSeconds.get() * 1_000; @@ -308,15 +299,21 @@ public class WorldGenModule implements Closeable long timeSinceFirstMessageInMs = (System.currentTimeMillis() - firstProgressMessageSentMs); // always show this message for the first tick if (firstProgressMessageSentMs == 0 - // show this message if there is still time - || timeSinceFirstMessageInMs < msToShowDisableInstructions) + // show this message if there is still time + || timeSinceFirstMessageInMs < msToShowDisableInstructions) { - // replace the current message - message = "DH Gen/Import progress. This message can be hidden in the DH config. ["+remainingChunkCountStr+"]"; + // append to the current message + message += " This message can be hidden in the DH config."; } } - + // add the remaining time estimate if available + double chunksPerSec = this.getEstimatedChunksPerSecond(); + if (chunksPerSec > 0) + { + long estimatedRemainingTime = (long) (remainingChunkCount / chunksPerSec); + message += " ETA: " + FormatUtil.formatEta(Duration.ofSeconds(estimatedRemainingTime));//+ " at " + F3Screen.NUMBER_FORMAT.format(chunksPerSec) + " chunks/sec"; + } // only log if there are chunks needing to be generated if (remainingChunkCount != 0) @@ -344,31 +341,6 @@ public class WorldGenModule implements Closeable } } } - private static String formatSeconds(long totalSeconds) - { - long days = totalSeconds / (24 * 3600); // 24 hours in a day - long hours = (totalSeconds % (24 * 3600)) / 3600; // Hours - long minutes = (totalSeconds % 3600) / 60; // Minutes - long seconds = totalSeconds % 60; // Seconds - - - String timeString = ""; - if (days > 0) - { - timeString += days+" "; - } - if (hours > 0) - { - timeString += hours+":"; - } - if (minutes > 0) - { - timeString += String.format("%02d", minutes)+":"; - } - timeString += String.format("%02d", seconds); - - return timeString; - } /** @return -1 if this method isn't supported or available */ public double getEstimatedChunksPerSecond() diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/FormatUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/FormatUtil.java new file mode 100644 index 000000000..0b5bd9ece --- /dev/null +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/FormatUtil.java @@ -0,0 +1,16 @@ +package com.seibel.distanthorizons.core.util; + +import java.time.Duration; + +public class FormatUtil +{ + public static String formatEta(Duration duration) + { + return duration.toString() + .substring(2) + .replaceAll("(\\d[HMS])(?!$)", "$1 ") + .replaceAll("\\.\\d+", "") + .toLowerCase(); + } + +}