Config and fixes for world managing

This commit is contained in:
mcrcortex
2025-03-16 16:10:57 +10:00
parent aea98cb6e4
commit 104bdf070c
7 changed files with 49 additions and 9 deletions

View File

@@ -31,6 +31,10 @@ public class VoxyClientInstance extends VoxyInstance {
vworld = this.createWorld(SELECTOR.getBestSelectionOrCreate(world).createSectionStorageBackend()); vworld = this.createWorld(SELECTOR.getBestSelectionOrCreate(world).createSectionStorageBackend());
((IVoxyWorldSetter)world).setWorldEngine(vworld); ((IVoxyWorldSetter)world).setWorldEngine(vworld);
this.importWrapper = new WorldImportWrapper(this.threadPool, vworld); this.importWrapper = new WorldImportWrapper(this.threadPool, vworld);
} else {
if (!this.activeWorlds.contains(vworld)) {
throw new IllegalStateException("World referenced does not exist in instance");
}
} }
return vworld; return vworld;
} }

View File

@@ -3,6 +3,8 @@ package me.cortex.voxy.client.config;
import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi; import com.terraformersmc.modmenu.api.ModMenuApi;
import me.cortex.voxy.client.core.IGetVoxyRenderSystem; import me.cortex.voxy.client.core.IGetVoxyRenderSystem;
import me.cortex.voxy.commonImpl.IVoxyWorldGetter;
import me.cortex.voxy.commonImpl.IVoxyWorldSetter;
import me.cortex.voxy.commonImpl.VoxyCommon; import me.cortex.voxy.commonImpl.VoxyCommon;
import me.shedaniel.clothconfig2.api.ConfigBuilder; import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory; import me.shedaniel.clothconfig2.api.ConfigCategory;
@@ -36,13 +38,24 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
builder.setSavingRunnable(() -> { builder.setSavingRunnable(() -> {
//After saving the core should be reloaded/reset //After saving the core should be reloaded/reset
var world = MinecraftClient.getInstance().worldRenderer; var worldRenderer = MinecraftClient.getInstance().worldRenderer;
if (world != null && ON_SAVE_RELOAD) { var world = MinecraftClient.getInstance().world;
if (worldRenderer != null && world != null && ON_SAVE_RELOAD) {
//Reload voxy //Reload voxy
((IGetVoxyRenderSystem)world).shutdownRenderer(); ((IGetVoxyRenderSystem)worldRenderer).shutdownRenderer();
//This is a hack inserted for the client world thing
//TODO: FIXME: MAKE BETTER
var engine = ((IVoxyWorldGetter)world).getWorldEngine();
if (engine != null) {
VoxyCommon.getInstance().stopWorld(engine);
}
((IVoxyWorldSetter)world).setWorldEngine(null);
VoxyCommon.shutdownInstance(); VoxyCommon.shutdownInstance();
VoxyCommon.createInstance(); VoxyCommon.createInstance();
((IGetVoxyRenderSystem)world).createRenderer(); ((IGetVoxyRenderSystem)worldRenderer).createRenderer();
} }
ON_SAVE_RELOAD = false; ON_SAVE_RELOAD = false;
VoxyConfig.CONFIG.save(); VoxyConfig.CONFIG.save();
@@ -71,6 +84,12 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
.setDefaultValue(DEFAULT.ingestEnabled) .setDefaultValue(DEFAULT.ingestEnabled)
.build()); .build());
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;})
.setDefaultValue(DEFAULT.enableRendering)
.build());
category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.subDivisionSize"), (int) config.subDivisionSize, 25, 256) category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.subDivisionSize"), (int) config.subDivisionSize, 25, 256)
.setTooltip(Text.translatable("voxy.config.general.subDivisionSize.tooltip")) .setTooltip(Text.translatable("voxy.config.general.subDivisionSize.tooltip"))
.setSaveConsumer(val -> config.subDivisionSize = val) .setSaveConsumer(val -> config.subDivisionSize = val)

View File

@@ -143,7 +143,7 @@ public class NodeManager {
long pos = sectionResult.position; long pos = sectionResult.position;
int nodeId = this.activeSectionMap.get(pos); int nodeId = this.activeSectionMap.get(pos);
if (nodeId == -1) { if (nodeId == -1) {
Logger.error("Got geometry update for pos " + WorldEngine.pprintPos(pos) + " but it was not in active map, discarding!"); Logger.warn("Got geometry update for pos " + WorldEngine.pprintPos(pos) + " but it was not in active map, discarding!");
sectionResult.free(); sectionResult.free();
return; return;
} }
@@ -988,7 +988,7 @@ public class NodeManager {
if (childExistence == 0) { if (childExistence == 0) {
if (!this.topLevelNodes.contains(pos)) {//Top level nodes are special, as they can have a request with child existence of 0 for performance reasons if (!this.topLevelNodes.contains(pos)) {//Top level nodes are special, as they can have a request with child existence of 0 for performance reasons
Logger.warn("Not creating a leaf request with existence mask of 0"); Logger.warn("Not creating a leaf request with existence mask of 0 at pos", WorldEngine.pprintPos(pos));
this.nodeData.unmarkRequestInFlight(nodeId); this.nodeData.unmarkRequestInFlight(nodeId);
this.invalidateNode(nodeId); this.invalidateNode(nodeId);
return; return;

View File

@@ -7,6 +7,7 @@ import me.cortex.voxy.client.core.rendering.VoxyRenderSystem;
import me.cortex.voxy.common.Logger; import me.cortex.voxy.common.Logger;
import me.cortex.voxy.common.world.WorldEngine; import me.cortex.voxy.common.world.WorldEngine;
import me.cortex.voxy.commonImpl.IVoxyWorldGetter; import me.cortex.voxy.commonImpl.IVoxyWorldGetter;
import me.cortex.voxy.commonImpl.IVoxyWorldSetter;
import me.cortex.voxy.commonImpl.VoxyCommon; import me.cortex.voxy.commonImpl.VoxyCommon;
import me.cortex.voxy.commonImpl.VoxyInstance; import me.cortex.voxy.commonImpl.VoxyInstance;
import net.minecraft.client.render.*; import net.minecraft.client.render.*;
@@ -50,7 +51,7 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
@Unique private ClientWorld refCopy; @Unique private ClientWorld refCopy;
@Inject(method = "setWorld", at = @At("HEAD")) @Inject(method = "setWorld", at = @At("HEAD"))
private void initVoxelCore(ClientWorld world, CallbackInfo ci) { private void voxy$captureSetWorld(ClientWorld world, CallbackInfo ci) {
this.refCopy = this.world; this.refCopy = this.world;
} }
@@ -65,6 +66,7 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
if (engine != null) { if (engine != null) {
VoxyCommon.getInstance().stopWorld(engine); VoxyCommon.getInstance().stopWorld(engine);
} }
((IVoxyWorldSetter)this.refCopy).setWorldEngine(null);
} }
} }

View File

@@ -1,5 +1,6 @@
package me.cortex.voxy.client.mixin.sodium; package me.cortex.voxy.client.mixin.sodium;
import me.cortex.voxy.client.VoxyClientInstance;
import me.cortex.voxy.client.config.VoxyConfig; import me.cortex.voxy.client.config.VoxyConfig;
import me.cortex.voxy.commonImpl.VoxyCommon; import me.cortex.voxy.commonImpl.VoxyCommon;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager; import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager;
@@ -20,7 +21,14 @@ public class MixinRenderSectionManager {
//TODO: Am not quite sure if this is right //TODO: Am not quite sure if this is right
var instance = VoxyCommon.getInstance(); var instance = VoxyCommon.getInstance();
if (instance != null && VoxyConfig.CONFIG.ingestEnabled) { if (instance != null && VoxyConfig.CONFIG.ingestEnabled) {
instance.getIngestService().enqueueIngest(this.level.getChunk(x, z), false); var chunk = this.level.getChunk(x, z);
var world = chunk.getWorld();
if (world instanceof ClientWorld cw) {
var engine = ((VoxyClientInstance)instance).getOrMakeRenderWorld(cw);
if (engine != null) {
instance.getIngestService().enqueueIngest(engine, chunk);
}
}
} }
} }
} }

View File

@@ -91,6 +91,9 @@ public class VoxelIngestService {
} }
public void enqueueIngest(WorldEngine engine, WorldChunk chunk) { public void enqueueIngest(WorldEngine engine, WorldChunk chunk) {
if (!engine.isLive()) {
throw new IllegalStateException("Tried inserting chunk into WorldEngine that was not alive");
}
var lightingProvider = chunk.getWorld().getLightingProvider(); var lightingProvider = chunk.getWorld().getLightingProvider();
var blp = lightingProvider.get(LightType.BLOCK); var blp = lightingProvider.get(LightType.BLOCK);
var slp = lightingProvider.get(LightType.SKY); var slp = lightingProvider.get(LightType.SKY);

View File

@@ -6,7 +6,10 @@ import me.cortex.voxy.commonImpl.IVoxyWorldGetter;
import me.cortex.voxy.commonImpl.IVoxyWorldSetter; import me.cortex.voxy.commonImpl.IVoxyWorldSetter;
import me.cortex.voxy.commonImpl.VoxyCommon; import me.cortex.voxy.commonImpl.VoxyCommon;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.block.NeighborUpdater;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@@ -14,6 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(World.class) @Mixin(World.class)
public class MixinWorld implements IVoxyWorldGetter, IVoxyWorldSetter { public class MixinWorld implements IVoxyWorldGetter, IVoxyWorldSetter {
@Shadow @Final protected NeighborUpdater neighborUpdater;
@Unique private WorldEngine voxyWorld; @Unique private WorldEngine voxyWorld;
@Override @Override
@@ -23,7 +27,7 @@ public class MixinWorld implements IVoxyWorldGetter, IVoxyWorldSetter {
@Override @Override
public void setWorldEngine(WorldEngine engine) { public void setWorldEngine(WorldEngine engine) {
if (this.voxyWorld != null) { if (engine != null && this.voxyWorld != null) {
throw new IllegalStateException("WorldEngine not null"); throw new IllegalStateException("WorldEngine not null");
} }
this.voxyWorld = engine; this.voxyWorld = engine;