From 7d4d899226d5586f70e55db8ae2b7255678e3bdc Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 13 Apr 2024 14:25:28 -0500 Subject: [PATCH] log migration status in F3 menu and chat --- .../core/api/internal/ClientApi.java | 17 +++++++++++++++++ .../distanthorizons/core/config/Config.java | 7 +++++++ .../fullDatafile/FullDataSourceProviderV1.java | 2 +- .../fullDatafile/FullDataSourceProviderV2.java | 11 +++++++++++ .../core/level/ClientLevelModule.java | 6 ++++++ .../assets/distanthorizons/lang/en_us.json | 2 ++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java index 6707f5f90..88a365e72 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java @@ -78,6 +78,8 @@ public class ClientApi public static final long SPAM_LOGGER_FLUSH_NS = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); private boolean configOverrideReminderPrinted = false; + private boolean showMigrationMessage = false; + public boolean rendererDisabledBecauseOfExceptions = false; private long lastFlushNanoTime = 0; @@ -470,6 +472,7 @@ public class ClientApi { // logging // + // dev build if (ModInfo.IS_DEV_BUILD && !this.configOverrideReminderPrinted && MC.playerExists()) { this.configOverrideReminderPrinted = true; @@ -478,6 +481,18 @@ public class ClientApi MC.sendChatMessage("Distant Horizons nightly experimental build version [" + ModInfo.VERSION+"]."); MC.sendChatMessage("You are running an unsupported version of Distant Horizons!"); MC.sendChatMessage("Here be dragons!"); + MC.sendChatMessage(""); + } + + // data migration + if (this.showMigrationMessage + && Config.Client.Advanced.LodBuilding.showMigrationChatWarning.get()) + { + this.showMigrationMessage = false; + + MC.sendChatMessage("Old Distant Horizons data is being migrated."); + MC.sendChatMessage("While running LODs may load slowly and DH world gen is disabled."); + MC.sendChatMessage(""); } IProfilerWrapper profiler = MC.getProfiler(); @@ -629,5 +644,7 @@ public class ClientApi } } + // TODO there's probably a better way of handling chat messages + public void showMigrationMessageOnNextFrame() { this.showMigrationMessage = true; } } 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 391aefa2d..136a6e66b 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 @@ -805,6 +805,13 @@ public class Config + "") .build(); + public static ConfigEntry showMigrationChatWarning = new ConfigEntry.Builder() + .set(true) + .comment("" + + "Determines if a message should be displayed in the chat when LOD migration starts. \n" + + "") + .build(); + } public static class Multiplayer diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV1.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV1.java index a994b60e4..9fb3bd9fc 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV1.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV1.java @@ -148,7 +148,7 @@ public class FullDataSourceProviderV1 { ArrayList dataSourceList = new ArrayList<>(); - ArrayList migrationPosList = ((FullDataSourceV1Repo) this.repo).getPositionsToMigrate(limit); + ArrayList migrationPosList = this.repo.getPositionsToMigrate(limit); for (int i = 0; i < migrationPosList.size(); i++) { DhSectionPos pos = migrationPosList.get(i); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java index 7844eb84f..da63e4857 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java @@ -20,9 +20,11 @@ package com.seibel.distanthorizons.core.file.fullDatafile; import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode; +import com.seibel.distanthorizons.core.api.internal.ClientApi; import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV1; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; +import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure; import com.seibel.distanthorizons.core.file.AbstractNewDataSourceHandler; import com.seibel.distanthorizons.core.level.IDhLevel; @@ -34,6 +36,7 @@ import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV2DTO; import com.seibel.distanthorizons.core.sql.repo.FullDataSourceV2Repo; import com.seibel.distanthorizons.core.util.ThreadUtil; import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil; +import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -56,6 +59,7 @@ public class FullDataSourceProviderV2 implements IDebugRenderable { private static final Logger LOGGER = DhLoggerBuilder.getLogger(); + private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); protected static final int NUMBER_OF_PARENT_UPDATE_TASKS_PER_THREAD = 50; /** how many parent update tasks can be in the queue at once */ @@ -75,6 +79,9 @@ public class FullDataSourceProviderV2 private static final int MIGRATION_MAX_UPDATE_TIMEOUT_IN_MS = 5 * 60 * 1_000; + private static boolean migrationMessageShown = false; + + protected final ThreadPoolExecutor migrationThreadPool; /** * Interrupting the migration thread pool doesn't work well and may corrupt the database @@ -356,6 +363,8 @@ public class FullDataSourceProviderV2 ArrayList legacyDataSourceList = this.legacyFileHandler.getDataSourcesToMigrate(MIGRATION_BATCH_COUNT); if (!legacyDataSourceList.isEmpty()) { + ClientApi.INSTANCE.showMigrationMessageOnNextFrame(); + // keep going until every data source has been migrated int progressCount = 0; while (!legacyDataSourceList.isEmpty() && this.migrationThreadRunning.get()) @@ -430,6 +439,8 @@ public class FullDataSourceProviderV2 this.migrationThreadRunning.set(false); } + public int getMigrationCount() { return this.legacyFileHandler.getDataSourceMigrationCount(); } + //=======================// diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/ClientLevelModule.java b/core/src/main/java/com/seibel/distanthorizons/core/level/ClientLevelModule.java index 801a2a256..90accbcde 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/ClientLevelModule.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/ClientLevelModule.java @@ -272,6 +272,8 @@ public class ClientLevelModule implements Closeable, AbstractNewDataSourceHandle String updateCompletedTaskSize = (updateExecutor != null) ? updateExecutor.getCompletedTaskCount()+"" : "-"; int unsavedDataSourceCount = this.fullDataSourceProvider.getUnsavedDataSourceCount(); + int migrationCount = this.fullDataSourceProvider.getMigrationCount(); + ArrayList lines = new ArrayList<>(); @@ -282,6 +284,10 @@ public class ClientLevelModule implements Closeable, AbstractNewDataSourceHandle { lines.add("File Handler [" + dimName + "]"); lines.add(" File thread pool tasks: " + fileQueueSize + " (completed: " + fileCompletedTaskSize + ")"); + if (migrationCount > 0) + { + lines.add(" Legacy Migration #: " + migrationCount); + } lines.add(" Update thread pool tasks: " + updateQueueSize + " (completed: " + updateCompletedTaskSize + ")"); lines.add(" Level Unsaved #: " + this.clientLevel.getUnsavedDataSourceCount()); if (unsavedDataSourceCount != -1) 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 d88fb35c3..d3694ab96 100644 --- a/core/src/main/resources/assets/distanthorizons/lang/en_us.json +++ b/core/src/main/resources/assets/distanthorizons/lang/en_us.json @@ -356,6 +356,8 @@ "Lossy World Compression", "distanthorizons.config.client.advanced.lodBuilding.worldCompression.@tooltip": "How should block data be compressed when creating LOD data? \nThis setting will only affect new or updated LOD data, \nany data already generated when this setting is changed will be \nunaffected until it is modified or re-loaded. \n\nMost Accurate: Merge Same Blocks \nHighest Compression: Visually Equal", + "distanthorizons.config.client.advanced.lodBuilding.showMigrationChatWarning": + "Log Migration In Chat", "distanthorizons.config.client.advanced.multiplayer":