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 {
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());
}

View File

@@ -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");

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
}
public int getActiveSectionCount() {
return this.sectionTracker.getLoadedCacheCount();
}
public void free() {
this.thisTracker.free();
this.isLive = false;

View File

@@ -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) {

View File

@@ -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() {

View File

@@ -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 {

View File

@@ -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",