From fd794cd55d874e89a988989f5cad61a1e2599140 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 21 Oct 2024 08:52:52 -0400 Subject: [PATCH] Center update propagation around player position This is done to make world gen appear faster since the LODs will be made visible sooner --- .../file/fullDatafile/FullDataSourceProviderV2.java | 13 +++++++++++-- .../core/sql/repo/FullDataSourceV2Repo.java | 13 ++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java index b81c40cf1..b9360801c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataSourceProviderV2.java @@ -31,6 +31,7 @@ import com.seibel.distanthorizons.core.file.AbstractDataSourceHandler; import com.seibel.distanthorizons.core.level.IDhLevel; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.pos.DhSectionPos; +import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos; import com.seibel.distanthorizons.core.render.renderer.DebugRenderer; import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable; import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV2DTO; @@ -63,7 +64,7 @@ public class FullDataSourceProviderV2 implements IDebugRenderable { private static final Logger LOGGER = DhLoggerBuilder.getLogger(); - private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); + private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); protected static final int NUMBER_OF_PARENT_UPDATE_TASKS_PER_THREAD = 50; /** how many parent update tasks can be in the queue at once */ @@ -213,12 +214,20 @@ public class FullDataSourceProviderV2 // TODO it might be worth skipping this logic if no parent updates happened + // update positions closest to the player (if not on a server) + // to make world gen appear faster + DhBlockPos targetBlockPos = DhBlockPos.ZERO; + if (MC_CLIENT != null && MC_CLIENT.playerExists()) + { + targetBlockPos = MC_CLIENT.getPlayerBlockPos(); + } + // queue parent updates if (executor.getQueue().size() < MAX_UPDATE_TASK_COUNT && this.parentUpdatingPosSet.size() < MAX_UPDATE_TASK_COUNT) { // get the positions that need to be applied to their parents - LongArrayList parentUpdatePosList = this.repo.getPositionsToUpdate(MAX_UPDATE_TASK_COUNT); + LongArrayList parentUpdatePosList = this.repo.getPositionsToUpdate(targetBlockPos.getX(), targetBlockPos.getZ(), MAX_UPDATE_TASK_COUNT); // combine updates together based on their parent HashMap> updatePosByParentPos = new HashMap<>(); 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 4f2bec4bb..6558775ee 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 @@ -217,15 +217,18 @@ public class FullDataSourceV2Repo extends AbstractDhRepo> resultMapList = this.queryDictionary( - "select DetailLevel, PosX, PosZ " + - "from "+this.getTableName()+" " + - "where ApplyToParent = 1 " + - "order by DetailLevel asc LIMIT "+returnCount+";"); + "SELECT DetailLevel, PosX, PosZ, " + + "(sqrt(pow(PosX - "+targetBlockPosX+", 2) + pow(PosZ - "+targetBlockPosZ+", 2))) AS Distance " + + "FROM "+this.getTableName()+" " + + "WHERE ApplyToParent = 1 " + + "ORDER BY Distance ASC " + + "LIMIT "+returnCount+"; " + ); for (Map resultMap : resultMapList) {