From b0f316f00268fec133cf147b87e6ffa45c9930b9 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Tue, 30 Jan 2024 14:37:06 +1000 Subject: [PATCH] E --- .../core/model/ColourDepthTextureData.java | 5 +++++ .../client/core/model/ModelManager.java | 22 +++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/cortex/zenith/client/core/model/ColourDepthTextureData.java b/src/main/java/me/cortex/zenith/client/core/model/ColourDepthTextureData.java index c9c3d689..5b07d55c 100644 --- a/src/main/java/me/cortex/zenith/client/core/model/ColourDepthTextureData.java +++ b/src/main/java/me/cortex/zenith/client/core/model/ColourDepthTextureData.java @@ -14,4 +14,9 @@ public record ColourDepthTextureData(int[] colour, int[] depth, int width, int h public int hashCode() { return (this.width * 312337173 * (Arrays.hashCode(this.colour) ^ Arrays.hashCode(this.depth))) ^ this.height; } + + @Override + public ColourDepthTextureData clone() { + return new ColourDepthTextureData(Arrays.copyOf(this.colour, this.colour.length), Arrays.copyOf(this.depth, this.depth.length), this.width, this.height); + } } diff --git a/src/main/java/me/cortex/zenith/client/core/model/ModelManager.java b/src/main/java/me/cortex/zenith/client/core/model/ModelManager.java index 913aa1b9..a783ea7f 100644 --- a/src/main/java/me/cortex/zenith/client/core/model/ModelManager.java +++ b/src/main/java/me/cortex/zenith/client/core/model/ModelManager.java @@ -30,6 +30,7 @@ import org.lwjgl.system.MemoryUtil; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11C.GL_NEAREST; @@ -97,7 +98,7 @@ public class ModelManager { //TODO: figure out how to do mipping :blobfox_pineapple: this.textures = new GlTexture().store(GL_RGBA8, 1, modelTextureSize*3*256,modelTextureSize*2*256); this.metadataCache = new long[1<<16]; - this.idMappings = new int[1<<16]; + this.idMappings = new int[1<<20];//Max of 1 million blockstates mapping to 65k model states Arrays.fill(this.idMappings, -1); @@ -133,10 +134,9 @@ public class ModelManager { } else {//Not a duplicate so create a new entry modelId = this.modelTexture2id.size(); this.idMappings[blockId] = modelId; - this.modelTexture2id.put(List.of(textureData), modelId); + this.modelTexture2id.put(Stream.of(textureData).map(ColourDepthTextureData::clone).toList(), modelId); } } - this.putTextures(modelId, textureData); var colourProvider = MinecraftClient.getInstance().getBlockColors().providers.get(Registries.BLOCK.getRawId(blockState.getBlock())); @@ -261,14 +261,22 @@ public class ModelManager { //modelFlags |= blockRenderLayer == RenderLayer.getSolid()?0:1;// should discard alpha MemoryUtil.memPutInt(uploadPtr, modelFlags); //Temporary override to always be non biome specific - if (colourProvider != null && ((!hasBiomeColourResolver) || true)) { + if (colourProvider == null) { + MemoryUtil.memPutInt(uploadPtr + 4, -1);//Set the default to nothing so that its faster on the gpu + } else if ((!hasBiomeColourResolver) || true) { Biome defaultBiome = MinecraftClient.getInstance().world.getRegistryManager().get(RegistryKeys.BIOME).get(BiomeKeys.PLAINS); MemoryUtil.memPutInt(uploadPtr + 4, captureColourConstant(colourProvider, blockState, defaultBiome)|0xFF000000); } else { - MemoryUtil.memPutInt(uploadPtr + 4, -1);//Set the default to nothing so that its faster on the gpu + //Populate the list of biomes for the model state } + //Note: if the layer isSolid then need to fill all the points in the texture where alpha == 0 with the average colour + // of the surrounding blocks but only within the computed face size bounds + //TODO + + + this.putTextures(modelId, textureData); return modelId; } @@ -445,7 +453,7 @@ public class ModelManager { while ((map = this.idMappings[blockId]) == -1) { Thread.onSpinWait(); try { - Thread.sleep(100); + Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } @@ -459,7 +467,7 @@ public class ModelManager { while ((meta = this.metadataCache[map]) == 0) { Thread.onSpinWait(); try { - Thread.sleep(100); + Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); }