From b8a862ddd822be2367fdf1bba6b8e1ee7241dbc2 Mon Sep 17 00:00:00 2001 From: s809 <43530948+s809@users.noreply.github.com> Date: Sun, 20 Oct 2024 20:00:02 +0500 Subject: [PATCH] Multiply update queue size by player count --- .../core/api/internal/SharedApi.java | 14 +++++++++++++- .../minecraft/IMinecraftSharedWrapper.java | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java index ec2f5b391..e2d5af8ab 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java @@ -39,6 +39,7 @@ import com.seibel.distanthorizons.core.world.*; import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper; +import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector; @@ -61,6 +62,7 @@ public class SharedApi /** will be null on the server-side */ @Nullable private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); + private static final IMinecraftSharedWrapper MC_SHARED = SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class); private static final UpdateChunkPosManager UPDATE_POS_MANAGER = new UpdateChunkPosManager(); /** how many chunks can be queued for updating per thread, used to prevent updates from infinitely pilling up if the user flies around extremely fast */ @@ -261,11 +263,21 @@ public class SharedApi { queueChunkUpdate(chunkWrapper, neighbourChunkList, dhLevel,false); } private static void queueChunkUpdate(IChunkWrapper chunkWrapper, @Nullable ArrayList neighbourChunkList, IDhLevel dhLevel, boolean lightUpdateOnly) { + int playerCount; if (MC_CLIENT != null && MC_CLIENT.playerExists()) { UPDATE_POS_MANAGER.setCenter(MC_CLIENT.getPlayerChunkPos()); - UPDATE_POS_MANAGER.maxSize = MAX_UPDATING_CHUNK_COUNT_PER_THREAD * Config.Common.MultiThreading.numberOfLodBuilderThreads.get(); + playerCount = MC_CLIENT.clientConnectedToDedicatedServer() ? 0 : MC_SHARED.getPlayerCount(); } + else + { + playerCount = MC_SHARED.getPlayerCount(); + } + + // Dedicated server get +1 to multiplier since it runs persistently and has spawn chunks + UPDATE_POS_MANAGER.maxSize = MAX_UPDATING_CHUNK_COUNT_PER_THREAD + * Config.Common.MultiThreading.numberOfLodBuilderThreads.get() + * (playerCount + (MC_SHARED.isDedicatedServer() ? 1 : 0)); UpdateChunkData updateData = new UpdateChunkData(chunkWrapper, neighbourChunkList, dhLevel, lightUpdateOnly); if(lightUpdateOnly) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftSharedWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftSharedWrapper.java index a4538ea92..fc2a761bc 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftSharedWrapper.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftSharedWrapper.java @@ -33,4 +33,6 @@ public interface IMinecraftSharedWrapper extends IBindable /** @return true if this is the first time loading this world */ boolean isWorldNew(); + int getPlayerCount(); + }