From 4863f607b8e6eb3a057ec9bbdc8804444d04fd05 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Sun, 26 Oct 2025 12:59:04 +1000 Subject: [PATCH] even more prep, is close --- .../core/model/ModelBakerySubsystem.java | 42 ++----------------- .../voxy/client/core/model/ModelFactory.java | 40 +++++++++++++----- 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java b/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java index dc2997a7..7178646c 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java @@ -27,7 +27,6 @@ public class ModelBakerySubsystem { private final Mapper mapper; private final AtomicInteger blockIdCount = new AtomicInteger(); private final ConcurrentLinkedDeque blockIdQueue = new ConcurrentLinkedDeque<>();//TODO: replace with custom DS - private final ConcurrentLinkedDeque biomeQueue = new ConcurrentLinkedDeque<>(); public ModelBakerySubsystem(Mapper mapper) { this.mapper = mapper; @@ -35,36 +34,6 @@ public class ModelBakerySubsystem { } public void tick(long totalBudget) { - //Upload all biomes - while (!this.biomeQueue.isEmpty()) { - var biome = this.biomeQueue.poll(); - var biomeReg = MinecraftClient.getInstance().world.getRegistryManager().getOrThrow(RegistryKeys.BIOME); - this.factory.addBiome(biome.id, biomeReg.get(Identifier.of(biome.biome))); - } - - - /* - //There should be a method to access the frame time IIRC, if the user framecap is unlimited lock it to like 60 fps for computation - int BUDGET = 16;//TODO: make this computed based on the remaining free time in a frame (and like div by 2 to reduce overhead) (with a min of 1) - if (!this.blockIdQueue.isEmpty()) { - int[] est = new int[Math.min(this.blockIdQueue.size(), BUDGET)]; - int i = 0; - synchronized (this.blockIdQueue) { - for (;i < est.length && !this.blockIdQueue.isEmpty(); i++) { - int blockId = this.blockIdQueue.removeFirstInt(); - if (blockId == -1) { - i--; - continue; - } - est[i] = blockId; - } - } - - for (int j = 0; j < i; j++) { - this.factory.addEntry(est[j]); - } - }*/ - //TimingStatistics.modelProcess.start(); if (this.blockIdCount.get() != 0) { //Always do 1 iteration minimum Integer i = this.blockIdQueue.poll(); @@ -87,11 +56,8 @@ public class ModelBakerySubsystem { this.factory.tick(); - long start = System.nanoTime(); - while (this.factory.processResult()) { - if (totalBudget<(System.nanoTime()-start)) - break; - } + this.factory.processAllThings(); + this.factory.processUploads(); //TimingStatistics.modelProcess.stop(); } @@ -120,7 +86,7 @@ public class ModelBakerySubsystem { } public void addBiome(Mapper.BiomeEntry biomeEntry) { - this.biomeQueue.add(biomeEntry); + this.factory.addBiome(biomeEntry); } public void addDebugData(List debug) { @@ -132,7 +98,7 @@ public class ModelBakerySubsystem { } public boolean areQueuesEmpty() { - return this.blockIdCount.get()==0 && this.factory.getInflightCount() == 0 && this.biomeQueue.isEmpty(); + return this.blockIdCount.get()==0 && this.factory.getInflightCount() == 0; } public int getProcessingCount() { diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelFactory.java b/src/main/java/me/cortex/voxy/client/core/model/ModelFactory.java index 764261b0..4b7f5859 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelFactory.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelFactory.java @@ -26,6 +26,7 @@ import net.minecraft.client.render.RenderLayers; import net.minecraft.fluid.FluidState; import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -40,6 +41,7 @@ import org.lwjgl.system.MemoryUtil; import java.lang.invoke.VarHandle; import java.util.*; +import java.util.concurrent.ConcurrentLinkedDeque; import static me.cortex.voxy.client.core.model.ModelStore.MODEL_SIZE; import static org.lwjgl.opengl.ARBDirectStateAccess.nglTextureSubImage2D; @@ -208,10 +210,9 @@ public class ModelFactory { return true; } - public boolean processResult() { - if (this.rawBakeResults.isEmpty()) - return false; + private boolean processModelResult() { var result = this.rawBakeResults.poll(); + if (result == null) return false; ColourDepthTextureData[] textureData = new ColourDepthTextureData[6]; {//Create texture data long ptr = result.rawData.address; @@ -238,6 +239,25 @@ public class ModelFactory { return !this.rawBakeResults.isEmpty(); } + private final ConcurrentLinkedDeque biomeQueue = new ConcurrentLinkedDeque<>(); + public void addBiome(Mapper.BiomeEntry biome) { + this.biomeQueue.add(biome); + } + + public void processAllThings() { + var biomeEntry = this.biomeQueue.poll(); + while (biomeEntry != null) { + var biomeRegistry = MinecraftClient.getInstance().world.getRegistryManager().getOrThrow(RegistryKeys.BIOME); + var res = this.addBiome0(biomeEntry.id, biomeRegistry.get(Identifier.of(biomeEntry.biome))); + if (res != null) { + this.uploadResults.add(res); + } + biomeEntry = this.biomeQueue.poll(); + } + + while (this.processModelResult()); + } + public void processUploads() { if (this.uploadResults.isEmpty()) return; @@ -635,13 +655,6 @@ public class ModelFactory { } } - public void addBiome(int id, Biome biome) { - var res = this.addBiome0(id, biome); - if (res != null) { - this.uploadResults.add(res); - } - } - private BiomeUploadResult addBiome0(int id, Biome biome) { for (int i = this.biomes.size(); i <= id; i++) { this.biomes.add(null); @@ -903,6 +916,11 @@ public class ModelFactory { } public int getInflightCount() { - return this.blockStatesInFlight.size(); + //TODO replace all of this with an atomic? + int size = this.blockStatesInFlight.size(); + size += this.uploadResults.size(); + size += this.rawBakeResults.size(); + size += this.biomeQueue.size(); + return size; } }