From 41585731298994b9149c2878c22e4c7e6337e060 Mon Sep 17 00:00:00 2001 From: TomTheFurry Date: Mon, 19 Sep 2022 12:28:39 +0800 Subject: [PATCH] Add render source flag debug mode & fix sparse source to render source transform bug --- .../lod/api/enums/rendering/EDebugMode.java | 18 +++++++++-- .../datatype/column/ColumnRenderSource.java | 30 +++++++++++++++++++ .../column/render/ColumnRenderBuffer.java | 3 +- .../column/render/CubicLodTemplate.java | 11 ++++++- .../datatype/full/IdBiomeBlockStateMap.java | 14 ++++----- .../core/datatype/full/SparseDataSource.java | 7 ++--- .../transform/FullToColumnTransformer.java | 4 +++ .../seibel/lod/core/render/LodQuadTree.java | 2 +- .../lod/core/render/renderer/LodRenderer.java | 3 +- .../com/seibel/lod/core/util/ColorUtil.java | 13 +++++++- 10 files changed, 85 insertions(+), 20 deletions(-) diff --git a/api/src/main/java/com/seibel/lod/api/enums/rendering/EDebugMode.java b/api/src/main/java/com/seibel/lod/api/enums/rendering/EDebugMode.java index 2ac01c6a2..ac30a42c9 100644 --- a/api/src/main/java/com/seibel/lod/api/enums/rendering/EDebugMode.java +++ b/api/src/main/java/com/seibel/lod/api/enums/rendering/EDebugMode.java @@ -28,6 +28,8 @@ package com.seibel.lod.api.enums.rendering; * SHOW_GENMODE_WIREFRAME,
* SHOW_OVERLAPPING_QUADS,
* SHOW_OVERLAPPING_QUADS_WIREFRAME,
+ * SHOW_RENDER_SOURCE_FLAG,
+ * SHOW_RENDER_SOURCE_FLAG_WIREFRAME,
* * @author Leetom * @author James Seibel @@ -62,8 +64,14 @@ public enum EDebugMode SHOW_OVERLAPPING_QUADS, /** Only draw overlapping LOD quads, and draws in wireframe. */ - SHOW_OVERLAPPING_QUADS_WIREFRAME; - + SHOW_OVERLAPPING_QUADS_WIREFRAME, + + /** LOD colors are based on renderSource flags. */ + SHOW_RENDER_SOURCE_FLAG, + + /** LOD colors are based on renderSource flags, and draws in wireframe. */ + SHOW_RENDER_SOURCE_FLAG_WIREFRAME; + /** returns the next debug mode */ // Deprecated: use DebugMode.next() instead @Deprecated @@ -81,13 +89,17 @@ public enum EDebugMode case SHOW_GENMODE: return SHOW_GENMODE_WIREFRAME; case SHOW_GENMODE_WIREFRAME: return SHOW_OVERLAPPING_QUADS; case SHOW_OVERLAPPING_QUADS: return SHOW_OVERLAPPING_QUADS_WIREFRAME; + case SHOW_OVERLAPPING_QUADS_WIREFRAME: return SHOW_RENDER_SOURCE_FLAG; + case SHOW_RENDER_SOURCE_FLAG: return SHOW_RENDER_SOURCE_FLAG_WIREFRAME; default: return OFF; } } public static EDebugMode previous(EDebugMode type) { switch (type) { - case OFF: return SHOW_OVERLAPPING_QUADS_WIREFRAME; + case OFF: return SHOW_RENDER_SOURCE_FLAG_WIREFRAME; + case SHOW_RENDER_SOURCE_FLAG_WIREFRAME: return SHOW_RENDER_SOURCE_FLAG; + case SHOW_RENDER_SOURCE_FLAG: return SHOW_OVERLAPPING_QUADS_WIREFRAME; case SHOW_OVERLAPPING_QUADS_WIREFRAME: return SHOW_OVERLAPPING_QUADS; case SHOW_OVERLAPPING_QUADS: return SHOW_GENMODE_WIREFRAME; case SHOW_GENMODE_WIREFRAME: return SHOW_GENMODE; diff --git a/core/src/main/java/com/seibel/lod/core/datatype/column/ColumnRenderSource.java b/core/src/main/java/com/seibel/lod/core/datatype/column/ColumnRenderSource.java index 63b62fd5a..9c27831b7 100644 --- a/core/src/main/java/com/seibel/lod/core/datatype/column/ColumnRenderSource.java +++ b/core/src/main/java/com/seibel/lod/core/datatype/column/ColumnRenderSource.java @@ -15,6 +15,7 @@ import com.seibel.lod.core.level.ILevel; import com.seibel.lod.core.render.LodQuadTree; import com.seibel.lod.core.render.LodRenderSection; import com.seibel.lod.core.datatype.LodRenderSource; +import com.seibel.lod.core.util.ColorUtil; import com.seibel.lod.core.util.objects.Reference; import com.seibel.lod.core.util.LodUtil; import org.apache.logging.log4j.Logger; @@ -45,6 +46,31 @@ public class ColumnRenderSource implements LodRenderSource, IColumnDatatype { public final long[] dataContainer; public final int[] airDataContainer; + public enum DebugSourceFlag { + FULL(ColorUtil.BLUE), + DIRECT(ColorUtil.WHITE), + SPARSE(ColorUtil.YELLOW), + FILE(ColorUtil.BROWN); + public final int color; + DebugSourceFlag(int color) { + this.color = color; + } + } + + public final DebugSourceFlag[] debugSourceFlags; + + public void debugFillFlag(int ox, int oz, int w, int h, DebugSourceFlag flag) { + for (int x = ox; x < ox + w; x++) { + for (int z = oz; z < oz + h; z++) { + debugSourceFlags[x * SECTION_SIZE + z] = flag; + } + } + } + + public DebugSourceFlag debugGetFlag(int ox, int oz) { + return debugSourceFlags[ox * SECTION_SIZE + oz]; + } + private boolean isEmpty = true; /** @@ -55,6 +81,7 @@ public class ColumnRenderSource implements LodRenderSource, IColumnDatatype { verticalSize = maxVerticalSize; dataContainer = new long[SECTION_SIZE * SECTION_SIZE * verticalSize]; airDataContainer = new int[AIR_SECTION_SIZE * AIR_SECTION_SIZE * verticalSize]; + debugSourceFlags = new DebugSourceFlag[SECTION_SIZE * SECTION_SIZE]; this.sectionPos = sectionPos; this.yOffset = yOffset; } @@ -98,6 +125,8 @@ public class ColumnRenderSource implements LodRenderSource, IColumnDatatype { verticalSize = inputData.readByte() & 0b01111111; dataContainer = loadData(inputData, version, verticalSize); airDataContainer = new int[AIR_SECTION_SIZE * AIR_SECTION_SIZE * verticalSize]; + debugSourceFlags = new DebugSourceFlag[SECTION_SIZE * SECTION_SIZE]; + debugFillFlag(0, 0, SECTION_SIZE, SECTION_SIZE, DebugSourceFlag.FILE); } @Override @@ -381,6 +410,7 @@ public class ColumnRenderSource implements LodRenderSource, IColumnDatatype { if (genMode <= srcGenMode) { new ColumnArrayView(dataContainer, verticalSize, i, verticalSize).copyFrom( new ColumnArrayView(src.dataContainer, verticalSize, i, verticalSize)); + debugSourceFlags[i/verticalSize] = src.debugSourceFlags[i/verticalSize]; } } } diff --git a/core/src/main/java/com/seibel/lod/core/datatype/column/render/ColumnRenderBuffer.java b/core/src/main/java/com/seibel/lod/core/datatype/column/render/ColumnRenderBuffer.java index a7813d2f0..29a44ea3e 100644 --- a/core/src/main/java/com/seibel/lod/core/datatype/column/render/ColumnRenderBuffer.java +++ b/core/src/main/java/com/seibel/lod/core/datatype/column/render/ColumnRenderBuffer.java @@ -302,6 +302,7 @@ public class ColumnRenderBuffer extends RenderBuffer { if (posData.size() == 0 || !ColumnFormat.doesItExist(posData.get(0)) || ColumnFormat.isVoid(posData.get(0))) continue; + ColumnRenderSource.DebugSourceFlag debugSourceFlag = region.debugGetFlag(x, z); ColumnArrayView[][] adjData = new ColumnArrayView[4][]; // We extract the adj data in the four cardinal direction @@ -381,7 +382,7 @@ public class ColumnRenderBuffer extends RenderBuffer { long adjDataBot = i + 1 < posData.size() ? posData.get(i + 1) : ColumnFormat.EMPTY_DATA; CubicLodTemplate.addLodToBuffer(data, adjDataTop, adjDataBot, adjData, detailLevel, - x, z, quadBuilder, debugMode); + x, z, quadBuilder, debugMode, debugSourceFlag); } } } diff --git a/core/src/main/java/com/seibel/lod/core/datatype/column/render/CubicLodTemplate.java b/core/src/main/java/com/seibel/lod/core/datatype/column/render/CubicLodTemplate.java index b1246799c..307170139 100644 --- a/core/src/main/java/com/seibel/lod/core/datatype/column/render/CubicLodTemplate.java +++ b/core/src/main/java/com/seibel/lod/core/datatype/column/render/CubicLodTemplate.java @@ -19,6 +19,7 @@ package com.seibel.lod.core.datatype.column.render; +import com.seibel.lod.core.datatype.column.ColumnRenderSource; import com.seibel.lod.core.datatype.column.accessor.ColumnFormat; import com.seibel.lod.api.enums.rendering.EDebugMode; import com.seibel.lod.core.dependencyInjection.SingletonInjector; @@ -38,7 +39,8 @@ public class CubicLodTemplate private static final ILodConfigWrapperSingleton CONFIG = SingletonInjector.INSTANCE.get(ILodConfigWrapperSingleton.class); - public static void addLodToBuffer(long data, long topData, long botData, ColumnArrayView[][] adjData, byte detailLevel, int offsetPosX, int offsetOosZ, LodQuadBuilder quadBuilder, EDebugMode debugging) + public static void addLodToBuffer(long data, long topData, long botData, ColumnArrayView[][] adjData, + byte detailLevel, int offsetPosX, int offsetOosZ, LodQuadBuilder quadBuilder, EDebugMode debugging, ColumnRenderSource.DebugSourceFlag debugSource) { short width = (short) (1 << detailLevel); short x = (short) LevelPosUtil.convert(detailLevel, offsetPosX, LodUtil.BLOCK_DETAIL_LEVEL); @@ -92,6 +94,13 @@ public class CubicLodTemplate fullBright = true; break; } + case SHOW_RENDER_SOURCE_FLAG: + case SHOW_RENDER_SOURCE_FLAG_WIREFRAME: + { + color = debugSource == null ? ColorUtil.RED : debugSource.color; + fullBright = true; + break; + } default: throw new IllegalArgumentException("Unknown debug mode: " + debugging); } diff --git a/core/src/main/java/com/seibel/lod/core/datatype/full/IdBiomeBlockStateMap.java b/core/src/main/java/com/seibel/lod/core/datatype/full/IdBiomeBlockStateMap.java index 03302a5f0..0179cb3cf 100644 --- a/core/src/main/java/com/seibel/lod/core/datatype/full/IdBiomeBlockStateMap.java +++ b/core/src/main/java/com/seibel/lod/core/datatype/full/IdBiomeBlockStateMap.java @@ -98,12 +98,12 @@ public class IdBiomeBlockStateMap { @Override public boolean equals(Object other) { if (other == this) return true; - if (!(other instanceof IdBiomeBlockStateMap)) return false; - IdBiomeBlockStateMap otherMap = (IdBiomeBlockStateMap) other; - if (entries.size() != otherMap.entries.size()) return false; - for (int i=0; i chunks*chunks/8+64) + if (length < 0 || length > (chunks*chunks/8+64)*2) throw new IOException(LodUtil.formatLog("Sparse Flag BitSet size outside reasonable range: {} (expects {} to {})", length, 1, chunks*chunks/8+63)); byte[] bytes = dos.readNBytes(length); BitSet set = BitSet.valueOf(bytes); - if (set.size() < chunks*chunks) - throw new IOException((LodUtil.formatLog("Sparse Flag BitSet too small: {} != {}*{}", - set.size(), chunks, chunks))); long[][][] dataChunks = new long[chunks*chunks][][]; @@ -332,6 +329,6 @@ public class SparseDataSource implements LodDataSource { int chunkZ = z / dataPerChunk; FullArrayView chunk = sparseData[chunkX * chunks + chunkZ]; if (chunk == null) return null; - return chunk.get(chunkX % dataPerChunk, chunkZ % dataPerChunk); + return chunk.get(x % dataPerChunk, z % dataPerChunk); } } diff --git a/core/src/main/java/com/seibel/lod/core/datatype/transform/FullToColumnTransformer.java b/core/src/main/java/com/seibel/lod/core/datatype/transform/FullToColumnTransformer.java index 289fc82e3..eb3d2478b 100644 --- a/core/src/main/java/com/seibel/lod/core/datatype/transform/FullToColumnTransformer.java +++ b/core/src/main/java/com/seibel/lod/core/datatype/transform/FullToColumnTransformer.java @@ -45,6 +45,7 @@ public class FullToColumnTransformer { if (fullArrayView.doesItExist()) LodUtil.assertTrue(columnSource.doesItExist(x, z)); } } + columnSource.debugFillFlag(0, 0, ColumnRenderSource.SECTION_SIZE, ColumnRenderSource.SECTION_SIZE, ColumnRenderSource.DebugSourceFlag.FULL); // } else if (dataDetail == 0 && columnSource.getDataDetail() > dataDetail) { // byte deltaDetail = (byte) (columnSource.getDataDetail() - dataDetail); // int perColumnWidth = 1 << deltaDetail; @@ -82,6 +83,7 @@ public class FullToColumnTransformer { if (fullArrayView == null) continue; ColumnArrayView columnArrayView = columnSource.getVerticalDataView(x, z); convertColumnData(level, baseX + x, baseZ + z, columnArrayView, fullArrayView, 1); + columnSource.debugFillFlag(x, z, 1, 1, ColumnRenderSource.DebugSourceFlag.SPARSE); if (fullArrayView.doesItExist()) LodUtil.assertTrue(columnSource.doesItExist(x, z)); } } @@ -117,6 +119,7 @@ public class FullToColumnTransformer { if (fullArrayView.doesItExist()) LodUtil.assertTrue(render.doesItExist(renderOffsetX + x, renderOffsetZ + z)); } } + render.debugFillFlag(renderOffsetX, renderOffsetZ, 16, 16, ColumnRenderSource.DebugSourceFlag.DIRECT); } else { final int dataPerRender = 1 << (render.getDataDetail() - data.dataDetail); final int dataSize = 16 / dataPerRender; @@ -141,6 +144,7 @@ public class FullToColumnTransformer { downSampledArrayView.mergeMultiDataFrom(tempQuadView); } } + render.debugFillFlag(renderOffsetX, renderOffsetZ, dataSize, dataSize, ColumnRenderSource.DebugSourceFlag.DIRECT); } } diff --git a/core/src/main/java/com/seibel/lod/core/render/LodQuadTree.java b/core/src/main/java/com/seibel/lod/core/render/LodQuadTree.java index ba74c246b..ce4076ac8 100644 --- a/core/src/main/java/com/seibel/lod/core/render/LodQuadTree.java +++ b/core/src/main/java/com/seibel/lod/core/render/LodQuadTree.java @@ -78,7 +78,7 @@ public class LodQuadTree implements AutoCloseable { for (byte i = LAYER_BEGINNING_OFFSET; i < numbersOfSectionLevels; i++) { byte targetDataDetail = getLayerDataDetail(i); int maxDist = getFurthestDistance(targetDataDetail); - int halfSize = MathUtil.ceilDiv(maxDist, (1 << i)) + 2; // +2 to make sure the section is fully contained in the ringList + int halfSize = MathUtil.ceilDiv(maxDist, (1 << i)) + 8; // +8 to make sure the section is fully contained in the ringList { DhSectionPos checkerPos = new DhSectionPos(i, halfSize, halfSize); byte checkedDetail = calculateExpectedDetailLevel(new DhBlockPos2D(initialPlayerX, initialPlayerZ),checkerPos); diff --git a/core/src/main/java/com/seibel/lod/core/render/renderer/LodRenderer.java b/core/src/main/java/com/seibel/lod/core/render/renderer/LodRenderer.java index 1c1943747..c55afd193 100644 --- a/core/src/main/java/com/seibel/lod/core/render/renderer/LodRenderer.java +++ b/core/src/main/java/com/seibel/lod/core/render/renderer/LodRenderer.java @@ -163,7 +163,8 @@ public class LodRenderer if (debugModeConfig.get() == EDebugMode.SHOW_DETAIL_WIREFRAME || debugModeConfig.get() == EDebugMode.SHOW_GENMODE_WIREFRAME || debugModeConfig.get() == EDebugMode.SHOW_WIREFRAME - || debugModeConfig.get() == EDebugMode.SHOW_OVERLAPPING_QUADS_WIREFRAME) { + || debugModeConfig.get() == EDebugMode.SHOW_OVERLAPPING_QUADS_WIREFRAME + || debugModeConfig.get() == EDebugMode.SHOW_RENDER_SOURCE_FLAG_WIREFRAME) { GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_LINE); //GL32.glDisable(GL32.GL_CULL_FACE); } diff --git a/core/src/main/java/com/seibel/lod/core/util/ColorUtil.java b/core/src/main/java/com/seibel/lod/core/util/ColorUtil.java index ecf07c627..44665731c 100644 --- a/core/src/main/java/com/seibel/lod/core/util/ColorUtil.java +++ b/core/src/main/java/com/seibel/lod/core/util/ColorUtil.java @@ -35,8 +35,19 @@ public class ColorUtil public static final int BLACK = rgbToInt(0,0,0); public static final int WHITE = rgbToInt(255,255,255); public static final int TRANSPARENT = rgbToInt(0, 0, 0, 0); - public static final int RED = rgbToInt(255,0,0); + public static final int GREEN = rgbToInt(0,255,0); + public static final int BLUE = rgbToInt(0,0,255); + public static final int YELLOW = rgbToInt(255,255,0); + public static final int CYAN = rgbToInt(0,255,255); + public static final int MAGENTA = rgbToInt(255,0,255); + public static final int ORANGE = rgbToInt(255,128,0); + public static final int PINK = rgbToInt(255,128,128); + public static final int GRAY = rgbToInt(128,128,128); + public static final int LIGHT_GRAY = rgbToInt(192,192,192); + public static final int DARK_GRAY = rgbToInt(64,64,64); + public static final int BROWN = rgbToInt(128,64,0); + public static final int PURPLE = rgbToInt(128,0,128); public static int rgbToInt(int red, int green, int blue) {