diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java index ec2f5b391..eb33942f0 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java @@ -66,9 +66,13 @@ public class SharedApi /** how many chunks can be queued for updating per thread, used to prevent updates from infinitely pilling up if the user flies around extremely fast */ private static final int MAX_UPDATING_CHUNK_COUNT_PER_THREAD = 500; + /** how many milliseconds must pass before an overloaded message can be sent in chat or the log */ + private static final int MIN_MS_BETWEEN_OVERLOADED_LOG_MESSAGE = 30_000; + private static AbstractDhWorld currentWorld; private static int lastWorldGenTickDelta = 0; + private static long lastOverloadedLogMessageMsTime = 0; @@ -272,7 +276,27 @@ public class SharedApi { UPDATE_POS_MANAGER.removeItem(chunkWrapper.getChunkPos()); } - UPDATE_POS_MANAGER.addItem(chunkWrapper.getChunkPos(), updateData); + boolean queueHasRemainingCapacity = UPDATE_POS_MANAGER.addItem(chunkWrapper.getChunkPos(), updateData); + if (!queueHasRemainingCapacity) + { + // limit how often an overloaded message can be sent + long msBetweenLastLog = System.currentTimeMillis() - lastOverloadedLogMessageMsTime; + if (msBetweenLastLog >= MIN_MS_BETWEEN_OVERLOADED_LOG_MESSAGE) + { + lastOverloadedLogMessageMsTime = System.currentTimeMillis(); + + String message = "\u00A76" + "Distant Horizons overloaded, too many chunks queued for LOD processing. " + "\u00A7r" + + "\nThis may result in holes in your LODs. " + + "\nFix: move through the world slower, decrease your vanilla render distance, slow down your world pre-generator (IE Chunky), or increase the Distant Horizons' CPU thread counts. " + + "\nMax queue count ["+UPDATE_POS_MANAGER.maxSize+"] (["+MAX_UPDATING_CHUNK_COUNT_PER_THREAD+"] per thread)."; + + if (Config.Common.Logging.Warning.showUpdateQueueOverloadedChatWarning.get()) + { + ClientApi.INSTANCE.showChatMessageNextFrame(message); + } + LOGGER.warn(message); + } + } @@ -495,7 +519,8 @@ public class SharedApi } } - public void addItem(DhChunkPos pos, UpdateChunkData updateData) + /** @return true if the queue has remaining slots, false if the queue is full */ + public boolean addItem(DhChunkPos pos, UpdateChunkData updateData) { try { @@ -503,20 +528,27 @@ public class SharedApi if (this.positionMap.containsKey(pos)) { - return; + // assume the queue has additional slots + return true; } + + boolean queueFull = false; if (this.positionMap.size() >= this.maxSize) { // Remove item furthest from the center DhChunkPos furthest = this.furthestQueue.poll(); this.closestQueue.remove(furthest); this.positionMap.remove(furthest); + + queueFull = true; } this.positionMap.put(pos, updateData); this.closestQueue.add(pos); this.furthestQueue.add(pos); + + return queueFull; } finally { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index 06207d222..f0385d525 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -1479,6 +1479,14 @@ public class Config + "") .build(); + public static ConfigEntry showUpdateQueueOverloadedChatWarning = new ConfigEntry.Builder() + .set(false) + .comment("" + + "If enabled, a chat message will be displayed when DH has too many chunks \n" + + "queued for updating. \n" + + "") + .build(); + public static ConfigEntry showModCompatibilityWarningsOnStartup = new ConfigEntry.Builder() .set(true) .comment("" diff --git a/core/src/main/resources/assets/distanthorizons/lang/en_us.json b/core/src/main/resources/assets/distanthorizons/lang/en_us.json index e4b8b8509..c79927c7a 100644 --- a/core/src/main/resources/assets/distanthorizons/lang/en_us.json +++ b/core/src/main/resources/assets/distanthorizons/lang/en_us.json @@ -652,6 +652,8 @@ "Show Low Memory Warning", "distanthorizons.config.common.logging.warning.showReplayWarningOnStartup": "Show Replay Warning", + "distanthorizons.config.common.logging.warning.showUpdateQueueOverloadedChatWarning": + "Show Update Queue Overloaded Warning", "distanthorizons.config.common.logging.warning.showModCompatibilityWarningsOnStartup": "Show Mod Compatibility Warnings",