Add priority distance limiting by ratio

This commit is contained in:
s809
2024-02-04 02:34:53 +05:00
parent e5e4551038
commit 1baa666d23
4 changed files with 48 additions and 15 deletions
@@ -894,14 +894,6 @@ public class Config
+ "")
.build();
public static ConfigEntry<Integer> genTaskPriorityRequestRateLimit = new ConfigEntry.Builder<Integer>()
.setServersideShortName("genTaskPriorityRequestRateLimit")
.setMinDefaultMax(1, 50, 200)
.comment(""
+ "Limits the amount of LOD sections that the client can request states for, per second. \n"
+ "")
.build();
public static ConfigEntry<Integer> generationRequestBeginDelay = new ConfigEntry.Builder<Integer>()
.setMinDefaultMax(0, 3, 10)
.comment(""
@@ -910,6 +902,23 @@ public class Config
+ "")
.build();
public static ConfigEntry<Double> genTaskPriorityDistanceRatio = new ConfigEntry.Builder<Double>()
.setServersideShortName("genTaskPriorityDistanceRatio")
.setMinDefaultMax(1d, 3d, 10d)
.comment(""
+ "Controls the max ratio between distances of nearest unloaded sections of each priority. \n"
+ "For example, value of 2 means that the nearest lower priority section will be allowed to stay \n"
+ "unloaded only if it's at most 2x closer than one of a higher priority. \n"
+ "")
.build();
public static ConfigEntry<Integer> genTaskPriorityRequestRateLimit = new ConfigEntry.Builder<Integer>()
.setServersideShortName("genTaskPriorityRequestRateLimit")
.setMinDefaultMax(1, 50, 200)
.comment(""
+ "Limits the amount of LOD sections that the client can request states for, per second. \n"
+ "")
.build();
public static ConfigUIComment realTimeUpdatesSectionNote = new ConfigUIComment();
public static ConfigEntry<Boolean> enableRealTimeUpdates = new ConfigEntry.Builder<Boolean>()
@@ -61,6 +61,12 @@ public class WorldRemoteGenerationQueue extends AbstractFullDataRequestQueue imp
return LodUtil.BLOCK_DETAIL_LEVEL;
}
@Override
protected double getPriorityDistanceRatio()
{
return Config.Client.Advanced.Multiplayer.ServerNetworking.genTaskPriorityDistanceRatio.get();
}
@Override
public CompletableFuture<WorldGenResult> submitGenTask(DhSectionPos sectionPos, byte requiredDataDetail, IWorldGenTaskTracker tracker)
{
@@ -62,6 +62,8 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
protected abstract String getQueueName();
protected double getPriorityDistanceRatio() { return 1; }
public AbstractFullDataRequestQueue(ClientNetworkState networkState, IDhClientLevel level, boolean changedOnly, ConfigEntry<Boolean> showDebugWireframeConfig)
{
@@ -143,11 +145,25 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
{
Map.Entry<DhSectionPos, RequestQueueEntry> mapEntry = this.waitingTasks.entrySet().stream()
.filter(task -> task.getValue().request == null)
.reduce(null, (a, b)
-> a == null
|| b.getValue().priority > a.getValue().priority
|| (b.getValue().priority == a.getValue().priority && this.posDistanceSquared(targetPos, b.getKey()) < this.posDistanceSquared(targetPos, a.getKey()))
? b : a);
.reduce(null, (a, b) -> {
if (a == null)
{
return b;
}
if (b.getValue().priority < a.getValue().priority)
{
Map.Entry<DhSectionPos, RequestQueueEntry> temp = b;
b = a;
a = temp;
}
double distanceRatio = Math.sqrt(this.posDistanceSquared(targetPos, b.getKey())) / Math.sqrt(this.posDistanceSquared(targetPos, a.getKey()));
double maxDistanceRatioScaled = Math.pow(this.getPriorityDistanceRatio(), b.getValue().priority - a.getValue().priority);
return distanceRatio < maxDistanceRatioScaled ? b : a;
});
if (mapEntry == null)
{
this.pendingTasksSemaphore.release();
@@ -353,10 +353,12 @@
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.generationSectionNote": " \u25cf Generation",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.generationRequestRCLimit": "Gen task rate/concurrency limit",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.generationRequestRCLimit.@tooltip": "Limits the amount of generation requests sent by client and processed by server.",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.genTaskPriorityRequestRateLimit": "Gen task priority check rate limit",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.genTaskPriorityRequestRateLimit.@tooltip": "Limits the amount of LOD sections that the client can request states for, per second.",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.generationRequestBeginDelay": "Generation request begin delay",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.generationRequestBeginDelay.@tooltip": "Adds a delay in seconds before sending LOD requests, when generation is enabled. \nIncrease this value if initial generation starts too far away.",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.genTaskPriorityDistanceRatio": "Gen task priority distance max ratio",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.genTaskPriorityDistanceRatio.@tooltip": "Controls the max ratio between distances of nearest unloaded sections of each priority. \nFor example, a value of 2 means that the nearest lower priority section will be allowed to stay \nunloaded only if it's at most 2x closer than one of a higher priority.",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.genTaskPriorityRequestRateLimit": "Gen task priority check rate limit",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.genTaskPriorityRequestRateLimit.@tooltip": "Limits the amount of LOD sections that the client can request states for, per second.",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.realTimeUpdatesSectionNote": " \u25cf Real Time Updates",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.enableRealTimeUpdates": "Enable Real Time Updates",
"distanthorizons.config.client.advanced.multiplayer.serverNetworking.enableRealTimeUpdates.@tooltip": "Enables real time updates from server.",