From 7c4a3fe7b48d4501e6fbf8d82fbde6e0e0ca1dff Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Fri, 2 May 2025 23:08:28 +1000 Subject: [PATCH] more jank --- .../core/rendering/ChunkBoundRenderer.java | 104 +++++++++--------- 1 file changed, 55 insertions(+), 49 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/ChunkBoundRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/ChunkBoundRenderer.java index 1c77e98a..44b18bb9 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/ChunkBoundRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/ChunkBoundRenderer.java @@ -2,6 +2,7 @@ package me.cortex.voxy.client.core.rendering; import it.unimi.dsi.fastutil.longs.Long2ByteOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.client.core.gl.GlFramebuffer; import me.cortex.voxy.client.core.gl.GlTexture; @@ -45,23 +46,31 @@ public class ChunkBoundRenderer { private GlTexture depthBuffer = new GlTexture().store(GL_DEPTH_COMPONENT24, 1, 128, 128); private final GlFramebuffer frameBuffer = new GlFramebuffer().bind(GL_DEPTH_ATTACHMENT, this.depthBuffer).verify(); - private final Long2ByteOpenHashMap updates = new Long2ByteOpenHashMap(); + private final LongOpenHashSet addQueue = new LongOpenHashSet(); + private final LongOpenHashSet remQueue = new LongOpenHashSet(); public ChunkBoundRenderer() { this.chunk2idx.defaultReturnValue(-1); } public void addSection(long pos) { - this.updates.addTo(pos, (byte) 1); + this.addQueue.add(pos); + this.remQueue.remove(pos); } public void removeSection(long pos) { - this.updates.addTo(pos, (byte) -1); + this.remQueue.add(pos); + this.addQueue.remove(pos); } //Bind and render, changing as little gl state as possible so that the caller may configure how it wants to render public void render(Viewport viewport) { - if (this.chunk2idx.isEmpty() && this.updates.isEmpty()) return; + if (!this.remQueue.isEmpty()) { + this.remQueue.forEach(this::_remPos); + this.remQueue.clear(); + } + + if (this.chunk2idx.isEmpty() && this.addQueue.isEmpty()) return; if (this.depthBuffer.getWidth() != viewport.width || this.depthBuffer.getHeight() != viewport.height) { this.depthBuffer.free(); @@ -121,54 +130,51 @@ public class ChunkBoundRenderer { glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); } - this.processUpdates(); + + + if (!this.addQueue.isEmpty()) { + this.addQueue.forEach(this::_addPos); + this.addQueue.clear(); + } } - private void processUpdates() { - if (this.updates.isEmpty()) return; - var iter = this.updates.long2ByteEntrySet().fastIterator(); - while (iter.hasNext()) { - var entry = iter.next(); - if (entry.getByteValue()==0) continue; - long pos = entry.getLongKey(); - if (0