From 2e9a2468886dd84d09134d7aebf1b792995d500a Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:08:15 +1000 Subject: [PATCH] Try catches --- build.gradle | 4 ++ .../me/cortex/voxy/client/core/VoxelCore.java | 3 + .../building/RenderGenerationService.java | 60 +++++++++------- .../world/service/SectionSavingService.java | 17 +++-- .../world/service/VoxelIngestService.java | 69 ++++++++++--------- src/main/resources/voxy.mixins.json | 8 +-- 6 files changed, 93 insertions(+), 68 deletions(-) diff --git a/build.gradle b/build.gradle index 8266250d..330c627c 100644 --- a/build.gradle +++ b/build.gradle @@ -79,6 +79,10 @@ dependencies { modCompileOnly("blusunrize.immersiveengineering:ImmersiveEngineering:1.20.4-10.0.1-pre.198") //modRuntimeOnly("blusunrize.immersiveengineering:ImmersiveEngineering:1.20.4-10.0.1-pre.198") + + modCompileOnly("maven.modrinth:chunky:1.3.138") + modRuntimeOnly("maven.modrinth:chunky:1.3.138") + } diff --git a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java index 021aa201..f6d5d2e9 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java @@ -204,9 +204,12 @@ public void addDebugInfo(List debug) { debug.add(""); debug.add(""); debug.add("Voxy Core: " + Voxy.VERSION); + /* debug.add("Ingest service tasks: " + this.world.ingestService.getTaskCount()); debug.add("Saving service tasks: " + this.world.savingService.getTaskCount()); debug.add("Render service tasks: " + this.renderGen.getTaskCount()); + */ + debug.add("I/S/R tasks: " + this.world.ingestService.getTaskCount() + "/"+this.world.savingService.getTaskCount()+"/"+this.renderGen.getTaskCount()); debug.add("Loaded cache sizes: " + Arrays.toString(this.world.getLoadedSectionCacheSizes())); debug.add("Mesh cache count: " + this.renderGen.getMeshCacheCount()); this.renderer.addDebugData(debug); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderGenerationService.java b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderGenerationService.java index 32bf760a..fc557d34 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderGenerationService.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderGenerationService.java @@ -5,6 +5,8 @@ import me.cortex.voxy.client.core.model.ModelManager; import me.cortex.voxy.common.world.WorldEngine; import me.cortex.voxy.common.world.WorldSection; +import net.minecraft.client.MinecraftClient; +import net.minecraft.text.Text; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Semaphore; @@ -49,36 +51,42 @@ private void renderWorker() { while (this.running) { this.taskCounter.acquireUninterruptibly(); if (!this.running) break; - BuildTask task; - synchronized (this.taskQueue) { - task = this.taskQueue.removeFirst(); - } - var section = task.sectionSupplier.get(); - if (section == null) { - continue; - } - section.assertNotFree(); - BuiltSection mesh = null; try { - mesh = factory.generateMesh(section); - } catch (IdNotYetComputedException e) { - try { - Thread.sleep(100); - } catch (InterruptedException ex) { - throw new RuntimeException(ex); - } - //We need to reinsert the build task into the queue - //System.err.println("Render task failed to complete due to un-computed client id"); + BuildTask task; synchronized (this.taskQueue) { - this.taskQueue.computeIfAbsent(section.key, key->{this.taskCounter.release(); return task;}); + task = this.taskQueue.removeFirst(); } - } - section.release(); - if (mesh != null) { - this.resultConsumer.accept(mesh.clone()); - if (!this.meshCache.putMesh(mesh)) { - mesh.free(); + var section = task.sectionSupplier.get(); + if (section == null) { + continue; + } + section.assertNotFree(); + BuiltSection mesh = null; + try { + mesh = factory.generateMesh(section); + } catch (IdNotYetComputedException e) { + try { + Thread.sleep(100); + } catch (InterruptedException ex) { + throw new RuntimeException(ex); + } + //We need to reinsert the build task into the queue + //System.err.println("Render task failed to complete due to un-computed client id"); + synchronized (this.taskQueue) { + this.taskQueue.computeIfAbsent(section.key, key->{this.taskCounter.release(); return task;}); + } + } + section.release(); + if (mesh != null) { + //TODO: if the mesh is null, need to clear the cache at that point + this.resultConsumer.accept(mesh.clone()); + if (!this.meshCache.putMesh(mesh)) { + mesh.free(); + } } + } catch (Exception e) { + System.err.println(e); + MinecraftClient.getInstance().executeSync(()->MinecraftClient.getInstance().player.sendMessage(Text.literal("Voxy render service had an exception while executing please check logs and report error"))); } } } diff --git a/src/main/java/me/cortex/voxy/common/world/service/SectionSavingService.java b/src/main/java/me/cortex/voxy/common/world/service/SectionSavingService.java index 0ba7847b..e40b5c87 100644 --- a/src/main/java/me/cortex/voxy/common/world/service/SectionSavingService.java +++ b/src/main/java/me/cortex/voxy/common/world/service/SectionSavingService.java @@ -4,6 +4,8 @@ import me.cortex.voxy.common.world.SaveLoadSystem; import me.cortex.voxy.common.world.WorldEngine; import me.cortex.voxy.common.world.WorldSection; +import net.minecraft.client.MinecraftClient; +import net.minecraft.text.Text; import org.lwjgl.system.MemoryUtil; import java.util.concurrent.ConcurrentLinkedDeque; @@ -40,12 +42,15 @@ private void saveWorker() { if (!this.running) break; var section = this.saveQueue.pop(); section.assertNotFree(); - section.inSaveQueue.set(false); - - var saveData = SaveLoadSystem.serialize(section); - this.world.storage.setSectionData(section.key, saveData); - MemoryUtil.memFree(saveData); - + try { + section.inSaveQueue.set(false); + var saveData = SaveLoadSystem.serialize(section); + this.world.storage.setSectionData(section.key, saveData); + MemoryUtil.memFree(saveData); + } catch (Exception e) { + System.err.println(e); + MinecraftClient.getInstance().executeSync(()->MinecraftClient.getInstance().player.sendMessage(Text.literal("Voxy saver had an exception while executing please check logs and report error"))); + } section.release(); } } 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 b903b061..8f8aa947 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 @@ -4,6 +4,8 @@ import me.cortex.voxy.common.voxelization.VoxelizedSection; import me.cortex.voxy.common.voxelization.WorldConversionFactory; import me.cortex.voxy.common.world.WorldEngine; +import net.minecraft.client.MinecraftClient; +import net.minecraft.text.Text; import net.minecraft.util.math.ChunkSectionPos; import net.minecraft.world.LightType; import net.minecraft.world.chunk.ChunkNibbleArray; @@ -42,39 +44,44 @@ private void ingestWorker() { while (this.running) { this.ingestCounter.acquireUninterruptibly(); if (!this.running) break; - var chunk = this.ingestQueue.pop(); - int i = chunk.getBottomSectionCoord() - 1; - for (var section : chunk.getSectionArray()) { - i++; - var lighting = this.captureLightMap.remove(ChunkSectionPos.from(chunk.getPos(), i).asLong()); - if (section.isEmpty()) { - this.world.insertUpdate(VoxelizedSection.createEmpty(chunk.getPos().x, i, chunk.getPos().z)); - } else { - VoxelizedSection csec = WorldConversionFactory.convert( - this.world.getMapper(), - section.getBlockStateContainer(), - section.getBiomeContainer(), - (x, y, z, state) -> { - if (lighting == null || ((lighting.first() != null && lighting.first().isUninitialized())&&(lighting.second()!=null&&lighting.second().isUninitialized()))) { - return (byte) 0x0f; - } else { - //Lighting is a piece of shit cause its done per face - int block = lighting.first()!=null?Math.min(15,lighting.first().get(x, y, z)):0; - int sky = lighting.second()!=null?Math.min(15,lighting.second().get(x, y, z)):0; - if (block { + if (lighting == null || ((lighting.first() != null && lighting.first().isUninitialized())&&(lighting.second()!=null&&lighting.second().isUninitialized()))) { + return (byte) 0x0f; + } else { + //Lighting is a piece of shit cause its done per face + int block = lighting.first()!=null?Math.min(15,lighting.first().get(x, y, z)):0; + int sky = lighting.second()!=null?Math.min(15,lighting.second().get(x, y, z)):0; + if (blockMinecraftClient.getInstance().player.sendMessage(Text.literal("Voxy ingester had an exception while executing please check logs and report error"))); } } } diff --git a/src/main/resources/voxy.mixins.json b/src/main/resources/voxy.mixins.json index da42f0b9..df537eb7 100644 --- a/src/main/resources/voxy.mixins.json +++ b/src/main/resources/voxy.mixins.json @@ -8,14 +8,12 @@ "minecraft.MixinDebugHud", "minecraft.MixinMinecraftClient", "minecraft.MixinWorldRenderer", - "sodium.MixinSodiumWorldRender", + "nvidium.MixinRenderPipeline", "sodium.MixinDefaultChunkRenderer", "sodium.MixinRenderSectionManager", - "nvidium.MixinRenderPipeline" + "sodium.MixinSodiumWorldRender" ], "injectors": { "defaultRequire": 1 - }, - "mixins": [ - ] + } }