feat: add properties to configure chunk queue

(cherry picked from commit a910ce359d)
This commit is contained in:
mworzala 2024-01-06 03:33:36 -05:00 committed by Matt Worzala
parent d7abff5c43
commit 8fafe723ae
2 changed files with 16 additions and 4 deletions

View File

@ -80,6 +80,7 @@ import net.minestom.server.statistic.PlayerStatistic;
import net.minestom.server.timer.Scheduler;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.PacketUtils;
import net.minestom.server.utils.PropertyUtils;
import net.minestom.server.utils.async.AsyncUtils;
import net.minestom.server.utils.chunk.ChunkUpdateLimitChecker;
import net.minestom.server.utils.chunk.ChunkUtils;
@ -120,8 +121,9 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
private static final Component REMOVE_MESSAGE = Component.text("You have been removed from the server without reason.", NamedTextColor.RED);
private static final float MIN_CHUNKS_PER_TICK = 0.01f;
private static final float MAX_CHUNKS_PER_TICK = 64.0f;
private static final float MIN_CHUNKS_PER_TICK = PropertyUtils.getFloat("minestom.chunk-queue.min-per-tick", 0.01f);
private static final float MAX_CHUNKS_PER_TICK = PropertyUtils.getFloat("minestom.chunk-queue.max-per-tick", 64.0f);
private static final float CHUNKS_PER_TICK_MULTIPLIER = PropertyUtils.getFloat("minestom.chunk-queue.multiplier", 1f);
public static final boolean EXPERIMENT_PERFORM_POSE_UPDATES = Boolean.getBoolean("minestom.experiment.pose-updates");
@ -772,8 +774,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
public void onChunkBatchReceived(float newTargetChunksPerTick) {
// logger.debug("chunk batch received player={} chunks/tick={} lead={}", username, newTargetChunksPerTick, chunkBatchLead);
chunkBatchLead -= 1;
targetChunksPerTick = Float.isNaN(newTargetChunksPerTick) ? MIN_CHUNKS_PER_TICK
: MathUtils.clamp(newTargetChunksPerTick, MIN_CHUNKS_PER_TICK, MAX_CHUNKS_PER_TICK);
targetChunksPerTick = Float.isNaN(newTargetChunksPerTick) ? MIN_CHUNKS_PER_TICK : MathUtils.clamp(
newTargetChunksPerTick * CHUNKS_PER_TICK_MULTIPLIER, MIN_CHUNKS_PER_TICK, MAX_CHUNKS_PER_TICK);
// Beyond the first batch we can preemptively send up to 10 (matching mojang server)
if (maxChunkBatchLead == 1) maxChunkBatchLead = 10;

View File

@ -23,4 +23,14 @@ public final class PropertyUtils {
public static String getString(@NotNull String name, @Nullable String defaultValue) {
return System.getProperty(name, defaultValue);
}
public static Float getFloat(String name, Float defaultValue) {
Float result = defaultValue;
try {
final String value = System.getProperty(name);
if (value != null) result = Float.parseFloat(value);
} catch (IllegalArgumentException | NullPointerException ignored) {
}
return result;
}
}