Center update propagation around player position

This is done to make world gen appear faster since the LODs will be made visible sooner
This commit is contained in:
James Seibel
2024-10-21 08:52:52 -04:00
parent 4a7881fbb5
commit fd794cd55d
2 changed files with 19 additions and 7 deletions
@@ -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<Long, HashSet<Long>> updatePosByParentPos = new HashMap<>();
@@ -217,15 +217,18 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<Long, FullDataSourceV2D
this.queryDictionaryFirst(sql);
}
public LongArrayList getPositionsToUpdate(int returnCount)
public LongArrayList getPositionsToUpdate(int targetBlockPosX, int targetBlockPosZ, int returnCount)
{
LongArrayList list = new LongArrayList();
List<Map<String, Object>> 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<String, Object> resultMap : resultMapList)
{