Changed config, fixed crashes and issues with world importing

This commit is contained in:
mcrcortex
2025-03-24 17:48:17 +10:00
parent 4a613ff145
commit 6cadf85b6a
7 changed files with 60 additions and 30 deletions

View File

@@ -16,7 +16,8 @@ import net.minecraft.text.Text;
public class VoxyConfigScreenFactory implements ModMenuApi { public class VoxyConfigScreenFactory implements ModMenuApi {
private static VoxyConfig DEFAULT; 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 @Override
public ConfigScreenFactory<?> getModConfigScreenFactory() { public ConfigScreenFactory<?> getModConfigScreenFactory() {
@@ -40,10 +41,12 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
//After saving the core should be reloaded/reset //After saving the core should be reloaded/reset
var worldRenderer = MinecraftClient.getInstance().worldRenderer; var worldRenderer = MinecraftClient.getInstance().worldRenderer;
var world = MinecraftClient.getInstance().world; var world = MinecraftClient.getInstance().world;
if (worldRenderer != null && world != null && ON_SAVE_RELOAD) { if (worldRenderer != null && (ON_SAVE_RELOAD_ALL||ON_SAVE_RELOAD_RENDERER)) {
//Reload voxy //Shudown renderer
((IGetVoxyRenderSystem) worldRenderer).shutdownRenderer(); ((IGetVoxyRenderSystem) worldRenderer).shutdownRenderer();
}
//Shutdown world
if (world != null && ON_SAVE_RELOAD_ALL) {
//This is a hack inserted for the client world thing //This is a hack inserted for the client world thing
//TODO: FIXME: MAKE BETTER //TODO: FIXME: MAKE BETTER
var engine = ((IVoxyWorldGetter) world).getWorldEngine(); var engine = ((IVoxyWorldGetter) world).getWorldEngine();
@@ -51,21 +54,35 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
VoxyCommon.getInstance().stopWorld(engine); VoxyCommon.getInstance().stopWorld(engine);
} }
((IVoxyWorldSetter) world).setWorldEngine(null); ((IVoxyWorldSetter) world).setWorldEngine(null);
}
//Shutdown instance
if (ON_SAVE_RELOAD_ALL) {
VoxyCommon.shutdownInstance(); VoxyCommon.shutdownInstance();
//Create instance
if (VoxyConfig.CONFIG.enabled)
VoxyCommon.createInstance(); VoxyCommon.createInstance();
}
if (worldRenderer != null && (ON_SAVE_RELOAD_ALL||ON_SAVE_RELOAD_RENDERER)) {
//Create renderer
((IGetVoxyRenderSystem) worldRenderer).createRenderer(); ((IGetVoxyRenderSystem) worldRenderer).createRenderer();
} }
ON_SAVE_RELOAD = false;
ON_SAVE_RELOAD_RENDERER = false;
ON_SAVE_RELOAD_ALL = false;
VoxyConfig.CONFIG.save(); VoxyConfig.CONFIG.save();
}); });
return builder.build();// return builder.build();//
} }
private static void reload() { private static void reloadAll() {
ON_SAVE_RELOAD = true; ON_SAVE_RELOAD_ALL = true;
}
private static void reloadRender() {
ON_SAVE_RELOAD_RENDERER = true;
} }
private static void addGeneralCategory(ConfigBuilder builder, VoxyConfig config) { 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) category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.enabled"), config.enabled)
.setTooltip(Text.translatable("voxy.config.general.enabled.tooltip")) .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) .setDefaultValue(DEFAULT.enabled)
.build()); .build());
@@ -86,7 +103,7 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.rendering"), config.enableRendering) category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.rendering"), config.enableRendering)
.setTooltip(Text.translatable("voxy.config.general.rendering.tooltip")) .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) .setDefaultValue(DEFAULT.enableRendering)
.build()); .build());
@@ -96,15 +113,15 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
.setDefaultValue((int) DEFAULT.subDivisionSize) .setDefaultValue((int) DEFAULT.subDivisionSize)
.build()); .build());
category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.lruCacheSize"), config.secondaryLruCacheSize, 16, 1<<13) //category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.lruCacheSize"), config.secondaryLruCacheSize, 16, 1<<13)
.setTooltip(Text.translatable("voxy.config.general.lruCacheSize.tooltip")) // .setTooltip(Text.translatable("voxy.config.general.lruCacheSize.tooltip"))
.setSaveConsumer(val ->{if (config.secondaryLruCacheSize != val) reload(); config.secondaryLruCacheSize = val;}) // .setSaveConsumer(val ->{if (config.secondaryLruCacheSize != val) reload(); config.secondaryLruCacheSize = val;})
.setDefaultValue(DEFAULT.secondaryLruCacheSize) // .setDefaultValue(DEFAULT.secondaryLruCacheSize)
.build()); // .build());
category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.serviceThreads"), config.serviceThreads, 1, Runtime.getRuntime().availableProcessors()) category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.serviceThreads"), config.serviceThreads, 1, Runtime.getRuntime().availableProcessors())
.setTooltip(Text.translatable("voxy.config.general.serviceThreads.tooltip")) .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) .setDefaultValue(DEFAULT.serviceThreads)
.build()); .build());
} }

View File

@@ -83,6 +83,10 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
Logger.info("Not creating renderer due to disabled"); Logger.info("Not creating renderer due to disabled");
return; return;
} }
if (this.world == null) {
Logger.error("Not creating renderer due to null world");
return;
}
var instance = (VoxyClientInstance)VoxyCommon.getInstance(); var instance = (VoxyClientInstance)VoxyCommon.getInstance();
if (instance == null) { if (instance == null) {
Logger.error("Not creating renderer due to null instance"); Logger.error("Not creating renderer due to null instance");

View File

@@ -196,6 +196,11 @@ public class WorldEngine {
debug.add("ACC/SCC: " + this.sectionTracker.getLoadedCacheCount()+"/"+this.sectionTracker.getSecondaryCacheSize());//Active cache count, Secondary cache counts 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() { public void free() {
this.thisTracker.free(); this.thisTracker.free();
this.isLive = false; this.isLive = false;

View File

@@ -107,9 +107,9 @@ public class ImportManager {
} }
private synchronized void jobFinished(ImportTask task) { private synchronized void jobFinished(ImportTask task) {
if (!task.isCompleted()) { //if (!task.isCompleted()) {
throw new IllegalStateException(); // throw new IllegalStateException();
} //}
var remTask = this.activeImporters.remove(task.importer.getEngine()); var remTask = this.activeImporters.remove(task.importer.getEngine());
if (remTask != null) { if (remTask != null) {

View File

@@ -13,6 +13,7 @@ import net.minecraft.client.world.ClientWorld;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
//TODO: add thread access verification (I.E. only accessible on a single thread) //TODO: add thread access verification (I.E. only accessible on a single thread)
public class VoxyInstance { public class VoxyInstance {
@@ -39,6 +40,7 @@ public class VoxyInstance {
debug.add("Voxy Core: " + VoxyCommon.MOD_VERSION); debug.add("Voxy Core: " + VoxyCommon.MOD_VERSION);
debug.add("MemoryBuffer, Count/Size (mb): " + MemoryBuffer.getCount() + "/" + (MemoryBuffer.getTotalSize()/1_000_000)); 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("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() { public void shutdown() {

View File

@@ -247,10 +247,9 @@ public class WorldImporter implements IDataImporter {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
this.completionCallback.onCompletion(this.totalChunks.get());
this.threadPool.shutdown();
this.worker = null; this.worker = null;
this.threadPool.shutdown();
this.completionCallback.onCompletion(this.totalChunks.get());
}); });
this.worker.setName("World importer"); this.worker.setName("World importer");
} }
@@ -260,7 +259,7 @@ public class WorldImporter implements IDataImporter {
} }
public boolean isRunning() { 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 { private void importRegionFile(File file) throws IOException {

View File

@@ -8,6 +8,9 @@
"voxy.config.general.enabled": "Enable Voxy", "voxy.config.general.enabled": "Enable Voxy",
"voxy.config.general.enabled.tooltip": "Fully enables or disables 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": "Chunk Ingest",
"voxy.config.general.ingest.tooltip": "Enables or disables voxies ability to convert new chunks into LoDs", "voxy.config.general.ingest.tooltip": "Enables or disables voxies ability to convert new chunks into LoDs",