From fd4d1d79104db3dc5e20f9bbdb8b529c9ff2aa74 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:53:46 +1000 Subject: [PATCH] More stuff --- .../me/cortex/voxy/client/VoxyClient.java | 3 +- .../voxy/client/core/WorldImportWrapper.java | 1 - .../rendering/hierachical/NodeManager.java | 12 ++++++-- .../sodium/MixinRenderSectionManager.java | 2 +- .../client/terrain/WorldImportCommand.java | 30 ++++++++++++------- .../voxelization/WorldConversionFactory.java | 1 + .../world/service/VoxelIngestService.java | 6 ++-- .../cortex/voxy/commonImpl/VoxyInstance.java | 25 ++++++++++++++++ .../mixin/chunky/MixinFabricWorld.java | 6 +++- .../mixin/minecraft/MixinWorld.java | 5 +++- 10 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/VoxyClient.java b/src/main/java/me/cortex/voxy/client/VoxyClient.java index 18f82d14..dd9cc13b 100644 --- a/src/main/java/me/cortex/voxy/client/VoxyClient.java +++ b/src/main/java/me/cortex/voxy/client/VoxyClient.java @@ -11,9 +11,8 @@ import net.minecraft.client.world.ClientWorld; public class VoxyClient implements ClientModInitializer { @Override public void onInitializeClient() { - /* ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { dispatcher.register(WorldImportCommand.register()); - });*/ + }); } } diff --git a/src/main/java/me/cortex/voxy/client/core/WorldImportWrapper.java b/src/main/java/me/cortex/voxy/client/core/WorldImportWrapper.java index bd876f6b..91e8fb82 100644 --- a/src/main/java/me/cortex/voxy/client/core/WorldImportWrapper.java +++ b/src/main/java/me/cortex/voxy/client/core/WorldImportWrapper.java @@ -17,7 +17,6 @@ import java.util.UUID; import java.util.function.Consumer; public class WorldImportWrapper { - private WorldImporter importer; private final ServiceThreadPool pool; private final WorldEngine world; diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java index 8d04282b..8ca63ee9 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java @@ -476,12 +476,18 @@ public class NodeManager { // childRequest // this is only valid if this node is an inner node - Logger.error("UNFINISHED OPERATION TODO: FIXME2"); + for (int i = 0; i < 8; i++) { + if ((childExistence&(1< register() { return ClientCommandManager.literal("voxy").requires((ctx)-> VoxyCommon.getInstance() != null) .then(ClientCommandManager.literal("import") @@ -42,14 +42,16 @@ public class WorldImportCommand { .executes(WorldImportCommand::importZip)))) .then(ClientCommandManager.literal("cancel") //.requires((ctx)->((IGetVoxelCore)MinecraftClient.getInstance().worldRenderer).getVoxelCore().importer.isImporterRunning()) - .executes((ctx)->{((IGetVoxelCore)MinecraftClient.getInstance().worldRenderer).getVoxelCore().importer.stopImporter(); return 0;})) + .executes(WorldImportCommand::cancelImport)) ); } private static boolean fileBasedImporter(File directory) { - var instance = MinecraftClient.getInstance(); - var core = ((IGetVoxelCore)instance.worldRenderer).getVoxelCore(); - return core.importer.createWorldImporter(instance.player.clientWorld, + var instance = VoxyCommon.getInstance(); + if (instance == null) { + return false; + } + return instance.importWrapper.createWorldImporter(MinecraftClient.getInstance().player.clientWorld, (importer, up, done)->importer.importRegionDirectoryAsyncStart(directory, up, done)); } @@ -131,13 +133,21 @@ public class WorldImportCommand { innerDir = ctx.getArgument("innerPath", String.class); } catch (Exception e) {} - var instance = MinecraftClient.getInstance(); - var core = ((IGetVoxelCore)instance.worldRenderer).getVoxelCore(); - if (core == null) { + var instance = VoxyCommon.getInstance(); + if (instance == null) { return 1; } String finalInnerDir = innerDir; - return core.importer.createWorldImporter(instance.player.clientWorld, + return instance.importWrapper.createWorldImporter(MinecraftClient.getInstance().player.clientWorld, (importer, up, done)->importer.importZippedRegionDirectoryAsyncStart(zip, finalInnerDir, up, done))?0:1; - }*/ + } + + private static int cancelImport(CommandContext fabricClientCommandSourceCommandContext) { + var instance = VoxyCommon.getInstance(); + if (instance == null) { + return 1; + } + instance.importWrapper.stopImporter(); + return 0; + } } \ No newline at end of file diff --git a/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java b/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java index 3019077c..834c8d0d 100644 --- a/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java +++ b/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java @@ -136,6 +136,7 @@ public class WorldConversionFactory { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { + //TODO: replace .get with a raw enumeration int bId = pc[bStor.get(i++)]; byte light = lightSupplier.supply(x,y,z); diff --git a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java index 537dfd2c..b7cd3a9f 100644 --- a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java +++ b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java @@ -79,10 +79,12 @@ public class VoxelIngestService { return true; } - public void enqueueIngest(WorldChunk chunk) { + public void enqueueIngest(WorldChunk chunk, boolean ignoreOnNullWorld) { var engine = ((IVoxyWorldGetter)chunk.getWorld()).getWorldEngine(); if (engine == null) { - Logger.error("Could not ingest chunk as does not have world engine"); + if (!ignoreOnNullWorld) { + Logger.error("Could not ingest chunk as does not have world engine"); + } return; } this.enqueueIngest(engine, chunk); diff --git a/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java b/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java index ea376c57..5594b38c 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java +++ b/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java @@ -1,7 +1,10 @@ package me.cortex.voxy.commonImpl; +import me.cortex.voxy.client.core.WorldImportWrapper; import me.cortex.voxy.client.saver.ContextSelectionSystem; import me.cortex.voxy.common.Logger; +import me.cortex.voxy.common.config.section.SectionStorage; +import me.cortex.voxy.common.config.storage.StorageBackend; import me.cortex.voxy.common.thread.ServiceThreadPool; import me.cortex.voxy.common.util.MemoryBuffer; import me.cortex.voxy.common.world.WorldEngine; @@ -9,12 +12,16 @@ import me.cortex.voxy.common.world.service.SectionSavingService; import me.cortex.voxy.common.world.service.VoxelIngestService; import net.minecraft.client.world.ClientWorld; +import java.util.HashSet; import java.util.List; +import java.util.Set; +//TODO: add thread access verification (I.E. only accessible on a single thread) public class VoxyInstance { private final ServiceThreadPool threadPool; private final SectionSavingService savingService; private final VoxelIngestService ingestService; + private final Set activeWorlds = new HashSet<>(); public VoxyInstance(int threadCount) { this.threadPool = new ServiceThreadPool(threadCount); @@ -60,6 +67,13 @@ public class VoxyInstance { } } + private WorldEngine createWorld(SectionStorage storage) { + var world = new WorldEngine(storage, 1024); + world.setSaveCallback(this.savingService::enqueueSave); + this.activeWorlds.add(world); + return world; + } + private static final ContextSelectionSystem SELECTOR = new ContextSelectionSystem(); public WorldEngine getOrMakeWorld(ClientWorld world) { @@ -68,8 +82,19 @@ public class VoxyInstance { vworld = new WorldEngine(SELECTOR.getBestSelectionOrCreate(world).createSectionStorageBackend(), 1024); vworld.setSaveCallback(this.savingService::enqueueSave); ((IVoxyWorldSetter)world).setWorldEngine(vworld); + this.importWrapper = new WorldImportWrapper(this.threadPool, vworld); } return vworld; } + + public WorldImportWrapper importWrapper; + + public void stopWorld(WorldEngine world) { + if (this.importWrapper != null) { + this.importWrapper.stopImporter(); + } + this.flush(); + world.shutdown(); + } } \ No newline at end of file diff --git a/src/main/java/me/cortex/voxy/commonImpl/mixin/chunky/MixinFabricWorld.java b/src/main/java/me/cortex/voxy/commonImpl/mixin/chunky/MixinFabricWorld.java index ea1ceb4b..83927cd8 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/mixin/chunky/MixinFabricWorld.java +++ b/src/main/java/me/cortex/voxy/commonImpl/mixin/chunky/MixinFabricWorld.java @@ -23,7 +23,11 @@ public class MixinFabricWorld { res.ifPresent(chunk -> { var voxyInstance = VoxyCommon.getInstance(); if (voxyInstance != null) { - voxyInstance.getIngestService().enqueueIngest((WorldChunk) chunk); + try { + voxyInstance.getIngestService().enqueueIngest((WorldChunk) chunk, true); + } catch (Exception e) { + + } } }); return res; diff --git a/src/main/java/me/cortex/voxy/commonImpl/mixin/minecraft/MixinWorld.java b/src/main/java/me/cortex/voxy/commonImpl/mixin/minecraft/MixinWorld.java index 45167a77..dceb8b74 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/mixin/minecraft/MixinWorld.java +++ b/src/main/java/me/cortex/voxy/commonImpl/mixin/minecraft/MixinWorld.java @@ -4,6 +4,7 @@ import me.cortex.voxy.common.Logger; import me.cortex.voxy.common.world.WorldEngine; import me.cortex.voxy.commonImpl.IVoxyWorldGetter; import me.cortex.voxy.commonImpl.IVoxyWorldSetter; +import me.cortex.voxy.commonImpl.VoxyCommon; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -18,7 +19,9 @@ public class MixinWorld implements IVoxyWorldGetter, IVoxyWorldSetter { @Inject(method = "close", at = @At("HEAD")) private void closeVoxyWorld(CallbackInfo ci) { if (this.voxyWorld != null) { - try {this.voxyWorld.shutdown();this.voxyWorld = null;} catch (Exception e) { + //TODO: FIXME: DONT DO THIS, this is a hack to ensure everything is saved + var instance = VoxyCommon.getInstance(); + try {instance.stopWorld(this.voxyWorld); this.voxyWorld = null;} catch (Exception e) { Logger.error("Failed to shutdown voxy world engine.", e); } }