Refactor FullDataSourceV2 variables

This commit is contained in:
James Seibel
2024-03-16 20:19:24 -05:00
parent dcd16cb84b
commit e14e122b6c
10 changed files with 35 additions and 44 deletions
@@ -219,7 +219,7 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
else
{
// attempt to get the LOD data from the data source
FullDataPointIdMap mapping = dataSource.getMapping();
FullDataPointIdMap mapping = dataSource.mapping;
long[] dataColumn = dataSource.get(relativePos.x, relativePos.z);
if (dataColumn != null)
{
@@ -127,10 +127,7 @@ public class FullDataSourceV1 implements IDataSource<IDhLevel>
@Override
public byte getDataFormatVersion() { return DATA_FORMAT_VERSION; }
@Override
public EDhApiWorldGenerationStep getWorldGenStep() { return this.worldGenStep; }
@Override
public EDhApiWorldGenerationStep getWorldGenStepAtRelativePos(int relX, int relZ) { return this.worldGenStep; }
public boolean isEmpty() { return this.isEmpty; }
@@ -54,7 +54,7 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
/** useful for debugging, but can slow down update operations quite a bit due to being called so often. */
private static final boolean RUN_UPDATE_DEV_VALIDATION = false; //ModInfo.IS_DEV_BUILD;
private static final boolean RUN_UPDATE_DEV_VALIDATION = false;
private static final boolean RUN_V1_MIGRATION_VALIDATION = false;
/** measured in data columns */
@@ -64,18 +64,21 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
// TODO make these fields private
private int cachedHashCode = 0;
private DhSectionPos pos;
@Override
public DhSectionPos getKey() { return this.pos; }
public final FullDataPointIdMap mapping;
public long lastModifiedUnixDateTime;
public long createdUnixDateTime;
public int levelMinY;
private int cachedHashCode = 0;
/**
* stores how far each column has been generated should start with {@link EDhApiWorldGenerationStep#EMPTY}
* @see EDhApiWorldGenerationStep
@@ -87,11 +90,8 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
* The y data should be sorted from bottom to top
*/
public long[][] dataPoints;
private boolean isEmpty;
private FullDataPointIdMap mapping;
public FullDataPointIdMap getMapping() { return this.mapping; }
public boolean isEmpty;
public boolean applyToParent = false;
@@ -651,7 +651,10 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
// helper methods //
//================//
// TODO make private, any external logic should go through a method, not interact with the arrays directly
/**
* Usually this should just be used internally, but there may be instances
* where the raw data arrays are available without the data source object.
*/
public static int relativePosToIndex(int relX, int relZ) throws IndexOutOfBoundsException
{
if (relX < 0 || relZ < 0 ||
@@ -678,19 +681,12 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
@Override
public byte getDataFormatVersion() { return DATA_FORMAT_VERSION; }
@Deprecated
@Override
public EDhApiWorldGenerationStep getWorldGenStep() { return this.getWorldGenStepAtRelativePos(0, 0); }
@Override
public EDhApiWorldGenerationStep getWorldGenStepAtRelativePos(int relX, int relZ)
{
int index = relativePosToIndex(relX, relZ);
return EDhApiWorldGenerationStep.fromValue(this.columnGenerationSteps[index]);
}
public boolean isEmpty() { return this.isEmpty; }
public void markNotEmpty() { this.isEmpty = false; }
public void setSingleColumn(long[] longArray, int relX, int relZ, EDhApiWorldGenerationStep worldGenStep)
{
int index = relativePosToIndex(relX, relZ);
@@ -714,6 +710,12 @@ public class FullDataSourceV2 implements IDataSource<IDhLevel>
}
}
//================//
// base overrides //
//================//
@Override
public String toString() { return this.pos.toString(); }
@@ -322,7 +322,7 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
if (dataColumn != null && worldGenStep != EDhApiWorldGenerationStep.EMPTY)
{
FullDataToRenderDataTransformer.convertColumnData(
level, inputFullDataSource.getMapping(),
level, inputFullDataSource.mapping,
minBlockPos.x + x,
minBlockPos.z + z,
columnArrayView, dataColumn);
@@ -373,11 +373,6 @@ public class ColumnRenderSource implements IDataSource<IDhClientLevel>
public byte getDataDetailLevel() { return (byte) (this.sectionPos.getDetailLevel() - SECTION_SIZE_OFFSET); }
@Override
public EDhApiWorldGenerationStep getWorldGenStep() { return EDhApiWorldGenerationStep.EMPTY; }
@Override
public EDhApiWorldGenerationStep getWorldGenStepAtRelativePos(int relX, int relZ) { return EDhApiWorldGenerationStep.EMPTY; }
/** @return how many data points wide this {@link ColumnRenderSource} is. */
public int getWidthInDataPoints() { return BitShiftUtil.powerOfTwo(this.getDetailOffset()); }
public byte getDetailOffset() { return SECTION_SIZE_OFFSET; }
@@ -98,7 +98,7 @@ public class FullDataToRenderDataTransformer
final byte dataDetail = fullDataSource.getDataDetailLevel();
final int vertSize = Config.Client.Advanced.Graphics.Quality.verticalQuality.get().calculateMaxVerticalData(fullDataSource.getDataDetailLevel());
final ColumnRenderSource columnSource = new ColumnRenderSource(pos, vertSize, level.getMinY());
if (fullDataSource.isEmpty())
if (fullDataSource.isEmpty)
{
return columnSource;
}
@@ -118,7 +118,7 @@ public class FullDataToRenderDataTransformer
ColumnArrayView columnArrayView = columnSource.getVerticalDataPointView(x, z);
long[] dataColumn = fullDataSource.get(x, z);
convertColumnData(level, fullDataSource.getMapping(), baseX + x, baseZ + z, columnArrayView, dataColumn);
convertColumnData(level, fullDataSource.mapping, baseX + x, baseZ + z, columnArrayView, dataColumn);
}
}
@@ -71,7 +71,7 @@ public class LodDataBuilder
DhSectionPos pos = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, sectionPosX, sectionPosZ);
FullDataSourceV2 dataSource = FullDataSourceV2.createEmpty(pos);
dataSource.markNotEmpty();
dataSource.isEmpty = false;
@@ -135,7 +135,7 @@ public class LodDataBuilder
int lastY = chunkWrapper.getMaxBuildHeight();
IBiomeWrapper biome = chunkWrapper.getBiome(chunkX, lastY, chunkZ);
IBlockStateWrapper blockState = AIR;
int mappedId = dataSource.getMapping().addIfNotPresentAndGetId(biome, blockState);
int mappedId = dataSource.mapping.addIfNotPresentAndGetId(biome, blockState);
// FIXME: The lastY +1 offset is to reproduce the old behavior. Remove this when we get per-face lighting
byte blockLight = (byte) chunkWrapper.getBlockLight(chunkX, lastY + 1, chunkZ);
byte skyLight = (byte) chunkWrapper.getSkyLight(chunkX, lastY + 1, chunkZ);
@@ -180,7 +180,7 @@ public class LodDataBuilder
longs.add(FullDataPointUtilV2.encode(mappedId, lastY - y, y + 1 - chunkWrapper.getMinBuildHeight(), blockLight, skyLight));
biome = newBiome;
blockState = newBlockState;
mappedId = dataSource.getMapping().addIfNotPresentAndGetId(biome, blockState);
mappedId = dataSource.mapping.addIfNotPresentAndGetId(biome, blockState);
blockLight = newBlockLight;
skyLight = newSkyLight;
lastY = y;
@@ -205,7 +205,7 @@ public class LodDataBuilder
}
}
LodUtil.assertTrue(!dataSource.isEmpty());
LodUtil.assertTrue(!dataSource.isEmpty);
return dataSource;
}
@@ -232,7 +232,7 @@ public class LodDataBuilder
{
DhApiTerrainDataPoint dataPoint = columnDataPoints.get(index);
int id = accessor.getMapping().addIfNotPresentAndGetId(
int id = accessor.mapping.addIfNotPresentAndGetId(
(IBiomeWrapper) (dataPoint.biomeWrapper),
(IBlockStateWrapper) (dataPoint.blockStateWrapper)
);
@@ -1,6 +1,7 @@
package com.seibel.distanthorizons.core.file;
import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
@@ -353,7 +354,7 @@ public abstract class AbstractLegacyDataSourceHandler<TDataSource extends IDataS
// save the DTO
LegacyDataSourceDTO newDto = new LegacyDataSourceDTO(
dataSource.getSectionPos(), checksum,
dataSource.getDataDetailLevel(), dataSource.getWorldGenStep(), ColumnRenderSource.DATA_NAME,
dataSource.getDataDetailLevel(), EDhApiWorldGenerationStep.EMPTY, ColumnRenderSource.DATA_NAME,
dataSource.getDataFormatVersion(),
byteArrayOutputStream.toByteArray());
this.repo.save(newDto);
@@ -46,10 +46,6 @@ public interface IDataSource<TDhLevel extends IDhLevel> extends IBaseDTO<DhSecti
*/
byte getDataDetailLevel();
@Deprecated // TODO only necessary for full data sources
EDhApiWorldGenerationStep getWorldGenStep();
EDhApiWorldGenerationStep getWorldGenStepAtRelativePos(int relX, int relZ);
/** Defines how the binary data is formatted. */
byte getDataFormatVersion();
@@ -240,8 +240,8 @@ public class SubDimensionLevelMatcher implements AutoCloseable
{
// compare each data point in the column
FullDataPointIdMap newDataMap = newDataSource.getMapping();
FullDataPointIdMap testDataMap = testFullDataSource.getMapping();
FullDataPointIdMap newDataMap = newDataSource.mapping;
FullDataPointIdMap testDataMap = testFullDataSource.mapping;
// use min to prevent going out of bounds
int minColumnIndex = Math.min(newColumn.length, testColumn.length);
@@ -69,7 +69,7 @@ public class FullDataSourceV2DTO implements IBaseDTO<DhSectionPos>
public static FullDataSourceV2DTO CreateFromDataSource(FullDataSourceV2 dataSource, EDhApiDataCompressionMode compressionModeEnum) throws IOException
{
CheckedByteArray checkedDataPointArray = writeDataSourceDataArrayToBlob(dataSource.dataPoints, compressionModeEnum);
byte[] mappingByteArray = writeDataMappingToBlob(dataSource.getMapping(), compressionModeEnum);
byte[] mappingByteArray = writeDataMappingToBlob(dataSource.mapping, compressionModeEnum);
return new FullDataSourceV2DTO(
dataSource.getSectionPos(),
@@ -133,7 +133,7 @@ public class FullDataSourceV2DTO implements IBaseDTO<DhSectionPos>
dataSource.columnGenerationSteps = this.columnGenStepByteArray;
dataSource.dataPoints = readBlobToDataSourceDataArray(this.dataByteArray, this.compressionModeEnum);
dataSource.getMapping().clear(dataSource.getSectionPos());
dataSource.mapping.clear(dataSource.getSectionPos());
// should only be null when used in a unit test
if (!unitTest)
{
@@ -142,7 +142,7 @@ public class FullDataSourceV2DTO implements IBaseDTO<DhSectionPos>
throw new NullPointerException("No level wrapper present, unable to deserialize data map. This should only be used for unit tests.");
}
dataSource.getMapping().mergeAndReturnRemappedEntityIds(readBlobToDataMapping(this.mappingByteArray, dataSource.getSectionPos(), levelWrapper, this.compressionModeEnum));
dataSource.mapping.mergeAndReturnRemappedEntityIds(readBlobToDataMapping(this.mappingByteArray, dataSource.getSectionPos(), levelWrapper, this.compressionModeEnum));
}
dataSource.lastModifiedUnixDateTime = this.lastModifiedUnixDateTime;
@@ -150,7 +150,7 @@ public class FullDataSourceV2DTO implements IBaseDTO<DhSectionPos>
dataSource.levelMinY = this.levelMinY;
dataSource.markNotEmpty();
dataSource.isEmpty = false;
return dataSource;
}