From 29cf0ead7d7c127ecf6b56e5f2fe0dccb25526d9 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Wed, 18 Jan 2023 07:22:58 -0600 Subject: [PATCH] refactor and rename selfSearch() -> getDataFilesForPosition() --- .../core/file/datafile/DataFileHandler.java | 148 +++++++----------- 1 file changed, 56 insertions(+), 92 deletions(-) diff --git a/core/src/main/java/com/seibel/lod/core/file/datafile/DataFileHandler.java b/core/src/main/java/com/seibel/lod/core/file/datafile/DataFileHandler.java index 9bdb5fa5d..02486c217 100644 --- a/core/src/main/java/com/seibel/lod/core/file/datafile/DataFileHandler.java +++ b/core/src/main/java/com/seibel/lod/core/file/datafile/DataFileHandler.java @@ -93,7 +93,7 @@ public class DataFileHandler implements IDataSourceProvider } } - // Warn for multiple files with the same pos, and then select the one with latest timestamp. + // Warn for multiple files with the same pos, and then select the one with the latest timestamp. for (DhSectionPos pos : filesByPos.keySet()) { Collection metaFiles = filesByPos.get(pos); @@ -174,26 +174,38 @@ public class DataFileHandler implements IDataSourceProvider return metaFile; } - protected void selfSearch(DhSectionPos basePos, DhSectionPos pos, ArrayList existFiles, ArrayList missing) + /** + * Populates the preexistingFiles and missingFilePositions ArrayLists. + * + * @param preexistingFiles the list of {@link DataMetaFile}'s that have been created for the given position. + * @param missingFilePositions the list of {@link DhSectionPos}'s that don't have {@link DataMetaFile} created for them yet. + */ + protected void getDataFilesForPosition(DhSectionPos basePos, DhSectionPos pos, + ArrayList preexistingFiles, ArrayList missingFilePositions) { - byte detail = pos.sectionDetailLevel; + byte sectionDetail = pos.sectionDetailLevel; boolean allEmpty = true; + outerLoop: - while (--detail >= this.minDetailLevel) + while (--sectionDetail >= this.minDetailLevel) { - DhLodPos min = pos.getCorner().getCorner(detail); - int count = pos.getSectionBBoxPos().getBlockWidth(detail); - for (int ox = 0; ox preexistingFiles, ArrayList missingFilePositions) + { + DhSectionPos childPos = pos.getChildByIndex(childIndex); + if (FullDataSource.neededForPosition(basePos, childPos)) + { + DataMetaFile metaFile = this.files.get(childPos); + if (metaFile != null) + { + // we have reached a populated leaf node in the quad tree + preexistingFiles.add(metaFile); + } + else if (childPos.sectionDetailLevel == this.minDetailLevel) + { + // we have reached an empty leaf node in the quad tree + missingFilePositions.add(childPos); + } + else + { + // recursively traverse down the tree + this.getDataFilesForPosition(basePos, childPos, preexistingFiles, missingFilePositions); + } + } + } /** @@ -374,7 +338,7 @@ public class DataFileHandler implements IDataSourceProvider DhSectionPos pos = file.pos; ArrayList existFiles = new ArrayList<>(); ArrayList missing = new ArrayList<>(); - this.selfSearch(pos, pos, existFiles, missing); + this.getDataFilesForPosition(pos, pos, existFiles, missing); LodUtil.assertTrue(!missing.isEmpty() || !existFiles.isEmpty()); if (missing.size() == 1 && existFiles.isEmpty() && missing.get(0).equals(pos)) {