From 6cadf85b6abc5c28ee91a44f84620c7b713437d9 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Mon, 24 Mar 2025 17:48:17 +1000 Subject: [PATCH] Changed config, fixed crashes and issues with world importing --- .../config/VoxyConfigScreenFactory.java | 63 ++++++++++++------- .../mixin/minecraft/MixinWorldRenderer.java | 4 ++ .../cortex/voxy/common/world/WorldEngine.java | 5 ++ .../cortex/voxy/commonImpl/ImportManager.java | 6 +- .../cortex/voxy/commonImpl/VoxyInstance.java | 2 + .../commonImpl/importers/WorldImporter.java | 7 +-- .../resources/assets/voxy/lang/en_us.json | 3 + 7 files changed, 60 insertions(+), 30 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java index 2553714e..9da13bf9 100644 --- a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java +++ b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java @@ -16,7 +16,8 @@ import net.minecraft.text.Text; public class VoxyConfigScreenFactory implements ModMenuApi { private static VoxyConfig DEFAULT; - private static boolean ON_SAVE_RELOAD = false; + private static boolean ON_SAVE_RELOAD_ALL = false; + private static boolean ON_SAVE_RELOAD_RENDERER = false; @Override public ConfigScreenFactory getModConfigScreenFactory() { @@ -40,32 +41,48 @@ public class VoxyConfigScreenFactory implements ModMenuApi { //After saving the core should be reloaded/reset var worldRenderer = MinecraftClient.getInstance().worldRenderer; var world = MinecraftClient.getInstance().world; - if (worldRenderer != null && world != null && ON_SAVE_RELOAD) { - //Reload voxy - ((IGetVoxyRenderSystem)worldRenderer).shutdownRenderer(); - + if (worldRenderer != null && (ON_SAVE_RELOAD_ALL||ON_SAVE_RELOAD_RENDERER)) { + //Shudown renderer + ((IGetVoxyRenderSystem) worldRenderer).shutdownRenderer(); + } + //Shutdown world + if (world != null && ON_SAVE_RELOAD_ALL) { //This is a hack inserted for the client world thing //TODO: FIXME: MAKE BETTER - var engine = ((IVoxyWorldGetter)world).getWorldEngine(); + var engine = ((IVoxyWorldGetter) world).getWorldEngine(); if (engine != null) { VoxyCommon.getInstance().stopWorld(engine); } - ((IVoxyWorldSetter)world).setWorldEngine(null); - - - VoxyCommon.shutdownInstance(); - VoxyCommon.createInstance(); - ((IGetVoxyRenderSystem)worldRenderer).createRenderer(); + ((IVoxyWorldSetter) world).setWorldEngine(null); } - ON_SAVE_RELOAD = false; + //Shutdown instance + if (ON_SAVE_RELOAD_ALL) { + VoxyCommon.shutdownInstance(); + + //Create instance + if (VoxyConfig.CONFIG.enabled) + VoxyCommon.createInstance(); + } + + if (worldRenderer != null && (ON_SAVE_RELOAD_ALL||ON_SAVE_RELOAD_RENDERER)) { + //Create renderer + ((IGetVoxyRenderSystem) worldRenderer).createRenderer(); + } + + ON_SAVE_RELOAD_RENDERER = false; + ON_SAVE_RELOAD_ALL = false; VoxyConfig.CONFIG.save(); }); return builder.build();// } - private static void reload() { - ON_SAVE_RELOAD = true; + private static void reloadAll() { + ON_SAVE_RELOAD_ALL = true; + } + + private static void reloadRender() { + ON_SAVE_RELOAD_RENDERER = true; } private static void addGeneralCategory(ConfigBuilder builder, VoxyConfig config) { @@ -74,7 +91,7 @@ public class VoxyConfigScreenFactory implements ModMenuApi { category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.enabled"), config.enabled) .setTooltip(Text.translatable("voxy.config.general.enabled.tooltip")) - .setSaveConsumer(val -> {if (config.enabled != val) reload(); config.enabled = val;}) + .setSaveConsumer(val -> {if (config.enabled != val) reloadAll(); config.enabled = val;}) .setDefaultValue(DEFAULT.enabled) .build()); @@ -86,7 +103,7 @@ public class VoxyConfigScreenFactory implements ModMenuApi { category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.rendering"), config.enableRendering) .setTooltip(Text.translatable("voxy.config.general.rendering.tooltip")) - .setSaveConsumer(val -> {if (config.enableRendering != val) reload(); config.enableRendering = val;}) + .setSaveConsumer(val -> {if (config.enableRendering != val) reloadRender(); config.enableRendering = val;}) .setDefaultValue(DEFAULT.enableRendering) .build()); @@ -96,15 +113,15 @@ public class VoxyConfigScreenFactory implements ModMenuApi { .setDefaultValue((int) DEFAULT.subDivisionSize) .build()); - category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.lruCacheSize"), config.secondaryLruCacheSize, 16, 1<<13) - .setTooltip(Text.translatable("voxy.config.general.lruCacheSize.tooltip")) - .setSaveConsumer(val ->{if (config.secondaryLruCacheSize != val) reload(); config.secondaryLruCacheSize = val;}) - .setDefaultValue(DEFAULT.secondaryLruCacheSize) - .build()); + //category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.lruCacheSize"), config.secondaryLruCacheSize, 16, 1<<13) + // .setTooltip(Text.translatable("voxy.config.general.lruCacheSize.tooltip")) + // .setSaveConsumer(val ->{if (config.secondaryLruCacheSize != val) reload(); config.secondaryLruCacheSize = val;}) + // .setDefaultValue(DEFAULT.secondaryLruCacheSize) + // .build()); category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.serviceThreads"), config.serviceThreads, 1, Runtime.getRuntime().availableProcessors()) .setTooltip(Text.translatable("voxy.config.general.serviceThreads.tooltip")) - .setSaveConsumer(val ->{if (config.serviceThreads != val) reload(); config.serviceThreads = val;}) + .setSaveConsumer(val ->{if (config.serviceThreads != val) reloadAll(); config.serviceThreads = val;}) .setDefaultValue(DEFAULT.serviceThreads) .build()); } diff --git a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java index c33432f9..763485b6 100644 --- a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java +++ b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java @@ -83,6 +83,10 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem { Logger.info("Not creating renderer due to disabled"); return; } + if (this.world == null) { + Logger.error("Not creating renderer due to null world"); + return; + } var instance = (VoxyClientInstance)VoxyCommon.getInstance(); if (instance == null) { Logger.error("Not creating renderer due to null instance"); diff --git a/src/main/java/me/cortex/voxy/common/world/WorldEngine.java b/src/main/java/me/cortex/voxy/common/world/WorldEngine.java index f4c32eda..011fded2 100644 --- a/src/main/java/me/cortex/voxy/common/world/WorldEngine.java +++ b/src/main/java/me/cortex/voxy/common/world/WorldEngine.java @@ -196,6 +196,11 @@ public class WorldEngine { debug.add("ACC/SCC: " + this.sectionTracker.getLoadedCacheCount()+"/"+this.sectionTracker.getSecondaryCacheSize());//Active cache count, Secondary cache counts } + public int getActiveSectionCount() { + return this.sectionTracker.getLoadedCacheCount(); + } + + public void free() { this.thisTracker.free(); this.isLive = false; diff --git a/src/main/java/me/cortex/voxy/commonImpl/ImportManager.java b/src/main/java/me/cortex/voxy/commonImpl/ImportManager.java index fcb0802a..82995299 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/ImportManager.java +++ b/src/main/java/me/cortex/voxy/commonImpl/ImportManager.java @@ -107,9 +107,9 @@ public class ImportManager { } private synchronized void jobFinished(ImportTask task) { - if (!task.isCompleted()) { - throw new IllegalStateException(); - } + //if (!task.isCompleted()) { + // throw new IllegalStateException(); + //} var remTask = this.activeImporters.remove(task.importer.getEngine()); if (remTask != null) { diff --git a/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java b/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java index 70897fe9..f58abf60 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java +++ b/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java @@ -13,6 +13,7 @@ import net.minecraft.client.world.ClientWorld; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; //TODO: add thread access verification (I.E. only accessible on a single thread) public class VoxyInstance { @@ -39,6 +40,7 @@ public class VoxyInstance { debug.add("Voxy Core: " + VoxyCommon.MOD_VERSION); debug.add("MemoryBuffer, Count/Size (mb): " + MemoryBuffer.getCount() + "/" + (MemoryBuffer.getTotalSize()/1_000_000)); debug.add("I/S: " + this.ingestService.getTaskCount() + "/" + this.savingService.getTaskCount()); + debug.add("AWSC: [" + this.activeWorlds.stream().map(a->""+a.getActiveSectionCount()).collect(Collectors.joining(", ")) + "]");//Active world section count } public void shutdown() { diff --git a/src/main/java/me/cortex/voxy/commonImpl/importers/WorldImporter.java b/src/main/java/me/cortex/voxy/commonImpl/importers/WorldImporter.java index 371ef9c8..6be79d44 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/importers/WorldImporter.java +++ b/src/main/java/me/cortex/voxy/commonImpl/importers/WorldImporter.java @@ -247,10 +247,9 @@ public class WorldImporter implements IDataImporter { throw new RuntimeException(e); } } - this.completionCallback.onCompletion(this.totalChunks.get()); - - this.threadPool.shutdown(); this.worker = null; + this.threadPool.shutdown(); + this.completionCallback.onCompletion(this.totalChunks.get()); }); this.worker.setName("World importer"); } @@ -260,7 +259,7 @@ public class WorldImporter implements IDataImporter { } public boolean isRunning() { - return this.isRunning || this.worker != null; + return this.isRunning || (this.worker != null && this.worker.isAlive()); } private void importRegionFile(File file) throws IOException { diff --git a/src/main/resources/assets/voxy/lang/en_us.json b/src/main/resources/assets/voxy/lang/en_us.json index 0f2f9a6f..cda52dda 100644 --- a/src/main/resources/assets/voxy/lang/en_us.json +++ b/src/main/resources/assets/voxy/lang/en_us.json @@ -8,6 +8,9 @@ "voxy.config.general.enabled": "Enable Voxy", "voxy.config.general.enabled.tooltip": "Fully enables or disables voxy", + "voxy.config.general.rendering": "Voxy Rendering", + "voxy.config.general.rendering.tooltip": "Enables or disables voxy rendering", + "voxy.config.general.ingest": "Chunk Ingest", "voxy.config.general.ingest.tooltip": "Enables or disables voxies ability to convert new chunks into LoDs",