From 9592cd80f349ffe89bf37067e182aa916b52e0b7 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 15 Jun 2024 07:20:38 -0500 Subject: [PATCH] Improve position error logging --- .../fullData/sources/FullDataSourceV1.java | 20 ++++++++++--------- .../fullData/sources/FullDataSourceV2.java | 2 ++ .../render/ColumnRenderSource.java | 2 ++ .../core/sql/dto/FullDataSourceV1DTO.java | 3 +++ .../core/sql/dto/FullDataSourceV2DTO.java | 3 +++ .../core/sql/dto/IBaseDTO.java | 2 ++ .../core/sql/repo/AbstractDhRepo.java | 4 ++-- 7 files changed, 25 insertions(+), 11 deletions(-) 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 bc82aa94a..30dbd7820 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 @@ -75,7 +75,7 @@ public class FullDataSourceV1 implements IDataSource /** A flattened 2D array (for the X and Z directions) containing an array for the Y direction. */ private final long[][] dataArrays; - private long sectionPos; + private long pos; private boolean isEmpty = true; @@ -86,11 +86,11 @@ public class FullDataSourceV1 implements IDataSource //==============// public static FullDataSourceV1 createEmpty(long pos) { return new FullDataSourceV1(pos); } - private FullDataSourceV1(long sectionPos) + private FullDataSourceV1(long pos) { this.dataArrays = new long[WIDTH * WIDTH][0]; - this.mapping = new FullDataPointIdMap(sectionPos); - this.sectionPos = sectionPos; + this.mapping = new FullDataPointIdMap(pos); + this.pos = pos; } @@ -111,19 +111,21 @@ public class FullDataSourceV1 implements IDataSource //=====================// @Override - public Long getKey() { return this.sectionPos; } + public Long getKey() { return this.pos; } + @Override + public String getKeyDisplayString() { return DhSectionPos.toString(this.pos); } @Override - public Long getPos() { return this.sectionPos; } + public Long getPos() { return this.pos; } public void resizeDataStructuresForRepopulation(long pos) { // no data structures need to be changed, only the source's position - this.sectionPos = pos; + this.pos = pos; } @Override - public byte getDataDetailLevel() { return (byte) (DhSectionPos.getDetailLevel(this.sectionPos) - SECTION_SIZE_OFFSET); } + public byte getDataDetailLevel() { return (byte) (DhSectionPos.getDetailLevel(this.pos) - SECTION_SIZE_OFFSET); } public boolean isEmpty() { return this.isEmpty; } @@ -370,7 +372,7 @@ public class FullDataSourceV1 implements IDataSource throw new IOException("Invalid data content end guard for ID mapping"); } - return FullDataPointIdMap.deserialize(inputStream, this.sectionPos, levelWrapper); + return FullDataPointIdMap.deserialize(inputStream, this.pos, levelWrapper); } public void setIdMapping(FullDataPointIdMap mappings) { this.mapping.mergeAndReturnRemappedEntityIds(mappings); } 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 e95957c62..fcfc8271f 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 @@ -74,6 +74,8 @@ public class FullDataSourceV2 implements IDataSource private long pos; @Override public Long getKey() { return this.pos; } + @Override + public String getKeyDisplayString() { return DhSectionPos.toString(this.pos); } public final FullDataPointIdMap mapping; 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 92626cbdb..9d3407c46 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 @@ -218,6 +218,8 @@ public class ColumnRenderSource implements IDataSource public Long getPos() { return this.pos; } @Override public Long getKey() { return this.pos; } + @Override + public String getKeyDisplayString() { return DhSectionPos.toString(this.pos); } public byte getDataDetailLevel() { return (byte) (DhSectionPos.getDetailLevel(this.pos) - SECTION_SIZE_OFFSET); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV1DTO.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV1DTO.java index 5aaf93546..9b849967f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV1DTO.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV1DTO.java @@ -22,6 +22,7 @@ package com.seibel.distanthorizons.core.sql.dto; import com.seibel.distanthorizons.api.enums.config.EDhApiDataCompressionMode; import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV1; +import com.seibel.distanthorizons.core.pos.DhSectionPos; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream; import java.io.ByteArrayInputStream; @@ -81,6 +82,8 @@ public class FullDataSourceV1DTO implements IBaseDTO @Override public Long getKey() { return this.pos; } + @Override + public String getKeyDisplayString() { return DhSectionPos.toString(this.pos); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV2DTO.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV2DTO.java index 62d622fc5..862ce4942 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV2DTO.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/FullDataSourceV2DTO.java @@ -24,6 +24,7 @@ import com.seibel.distanthorizons.api.enums.config.EDhApiWorldCompressionMode; import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep; import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; +import com.seibel.distanthorizons.core.pos.DhSectionPos; import com.seibel.distanthorizons.core.util.FullDataPointUtil; import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.util.objects.DataCorruptedException; @@ -358,6 +359,8 @@ public class FullDataSourceV2DTO implements IBaseDTO @Override public Long getKey() { return this.pos; } + @Override + public String getKeyDisplayString() { return DhSectionPos.toString(this.pos); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/IBaseDTO.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/IBaseDTO.java index 36405f26b..3d9ebba20 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/IBaseDTO.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/dto/IBaseDTO.java @@ -26,6 +26,8 @@ package com.seibel.distanthorizons.core.sql.dto; public interface IBaseDTO { TKey getKey(); + /** Can be used for keys that don't have a clean human readable toString() method. */ + default String getKeyDisplayString() { return this.getKey().toString(); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java index 5b3316748..9d9b548e4 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java @@ -173,7 +173,7 @@ public abstract class AbstractDhRepo> implemen } catch (DbConnectionClosedException ignored) { - LOGGER.warn("Attempted to insert ["+this.dtoClass.getSimpleName()+"] with primary key ["+(dto != null ? dto.getKey() : "NULL")+"] on closed repo ["+this.connectionString+"]."); + LOGGER.warn("Attempted to insert ["+this.dtoClass.getSimpleName()+"] with primary key ["+(dto != null ? dto.getKeyDisplayString() : "NULL")+"] on closed repo ["+this.connectionString+"]."); } catch (SQLException e) { @@ -190,7 +190,7 @@ public abstract class AbstractDhRepo> implemen } catch (DbConnectionClosedException e) { - LOGGER.warn("Attempted to update ["+this.dtoClass.getSimpleName()+"] with primary key ["+(dto != null ? dto.getKey() : "NULL")+"] on closed repo ["+this.connectionString+"]."); + LOGGER.warn("Attempted to update ["+this.dtoClass.getSimpleName()+"] with primary key ["+(dto != null ? dto.getKeyDisplayString() : "NULL")+"] on closed repo ["+this.connectionString+"]."); } catch (SQLException e) {