Something renders! And introduce mem leaks, missing texture color, and inverted lights! What a great set of features!

This commit is contained in:
TomTheFurry
2022-07-30 16:06:54 +08:00
parent 823da76896
commit 6fe2b6f331
11 changed files with 70 additions and 57 deletions
@@ -1,6 +1,7 @@
package com.seibel.lod.core.a7.datatype.column;
import com.seibel.lod.core.a7.datatype.column.accessor.ColumnArrayView;
import com.seibel.lod.core.a7.datatype.column.accessor.ColumnFormat;
import com.seibel.lod.core.a7.datatype.column.accessor.ColumnQuadView;
import com.seibel.lod.core.a7.datatype.column.accessor.IColumnDatatype;
import com.seibel.lod.core.a7.datatype.column.render.ColumnRenderBuffer;
@@ -1,15 +1,13 @@
package com.seibel.lod.core.a7.datatype.column.accessor;
import com.seibel.lod.core.a7.datatype.column.ColumnFormat;
import java.util.Arrays;
public final class ColumnArrayView implements IColumnDataView {
private final long[] data;
private final int size; // size in longs
private final int offset; // offset in longs
private final int vertSize; // vertical size in longs
final long[] data;
final int size; // size in longs
final int offset; // offset in longs
final int vertSize; // vertical size in longs
public ColumnArrayView(long[] data, int size, int offset, int vertSize) {
this.data = data;
@@ -53,12 +51,12 @@ public final class ColumnArrayView implements IColumnDataView {
if (source.verticalSize() != vertSize) {
for (int i = 0; i < source.dataCount(); i++) {
int outputOffset = offset + outputDataIndexOffset * vertSize + i * vertSize;
source.subView(i, 1).copyTo(data, outputOffset);
source.subView(i, 1).copyTo(data, outputOffset, source.verticalSize());
Arrays.fill(data, outputOffset + source.verticalSize(),
outputOffset + vertSize, 0);
}
} else {
source.copyTo(data, offset + outputDataIndexOffset * vertSize);
source.copyTo(data, offset + outputDataIndexOffset * vertSize, source.size());
}
}
public void copyFrom(IColumnDataView source) {
@@ -66,7 +64,7 @@ public final class ColumnArrayView implements IColumnDataView {
}
@Override
public void copyTo(long[] target, int offset) {
public void copyTo(long[] target, int offset, int size) {
System.arraycopy(data, this.offset, target, offset, size);
}
@@ -113,4 +111,22 @@ public final class ColumnArrayView implements IColumnDataView {
}
ColumnFormat.mergeMultiData(source, this);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("S:");
sb.append(size);
sb.append(" V:");
sb.append(vertSize);
sb.append(" O:");
sb.append(offset);
sb.append(" [");
for (int i=0; i<size; i++) {
sb.append(ColumnFormat.toString(data[offset+i]));
if (i < size-1) sb.append(",\n");
}
sb.append("]");
return sb.toString();
}
}
@@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.core.a7.datatype.column;
package com.seibel.lod.core.a7.datatype.column.accessor;
import com.seibel.lod.core.a7.datatype.column.accessor.ColumnArrayView;
import com.seibel.lod.core.a7.datatype.column.accessor.IColumnDataView;
@@ -111,7 +111,7 @@ public class ColumnFormat
public static long createDataPoint(int height, int depth, int color, int light, int generationMode)
{
LodUtil.assertTrue(light >= 0 && light <= 255, "Raw Light value must be between 0 and 255!");
LodUtil.assertTrue(light >= 0 && light < 256, "Raw Light value must be between 0 and 255!");
return createDataPoint(
ColorUtil.getAlpha(color),
ColorUtil.getRed(color),
@@ -127,10 +127,10 @@ public class ColumnFormat
LodUtil.assertTrue(depth >= 0 && depth < MAX_WORLD_Y_SIZE, "Trying to create datapoint with depth[{}] out of range!", depth);
LodUtil.assertTrue(lightSky >= 0 && lightSky < 16, "Trying to create datapoint with lightSky[{}] out of range!", lightSky);
LodUtil.assertTrue(lightBlock >= 0 && lightBlock < 16, "Trying to create datapoint with lightBlock[{}] out of range!", lightBlock);
LodUtil.assertTrue(alpha >= 0 && alpha < 255, "Trying to create datapoint with alpha[{}] out of range!", alpha);
LodUtil.assertTrue(red >= 0 && red < 255, "Trying to create datapoint with red[{}] out of range!", red);
LodUtil.assertTrue(green >= 0 && green < 255, "Trying to create datapoint with green[{}] out of range!", green);
LodUtil.assertTrue(blue >= 0 && blue < 255, "Trying to create datapoint with blue[{}] out of range!", blue);
LodUtil.assertTrue(alpha >= 0 && alpha < 256, "Trying to create datapoint with alpha[{}] out of range!", alpha);
LodUtil.assertTrue(red >= 0 && red < 256, "Trying to create datapoint with red[{}] out of range!", red);
LodUtil.assertTrue(green >= 0 && green < 256, "Trying to create datapoint with green[{}] out of range!", green);
LodUtil.assertTrue(blue >= 0 && blue < 256, "Trying to create datapoint with blue[{}] out of range!", blue);
LodUtil.assertTrue(generationMode >= 0 && generationMode < 8, "Trying to create datapoint with genMode[{}] out of range!", generationMode);
LodUtil.assertTrue(depth <= height, "Trying to create datapoint with depth[{}] greater than height[{}]!", depth, height);
@@ -253,17 +253,17 @@ public class ColumnFormat
@SuppressWarnings("unused")
public static String toString(long dataPoint)
{
return getHeight(dataPoint) + " " +
getDepth(dataPoint) + " " +
getAlpha(dataPoint) + " " +
if (!doesItExist(dataPoint)) return "null";
if (isVoid(dataPoint)) return "void";
return "H:" + getHeight(dataPoint) +
" D:" + getDepth(dataPoint) +
" argb:" + getAlpha(dataPoint) + " " +
getRed(dataPoint) + " " +
getBlue(dataPoint) + " " +
getGreen(dataPoint) + " " +
getLightBlock(dataPoint) + " " +
getLightSky(dataPoint) + " " +
getGenerationMode(dataPoint) + " " +
isVoid(dataPoint) + " " +
doesItExist(dataPoint) + '\n';
getGreen(dataPoint) +
" BL/SL:" + getLightBlock(dataPoint) + " " +
getLightSky(dataPoint) +
" G:" + getGenerationMode(dataPoint);
}
@@ -664,7 +664,7 @@ public class ColumnFormat
if (!limited && dataCount == 1) // This mean source vertSize < output vertSize AND both dataCount == 1
{
output.copyFrom(sourceData);
sourceData.copyTo(output.data, output.offset, output.vertSize);
}
else
{
@@ -54,7 +54,7 @@ public class ColumnQuadView implements IColumnDataView {
public void set(int x, int z, IColumnDataView singleColumn) {
if (singleColumn.verticalSize() != vertSize) throw new IllegalArgumentException("Vertical size of singleColumn must be equal to vertSize");
if (singleColumn.dataCount() != 1) throw new IllegalArgumentException("SingleColumn must contain exactly one data point");
singleColumn.copyTo(data, x * perColumnOffset + z * vertSize);
singleColumn.copyTo(data, x * perColumnOffset + z * vertSize, singleColumn.size());
}
@Override
@@ -86,9 +86,14 @@ public class ColumnQuadView implements IColumnDataView {
}
@Override
public void copyTo(long[] target, int offset) {
for (int x = 0; x < xSize; x++) {
System.arraycopy(data, this.offset + x * perColumnOffset, target, offset + x * xSize * vertSize, zSize * vertSize);
public void copyTo(long[] target, int offset, int size) {
if (size != this.size() && size > zSize * vertSize) throw new UnsupportedOperationException("Not supported yet");
if (size <= zSize * vertSize) {
System.arraycopy(data, this.offset, target, offset, size);
} else {
for (int x = 0; x < xSize; x++) {
System.arraycopy(data, this.offset + x * perColumnOffset, target, offset + x * xSize * vertSize, zSize * vertSize);
}
}
}
@@ -29,6 +29,5 @@ public interface IColumnDataView {
IColumnDataView subView(int dataIndexStart, int dataCount);
@Deprecated //This is unsafe for quadViews. And its a mess for multi-columns!
void copyTo(long[] target, int offset);
void copyTo(long[] target, int offset, int count);
}
@@ -191,7 +191,7 @@ public class ColumnRenderBuffer extends RenderBuffer {
(short) (skyLightCullingBelow - clientLevel.getMinY()));
makeLodRenderData(builder, data, adjData);
if (builder.getCurrentQuadsCount() > 0) {
LOGGER.info("her");
//LOGGER.info("her");
}
EVENT_LOGGER.trace("RenderRegion end QuadBuild @ {}", data.sectionPos);
return builder;
@@ -248,9 +248,8 @@ public class ColumnRenderBuffer extends RenderBuffer {
EDebugMode debugMode = Config.Client.Advanced.Debugging.debugMode.get();
byte detailLevel = region.getDataDetail();
int dataSize = 1 << detailLevel;
for (int x = 0; x < dataSize; x++) {
for (int z = 0; z < dataSize; z++) {
for (int x = 0; x < ColumnRenderSource.SECTION_SIZE; x++) {
for (int z = 0; z < ColumnRenderSource.SECTION_SIZE; z++) {
UncheckedInterruptedException.throwIfInterrupted();
ColumnArrayView posData = region.getVerticalDataView(x, z);
@@ -278,8 +277,8 @@ public class ColumnRenderBuffer extends RenderBuffer {
try {
int xAdj = x + lodDirection.getNormal().x;
int zAdj = z + lodDirection.getNormal().z;
boolean isCrossRegionBoundary = (xAdj < 0 || xAdj >= dataSize) ||
(zAdj < 0 || zAdj >= dataSize);
boolean isCrossRegionBoundary = (xAdj < 0 || xAdj >= ColumnRenderSource.SECTION_SIZE) ||
(zAdj < 0 || zAdj >= ColumnRenderSource.SECTION_SIZE);
ColumnRenderSource adjRegion;
byte adjDetail;
@@ -293,10 +292,10 @@ public class ColumnRenderBuffer extends RenderBuffer {
if (adjDetail != detailLevel) {
//TODO: Implement this
} else {
if (xAdj < 0) xAdj += dataSize;
if (zAdj < 0) zAdj += dataSize;
if (xAdj >= dataSize) xAdj -= dataSize;
if (zAdj >= dataSize) zAdj -= dataSize;
if (xAdj < 0) xAdj += ColumnRenderSource.SECTION_SIZE;
if (zAdj < 0) zAdj += ColumnRenderSource.SECTION_SIZE;
if (xAdj >= ColumnRenderSource.SECTION_SIZE) xAdj -= ColumnRenderSource.SECTION_SIZE;
if (zAdj >= ColumnRenderSource.SECTION_SIZE) zAdj -= ColumnRenderSource.SECTION_SIZE;
}
} else {
adjRegion = region;
@@ -16,7 +16,7 @@ package com.seibel.lod.core.a7.datatype.full;
import com.seibel.lod.core.util.LodUtil;
import org.jetbrains.annotations.Contract;
import static com.seibel.lod.core.a7.datatype.column.ColumnFormat.MAX_WORLD_Y_SIZE;
import static com.seibel.lod.core.a7.datatype.column.accessor.ColumnFormat.MAX_WORLD_Y_SIZE;
public class FullFormat {
@@ -1,6 +1,6 @@
package com.seibel.lod.core.a7.datatype.transform;
import com.seibel.lod.core.a7.datatype.column.ColumnFormat;
import com.seibel.lod.core.a7.datatype.column.accessor.ColumnFormat;
import com.seibel.lod.core.a7.datatype.column.ColumnRenderSource;
import com.seibel.lod.core.a7.datatype.column.accessor.ColumnArrayView;
import com.seibel.lod.core.a7.datatype.full.FullDataSource;
@@ -82,6 +82,7 @@ public class FullToColumnTransformer {
private static void iterateAndConvert(IClientLevel level, int blockX, int blockZ, int genMode, ColumnArrayView column, SingleFullArrayView data) {
IdBiomeBlockStateMap mapping = data.getMapping();
boolean isVoid = true;
int offset = 0;
for (int i = 0; i < data.getSingleLength(); i++) {
long fullData = data.getSingle(i);
int y = FullFormat.getY(fullData);
@@ -95,7 +96,8 @@ public class FullToColumnTransformer {
isVoid = false;
int color = level.computeBaseColor(new DHBlockPos(blockX, y + level.getMinY(), blockZ), biome, block);
long columnData = ColumnFormat.createDataPoint(y + blockLength, y, color, light, genMode);
column.set(i, columnData);
column.set(offset, columnData);
offset++;
}
if (isVoid) {
column.set(0, ColumnFormat.createVoidDataPoint((byte) genMode));
@@ -70,7 +70,8 @@ public class a7LodRenderer
public static final boolean ENABLE_IBO = true;
public void setupOffset(DHBlockPos pos) {
shaderProgram.setModelPos(new Vec3f(pos.x, pos.y, pos.z));
Vec3d cam = MC_RENDER.getCameraExactPosition();
shaderProgram.setModelPos(new Vec3f((float) (pos.x - cam.x), (float) (pos.y - cam.y), (float) (pos.z - cam.z)));
}
public void drawVbo(GLVertexBuffer vbo) {
@@ -60,7 +60,7 @@ public class MetaFile {
public long dataTypeId;
public byte loaderVersion;
private static final ReentrantReadWriteLock assertLock = new ReentrantReadWriteLock();
private final ReentrantReadWriteLock assertLock = new ReentrantReadWriteLock();
// Load a metaFile in this path. It also automatically read the metadata.
protected MetaFile(File path) throws IOException {
@@ -40,15 +40,6 @@ public interface IChunkWrapper extends IBindable
int getMaxBuildHeight();
int getHeightMapValue(int xRel, int zRel);
IBiomeWrapper getBiome(int x, int y, int z);
@Deprecated
IBlockDetailWrapper getBlockDetail(int x, int y, int z);
/** Returns null if block doesn't exist. Note that this can cross chunk boundaries. */
@Deprecated
IBlockDetailWrapper getBlockDetailAtFace(int x, int y, int z, ELodDirection dir);
@Deprecated
int getChunkPosX();
@@ -85,8 +76,6 @@ public interface IChunkWrapper extends IBindable
boolean doesNearbyChunksExist();
String toString();
/** This is a bad hash algorithm, but can be used for rough debugging. */
default int roughHashCode()
{
@@ -105,6 +94,7 @@ public interface IChunkWrapper extends IBindable
}
IBlockStateWrapper getBlockState(int x, int y, int z);
IBiomeWrapper getBiome(int x, int y, int z);
default DHChunkPos getChunkPos() {
return new DHChunkPos(getChunkPosX(), getChunkPosZ());