From 9343854b4aead1088f8bba9a8868711028bb83b0 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 6 Nov 2025 07:42:58 -0600 Subject: [PATCH] Clean up data source getters --- .../methods/data/DhApiTerrainDataRepo.java | 2 +- .../GeneratedFullDataSourceProvider.java | 2 +- .../RemoteFullDataSourceProvider.java | 8 +-- .../V2/FullDataSourceProviderV2.java | 54 +++++-------------- .../V2/FullDataUpdatePropagatorV2.java | 8 +-- .../fullDatafile/V2/FullDataUpdaterV2.java | 2 +- .../core/generation/PregenManager.java | 2 +- .../server/FullDataSourceRequestHandler.java | 4 +- .../core/render/LodRenderSection.java | 2 +- .../core/sql/repo/FullDataSourceV2Repo.java | 6 --- 10 files changed, 29 insertions(+), 61 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 0dd8f2d15..c27b8a58e 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 @@ -238,7 +238,7 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo if (dataSource == null) { // attempt to get/generate the data source for this section - dataSource = level.getFullDataProvider().getAsync(sectionPos, false).get(); + dataSource = level.getFullDataProvider().getAsync(sectionPos).get(); if (dataSource == null) { return DhApiResult.createFail("Unable to find/generate any data at the " + DhSectionPos.class.getSimpleName() + " [" + DhSectionPos.toString(sectionPos) + "]."); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java index 47040c4a7..7d21a5898 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java @@ -489,7 +489,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im @Override public CompletableFuture shouldGenerateSplitChild(long pos) { - return GeneratedFullDataSourceProvider.this.getAsync(pos, false).thenApply(fullDataSource -> + return GeneratedFullDataSourceProvider.this.getAsync(pos).thenApply(fullDataSource -> { //noinspection TryFinallyCanBeTryWithResources try diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/RemoteFullDataSourceProvider.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/RemoteFullDataSourceProvider.java index 618523718..b3dbae741 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/RemoteFullDataSourceProvider.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/RemoteFullDataSourceProvider.java @@ -75,18 +75,18 @@ public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvide @Override @Nullable - public FullDataSourceV2 get(long pos, boolean includeAdjacentData) + public FullDataSourceV2 get(long pos) { if (this.syncOnLoadRequestQueue == null) { // we have local data, but networking is unavailable. - return super.get(pos, includeAdjacentData); + return super.get(pos); } if (!this.visitedPositions.add(pos)) { // This position has already been accessed before - return super.get(pos, includeAdjacentData); + return super.get(pos); } @@ -105,7 +105,7 @@ public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvide }); } - return super.get(pos, includeAdjacentData); + return super.get(pos); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataSourceProviderV2.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataSourceProviderV2.java index d3d83bf23..4487803b4 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataSourceProviderV2.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataSourceProviderV2.java @@ -171,7 +171,7 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable * * This call is concurrent. I.e. it supports being called by multiple threads at the same time. */ - public CompletableFuture getAsync(long pos, boolean includeAdjacentData) + public CompletableFuture getAsync(long pos) { AbstractExecutorService executor = ThreadPoolUtil.getFileHandlerExecutor(); if (executor == null || executor.isTerminated()) @@ -182,7 +182,7 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable try { - return CompletableFuture.supplyAsync(() -> this.get(pos, includeAdjacentData), executor); + return CompletableFuture.supplyAsync(() -> this.get(pos), executor); } catch (RejectedExecutionException ignore) { @@ -193,14 +193,12 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable /** * Should only be used in internal file handler methods where we are already running on a file handler thread. * Can return null if the repo is in the process of being shut down - * @see FullDataSourceProviderV2#getAsync(long, boolean) + * @see FullDataSourceProviderV2#getAsync(long) */ @Nullable - public FullDataSourceV2 get(long pos, boolean includeAdjacentData) + public FullDataSourceV2 get(long pos) { - try(FullDataSourceV2DTO dto = includeAdjacentData - ? this.repo.getByKey(pos) - : this.repo.getByPosNoAdj(pos)) + try(FullDataSourceV2DTO dto = this.repo.getByPosNoAdj(pos)) { if (dto == null) { @@ -245,10 +243,16 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable - // - // TODO name? - // + //=================// + // partial getters // + //=================// + /** + * Only returns the data row/column for the given compass-cardinal + * direction.
+ * This is generally used for generating LOD render data + * where we only need the adjacent data, not the full thing. + */ public FullDataSourceV2 getAdjForDirection(long pos, EDhDirection direction) { try(FullDataSourceV2DTO dto = this.repo.getAdjByPosAndDirection(pos, direction)) @@ -279,36 +283,6 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable return null; } - public FullDataSourceV2 getCenter(long pos) - { - try(FullDataSourceV2DTO dto = this.repo.getByPosNoAdj(pos)) - { - if (dto == null) - { - return FullDataSourceV2.createEmpty(pos); - } - - try - { - // load from database - return this.createDataSourceFromDto(dto); - } - catch (DataCorruptedException e) - { - this.tryLogCorruptedDataError(DhSectionPos.toString(pos), e); - this.repo.deleteWithKey(pos); - } - } - catch (InterruptedException ignore) { } - catch (IOException e) - { - LOGGER.warn("File read Error for pos ["+DhSectionPos.toString(pos)+"], error: "+e.getMessage(), e); - } - - // an error occurred - return null; - } - //=======================// diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataUpdatePropagatorV2.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataUpdatePropagatorV2.java index f1de0c42e..8f47ac19f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataUpdatePropagatorV2.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataUpdatePropagatorV2.java @@ -183,7 +183,7 @@ public class FullDataUpdatePropagatorV2 implements IDebugRenderable, AutoCloseab parentLocked = true; this.dataUpdater.lockedPosSet.add(parentUpdatePos); - try (FullDataSourceV2 parentDataSource = this.provider.get(parentUpdatePos, false)) + try (FullDataSourceV2 parentDataSource = this.provider.get(parentUpdatePos)) { // will return null if the file handler is shutting down if (parentDataSource != null) @@ -197,7 +197,7 @@ public class FullDataUpdatePropagatorV2 implements IDebugRenderable, AutoCloseab childReadLock.lock(); this.dataUpdater.lockedPosSet.add(childPos); - try (FullDataSourceV2 childDataSource = this.provider.get(childPos, false)) + try (FullDataSourceV2 childDataSource = this.provider.get(childPos)) { // can return null when the file handler is being shut down if (childDataSource != null) @@ -299,7 +299,7 @@ public class FullDataUpdatePropagatorV2 implements IDebugRenderable, AutoCloseab parentLocked = true; this.dataUpdater.lockedPosSet.add(parentUpdatePos); - try (FullDataSourceV2 parentDataSource = this.provider.get(parentUpdatePos, false)) + try (FullDataSourceV2 parentDataSource = this.provider.get(parentUpdatePos)) { // will return null if the file handler is shutting down if (parentDataSource != null) @@ -315,7 +315,7 @@ public class FullDataUpdatePropagatorV2 implements IDebugRenderable, AutoCloseab childWriteLock.lock(); this.dataUpdater.lockedPosSet.add(childPos); - try (FullDataSourceV2 childDataSource = this.provider.get(childPos, false)) + try (FullDataSourceV2 childDataSource = this.provider.get(childPos)) { // will return null if the file handler is shutting down if (childDataSource != null) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataUpdaterV2.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataUpdaterV2.java index c18a651b2..eefb76c3b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataUpdaterV2.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/V2/FullDataUpdaterV2.java @@ -122,7 +122,7 @@ public class FullDataUpdaterV2 implements IDebugRenderable, AutoCloseable // get or create the data source - try (FullDataSourceV2 recipientDataSource = this.provider.get(updatePos, false)) + try (FullDataSourceV2 recipientDataSource = this.provider.get(updatePos)) { if (recipientDataSource != null) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/PregenManager.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/PregenManager.java index 53cabc7ef..044060296 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/PregenManager.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/PregenManager.java @@ -140,7 +140,7 @@ public class PregenManager } this.pendingGenerations.put(nextSectionPos, System.currentTimeMillis()); - this.fullDataSourceProvider.getAsync(nextSectionPos, false) + this.fullDataSourceProvider.getAsync(nextSectionPos) .thenAccept(fullDataSource -> { if (this.fullDataSourceProvider.isFullyGenerated(fullDataSource.columnGenerationSteps)) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/server/FullDataSourceRequestHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/server/FullDataSourceRequestHandler.java index 0b0be6c17..2e523ea25 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/server/FullDataSourceRequestHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/server/FullDataSourceRequestHandler.java @@ -99,7 +99,7 @@ public class FullDataSourceRequestHandler } // get the server's datasource - return this.fullDataSourceProvider().get(message.sectionPos, false); + return this.fullDataSourceProvider().get(message.sectionPos); } catch (Exception e) { @@ -262,7 +262,7 @@ public class FullDataSourceRequestHandler private void tryFulfillDataSourceRequestGroup(DataSourceRequestGroup requestGroup, long pos) { - this.fullDataSourceProvider().getAsync(pos, false).thenAccept(fullDataSource -> + this.fullDataSourceProvider().getAsync(pos).thenAccept(fullDataSource -> { if (this.fullDataSourceProvider().isFullyGenerated(fullDataSource.columnGenerationSteps)) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/LodRenderSection.java b/core/src/main/java/com/seibel/distanthorizons/core/render/LodRenderSection.java index 9732596df..4984bdb7b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/LodRenderSection.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/LodRenderSection.java @@ -356,7 +356,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable try (FullDataSourceV2 fullDataSource = // no direction means get the center LOD (direction == null) - ? this.fullDataSourceProvider.getCenter(finalPos) + ? this.fullDataSourceProvider.get(finalPos) : this.fullDataSourceProvider.getAdjForDirection(finalPos, direction.opposite())) { getFull.end(); 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 7ba0eeaa7..5ca9c302c 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 @@ -356,12 +356,6 @@ public class FullDataSourceV2Repo extends AbstractDhRepo