From 3618c136f74d8a50e7b91aec3f6aacd7da76b51e Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:27:18 +1000 Subject: [PATCH] New mesher --- .../voxy/client/core/util/ScanMesher2D.java | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 src/main/java/me/cortex/voxy/client/core/util/ScanMesher2D.java 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 new file mode 100644 index 00000000..44a56a10 --- /dev/null +++ b/src/main/java/me/cortex/voxy/client/core/util/ScanMesher2D.java @@ -0,0 +1,145 @@ +package me.cortex.voxy.client.core.util; + +public class ScanMesher2D { + // is much faster if implemented inline into parent + private long[] rowData = new long[32]; + private int[] rowLength = new int[32];//How long down does a row entry go + private int[] rowDepth = new int[32];//How many rows does it cover + private int rowBitset = 0; + + int currentIndex = 0; + int currentSum = 0; + 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 + public void putNext(long data) { + int thisIdx = (this.currentIndex++)&31;//Mask to current row, but keep total so can compute actual indexing + + //If we are on the zero index, ignore it as we are going from empty state to maybe something state + // setup data + if (thisIdx == 0) { + //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]); + } + this.rowBitset |= 1<<31; + this.rowLength[31] = this.currentSum; + this.rowDepth[31] = 1; + this.rowData[31] = this.currentData; + } + + //Set the data to the first element + this.currentData = data; + this.currentSum = 0; + } + + //If we are the same as last data increment + if (data == this.currentData) { + this.currentSum++; + //If we merge, then just continue + this.mergeCurrentIfPossibleOrEmit(thisIdx); + return; + } + + //write out previous data + if (this.currentData != 0) { + int prev = thisIdx-1;//We need to write in the previous entry + this.rowDepth[prev] = 1; + this.rowLength[prev] = this.currentSum; + this.rowData[prev] = this.currentData; + this.rowBitset |= 1<