From 00a123b150ea1db01155119892249c309523453d Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Mon, 2 Dec 2024 22:56:06 +1000 Subject: [PATCH] Tweeked mesher --- .../voxy/client/core/util/ScanMesher2D.java | 58 +++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/util/ScanMesher2D.java b/src/main/java/me/cortex/voxy/client/core/util/ScanMesher2D.java index d92d4baf..1f18fb2d 100644 --- a/src/main/java/me/cortex/voxy/client/core/util/ScanMesher2D.java +++ b/src/main/java/me/cortex/voxy/client/core/util/ScanMesher2D.java @@ -9,9 +9,9 @@ public abstract class ScanMesher2D { private final int[] rowDepth = new int[32];//How many rows does it cover private int rowBitset = 0; - int currentIndex = 0; - int currentSum = 0; - long currentData = 0; + private int currentIndex = 0; + private int currentSum = 0; + private long currentData = 0; //Two different ways to do it, scanline then only merge on change, or try to merge with previous row at every step // or even can also attempt to merge previous but if the lengths are different split the current one and merge to previous @@ -24,7 +24,7 @@ public abstract class ScanMesher2D { //If the previous data is not zero, that means it was not merge-able, so emit it at the pos if (this.currentData!=0) { if ((this.rowBitset&(1<<31))!=0) { - emitQuad(this.rowLength[31], this.rowDepth[31], this.rowData[31]); + emitQuad(31, (this.currentIndex-1)>>5, this.rowLength[31], this.rowDepth[31], this.rowData[31]); } this.rowBitset |= 1<<31; this.rowLength[31] = this.currentSum; @@ -67,7 +67,7 @@ public abstract class ScanMesher2D { this.currentSum = 0;//Clear sum since we went down this.currentData = 0;//Zero is sentinel value for absent } else if (isSet) { - this.emitQuad(this.rowLength[idx], this.rowDepth[idx], this.rowData[idx]); + this.emitQuad(idx&31, (this.currentIndex-1)>>5, this.rowLength[idx], this.rowDepth[idx], this.rowData[idx]); this.rowBitset &= ~(1<>5, this.rowLength[index], this.rowDepth[index], this.rowData[index]); } this.rowBitset &= ~msk; } } - public final void endPush() { - putNext(0); - this.currentIndex--;//HACK - this.emitRanged(-1); + //Note it is illegal for count to cause `this.currentIndex&31` to wrap and continue + public final void skip(int count) { + if (count == 0) return; + //TODO: replace with much better method + this.putNext(0); + this.emitRanged(((1<<(count-1))-1)<>5, val); } } - mesher.endPush(); + mesher.finish(); if (c != qc[1]) { System.out.println(c+", " + qc[1]); } @@ -228,7 +252,7 @@ public abstract class ScanMesher2D { sample[31+32*8] = 8; var mesher = new ScanMesher2D() { @Override - protected void emitQuad(int length, int width, long data) { + protected void emitQuad(int x, int z, int length, int width, long data) { System.out.println(length + ", " + width + ", " + data); } };