Remove ColumnRenderSourceLoader

This commit is contained in:
James Seibel
2024-03-30 22:07:08 -05:00
parent ddd475d537
commit 0ddf1dd640
3 changed files with 2 additions and 196 deletions
@@ -108,29 +108,6 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
this.worldGenStep = EDhApiWorldGenerationStep.EMPTY;
}
/**
* Creates a new ColumnRenderSource from the parsedColumnData.
*
* @throws IOException if the DataInputStream's detail level isn't what was expected
*/
public ColumnRenderSource(DhSectionPos sectionPos, ColumnRenderSourceLoader.ParsedColumnData parsedColumnData, IDhLevel level) throws IOException
{
if (sectionPos.getDetailLevel() - SECTION_SIZE_OFFSET != parsedColumnData.detailLevel)
{
throw new IOException("Invalid data: detail level does not match");
}
this.sectionPos = sectionPos;
this.yOffset = level.getMinY();
this.verticalDataCount = parsedColumnData.verticalSize;
this.renderDataContainer = parsedColumnData.dataContainer;
this.worldGenStep = parsedColumnData.worldGenStep;
this.isEmpty = parsedColumnData.isEmpty;
this.debugSourceFlags = new DebugSourceFlag[SECTION_SIZE * SECTION_SIZE];
this.fillDebugFlag(0, 0, SECTION_SIZE, SECTION_SIZE, DebugSourceFlag.FILE);
}
//========================//
@@ -1,171 +0,0 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2023 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.distanthorizons.core.dataObjects.render;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV1DTO;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* Handles loading and parsing {@link FullDataSourceV1DTO}s to create {@link ColumnRenderSource}s. <br><br>
*
* Please see the {@link ColumnRenderSourceLoader#loadRenderSource} method to see what
* file versions this class can handle.
*/
public class ColumnRenderSourceLoader
{
public static ColumnRenderSourceLoader INSTANCE = new ColumnRenderSourceLoader();
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
private ColumnRenderSourceLoader() { }
public ColumnRenderSource loadRenderSource(FullDataSourceV1DTO dto, DhDataInputStream inputStream, IDhLevel level) throws IOException
{
int dataFileVersion = dto.binaryDataFormatVersion;
switch (dataFileVersion)
{
case 1:
ParsedColumnData parsedColumnData = readDataV1(inputStream, level.getMinY());
return new ColumnRenderSource(dto.pos, parsedColumnData, level);
default:
throw new IOException("Invalid Data: The data version [" + dataFileVersion + "] is not supported");
}
}
//========================//
// versioned file parsing //
//========================//
/**
* @param inputStream Expected format: 1st byte: detail level, 2nd byte: vertical size, 3rd byte on: column data
* @throws IOException if there was an issue reading the stream
*/
private static ParsedColumnData readDataV1(DhDataInputStream inputStream, int expectedYOffset) throws IOException
{
// TODO move into ColumnRenderSource
byte detailLevel = inputStream.readByte();
int verticalDataCount = inputStream.readInt();
if (verticalDataCount <= 0)
{
throw new IOException("Invalid data: vertical size must be 0 or greater");
}
int maxNumberOfDataPoints = ColumnRenderSource.SECTION_SIZE * ColumnRenderSource.SECTION_SIZE * verticalDataCount;
byte dataPresentFlag = inputStream.readByte();
if (dataPresentFlag != ColumnRenderSource.NO_DATA_FLAG_BYTE && dataPresentFlag != ColumnRenderSource.DATA_GUARD_BYTE)
{
throw new IOException("Incorrect render file format. Expected either: NO_DATA_FLAG_BYTE [" + ColumnRenderSource.NO_DATA_FLAG_BYTE + "] or DATA_GUARD_BYTE [" + ColumnRenderSource.DATA_GUARD_BYTE + "], Found: [" + dataPresentFlag + "]");
}
else if (dataPresentFlag == ColumnRenderSource.NO_DATA_FLAG_BYTE)
{
// no data is present
return new ParsedColumnData(detailLevel, verticalDataCount, EDhApiWorldGenerationStep.EMPTY, new long[maxNumberOfDataPoints], true);
}
else
{
// data is present
int fileYOffset = inputStream.readInt();
if (fileYOffset != expectedYOffset)
{
throw new IOException("Invalid data: yOffset is incorrect. Expected: [" + expectedYOffset + "], found: [" + fileYOffset + "].");
}
// read the column data
byte[] rawByteData = new byte[maxNumberOfDataPoints * Long.BYTES];
ByteBuffer columnDataByteBuffer = ByteBuffer.wrap(rawByteData).order(ByteOrder.LITTLE_ENDIAN);
inputStream.readFully(rawByteData);
// parse the column data
long[] dataPoints = new long[maxNumberOfDataPoints];
columnDataByteBuffer.asLongBuffer().get(dataPoints);
boolean isEmpty = true;
for (long dataPoint : dataPoints)
{
if (dataPoint != 0)
{
isEmpty = false;
break;
}
}
byte guardByteFlag = inputStream.readByte();
if (guardByteFlag != ColumnRenderSource.DATA_GUARD_BYTE)
{
throw new IOException("invalid world gen step end guard");
}
EDhApiWorldGenerationStep worldGenStep = EDhApiWorldGenerationStep.fromValue(inputStream.readByte());
if (worldGenStep == null)
{
LOGGER.warn("Missing WorldGenStep, defaulting to: " + EDhApiWorldGenerationStep.SURFACE.name());
worldGenStep = EDhApiWorldGenerationStep.SURFACE;
}
return new ParsedColumnData(detailLevel, verticalDataCount, worldGenStep, dataPoints, isEmpty);
}
}
public static class ParsedColumnData
{
public final byte detailLevel;
public final int verticalSize;
public final EDhApiWorldGenerationStep worldGenStep;
public final long[] dataContainer;
public final boolean isEmpty;
public ParsedColumnData(byte detailLevel, int verticalSize, EDhApiWorldGenerationStep worldGenStep, long[] dataContainer, boolean isEmpty)
{
this.detailLevel = detailLevel;
this.verticalSize = verticalSize;
this.worldGenStep = worldGenStep;
this.dataContainer = dataContainer;
this.isEmpty = isEmpty;
}
}
}
@@ -58,8 +58,8 @@ public class LodRenderSection implements IDebugRenderable
private boolean isRenderingEnabled = false;
/**
* If this is true, then {@ link LodRenderSection#reload(IRenderSourceProvider)} was called while
* a {@ link IRenderSourceProvider} was already being loaded.
* If this is true, then {@link LodRenderSection#reload(FullDataSourceProviderV2)} was called while
* a {@link ColumnRenderSource} was already being loaded.
*/
private boolean reloadRenderSourceOnceLoaded = false;