From 1178ef0706c402c4cdec3d43cf85d4dbfac1acb3 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 8 Feb 2026 19:56:24 -0600 Subject: [PATCH] Remove unused ID mappings after data update Requires re-downsampling all LODs --- .../fullData/sources/FullDataSourceV2.java | 68 ++++++++++++++++++- .../core/sql/repo/FullDataSourceV2Repo.java | 7 +- ...0090-sqlite-addAdjacentFullDataColumns.sql | 3 +- ...100-sqlite-deleteLowDetailDataForRegen.sql | 13 ++++ .../main/resources/sqlScripts/scriptList.txt | 1 + 5 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 core/src/main/resources/sqlScripts/0100-sqlite-deleteLowDetailDataForRegen.sql 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 d5ed5643a..e9bb98707 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 @@ -78,7 +78,9 @@ public class FullDataSourceV2 /** how many chunks wide this datasource is at detail level 0. */ public static final int NUMB_OF_CHUNKS_WIDE = WIDTH / LodUtil.CHUNK_WIDTH; - public static final PhantomArrayListPool ARRAY_LIST_POOL = new PhantomArrayListPool("FullDataV2"); + private static final PhantomArrayListPool ARRAY_LIST_POOL = new PhantomArrayListPool("FullDataV2"); + + private static final ThreadLocal DATA_MAP_FOR_REMAPPING_REF = ThreadLocal.withInitial(() -> new FullDataPointIdMap(DhSectionPos.encode((byte)0, 0, 0))); @@ -441,6 +443,8 @@ public class FullDataSourceV2 } + // needed to prevent infinite mapped ID growth + this.removeUnusedIdsAndRemap(); @@ -1130,6 +1134,68 @@ public class FullDataSourceV2 return dataChanged; } + /** + * Should be run at the end of {@link FullDataSourceV2#updateFromDataSource} + * so the {@link FullDataPointIdMap} will only contain ID's that are actively in use.

+ * + * This prevents the {@link FullDataPointIdMap} from growing infinitely when merged. + * + * @see FullDataPointIdMap#mergeAndReturnRemappedEntityIds(FullDataPointIdMap) + */ + private void removeUnusedIdsAndRemap() + { + Int2IntOpenHashMap newIdByOldId = new Int2IntOpenHashMap(); + FullDataPointIdMap newMap = DATA_MAP_FOR_REMAPPING_REF.get(); + newMap.clear(this.pos); + + + // find all the IDs that are currently in use + for (int x = 0; x < WIDTH; x++) + { + for (int z = 0; z < WIDTH; z++) + { + int index = relativePosToIndex(x, z); + LongArrayList dataColumn = this.dataPoints[index]; + for (int i = 0; i < dataColumn.size(); i++) + { + long dataPoint = dataColumn.getLong(i); + int oldId = FullDataPointUtil.getId(dataPoint); + + int newId = newMap.addIfNotPresentAndGetId( + this.mapping.getBiomeWrapper(oldId), + this.mapping.getBlockStateWrapper(oldId)); + + newIdByOldId.put(oldId, newId); + } + } + } + + + // replace the old entries to remove any unneeded ones + this.mapping.clear(this.pos); + this.mapping.addAll(newMap); + + + // remap the data + for (int x = 0; x < WIDTH; x++) + { + for (int z = 0; z < WIDTH; z++) + { + int index = relativePosToIndex(x, z); + LongArrayList dataColumn = this.dataPoints[index]; + for (int i = 0; i < dataColumn.size(); i++) + { + long oldDataPoint = dataColumn.getLong(i); + int oldId = FullDataPointUtil.getId(oldDataPoint); + + int newId = newIdByOldId.get(oldId); + long newDataPoint = FullDataPointUtil.setId(oldDataPoint, newId); + dataColumn.set(i, newDataPoint); + } + } + } + } + //endregion diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java index 5af658040..c9253d40e 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java @@ -477,7 +477,10 @@ public class FullDataSourceV2Repo extends AbstractDhRepo 0; +--batch-- + +-- re-downsample all LOD data +update FullData set ApplyToParent = 1; diff --git a/core/src/main/resources/sqlScripts/scriptList.txt b/core/src/main/resources/sqlScripts/scriptList.txt index 7274defa2..b64a0d320 100644 --- a/core/src/main/resources/sqlScripts/scriptList.txt +++ b/core/src/main/resources/sqlScripts/scriptList.txt @@ -9,3 +9,4 @@ 0070-sqlite-createBeaconBeamTable.sql 0080-sqlite-addApplyToChildrenColumn.sql 0090-sqlite-addAdjacentFullDataColumns.sql +0100-sqlite-deleteLowDetailDataForRegen.sql