From e14e122b6c24445ec9ee96b9b98c8f1fe460b5db Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 16 Mar 2024 20:19:24 -0500 Subject: [PATCH] Refactor FullDataSourceV2 variables --- .../methods/data/DhApiTerrainDataRepo.java | 2 +- .../fullData/sources/FullDataSourceV1.java | 3 -- .../fullData/sources/FullDataSourceV2.java | 34 ++++++++++--------- .../render/ColumnRenderSource.java | 7 +--- .../FullDataToRenderDataTransformer.java | 4 +-- .../transformers/LodDataBuilder.java | 10 +++--- .../file/AbstractLegacyDataSourceHandler.java | 3 +- .../core/file/IDataSource.java | 4 --- .../SubDimensionLevelMatcher.java | 4 +-- .../core/sql/dto/FullDataSourceV2DTO.java | 8 ++--- 10 files changed, 35 insertions(+), 44 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java index ce7ef834a..933b29210 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/data/DhApiTerrainDataRepo.java @@ -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) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV1.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV1.java index 9a6f4c0e5..22b9db0c7 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV1.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV1.java @@ -127,10 +127,7 @@ public class FullDataSourceV1 implements IDataSource @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; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java index c0d311889..9f012419c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/FullDataSourceV2.java @@ -54,7 +54,7 @@ public class FullDataSourceV2 implements IDataSource { 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 - // 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 * 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 // 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 @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 } } + + + //================// + // base overrides // + //================// + @Override public String toString() { return this.pos.toString(); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/ColumnRenderSource.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/ColumnRenderSource.java index 9eb58d3bb..208aa4df5 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/ColumnRenderSource.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/render/ColumnRenderSource.java @@ -322,7 +322,7 @@ public class ColumnRenderSource implements IDataSource 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 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; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/FullDataToRenderDataTransformer.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/FullDataToRenderDataTransformer.java index 37cbfb931..b4f12126c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/FullDataToRenderDataTransformer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/FullDataToRenderDataTransformer.java @@ -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); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/LodDataBuilder.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/LodDataBuilder.java index b2af153c1..eb796421f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/LodDataBuilder.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/LodDataBuilder.java @@ -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) ); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/AbstractLegacyDataSourceHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/file/AbstractLegacyDataSourceHandler.java index 71ca44501..117177e65 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/AbstractLegacyDataSourceHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/AbstractLegacyDataSourceHandler.java @@ -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 extends IBaseDTO 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 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 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 dataSource.levelMinY = this.levelMinY; - dataSource.markNotEmpty(); + dataSource.isEmpty = false; return dataSource; }